openasce.discovery.regression_discovery package

Submodules

openasce.discovery.regression_discovery.lbfgsb_optimizer module

class openasce.discovery.regression_discovery.lbfgsb_optimizer.LBFGSBOptimizer(params)[source]

Bases: Optimizer

Wrap L-BFGS-B algorithm, using scipy routines.

__init__(params)[source]
step(closure)[source]

Performs a single optimization step.

Parameters

closure (callable) – A closure that reevaluates the model and returns the loss.

openasce.discovery.regression_discovery.locally_connected module

class openasce.discovery.regression_discovery.locally_connected.LocallyConnected(num_linear, input_features, output_features, bias=True)[source]

Bases: Module

Local linear layer

Argument:

num_linear: num of local linear layers, i.e. in_features: m1 out_features: m2 bias: whether to include bias or not

Shape:
  • Input: [n, d, m1]

  • Output: [n, d, m2]

weight

[d, m1, m2]

bias

[d, m2]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

__init__(num_linear, input_features, output_features, bias=True)[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(input: Tensor)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

reset_parameters()[source]

openasce.discovery.regression_discovery.notears_mlp module

class openasce.discovery.regression_discovery.notears_mlp.NotearsMLP(dims, bias=True)[source]

Bases: Module

Initializes internal Module state, shared by both nn.Module and ScriptModule.

__init__(dims, bias=True)[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

fc1_l1_reg()[source]

Take l1 norm of fc1 weight

fc1_to_adj() ndarray[source]

Get W from fc1 weights, take 2-norm over m1 dim

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

h_func()[source]

Constrain 2-norm-squared of fc1 weights along m1 dim to be a DAG

l2_reg()[source]

Take 2-norm-squared of all parameters

openasce.discovery.regression_discovery.regression_discovery module

class openasce.discovery.regression_discovery.regression_discovery.CausalRegressionDiscovery[source]

Bases: Discovery

Execute the causal discovery by notears method

Attributes:

Constructor

Arguments:

Returns:

__init__() None[source]

Constructor

Arguments:

Returns:

fit(*, X: Union[ndarray, Callable], **kwargs)[source]

Feed the sample data

Parameters

X (num of samples, features or callable returning np.ndarray) – samples

Returns:

get_result() Tuple[CausalGraph, float][source]

Get the causal graph sample data

Parameters

X (num of samples, features or callable returning np.ndarray) – samples

Returns:

openasce.discovery.regression_discovery.regression_strategy module

class openasce.discovery.regression_discovery.regression_strategy.Strategy(node_names: List[str], **kwargs)[source]

Bases: object

General class to implement different structure learning methods

Attributes

Contructor

Parameters

node_names – the name of nodes

__init__(node_names: List[str], **kwargs)[source]

Contructor

Parameters

node_names – the name of nodes

dual_ascent(model, X, lambda1, lambda2, rho_max, rho, alpha, h)[source]

Perform one step of dual ascent in augmented Lagrangian.

run(*, model: Module, data: ndarray, max_iteration: int = 3, lambda1: float = 0.1, lambda2: float = 0.1, h_tol: float = 1e-08, rho_max: float = 1e+16, w_threshold: float = 0.3, **kwargs) Tuple[source]

Run the actual strategy

Parameters
  • model – the model used to discover the better graph

  • data – the features of samples

  • **kwargs (dict) – dictionnary with method specific args

Returns:

openasce.discovery.regression_discovery.regression_strategy.squared_loss(output, target)[source]

openasce.discovery.regression_discovery.trace_expm module

class openasce.discovery.regression_discovery.trace_expm.TraceExpm(*args, **kwargs)[source]

Bases: Function

static backward(ctx, grad_output)[source]

Backward

Parameters
  • ctx – the context object used to retrieve the information.

  • grad_output – tensor containing the gradient

Returns

tensor

static forward(ctx, input)[source]

Forward

Parameters
  • ctx – the context object used to stash information.

  • input – the input tensor

Returns

tensor for output