Skip to contents

Fit TOPO from Deng et al 2023

Usage

fit_topo(
  X,
  topo = 1:ncol(X),
  size_small = NULL,
  size_large = NULL,
  use_large_space = d <= 10,
  model_type = c("linear", "nonlinear"),
  loss_type = c("l2"),
  h_func = h_logdet,
  h_func_grad = h_logdet_grad,
  s = 1.1,
  verbose = F
)

Arguments

X

A matrix of data in which each of the columns is a variable of interest in a directed acyclic graph

topo

A vector of integers indicating the initial topological order of the variables

size_small

The minimum size of the search space.

size_large

The maximum size of the search space.

use_large_space

A boolean indicating if the search space should be expanded if the minimum size is not sufficient.

model_type

The type of model to fit. Currently only linear models are supported.

loss_type

Currently only supports l2 loss

h_func

The continuous acyclic function to use. See h_logdet.

h_func_grad

The gradient of the acyclic funtion to use. See h_logdet_grad.

s

penalty parameter for the logdet function. Should be larger than the spectral radius of X.

verbose

A boolean indicating if the function should print out progress

Value

A list containing the estimated W matrix, the topological order, the Z matrix, and the loss

Examples


B <- matrix(
c(0, 3, 3, 1,
  0, 0, 1, 5,
  0, 0, 0, 1,
  0, 0, 0, 0),
nrow = 4, ncol = 4, byrow = TRUE)

d <- ncol(B)
X <- sim_linear_sem(B, n = 1000, Sigma = diag(0.01, nrow = d))
(est_B <- fit_topo(X, d:1))
#> $W
#>      [,1]     [,2]     [,3]      [,4]
#> [1,]    0 2.948647 3.002588 0.7169274
#> [2,]    0 0.000000 1.013707 4.9582267
#> [3,]    0 0.000000 0.000000 1.0616670
#> [4,]    0 0.000000 0.000000 0.0000000
#> 
#> $topo
#> [1] 1 2 3 4
#> 
#> $Z
#>      [,1]  [,2]  [,3]  [,4]
#> [1,] TRUE FALSE FALSE FALSE
#> [2,] TRUE  TRUE FALSE FALSE
#> [3,] TRUE  TRUE  TRUE FALSE
#> [4,] TRUE  TRUE  TRUE  TRUE
#> 
#> $loss
#> [1] 0.01966563
#>