本文整理汇总了Python中skbio.stats.composition.closure函数的典型用法代码示例。如果您正苦于以下问题:Python closure函数的具体用法?Python closure怎么用?Python closure使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了closure函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multiplicative_replacement
def test_multiplicative_replacement(self):
amat = multiplicative_replacement(closure(self.data3))
npt.assert_allclose(amat,
np.array([[0.087273, 0.174545, 0.261818,
0.04, 0.436364],
[0.092, 0.04, 0.04, 0.368, 0.46],
[0.066667, 0.133333, 0.2,
0.266667, 0.333333]]),
rtol=1e-5, atol=1e-5)
amat = multiplicative_replacement(closure(self.data4))
npt.assert_allclose(amat,
np.array([0.087273, 0.174545, 0.261818,
0.04, 0.436364]),
rtol=1e-5, atol=1e-5)
amat = multiplicative_replacement(closure(self.data6))
npt.assert_allclose(amat,
np.array([[0.087273, 0.174545, 0.261818,
0.04, 0.436364],
[0.092, 0.04, 0.04, 0.368, 0.46],
[0.066667, 0.133333, 0.2,
0.266667, 0.333333]]),
rtol=1e-5, atol=1e-5)
with self.assertRaises(ValueError):
multiplicative_replacement(self.bad1)
with self.assertRaises(ValueError):
multiplicative_replacement(self.bad2)
# make sure that inplace modification is not occurring
multiplicative_replacement(self.data4)
npt.assert_allclose(self.data4, np.array([1, 2, 3, 0, 5]))
示例2: test_clr
def test_clr(self):
cmat = clr(closure(self.data1))
A = np.array([.2, .2, .6])
B = np.array([.4, .4, .2])
npt.assert_allclose(cmat,
[np.log(A / np.exp(np.log(A).mean())),
np.log(B / np.exp(np.log(B).mean()))])
cmat = clr(closure(self.data2))
A = np.array([.2, .2, .6])
npt.assert_allclose(cmat,
np.log(A / np.exp(np.log(A).mean())))
cmat = clr(closure(self.data5))
A = np.array([.2, .2, .6])
B = np.array([.4, .4, .2])
npt.assert_allclose(cmat,
[np.log(A / np.exp(np.log(A).mean())),
np.log(B / np.exp(np.log(B).mean()))])
with self.assertRaises(ValueError):
clr(self.bad1)
with self.assertRaises(ValueError):
clr(self.bad2)
# make sure that inplace modification is not occurring
clr(self.data2)
npt.assert_allclose(self.data2, np.array([2, 2, 6]))
示例3: test_closure_warning
def test_closure_warning(self):
with self.assertRaises(ValueError):
closure([0., 0., 0.])
with self.assertRaises(ValueError):
closure([[0., 0., 0.],
[0., 5., 5.]])
示例4: setUp
def setUp(self):
data_dir = "../../data/tick/meshnick_tech_reps"
biom_file = "%s/373_otu_table.biom" % data_dir
meta_file = "%s/meta.txt" % data_dir
table = load_table(biom_file)
Z = 1
mat = np.array(table._get_sparse_data().todense()).T
x = np.ravel(mat[Z, :])
self.tick_pvals = closure(np.array(x[x > 0]))
self.uniform_pvals = closure(np.array([10000] * len(self.tick_pvals)))
self.exponential_pvals = closure(np.exp(
np.linspace(0, 4,len(self.tick_pvals))))
示例5: test_permutative_f_scaled
def test_permutative_f_scaled(self):
test_table = pd.DataFrame(
closure([[12, 11, 10, 10, 10, 10, 10],
[9, 11, 12, 10, 10, 10, 10],
[1, 11, 10, 11, 10, 5, 9],
[2, 11, 10, 11, 10, 5, 9],
[221, 210, 9, 10, 10, 10, 10],
[220, 210, 9, 10, 10, 10, 10],
[200, 220, 10, 10, 13, 10, 10],
[230, 210, 14, 10, 10, 10, 10]]),
index=['s1', 's2', 's3', 's4',
's5', 's6', 's7', 's8'],
columns=['b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7'])
test_cats = pd.Series([0, 0, 0, 0, 1, 1, 1, 1],
index=['s1', 's2', 's3', 's4',
's5', 's6', 's7', 's8'])
np.random.seed(0)
original_table = copy.deepcopy(test_table)
original_cats = copy.deepcopy(test_cats)
result = ancom(test_table, test_cats,
significance_test='permutative-anova')
# Test to make sure that the input table hasn't be altered
assert_data_frame_almost_equal(original_table, test_table)
# Test to make sure that the input table hasn't be altered
pdt.assert_series_equal(original_cats, test_cats)
exp = pd.DataFrame({'W': np.array([5, 5, 2, 2, 2, 2, 2]),
'reject': np.array([True, True, False, False,
False, False, False],
dtype=bool)},
index=['b1', 'b2', 'b3', 'b4',
'b5', 'b6', 'b7'])
assert_data_frame_almost_equal(result, exp)
示例6: test_exponential_uniform
def test_exponential_uniform(self):
samp_table = np.random.multinomial(n=500,
pvals=self.exponential_pvals)
bvals = brive(samp_table, replace_zeros=False)
rel = closure(samp_table)
m = bvals.sum()
npt.assert_array_less(rel-bvals, 1.1/500)
self.assertLess(m, 1 - robbins(samp_table))
示例7: test_centralize
def test_centralize(self):
cmat = centralize(closure(self.data1))
npt.assert_allclose(cmat,
np.array([[0.22474487, 0.22474487, 0.55051026],
[0.41523958, 0.41523958, 0.16952085]]))
cmat = centralize(closure(self.data5))
npt.assert_allclose(cmat,
np.array([[0.22474487, 0.22474487, 0.55051026],
[0.41523958, 0.41523958, 0.16952085]]))
with self.assertRaises(ValueError):
centralize(self.bad1)
with self.assertRaises(ValueError):
centralize(self.bad2)
centralize(self.data1)
npt.assert_allclose(self.data1,
np.array([[2, 2, 6],
[4, 4, 2]]))
示例8: test_power
def test_power(self):
pmat = power(closure(self.data1), 2)
npt.assert_allclose(pmat,
np.array([[.04/.44, .04/.44, .36/.44],
[.16/.36, .16/.36, .04/.36]]))
pmat = power(closure(self.data2), 2)
npt.assert_allclose(pmat, np.array([.04, .04, .36])/.44)
pmat = power(closure(self.data5), 2)
npt.assert_allclose(pmat,
np.array([[.04/.44, .04/.44, .36/.44],
[.16/.36, .16/.36, .04/.36]]))
with self.assertRaises(ValueError):
power(self.bad1, 2)
# make sure that inplace modification is not occurring
power(self.data2, 4)
npt.assert_allclose(self.data2, np.array([2, 2, 6]))
示例9: test_centralize
def test_centralize(self):
cmat = centralize(closure(self.cdata1))
npt.assert_allclose(cmat,
np.array([[0.22474487, 0.22474487, 0.55051026],
[0.41523958, 0.41523958, 0.16952085]]))
cmat = centralize(closure(self.cdata5))
npt.assert_allclose(cmat,
np.array([[0.22474487, 0.22474487, 0.55051026],
[0.41523958, 0.41523958, 0.16952085]]))
with self.assertRaises(ValueError):
centralize(self.bad1)
with self.assertRaises(ValueError):
centralize(self.bad2)
# make sure that inplace modification is not occurring
centralize(self.cdata1)
npt.assert_allclose(self.cdata1,
np.array([[2, 2, 6],
[4, 4, 2]]))
示例10: test_closure
def test_closure(self):
npt.assert_allclose(closure(self.data1),
np.array([[.2, .2, .6],
[.4, .4, .2]]))
npt.assert_allclose(closure(self.data2),
np.array([.2, .2, .6]))
npt.assert_allclose(closure(self.data5),
np.array([[.2, .2, .6],
[.4, .4, .2]]))
with self.assertRaises(ValueError):
closure(self.bad1)
with self.assertRaises(ValueError):
closure(self.bad2)
# make sure that inplace modification is not occurring
closure(self.data2)
npt.assert_allclose(self.data2, np.array([2, 2, 6]))
示例11: test_ilr_inv_basis
def test_ilr_inv_basis(self):
exp = closure(np.array([[1., 10.],
[1.14141414, 9.90909091],
[1.28282828, 9.81818182],
[1.42424242, 9.72727273],
[1.56565657, 9.63636364]]))
basis = np.array([[0.80442968, 0.19557032]])
table = np.array([[np.log(1/10)*np.sqrt(1/2),
np.log(1.14141414 / 9.90909091)*np.sqrt(1/2),
np.log(1.28282828 / 9.81818182)*np.sqrt(1/2),
np.log(1.42424242 / 9.72727273)*np.sqrt(1/2),
np.log(1.56565657 / 9.63636364)*np.sqrt(1/2)]]).T
res = ilr_inv(table, basis=basis)
npt.assert_allclose(res, exp)
示例12: test_ilr_inv
def test_ilr_inv(self):
mat = closure(self.cdata7)
npt.assert_array_almost_equal(ilr_inv(ilr(mat)), mat)
npt.assert_allclose(ilr_inv(np.identity(3)), self.ortho1,
rtol=1e-04, atol=1e-06)
with self.assertRaises(ValueError):
ilr_inv(self.cdata1, basis=self.cdata1)
# make sure that inplace modification is not occurring
ilr_inv(self.cdata1)
npt.assert_allclose(self.cdata1,
np.array([[2, 2, 6],
[4, 4, 2]]))
示例13: test_ilr
def test_ilr(self):
mat = closure(self.cdata7)
npt.assert_array_almost_equal(ilr(mat),
np.array([0.70710678, 0.40824829]))
# Should give same result as inner
npt.assert_allclose(ilr(self.ortho1), np.identity(3),
rtol=1e-04, atol=1e-06)
with self.assertRaises(ValueError):
ilr(self.cdata1, basis=self.cdata1)
# make sure that inplace modification is not occurring
ilr(self.cdata1)
npt.assert_allclose(self.cdata1,
np.array([[2, 2, 6],
[4, 4, 2]]))
示例14: test_ancom_basic_proportions
def test_ancom_basic_proportions(self):
# Converts from counts to proportions
test_table = pd.DataFrame(closure(self.table1))
original_table = copy.deepcopy(test_table)
test_cats = pd.Series(self.cats1)
original_cats = copy.deepcopy(test_cats)
result = ancom(test_table,
test_cats,
multiple_comparisons_correction=None)
# Test to make sure that the input table hasn't be altered
assert_data_frame_almost_equal(original_table, test_table)
# Test to make sure that the input table hasn't be altered
pdt.assert_series_equal(original_cats, test_cats)
exp = pd.DataFrame({'W': np.array([5, 5, 2, 2, 2, 2, 2]),
'reject': np.array([True, True, False, False,
False, False, False],
dtype=bool)})
assert_data_frame_almost_equal(result, exp)
示例15: split_balance
def split_balance(balance, tree):
""" Splits a balance into its log ratio components.
Parameters
----------
balance : pd.Series
A vector corresponding to a single balance. These values
that will be split into its numberator and denominator
components.
Returns
-------
pd.DataFrame
Dataframe where the first column contains the numerator and the
second column contains the denominator of the balance.
Note
----
The balance must have a name associated with it.
"""
node = tree.find(balance.name)
if node.is_tip():
raise ValueError("%s is not a balance." % balance.name)
left = node.children[0]
right = node.children[1]
if left.is_tip():
L = 1
else:
L = len([n for n in left.tips()])
if right.is_tip():
R = 1
else:
R = len([n for n in right.tips()])
b = np.expand_dims(balance.values, axis=1)
# need to scale down by the number of children in subtrees
b = np.exp(b / (np.sqrt((L*R) / (L + R))))
o = np.ones((len(b), 1))
k = np.hstack((b, o))
p = closure(k)
return pd.DataFrame(p, columns=[left.name, right.name],
index=balance.index)