Subpackages
- Distributions
- Dirichlet
- Discrete decomposable log linear
conditional_prob_dec()est_parameters()get_all_counts()hyperconsistent_cliques()ll_complete_set_ratio()locals_to_joint_prob_table()log_likelihood_partial()prob_dec()read_local_hyper_consistent_parameters_from_json_file()sample()sample_hyper_consistent_counts()sample_hyper_consistent_parameters()sample_joint_prob_table()sample_prob_table()
- Graph intra-class
- Graph inverse-Wishart
- Gaussian graphical model
- Junction tree clustering
- Matrix multivariate normal
- Multivariate students-t
- Sequential junction tree distribution
- Wishart distribution
- Graph
- Decomposable graph
- Empirical graph distribution
- Undirected graph
- Connect/disconnect cliques
connect_a()connect_b()connect_c()connect_d()connect_logprob()connect_move()connect_select_subsets()disconnect_a()disconnect_b()disconnect_c()disconnect_d()disconnect_get_CXCY()disconnect_get_neighbors()disconnect_logprob_a()disconnect_logprob_bcd()disconnect_move()disconnect_select_subsets()
- Junction tree
JunctionTreeJunctionTree.add_edge()JunctionTree.add_edges_from()JunctionTree.connected_component_vertices()JunctionTree.connected_components()JunctionTree.fresh_copy()JunctionTree.get_separators()JunctionTree.log_n_junction_trees()JunctionTree.log_nu()JunctionTree.remove_edge()JunctionTree.remove_edges_from()JunctionTree.remove_node()JunctionTree.to_graph()JunctionTree.tuple()
forest_induced_by_sep()from_prufer()graph()induced_subtree_nodes()is_junction_tree()jt_to_prufer()log_n_junction_trees()log_n_junction_trees_update_ratio()log_nu()n_junction_trees()n_junction_trees_update()n_subtrees()n_subtrees_aux()peo()random_tree_from_forest()randomize()randomize_at_sep()sample()separators()subtree_induced_by_subset()to_prufer()
- Junction tree collapser
- Junction tree expander
- Subtree sampler
- Graph trajectory
TrajectoryTrajectory.add_sample()Trajectory.empirical_distribution()Trajectory.from_json()Trajectory.get_adjvec_trajectory()Trajectory.graph_diff_trajectory_df()Trajectory.log_likelihood()Trajectory.maximum_likelihood_graph()Trajectory.read_file()Trajectory.set_sampling_method()Trajectory.set_sequential_distribution()Trajectory.set_time()Trajectory.set_trajectory()Trajectory.size()Trajectory.to_json()Trajectory.write_adjvec_trajectory()Trajectory.write_file()
Distributions
Auxiliary functions
- trilearn.auxiliary_functions.get_marg_counts(full_data, subset)[source]
Returns a contingency table in dictionary form.
- Parameters:
data (np.array) – The data in n x p form.
subset (list) – The subset of interest
- trilearn.auxiliary_functions.l1_loss(m1, m2)[source]
L1 loss.
- Parameters:
m1 (Numpy array) – A matrix
m1 – A matrix
- Returns:
float
- trilearn.auxiliary_functions.l2_loss(m1, m2)[source]
L2 loss between m1 and m2.
- Parameters:
m1 (Numpy array) – A matrix
m1 – A matrix
- Returns:
float
- trilearn.auxiliary_functions.plot_heatmap(heatmap, cbar=False, annot=False, xticklabels=1, yticklabels=1)[source]
- trilearn.auxiliary_functions.plot_matrix(m, filename, extension, title='Adjmat')[source]
Plots a 2-dim numpy array as heatmap. :param m: matrix to plot. :type m: numpy array
- trilearn.auxiliary_functions.plot_multiple_traj_statistics(trajs, burnin_end, write_to_file=False, annot=False, output_directory='./', file_extension='eps')[source]
- trilearn.auxiliary_functions.random_subset(A)[source]
Draws a random subset of elements in a list, inclding the empty set.
- Parameters:
A (list) –
- Returns:
Subset of A.
- Return type:
set
Graph predictive classification
P. Green & A. Thomas MH-sampler
- trilearn.mh_greenthomas.sample_trajectories_ggm_parallel(dataframe, n_samples, randomize=[1000], D=None, delta=1.0, reps=1, output_directory='.', **args)[source]
- trilearn.mh_greenthomas.sample_trajectories_ggm_to_file(dataframe, n_samples, randomize=[1000], D=None, delta=1.0, reps=1, output_directory='.', **args)[source]
- trilearn.mh_greenthomas.sample_trajectories_loglin_parallel(dataframe, n_samples, randomize=[1000], pseudo_obs=[1.0], reps=1, output_directory='.', **args)[source]
- trilearn.mh_greenthomas.sample_trajectories_loglin_to_file(dataframe, n_samples, randomize=[1000], pseudo_obs=[1.0], reps=1, output_directory='.', **args)[source]
- trilearn.mh_greenthomas.sample_trajectory_ggm(dataframe, n_samples, randomize=1000, D=None, delta=1.0, cache={}, **args)[source]
- trilearn.mh_greenthomas.sample_trajectory_loglin(dataframe, n_samples, pseudo_obs=1.0, randomize=1000, cache={}, **args)[source]
- trilearn.mh_greenthomas.sample_trajectory_uniform(n_samples, randomize=100, graph_size=5, cache={}, **args)[source]
- trilearn.mh_greenthomas.trajectory_to_file(n_samples, randomize, seqdist, dir='.', reseed=False)[source]
Writes the trajectory of graphs generated by particle Gibbs to file.
- Parameters:
seq_dist (SequentialJTDistributions) – the distribution to be sampled from
filename_prefix (string) – prefix to the filename
- Returns:
Markov chain of underlying graphs of the junction trees sampled by pgibbs.
- Return type:
- trilearn.mh_greenthomas.trajectory_to_queue(n_samples, randomize, seqdist, queue, reseed=False)[source]
Writes the trajectory of graphs generated by particle Gibbs to file.
- Parameters:
seq_dist (SequentialJTDistributions) – the distribution to be sampled from
filename_prefix (string) – prefix to the filename
- Returns:
Markov chain of underlying graphs of the junction trees sampled by pgibbs.
- Return type:
Particle Gibbs
- trilearn.pgibbs.sample_trajectories_ggm(dataframe, n_particles, n_samples, D=None, delta=1.0, alphas=[0.5], betas=[0.5], radii=[None], reset_cache=True, reps=1, **args)[source]
- trilearn.pgibbs.sample_trajectories_ggm_parallel(dataframe, n_particles, n_samples, D=None, delta=1.0, alphas=[0.5], betas=[0.5], radii=[None], reset_cache=True, reps=1, **args)[source]
- trilearn.pgibbs.sample_trajectories_ggm_to_file(dataframe, n_particles, n_samples, D=None, delta=1.0, alphas=[0.5], betas=[0.5], radii=[None], reset_cache=True, reps=1, output_directory='.', output_filename='trajectory.json', **args)[source]
- trilearn.pgibbs.sample_trajectories_loglin(dataframe, n_particles, n_samples, pseudo_observations=[1.0], alphas=[0.5], betas=[0.5], radii=[None], reset_cache=True, reps=1, **args)[source]
- trilearn.pgibbs.sample_trajectories_loglin_parallel(dataframe, n_particles, n_samples, pseudo_observations=[1.0], alphas=[0.5], betas=[0.5], radii=[None], reset_cache=True, reps=1, output_directory='.', **args)[source]
- trilearn.pgibbs.sample_trajectories_loglin_to_file(dataframe, n_particles, n_samples, pseudo_observations=[1.0], alphas=[0.5], betas=[0.5], radii=[None], reset_cache=True, reps=1, output_directory='.', output_filename='trajectory.json', **args)[source]
- trilearn.pgibbs.sample_trajectory(smc_N, alpha, beta, radius, n_samples, seq_dist, jt_traj=None, debug=False, reset_cache=True)[source]
A particle Gibbs implementation for approximating distributions over junction trees.
- Parameters:
smc_N (int) – Number of particles in SMC in each Gibbs iteration
n_samples (int) – Number of Gibbs iterations (samples)
alpha (float) – sparsity parameter for the Christmas tree algorithm
beta (float) – sparsity parameter for the Christmas tree algorithm
radius (float) – defines the radius within which ned nodes are selected
seq_dist (SequentialJTDistributions) – the distribution to be sampled from
- Returns:
Markov chain of the underlying graphs of the junction trees sampled by pgibbs.
- Return type:
- trilearn.pgibbs.sample_trajectory_ggm(dataframe, n_particles, n_samples, D=None, delta=1.0, alpha=0.5, beta=0.5, radius=None, reset_cache=True, **args)[source]
Particle Gibbs for approximating distributions over Gaussian graphical models.
- Parameters:
n_particles (int) – Number of particles in SMC in each Gibbs iteration
n_samples (int) – Number of Gibbs iterations (samples)
alpha (float) – sparsity parameter for the Christmas tree algorithm
beta (float) – sparsity parameter for the Christmas tree algorithm
radius (float) – defines the radius within which ned nodes are selected
dataframe (np.matrix) – row matrix of data
D (np.matrix) – matrix parameter for the hyper inverse wishart prior
delta (float) – degrees of freedom for the hyper inverse wishart prior
cache (dict) – cache for clique likelihoods
- Returns:
Markov chain of the underlying graphs of the junction trees sampled by pgibbs.
- Return type:
- trilearn.pgibbs.sample_trajectory_loglin(dataframe, n_particles, n_samples, pseudo_obs=1.0, alpha=0.5, beta=0.5, radius=None, reset_cache=True, **args)[source]
- trilearn.pgibbs.trajectory_to_file(n_particles, n_samples, alpha, beta, radius, seqdist, node_labels, reset_cache=True, dir='.', output_filename='trajectory.csv', reseed=False)[source]
Writes the trajectory of graphs generated by particle Gibbs to file.
- Parameters:
n_particles (int) – Number of particles in SMC in each Gibbs iteration
n_samples (int) – Number of Gibbs iterations (samples)
alpha (float) – sparsity parameter for the Christmas tree algorithm
beta (float) – sparsity parameter for the Christmas tree algorithm
radius (float) – defines the radius within which ned nodes are selected
seq_dist (SequentialJTDistributions) – the distribution to be sampled from
filename_prefix (string) – prefix to the filename
- Returns:
Markov chain of underlying graphs of the junction trees sampled by pgibbs.
- Return type:
- trilearn.pgibbs.trajectory_to_queue(n_particles, n_samples, alpha, beta, radius, seqdist, queue, reset_cache=True, reseed=False)[source]
Writes the trajectory of graphs generated by particle Gibbs to file.
- Parameters:
n_particles (int) – Number of particles in SMC in each Gibbs iteration
n_samples (int) – Number of Gibbs iterations (samples)
alpha (float) – sparsity parameter for the Christmas tree algorithm
beta (float) – sparsity parameter for the Christmas tree algorithm
radius (float) – defines the radius within which ned nodes are selected
seq_dist (SequentialJTDistributions) – the distribution to be sampled from
filename_prefix (string) – prefix to the filename
- Returns:
Markov chain of underlying graphs of the junction trees sampled by pgibbs.
- Return type:
Stochastic set process
- trilearn.set_process.backward_order_neigh_log_prob(from_order, to_order, radius, maxradius)[source]
Probability of generating order from_order from the larger order to_order under the restriction that no hole greater than radius is created.
- trilearn.set_process.backward_order_neigh_set(from_order, radius, maxradius)[source]
Returns the list of nodes that can be removed from from_order (the greater order).
- trilearn.set_process.backward_perm_traj_sample(p, radius)[source]
Samples a permutation tajectory with maximum p indices.
- trilearn.set_process.gen_backward_order_neigh(from_order, radius, maxradius)[source]
Returns: A permutation wit one less element than fromm_order
- trilearn.set_process.gen_order_neigh(from_order, radius, total_set)[source]
- Returns a list with one more element than from_order
such that the new element is within the radius and belongs to total_set.
- Parameters:
from_order (list) – list of elements
radius (int) – specifies the radius within which the new element can be taken
total_set (list) – the full set of elements
- Returns:
numpy array
SMC
Sequential Monte Carlo sampler for junction tree distributions.
- trilearn.smc.approximate(N, alpha, beta, radius, seq_dist, debug=False, neig_set_cache={})[source]
Sequential Monte Carlo for junction trees using the christmas tree algorithm as proposal kernel.
- Parameters:
N (int) – number
alpha (float) – sparsity parameter for the Christmas tree algorithm
beta (float) – sparsity parameter for the Christmas tree algorithm
radius (float) – defines the radius within which ned nodes are selected
seqdist (SequentialJTDistributions) – the distribution to be sampled from
- Returns:
(new_trees, log_w)
References:
- trilearn.smc.approximate_cond(N, alpha, beta, radius, seq_dist, T_cond, perm_cond, debug=False, neig_set_cache={})[source]
SMC an junction trees conditioned on the trajectories T_cond and perm_cond.
- trilearn.smc.est_dec_max_clique_size(order, n_particles, alpha=0.5, beta=0.5, n_smc_estimates=1, debug=False)[source]
- trilearn.smc.est_log_norm_consts(order, n_particles, sequential_distribution, alpha=0.5, beta=0.5, n_smc_estimates=1, debug=False)[source]
- trilearn.smc.est_n_dec_graphs(order, n_particles, alpha=0.5, beta=0.5, n_smc_estimates=1, debug=False)[source]