openasce.discovery.regression_discovery package¶
Submodules¶
openasce.discovery.regression_discovery.lbfgsb_optimizer module¶
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:
ModuleLocal 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.
- __annotations__ = {}¶
- __doc__ = 'Local linear layer\n\n Argument:\n num_linear: num of local linear layers, i.e.\n in_features: m1\n out_features: m2\n bias: whether to include bias or not\n\n Shape:\n - Input: [n, d, m1]\n - Output: [n, d, m2]\n\n Attributes:\n weight: [d, m1, m2]\n bias: [d, m2]\n '¶
- __init__(num_linear, input_features, output_features, bias=True)[source]¶
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- __module__ = 'openasce.discovery.regression_discovery.locally_connected'¶
- 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
openasce.discovery.regression_discovery.notears_mlp module¶
- class openasce.discovery.regression_discovery.notears_mlp.NotearsMLP(dims, bias=True)[source]¶
Bases:
ModuleInitializes internal Module state, shared by both nn.Module and ScriptModule.
- __annotations__ = {}¶
- __doc__ = None¶
- __init__(dims, bias=True)[source]¶
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- __module__ = 'openasce.discovery.regression_discovery.notears_mlp'¶
- 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
openasce.discovery.regression_discovery.regression_discovery module¶
- class openasce.discovery.regression_discovery.regression_discovery.CausalRegressionDiscovery[source]¶
Bases:
DiscoveryExecute the causal discovery by notears method
Attributes:
Constructor
Arguments:
Returns:
- __annotations__ = {}¶
- __doc__ = 'Execute the causal discovery by notears method\n\n Attributes:\n\n '¶
- __module__ = 'openasce.discovery.regression_discovery.regression_discovery'¶
- 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_discovery_test module¶
openasce.discovery.regression_discovery.regression_strategy module¶
- class openasce.discovery.regression_discovery.regression_strategy.Strategy(node_names: List[str], **kwargs)[source]¶
Bases:
objectGeneral class to implement different structure learning methods
Attributes
Contructor
- Parameters
node_names – the name of nodes
- __dict__ = mappingproxy({'__module__': 'openasce.discovery.regression_discovery.regression_strategy', '__doc__': 'General class to implement different structure learning methods\n\n Attributes\n\n ', '__init__': <function Strategy.__init__>, 'run': <function Strategy.run>, 'dual_ascent': <function Strategy.dual_ascent>, '__dict__': <attribute '__dict__' of 'Strategy' objects>, '__weakref__': <attribute '__weakref__' of 'Strategy' objects>, '__annotations__': {}})¶
- __doc__ = 'General class to implement different structure learning methods\n\n Attributes\n\n '¶
- __init__(node_names: List[str], **kwargs)[source]¶
Contructor
- Parameters
node_names – the name of nodes
- __module__ = 'openasce.discovery.regression_discovery.regression_strategy'¶
- __weakref__¶
list of weak references to the object (if defined)
- 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.trace_expm module¶
- class openasce.discovery.regression_discovery.trace_expm.TraceExpm(*args, **kwargs)[source]¶
Bases:
Function- __doc__ = None¶
- __module__ = 'openasce.discovery.regression_discovery.trace_expm'¶
- _backward_cls¶
alias of
TraceExpmBackward
- static backward(ctx, grad_output)[source]¶
Defines a formula for differentiating the operation with backward mode automatic differentiation (alias to the vjp function).
This function is to be overridden by all subclasses.
It must accept a context
ctxas the first argument, followed by as many outputs as theforward()returned (None will be passed in for non tensor outputs of the forward function), and it should return as many tensors, as there were inputs toforward(). Each argument is the gradient w.r.t the given output, and each returned value should be the gradient w.r.t. the corresponding input. If an input is not a Tensor or is a Tensor not requiring grads, you can just pass None as a gradient for that input.The context can be used to retrieve tensors saved during the forward pass. It also has an attribute
ctx.needs_input_gradas a tuple of booleans representing whether each input needs gradient. E.g.,backward()will havectx.needs_input_grad[0] = Trueif the first input toforward()needs gradient computated w.r.t. the output.
- static forward(ctx, input)[source]¶
This function is to be overridden by all subclasses. There are two ways to define forward:
Usage 1 (Combined forward and ctx):
@staticmethod def forward(ctx: Any, *args: Any, **kwargs: Any) -> Any: pass
It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types).
See combining-forward-context for more details
Usage 2 (Separate forward and ctx):
@staticmethod def forward(*args: Any, **kwargs: Any) -> Any: pass @staticmethod def setup_context(ctx: Any, inputs: Tuple[Any, ...], output: Any) -> None: pass
The forward no longer accepts a ctx argument.
Instead, you must also override the
torch.autograd.Function.setup_context()staticmethod to handle setting up thectxobject.outputis the output of the forward,inputsare a Tuple of inputs to the forward.See extending-autograd for more details
The context can be used to store arbitrary data that can be then retrieved during the backward pass. Tensors should not be stored directly on ctx (though this is not currently enforced for backward compatibility). Instead, tensors should be saved either with
ctx.save_for_backward()if they are intended to be used inbackward(equivalently,vjp) orctx.save_for_forward()if they are intended to be used for injvp.