datasets

builtin_dataset

class castle.datasets.builtin_dataset.BuiltinDataSet[source]

Bases: object

property data
load(*args, **kwargs)[source]
property topology_matrix
property true_graph_matrix
class castle.datasets.builtin_dataset.DataSetRegistry[source]

Bases: object

A class for resgistering the datasets, in which each dataset can be loaded by ‘load_dataset’ api.

meta = {'IID_Test': <class 'castle.datasets.builtin_dataset.IID_Test'>, 'THP_Test': <class 'castle.datasets.builtin_dataset.THP_Test'>, 'V18_N55_Wireless': <class 'castle.datasets.builtin_dataset.V18_N55_Wireless'>, 'V24_N439_Microwave': <class 'castle.datasets.builtin_dataset.V24_N439_Microwave'>, 'V25_N474_Microwave': <class 'castle.datasets.builtin_dataset.V25_N474_Microwave'>}
class castle.datasets.builtin_dataset.IID_Test[source]

Bases: BuiltinDataSet

A function for loading IID dataset

load(*args, **kwargs)[source]
class castle.datasets.builtin_dataset.RealDataSet[source]

Bases: BuiltinDataSet

load(root=None, download=False)[source]
class castle.datasets.builtin_dataset.THP_Test[source]

Bases: BuiltinDataSet

A function for loading THP dataset

load(*args, **kwargs)[source]
class castle.datasets.builtin_dataset.V18_N55_Wireless[source]

Bases: RealDataSet

A function for loading the real dataset: V18_N55_Wireless url: https://raw.githubusercontent.com/gcastle-hub/dataset/master/alarm/18V_55N_Wireless.tar.gz

class castle.datasets.builtin_dataset.V24_N439_Microwave[source]

Bases: RealDataSet

A function for loading the real dataset: V24_N439_Microwave url: https://raw.githubusercontent.com/gcastle-hub/dataset/master/alarm/24V_439N_Microwave.tar.gz

class castle.datasets.builtin_dataset.V25_N474_Microwave[source]

Bases: RealDataSet

A function for loading the real dataset: V25_N474_Microwave url: https://raw.githubusercontent.com/gcastle-hub/dataset/master/alarm/25V_474N_Microwave.tar.gz

loader

castle.datasets.loader.load_dataset(name='IID_Test', root=None, download=False)[source]

A function for loading some well-known datasets.

Parameters

name: class, default=’IID_Test’

Dataset name, independent and identically distributed (IID), Topological Hawkes Process (THP) and real datasets.

root: str

Root directory in which the dataset will be saved.

download: bool

If true, downloads the dataset from the internet and puts it in root directory. If dataset is already downloaded, it is not downloaded again.

Return

out: tuple
true_graph_matrix: numpy.matrix

adjacency matrix for the target causal graph.

topology_matrix: numpy.matrix

adjacency matrix for the topology.

data: pandas.core.frame.DataFrame

standard trainning dataset.

simulator

class castle.datasets.simulator.DAG[source]

Bases: object

A class for simulating random (causal) DAG, where any DAG generator method would return the weighed/binary adjacency matrix of a DAG. Besides, we recommend using the python package “NetworkX” to create more structures types.

static bipartite(n_nodes, n_edges, split_ratio=0.2, weight_range=None, seed=None)[source]
static erdos_renyi(n_nodes, n_edges, weight_range=None, seed=None)[source]
static hierarchical(n_nodes, degree=5, graph_level=5, weight_range=None, seed=None)[source]
static low_rank(n_nodes, degree=1, rank=5, weight_range=None, seed=None)[source]
static scale_free(n_nodes, n_edges, weight_range=None, seed=None)[source]
class castle.datasets.simulator.IIDSimulation(W, n=1000, method='linear', sem_type='gauss', noise_scale=1.0)[source]

Bases: object

Simulate IID datasets for causal structure learning.

Parameters

W: np.ndarray

Weighted adjacency matrix for the target causal graph.

n: int

Number of samples for standard trainning dataset.

method: str, (linear or nonlinear), default=’linear’

Distribution for standard trainning dataset.

sem_type: str

gauss, exp, gumbel, uniform, logistic (linear); mlp, mim, gp, gp-add, quadratic (nonlinear).

noise_scale: float

Scale parameter of noise distribution in linear SEM.

class castle.datasets.simulator.THPSimulation(causal_matrix, topology_matrix, mu_range=(5e-05, 0.0001), alpha_range=(0.005, 0.007))[source]

Bases: object

A class for simulating event sequences with THP (Topological Hawkes Process) setting.

Parameters

causal_matrix: np.matrix

The casual matrix.

topology_matrix: np.matrix

Interpreted as an adjacency matrix to generate graph. Has two dimension, should be square.

mu_range: tuple, default=(0.00005, 0.0001) alpha_range: tuple, default=(0.005, 0.007)

simulate(T, max_hop=1, beta=10)[source]

Generate simulation data.

class castle.datasets.simulator.Topology[source]

Bases: object

A class for generating some classical (undirected) network structures, in which any graph generator method would return the adjacency matrix of a network structure. In fact, we recommend to directly use the python package “NetworkX” to create various structures you need.

static erdos_renyi(n_nodes, n_edges, seed=None)[source]

Generate topology matrix

Parameters

n_nodesint, greater than 0

The number of nodes.

n_edgesint, greater than 0

Use to calculate probability for edge creation.

seedinteger, random_state, or None (default)

Indicator of random number generation state.

Returns

B: np.matrix

castle.datasets.simulator.set_random_seed(seed)[source]