datasets
builtin_dataset
- class castle.datasets.builtin_dataset.BuiltinDataSet[source]
Bases:
object- property data
- property topology_matrix
- property true_graph_matrix
- class castle.datasets.builtin_dataset.DataSetRegistry[source]
Bases:
objectA 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:
BuiltinDataSetA function for loading IID dataset
- class castle.datasets.builtin_dataset.RealDataSet[source]
Bases:
BuiltinDataSet
- class castle.datasets.builtin_dataset.THP_Test[source]
Bases:
BuiltinDataSetA function for loading THP dataset
- class castle.datasets.builtin_dataset.V18_N55_Wireless[source]
Bases:
RealDataSetA 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:
RealDataSetA 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:
RealDataSetA 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:
objectA 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.
- class castle.datasets.simulator.IIDSimulation(W, n=1000, method='linear', sem_type='gauss', noise_scale=1.0)[source]
Bases:
objectSimulate 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:
objectA 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)
- class castle.datasets.simulator.Topology[source]
Bases:
objectA 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