In [220]:
import numpy as np
from depimpact.utils import get_pairs_by_levels, get_possible_structures, fill_structure, check_node_loop
%load_ext autoreload
%autoreload 2


The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload

In [364]:
np.random.seed()
dim = 5
n_pairs = int(dim*(dim-1)/2)
n_forced_pairs = n_pairs-1
n_forced_pairs = min(n_forced_pairs, n_pairs)
forced_pairs_ids = np.random.choice(range(n_pairs), n_forced_pairs, replace=False)
forced_pairs_ids = [4, 5, 2, 0, 3]
# forced_pairs_ids = [11, 12,  8,  4,  2,  5,  7, 14, 13,  1,  3,  6,  0, 10]
# forced_pairs_ids = [13,  3,  9, 12,  2, 10, 14,  6,  4, 11,  1,  5,  8,  7]
# forced_pairs_ids = [ 9, 11,  8,  5,  1,  6,  3,  2, 12, 14, 13,  4,  7, 10]
# forced_pairs_ids = [14,  8, 27, 23, 20, 10,  1, 19,  7, 11, 12, 13, 25, 15, 18,  4,  2,
#         6, 22, 16,  5, 21, 24, 26, 17,  9,  3]

In [416]:
pairs_by_levels = get_pairs_by_levels(dim, forced_pairs_ids, verbose=True)
pairs_by_levels


Vine dimension: 5
Conditioning information:
	4 pairs with 0 conditionned variables
Pairs: [(4, 2), (4, 3), (3, 2), (2, 1)]
	3 pairs with 1 conditionned variables
Pairs: [(4, 1)]
	2 pairs with 2 conditionned variables
Pairs: []
	1 pairs with 3 conditionned variables
Pairs: []
Concerned pairs: [(4, 2), (4, 3), (3, 2), (2, 1), (4, 1)]
Remaining pairs: [(3, 1), (5, 1), (5, 2), (5, 3), (5, 4)]
('Level:', 0)
('Before:', [(4, 2), (4, 3), (3, 2), (2, 1)])
('After:', [(4, 2), (4, 3), (3, 2), (4, 1)])
('n_moving:', 1)
('idx:', 0)
('move_up:', 1)
('Is OK?', False)
('Level:', 0)
('Before:', [(4, 2), (4, 3), (3, 2), (2, 1)])
('After:', [(4, 2), (4, 3), (3, 2)])
('n_moving:', 1)
('idx:', 0)
('move_up:', 0)
('Is OK?', False)
('Level:', 0)
('Before:', [(4, 2), (4, 3), (3, 2), (2, 1)])
('After:', [(4, 2), (4, 3), (2, 1)])
('n_moving:', 1)
('idx:', 1)
('move_up:', 0)
('Is OK?', True)
('Level:', 1)
('Before:', [(3, 2), (4, 1)])
Out[416]:
[[(4, 2), (4, 3), (2, 1)], [(3, 2), (4, 1)]]

In [417]:
good_structures = get_possible_structures(dim, pairs_by_levels, verbose=False)
for struct in good_structures:
    print struct


[[3 0 0 0 0]
 [5 4 0 0 0]
 [1 5 2 0 0]
 [2 1 5 1 0]
 [4 2 1 5 5]]
[[3 0 0 0 0]
 [5 4 0 0 0]
 [1 5 1 0 0]
 [2 1 5 2 0]
 [4 2 2 5 5]]
[[1 0 0 0 0]
 [5 2 0 0 0]
 [3 5 4 0 0]
 [4 3 5 3 0]
 [2 4 3 5 5]]
[[1 0 0 0 0]
 [5 2 0 0 0]
 [3 5 3 0 0]
 [4 3 5 4 0]
 [2 4 4 5 5]]

In [5]:
from depimpact.utils import add_pairs
structure = np.zeros((dim, dim))
for i, pairs in enumerate(pairs_by_levels):
    structure = add_pairs(structure, pairs, i, verbose=True)
    print(structure)


Did not succeded to fill the structure with the given pairs
[[ 0.  0.  0.  0.  0.]
 [ 0.  2.  0.  0.  0.]
 [ 0.  0.  4.  0.  0.]
 [ 0.  0.  0.  4.  0.]
 [ 0.  1.  3.  2.  0.]]
Did not succeded to fill the structure with the given pairs
[[ 0.  0.  0.  0.  0.]
 [ 0.  2.  0.  0.  0.]
 [ 0.  0.  4.  0.  0.]
 [ 0.  0.  0.  4.  0.]
 [ 0.  1.  3.  2.  0.]]

In [14]:
for pairs_level in pairs_by_levels:
    print(check_node_loop(pairs_level))
    print(pairs_level)


True
[[4, 2], [3, 2], [4, 1]]
True
[[4, 3]]

In [ ]:


In [ ]: