openasce.inference package

class openasce.inference.GraphInferModel(*, graph: CausalGraph = None, column_names: List[str] = None, treatment_name: str = None, label_name: str = None, num_iteration=20)[source]

Bases: InferenceModel

The inference using the causal graph

graph

The causal graph. If not set, the class will try to find it out if discovery is available.

column_names

all names of sample

treatment_name

treatment column name in column_names

label_name

target column name in column_names

Parameters
  • graph – causal graph

  • column_names – all names of column

  • treatment_name – the name of treatment column

  • label_name – the name of target name

__init__(*, graph: CausalGraph = None, column_names: List[str] = None, treatment_name: str = None, label_name: str = None, num_iteration=20) None[source]
Parameters
  • graph – causal graph

  • column_names – all names of column

  • treatment_name – the name of treatment column

  • label_name – the name of target name

property column_names

All nodes’ name. Note: should include the treatment node and label node.

property data

Return the sample data

property discovery: Discovery
estimate(*, X: Iterable[ndarray] = None, Y: Iterable[ndarray] = None, T: Iterable[ndarray] = None, **kwargs) None[source]

Feed the sample data and estimate the outcome on the samples

Parameters
  • X – Features of the samples.

  • Y – Ignore in causal graph inference

  • T – Ignore in causal graph inference

  • kwargs – {‘treat_value’: treat_value, ‘label_value’:label_value}

Returns:

fit(*, X: Iterable[ndarray], Y: Iterable[ndarray] = None, T: Iterable[ndarray] = None, **kwargs) None[source]

Feed the sample data to train the graph

Parameters
  • X – All features of the samples including the treatment and the label node.

  • Y – Ignore in causal graph inference

  • T – Ignore in causal graph inference.

Returns:

get_result()[source]

Get the estimated result

The sub-class should implement this routine and runtime invokes it.

Arguments:

Returns

The estimation result.

property graph
property label_name
output()[source]

Output the estimated result to files

The sub-class should implement this routine and runtime invokes it.

Arguments:

Returns:

property treatment_name
class openasce.inference.TModel(hidden_units: Dict, lr: float = 0.1, name: str = 't_model')[source]

Bases: InferenceModel

T_model based on NN

Initialize.

Parameters
  • hidden_units (dict) – list of positive integer, the layer number and units in each layer.

  • lr (float) – learning rate

__init__(hidden_units: Dict, lr: float = 0.1, name: str = 't_model') None[source]

Initialize.

Parameters
  • hidden_units (dict) – list of positive integer, the layer number and units in each layer.

  • lr (float) – learning rate

estimate(X: Iterable[Tensor] = None, T: Iterable[Tensor] = None, *, Z: Iterable[Tuple[Tensor, Tensor, Tensor]] = None, **kwargs) None[source]

Feed the sample data Estimate the effect on the samples, and get_result method can be used to get the result of prediction :param X: Features of the samples. :param T: Treatments of the samples. :param Z: The iterable object returning (a batch of X, a batch of Y, a batch of T)

Returns

None

fit(X: Iterable[Tensor] = None, Y: Iterable[Tensor] = None, T: Iterable[Tensor] = None, *, Z: Iterable[Tuple[Tensor, Tensor, Tensor]] = None, num_epochs: int = 1, **kwargs) None[source]

Feed the sample data and train the model on the samples.

Parameters
  • X – Features of the samples.

  • Y – Outcomes of the samples.

  • T – Treatments of the samples.

  • Z – The iterable object returning (a batch of X, a batch of Y, a batch of T)

  • num_epochs – number of the train epoch

Returns

None

forward(x: Tensor, t: Tensor, training: bool) Dict[str, Tensor][source]
get_optimizer(lr: float = 0.01)[source]

Build the optimizer.

Args:

Returns

An optimizer.

loss(predictions: Dict, labels: List[Tensor])[source]
property trainable_variables

Subpackages

Submodules

openasce.inference.graph_inference module

class openasce.inference.graph_inference.GraphInferModel(*, graph: CausalGraph = None, column_names: List[str] = None, treatment_name: str = None, label_name: str = None, num_iteration=20)[source]

Bases: InferenceModel

The inference using the causal graph

graph

The causal graph. If not set, the class will try to find it out if discovery is available.

column_names

all names of sample

treatment_name

treatment column name in column_names

label_name

target column name in column_names

Parameters
  • graph – causal graph

  • column_names – all names of column

  • treatment_name – the name of treatment column

  • label_name – the name of target name

