def test_ilr(self):
     np.random.seed(0)
     table = pd.DataFrame([[1, 1, 2, 2], [1, 2, 2, 1], [2, 2, 1, 1]],
                          index=[1, 2, 3],
                          columns=['a', 'b', 'c', 'd'])
     table = table.reindex(columns=np.random.permutation(table.columns))
     ph = pd.Series([1, 2, 3], index=table.index)
     tree = gradient_linkage(table, ph)
     res_balances = ilr_transform(table, tree)
     exp_balances = pd.DataFrame([[0.693147, -5.551115e-17, 2.775558e-17],
                                  [0.000000, -4.901291e-01, -4.901291e-01],
                                  [-0.693147, 5.551115e-17, -2.775558e-17]],
                                 columns=['y0', 'y1', 'y2'],
                                 index=[1, 2, 3])
     pdt.assert_frame_equal(res_balances, exp_balances)
Exemple #2
0
 def test_ilr(self):
     np.random.seed(0)
     table = pd.DataFrame([[1, 1, 2, 2],
                           [1, 2, 2, 1],
                           [2, 2, 1, 1]],
                          index=[1, 2, 3],
                          columns=['a', 'b', 'c', 'd'])
     table = table.reindex(columns=np.random.permutation(table.columns))
     ph = pd.Series([1, 2, 3], index=table.index)
     tree = gradient_linkage(table, ph)
     res_balances = ilr_transform(table, tree)
     exp_balances = pd.DataFrame(
         [[0.693147, -5.551115e-17, 2.775558e-17],
          [0.000000, -4.901291e-01, -4.901291e-01],
          [-0.693147, 5.551115e-17, -2.775558e-17]],
         columns=['y0', 'y1', 'y2'],
         index=[1, 2, 3])
     pdt.assert_frame_equal(res_balances, exp_balances)