copulas.multivariate.tree module

class copulas.multivariate.tree.CenterTree(random_seed=None)[source]

Bases: copulas.multivariate.tree.Tree

get_anchor()[source]

Find anchor variable with highest sum of dependence with the rest.

Returns

Anchor variable.

Return type

int

tree_type = 0
class copulas.multivariate.tree.DirectTree(random_seed=None)[source]

Bases: copulas.multivariate.tree.Tree

tree_type = 1
class copulas.multivariate.tree.Edge(index, left, right, copula_name, copula_theta)[source]

Bases: object

classmethod from_dict(edge_dict)[source]

Create a new instance from a parameters dictionary.

Parameters

params (dict) – Parameters of the Edge, in the same format as the one returned by the to_dict method.

Returns

Instance of the edge defined on the parameters.

Return type

Edge

classmethod get_child_edge(index, left_parent, right_parent)[source]

Construct a child edge from two parent edges.

Parameters
  • index (int) – Index of the new Edge.

  • left_parent (Edge) – Left parent

  • right_parent (Edge) – Right parent

Returns

The new child edge.

Return type

Edge

classmethod get_conditional_uni(left_parent, right_parent)[source]

Identify pair univariate value from parents.

Parameters
  • left_parent (Edge) – left parent

  • right_parent (Edge) – right parent

Returns

left and right parents univariate.

Return type

tuple[np.ndarray, np.ndarray]

get_likelihood(uni_matrix)[source]

Compute likelihood given a U matrix.

Parameters

uni_matrix (numpy.array) – Matrix to compute the likelihood.

Returns

likelihood and conditional values.

Return type

tuple (np.ndarray, np.ndarray, np.array)

is_adjacent(another_edge)[source]

Check if two edges are adjacent.

Parameters

another_edge (Edge) – edge object of another edge

Returns

True if the two edges are adjacent.

Return type

bool

static sort_edge(edges)[source]

Sort iterable of edges first by left node indices then right.

Parameters

edges (list[Edge]) – List of edges to be sorted.

Returns

Sorted list by left and right node indices.

Return type

list[Edge]

to_dict()[source]

Return a dict with the parameters to replicate this Edge.

Returns

Parameters of this Edge.

Return type

dict

class copulas.multivariate.tree.RegularTree(random_seed=None)[source]

Bases: copulas.multivariate.tree.Tree

tree_type = 2
class copulas.multivariate.tree.Tree(random_seed=None)[source]

Bases: copulas.multivariate.base.Multivariate

Helper class to instantiate a single tree in the vine model.

fit(index, n_nodes, tau_matrix, previous_tree, edges=None)[source]

Fit this tree object.

Parameters
  • index (int) – index of the tree.

  • n_nodes (int) – number of nodes in the tree.

  • tau_matrix (numpy.array) – kendall’s tau matrix of the data, shape (n_nodes, n_nodes).

  • previous_tree (Tree) – tree object of previous level.

fitted = False
classmethod from_dict(tree_dict, previous=None)[source]

Create a new instance from a parameters dictionary.

Parameters

params (dict) – Parameters of the Tree, in the same format as the one returned by the to_dict method.

Returns

Instance of the tree defined on the parameters.

Return type

Tree

get_adjacent_matrix()[source]

Get adjacency matrix.

Returns

adjacency matrix

Return type

numpy.ndarray

get_likelihood(uni_matrix)[source]

Compute likelihood of the tree given an U matrix.

Parameters

uni_matrix (numpy.array) – univariate matrix to evaluate likelihood on.

Returns

likelihood of the current tree, next level conditional univariate matrix

Return type

tuple[float, numpy.array]

get_tau_matrix()[source]

Get tau matrix for adjacent pairs.

Returns

tau matrix for the current tree

Return type

tau (numpy.ndarray)

prepare_next_tree()[source]

Prepare conditional U matrix for next tree.

to_dict()[source]

Return a dict with the parameters to replicate this Tree.

Returns

Parameters of this Tree.

Return type

dict

tree_type = None
class copulas.multivariate.tree.TreeTypes[source]

Bases: enum.Enum

An enumeration.

CENTER = 0
DIRECT = 1
REGULAR = 2
copulas.multivariate.tree.get_tree(tree_type)[source]

Get a Tree instance of the specified type.

Parameters

tree_type (str or TreeTypes) – Type of tree of which to get an instance.

Returns

Instance of a Tree of the specified type.

Return type

Tree