| | |
- structure_learning.approximators.approximator.Approximator(abc.ABC)
-
- MCMC
class MCMC(structure_learning.approximators.approximator.Approximator) |
| |
MCMC(data: pandas.core.frame.DataFrame, initial_state: ~State, max_iter: int = 30000, score_object: Union[str, structure_learning.scores.score.Score] = None, proposal_object: Union[str, structure_learning.proposals.proposal.StructureLearningProposal] = None, pc_init: bool = True, pc_significance_level=0.01, pc_ci_test='pearsonr', blacklist: numpy.ndarray = None, whitelist: numpy.ndarray = None, seed: int = None, result_type: str = 'distribution', graph_type='dag', burn_in: float = 0.1)
Base class for Markov Chain Monte Carlo (MCMC) simulations.
Inheriting classes must implement the `step` method to define the behavior of a single MCMC iteration. |
| |
- Method resolution order:
- MCMC
- structure_learning.approximators.approximator.Approximator
- abc.ABC
- builtins.object
Methods defined here:
- __init__(self, data: pandas.core.frame.DataFrame, initial_state: ~State, max_iter: int = 30000, score_object: Union[str, structure_learning.scores.score.Score] = None, proposal_object: Union[str, structure_learning.proposals.proposal.StructureLearningProposal] = None, pc_init: bool = True, pc_significance_level=0.01, pc_ci_test='pearsonr', blacklist: numpy.ndarray = None, whitelist: numpy.ndarray = None, seed: int = None, result_type: str = 'distribution', graph_type='dag', burn_in: float = 0.1)
- Initialize the MCMC instance.
Parameters:
data (pd.DataFrame): Dataset for the MCMC simulation.
initial_state (State): Initial state for the simulation.
max_iter (int): Maximum number of iterations. Default is 30000.
score_object (Union[str, Score]): Scoring object or type. Default is None.
proposal_object (Union[str, StructureLearningProposal]): Proposal object or type. Default is None.
pc_init (bool): Whether to initialize using the PC algorithm. Default is True.
pc_significance_level (float): Significance level for the PC algorithm. Default is 0.01.
pc_ci_test (str): Conditional independence test for the PC algorithm. Default is 'pearsonr'.
blacklist (np.ndarray): Mask for edges to ignore in the proposal.
whitelist (np.ndarray): Mask for edges to include in the proposal.
plus1 (bool): Whether to use plus1 neighborhood. Default is False.
seed (int): Random seed for reproducibility. Default is 32.
result_type (str): Type of result to generate. Default is 'distribution'.
graph_type (str): Type of graph ('dag' or 'cpdag'). Default is 'dag'.
- __str__(self)
- Return str(self).
- config(self)
- Get the configuration of the MCMC instance.
Returns:
dict: Configuration dictionary.
- get_chain_info(self, results, key='graph')
- Extract chain information from the MCMC results.
Parameters:
results (dict): Results of the MCMC simulation.
key (str): Key to extract information for. Default is 'graph'.
Returns:
list: Chain information.
- get_graphs(self, results)
- Retrieve a list of sampled graphs from the MCMC results.
Parameters:
results (dict): Results of the MCMC simulation.
Returns:
list: Sampled graphs.
- run(self, intervals=-1) -> Tuple[dict, float]
- Execute the MCMC simulation.
Returns:
Tuple[dict, float]: Results of the simulation and acceptance ratio.
- step(self) -> dict
- Perform one iteration of the MCMC simulation.
Returns:
dict: Information about the current iteration.
- to_cpdag_distribution(self)
- to_distribution(self)
- Convert the MCMC results to a distribution.
Returns:
MCMCDistribution: Distribution object.
- to_opad(self, plus=False)
- Convert the MCMC results to an OPAD object.
Parameters:
plus (bool): Whether to use the plus1 neighborhood. Default is False.
Returns:
OPAD: OPAD object.
- traceplot(self, ax=None)
- Generate a trace plot of the MCMC simulation.
Parameters:
ax (matplotlib.axes.Axes): Matplotlib axis to plot on. Default is None.
Returns:
list: Plot object.
- update_results(self, iteration, info)
- Update the results of the MCMC simulation with information from the current iteration.
Parameters:
iteration (int): Current iteration number.
info (dict): Information about the current iteration.
Readonly properties defined here:
- trace
Data and other attributes defined here:
- RESULT_TYPE_DIST = 'distribution'
- RESULT_TYPE_ITER = 'iterates'
- RESULT_TYPE_OPAD = 'opad'
- RESULT_TYPE_OPAD_PLUS = 'opad+'
- __abstractmethods__ = frozenset({'step'})
Methods inherited from structure_learning.approximators.approximator.Approximator:
- save(self, filename: str, compression='gzip')
- Saves the Graph object to a file.
Parameters:
filename (str): Path to the output file.
Class methods inherited from structure_learning.approximators.approximator.Approximator:
- load(filename: str, compression='gzip')
- Loads a Graph object from a file.
Parameters:
filename (str): Path to the input file.
Returns:
Graph: Loaded Graph object.
Data descriptors inherited from structure_learning.approximators.approximator.Approximator:
- __dict__
- dictionary for instance variables
- __weakref__
- list of weak references to the object
| |