__init__(*, graph: CausalGraph = None, column_names: List[str] = None, treatment_name: str = None, label_name: str = None, num_iteration=20) None[source]
Parameters
  • graph – causal graph

  • column_names – all names of column

  • treatment_name – the name of treatment column

  • label_name – the name of target name

property column_names

All nodes’ name. Note: should include the treatment node and label node.

property data

Return the sample data

property discovery: Discovery
estimate(*, X: Iterable[ndarray] = None, Y: Iterable[ndarray] = None, T: Iterable[ndarray] = None, **kwargs) None[source]

Feed the sample data and estimate the outcome on the samples

Parameters
  • X – Features of the samples.

  • Y – Ignore in causal graph inference

  • T – Ignore in causal graph inference

  • kwargs – {‘treat_value’: treat_value, ‘label_value’:label_value}

Returns:

fit(*, X: Iterable[ndarray], Y: Iterable[ndarray] = None, T: Iterable[ndarray] = None, **kwargs) None[source]

Feed the sample data to train the graph

Parameters
  • X – All features of the samples including the treatment and the label node.

  • Y – Ignore in causal graph inference

  • T – Ignore in causal graph inference.

Returns:

get_result()[source]

Get the estimated result

The sub-class should implement this routine and runtime invokes it.

Arguments:

Returns

The estimation result.

property graph
property label_name
output()[source]

Output the estimated result to files

The sub-class should implement this routine and runtime invokes it.

Arguments:

Returns:

property treatment_name

openasce.inference.inference_model module

class openasce.inference.inference_model.InferenceModel[source]

Bases: Runtime

Inference Class

Base class of the causal inference

Attributes:

CONDITION_DICT_NAME = 'condition'
LABEL_VALUE = 'label_value'
TREATMENT_VALUE = 'treatment_value'
__init__() None[source]
property data

Return the sample data

estimate(*, X: Iterable[ndarray], T: Iterable[ndarray], **kwargs) None[source]

Feed the sample data and estimate the effect on the samples

Parameters
  • X – Features of the samples.

  • T – Treatments of the samples.

Returns

None

fit(*, X: Iterable[ndarray], Y: Iterable[ndarray], T: Iterable[ndarray], **kwargs) None[source]

Feed the sample data and train the model used to effect on the samples.

Parameters
  • X – Features of the samples.

  • Y – Outcomes of the samples.

  • T – Treatments of the samples.

Returns

None

get_result() Any[source]

Get the estimated result

The sub-class should implement this routine and runtime invokes it.

Returns

The estimation result.

output(output_path: str) None[source]

Output the estimated result to files

The sub-class should implement this routine and runtime invokes it.

Parameters

output_path – The path of output file.

Returns

None

openasce.inference.t_model module

class openasce.inference.t_model.TModel(hidden_units: Dict, lr: float = 0.1, name: str = 't_model')[source]

Bases: InferenceModel

T_model based on NN

Initialize.

Parameters
  • hidden_units (dict) – list of positive integer, the layer number and units in each layer.

  • lr (float) – learning rate

__init__(hidden_units: Dict, lr: float = 0.1, name: str = 't_model') None[source]

Initialize.

Parameters
  • hidden_units (dict) – list of positive integer, the layer number and units in each layer.

  • lr (float) – learning rate

estimate(X: Iterable[Tensor] = None, T: Iterable[Tensor] = None, *, Z: Iterable[Tuple[Tensor, Tensor, Tensor]] = None, **kwargs) None[source]

Feed the sample data Estimate the effect on the samples, and get_result method can be used to get the result of prediction :param X: Features of the samples. :param T: Treatments of the samples. :param Z: The iterable object returning (a batch of X, a batch of Y, a batch of T)

Returns

None

fit(X: Iterable[Tensor] = None, Y: Iterable[Tensor] = None, T: Iterable[Tensor] = None, *, Z: Iterable[Tuple[Tensor, Tensor, Tensor]] = None, num_epochs: int = 1, **kwargs) None[source]

Feed the sample data and train the model on the samples.

Parameters
  • X – Features of the samples.

  • Y – Outcomes of the samples.

  • T – Treatments of the samples.

  • Z – The iterable object returning (a batch of X, a batch of Y, a batch of T)

  • num_epochs – number of the train epoch

Returns

None

forward(x: Tensor, t: Tensor, training: bool) Dict[str, Tensor][source]
get_optimizer(lr: float = 0.01)[source]

Build the optimizer.

Args:

Returns

An optimizer.

loss(predictions: Dict, labels: List[Tensor])[source]
property trainable_variables