def testLast(self): clst1 = DPCluster(0.5, self.mu1, self.sig) clst3 = DPCluster(0.5, self.mu1 + 3, self.sig) clst5 = DPCluster(0.5, self.mu1 + 5, self.sig) clst7 = DPCluster(0.5, self.mu1 + 7, self.sig) clst2 = DPCluster(0.5, self.mu2 + 2, self.sig) clst4 = DPCluster(0.5, self.mu2 + 4, self.sig) clst6 = DPCluster(0.5, self.mu2 + 6, self.sig) clst8 = DPCluster(0.5, self.mu2 + 8, self.sig) mix = DPMixture( [clst1, clst2, clst3, clst4, clst5, clst6, clst7, clst8], niter=4) new_r = mix.last() assert len(new_r.clusters) == 2 assert all(new_r.clusters[0].mu == clst7.mu) assert all(new_r.clusters[1].mu == clst8.mu) new_r = mix.last(2) assert len(new_r.clusters) == 4 assert all(new_r.clusters[0].mu == clst5.mu) assert all(new_r.clusters[1].mu == clst6.mu) assert all(new_r.clusters[2].mu == clst7.mu) assert all(new_r.clusters[3].mu == clst8.mu) try: new_r = mix.last(10) except ValueError: pass
def test_average(self): cluster1 = DPCluster(0.5, self.mu1, self.sig) cluster3 = DPCluster(0.5, self.mu1, self.sig) cluster5 = DPCluster(0.5, self.mu1, self.sig) cluster7 = DPCluster(0.5, self.mu1, self.sig) cluster2 = DPCluster(0.5, self.mu2, self.sig) cluster4 = DPCluster(0.5, self.mu2, self.sig) cluster6 = DPCluster(0.5, self.mu2, self.sig) cluster8 = DPCluster(0.5, self.mu2, self.sig) mix = DPMixture( [ cluster1, cluster2, cluster3, cluster4, cluster5, cluster6, cluster7, cluster8 ], niter=4) avg = mix.average() assert len(avg.clusters) == 2 assert all(avg.mus[0] == self.mu1) assert all(avg.mus[1] == self.mu2) assert all(avg.sigmas[0] == self.sig) assert all(avg.sigmas[1] == self.sig) assert avg.pis[0] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0] assert avg.pis[1] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0]
def test_last(self): cluster1 = DPCluster(0.5, self.mu1, self.sig) cluster3 = DPCluster(0.5, self.mu1 + 3, self.sig) cluster5 = DPCluster(0.5, self.mu1 + 5, self.sig) cluster7 = DPCluster(0.5, self.mu1 + 7, self.sig) cluster2 = DPCluster(0.5, self.mu2 + 2, self.sig) cluster4 = DPCluster(0.5, self.mu2 + 4, self.sig) cluster6 = DPCluster(0.5, self.mu2 + 6, self.sig) cluster8 = DPCluster(0.5, self.mu2 + 8, self.sig) mix = DPMixture([ cluster1, cluster2, cluster3, cluster4, cluster5, cluster6, cluster7, cluster8 ], niter=4) new_r = mix.last() assert len(new_r.clusters) == 2 assert all(new_r.clusters[0].mu == cluster7.mu) assert all(new_r.clusters[1].mu == cluster8.mu) new_r = mix.last(2) assert len(new_r.clusters) == 4 assert all(new_r.clusters[0].mu == cluster5.mu) assert all(new_r.clusters[1].mu == cluster6.mu) assert all(new_r.clusters[2].mu == cluster7.mu) assert all(new_r.clusters[3].mu == cluster8.mu)
def testLast(self): clst1 = DPCluster(0.5, self.mu1, self.sig) clst3 = DPCluster(0.5, self.mu1 + 3, self.sig) clst5 = DPCluster(0.5, self.mu1 + 5, self.sig) clst7 = DPCluster(0.5, self.mu1 + 7, self.sig) clst2 = DPCluster(0.5, self.mu2 + 2, self.sig) clst4 = DPCluster(0.5, self.mu2 + 4, self.sig) clst6 = DPCluster(0.5, self.mu2 + 6, self.sig) clst8 = DPCluster(0.5, self.mu2 + 8, self.sig) mix = DPMixture([clst1, clst2, clst3, clst4, clst5, clst6, clst7, clst8], niter=4) new_r = mix.last() assert len(new_r.clusters) == 2 assert all(new_r.clusters[0].mu == clst7.mu) assert all(new_r.clusters[1].mu == clst8.mu) new_r = mix.last(2) assert len(new_r.clusters) == 4 assert all(new_r.clusters[0].mu == clst5.mu) assert all(new_r.clusters[1].mu == clst6.mu) assert all(new_r.clusters[2].mu == clst7.mu) assert all(new_r.clusters[3].mu == clst8.mu) try: new_r = mix.last(10) except ValueError: pass
def test_last(self): cluster1 = DPCluster(0.5, self.mu1, self.sig) cluster3 = DPCluster(0.5, self.mu1 + 3, self.sig) cluster5 = DPCluster(0.5, self.mu1 + 5, self.sig) cluster7 = DPCluster(0.5, self.mu1 + 7, self.sig) cluster2 = DPCluster(0.5, self.mu2 + 2, self.sig) cluster4 = DPCluster(0.5, self.mu2 + 4, self.sig) cluster6 = DPCluster(0.5, self.mu2 + 6, self.sig) cluster8 = DPCluster(0.5, self.mu2 + 8, self.sig) mix = DPMixture( [ cluster1, cluster2, cluster3, cluster4, cluster5, cluster6, cluster7, cluster8 ], niter=4) new_r = mix.last() assert len(new_r.clusters) == 2 assert all(new_r.clusters[0].mu == cluster7.mu) assert all(new_r.clusters[1].mu == cluster8.mu) new_r = mix.last(2) assert len(new_r.clusters) == 4 assert all(new_r.clusters[0].mu == cluster5.mu) assert all(new_r.clusters[1].mu == cluster6.mu) assert all(new_r.clusters[2].mu == cluster7.mu) assert all(new_r.clusters[3].mu == cluster8.mu)
def setUp(self): self.mu1 = array([0, 0, 0]) self.sig = eye(3) self.mu2 = array([5, 5, 5]) self.clst1 = DPCluster(.5, self.mu1, self.sig) self.clst2 = DPCluster(.5, self.mu2, self.sig) self.mix = DPMixture([self.clst1, self.clst2])
def setUp(self): mus = np.array([[0, 0], [0, 10], [10, 0], [10, 10]]) sigmas = np.array([np.eye(2), np.eye(2), np.eye(2), np.eye(2)]) pis = np.array([1.0 / 3, 1.0 / 3, 1.0 / 3, 1.0 / 3]) clusters = [DPCluster(i, j, k) for i, j, k in zip(pis, mus, sigmas)] self.mx = DPMixture(clusters[0:]).get_submodel([0, 1, 2, 3]) self.my = DPMixture(clusters[1:])
def setUp(self): self.mu1 = array([0, 0, 0]) self.sig = eye(3) self.mu2 = array([5, 5, 5]) self.cluster1 = DPCluster(.5 / 3, self.mu1, self.sig) self.cluster2 = DPCluster(.5 / 3, self.mu2, self.sig) self.clusters = [ self.cluster1, self.cluster2, self.cluster1, self.cluster2, self.cluster1, self.cluster2 ] self.mix = DPMixture(self.clusters, niter=3, identified=True)
def testBiasSubsample(self): neg_mu = array([0, 1, 2]) pos_mu = array([3, 4, 5]) sig = array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) neg_cluster = DPCluster(1.0, neg_mu, sig) neg_mix = DPMixture([neg_cluster]) pos_cluster0 = DPCluster(0.5, neg_mu, sig) pos_cluster1 = DPCluster(0.5, pos_mu, sig) pos_mix = DPMixture([pos_cluster0, pos_cluster1]) self.fcm.subsample(1, 'bias', pos=pos_mix, neg=neg_mix) self.assertEqual(1, self.fcm.shape[0], 'bias subsampling failed') self.assertTrue(self.fcm[0] in self.pnts, 'bias subsample geneterated non-existant point')
def setUp(self): self.mux = np.array([0, 0, 0]) self.sigx = 2 * np.eye(3) self.muy = np.array([0, .5, .5]) self.sigy = np.eye(3) self.clustx = DPCluster(1, self.mux, self.sigx) self.clustersx = [self.clustx] self.clusty = DPCluster(1, self.muy, self.sigy) self.clustersy = [self.clusty] self.x = DPMixture(self.clustersx, niter=1, identified=True) self.y = DPMixture(self.clustersy, niter=1, identified=True)
def testAnomalySubsample(self): mu = array([0, 1, 2]) sig = array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) cluster = DPCluster(1.0, mu, sig) mix = DPMixture([cluster]) self.fcm.subsample(1, 'anomaly', mix) self.assertEqual(1, self.fcm.shape[0], 'anomaly subsampling failed') self.assertTrue(self.fcm[0] in self.pnts, 'anomaly subsample geneterated non-existant point')
def setUp(self): self.mu1 = array([0, 0, 0]) self.sig = eye(3) self.mu2 = array([5, 5, 5]) self.clust1 = DPCluster(.5 / 3, self.mu1, self.sig) self.clust2 = DPCluster(.5 / 3, self.mu2, self.sig) self.clusters = [self.clust1, self.clust2, self.clust1, self.clust2, self.clust1, self.clust2] self.mix = DPMixture(self.clusters, niter=3, identified=True)
def testAverage(self): clst1 = DPCluster(0.5, self.mu1, self.sig) clst3 = DPCluster(0.5, self.mu1, self.sig) clst5 = DPCluster(0.5, self.mu1, self.sig) clst7 = DPCluster(0.5, self.mu1, self.sig) clst2 = DPCluster(0.5, self.mu2, self.sig) clst4 = DPCluster(0.5, self.mu2, self.sig) clst6 = DPCluster(0.5, self.mu2, self.sig) clst8 = DPCluster(0.5, self.mu2, self.sig) mix = DPMixture([clst1, clst2, clst3, clst4, clst5, clst6, clst7, clst8], niter=4) avg = mix.average() assert len(avg.clusters) == 2 assert all(avg.mus[0] == self.mu1) assert all(avg.mus[1] == self.mu2) assert all(avg.sigmas[0] == self.sig) assert all(avg.sigmas[1] == self.sig) assert avg.pis[0] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0] assert avg.pis[1] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0]
def testAverage(self): clst1 = DPCluster(0.5, self.mu1, self.sig) clst3 = DPCluster(0.5, self.mu1, self.sig) clst5 = DPCluster(0.5, self.mu1, self.sig) clst7 = DPCluster(0.5, self.mu1, self.sig) clst2 = DPCluster(0.5, self.mu2, self.sig) clst4 = DPCluster(0.5, self.mu2, self.sig) clst6 = DPCluster(0.5, self.mu2, self.sig) clst8 = DPCluster(0.5, self.mu2, self.sig) mix = DPMixture( [clst1, clst2, clst3, clst4, clst5, clst6, clst7, clst8], niter=4) avg = mix.average() assert len(avg.clusters) == 2 assert all(avg.mus[0] == self.mu1) assert all(avg.mus[1] == self.mu2) assert all(avg.sigmas[0] == self.sig) assert all(avg.sigmas[1] == self.sig) assert avg.pis[0] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0] assert avg.pis[1] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0]
def testClassify(self): from fcm.statistics import DPCluster, DPMixture mu1 = array([0, 0, 0]) sig = eye(3) mu2 = array([5, 5, 5]) clst1 = DPCluster(.5, mu1, sig) clst2 = DPCluster(.5, mu2, sig) mix = DPMixture([clst1, clst2]) cls = self.fcms.classify(mix) assert_array_equal(cls['test_fcm1'], array([0, 1]), 'Calssify failed') assert_array_equal(cls['test_fcm2'], array([0, 1]), 'Calssify failed')
def setUp(self): self.mu1 = np.array([0, 0, 0]) self.sig = 2 * np.eye(3) self.mu2 = np.array([5, 5, 5]) self.clust1 = DPCluster(.5, self.mu1, self.sig) self.clust2 = DPCluster(.5, self.mu2, self.sig) self.clusters = [self.clust1, self.clust2] self.x = DPMixture(self.clusters, niter=1, identified=True) self.diag = DiagonalAlignData(self.x, size=100000) self.comp = CompAlignData(self.x, size=100000) self.full = FullAlignData(self.x, size=200000)
def test_average(self): cluster1 = DPCluster(0.5, self.mu1, self.sig) cluster3 = DPCluster(0.5, self.mu1, self.sig) cluster5 = DPCluster(0.5, self.mu1, self.sig) cluster7 = DPCluster(0.5, self.mu1, self.sig) cluster2 = DPCluster(0.5, self.mu2, self.sig) cluster4 = DPCluster(0.5, self.mu2, self.sig) cluster6 = DPCluster(0.5, self.mu2, self.sig) cluster8 = DPCluster(0.5, self.mu2, self.sig) mix = DPMixture([ cluster1, cluster2, cluster3, cluster4, cluster5, cluster6, cluster7, cluster8 ], niter=4) avg = mix.average() assert len(avg.clusters) == 2 assert all(avg.mus[0] == self.mu1) assert all(avg.mus[1] == self.mu2) assert all(avg.sigmas[0] == self.sig) assert all(avg.sigmas[1] == self.sig) assert avg.pis[0] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0] assert avg.pis[1] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0]
class DPMixtureTestCase(unittest.TestCase): def setUp(self): self.mu1 = array([0, 0, 0]) self.sig = eye(3) self.mu2 = array([5, 5, 5]) self.cluster1 = DPCluster(.5 / 3, self.mu1, self.sig) self.cluster2 = DPCluster(.5 / 3, self.mu2, self.sig) self.clusters = [ self.cluster1, self.cluster2, self.cluster1, self.cluster2, self.cluster1, self.cluster2 ] self.mix = DPMixture(self.clusters, niter=3, identified=True) def tearDown(self): pass def test_prob(self): pnt = array([[1, 1, 1]]) for i in [self.cluster1, self.cluster2]: assert i.prob(pnt) <= 1, 'prob of cluster %s is > 1' % i assert i.prob(pnt) >= 0, 'prob of cluster %s is < 0' % i def test_mix_prob(self): pnt = array([1, 1, 1]) assert self.mix.prob(pnt)[0] == \ self.cluster1.prob(pnt), \ 'mixture generates different prob then component 1' assert self.mix.prob(pnt)[1] == \ self.cluster2.prob(pnt), \ 'mixture generates different prob then component 2' def test_classify(self): pnt = array([self.mu1, self.mu2]) assert self.mix.classify(pnt)[0] == \ 0, \ 'classify classifies mu1 as belonging to something else' assert self.mix.classify(pnt)[1] == \ 1, \ 'classify classifies m21 as belonging to something else' def test_make_modal(self): modal = self.mix.make_modal() assert modal.classify( array([self.mu1, self.mu2, self.mu1, self.mu2, self.mu1, self.mu2])).tolist() == [1, 0, 1, 0, 1, 0], 'classify not working' #TODO do actual lookup. modal = self.mix.make_modal(delta=9) assert modal.classify( array([self.mu1, self.mu2, self.mu1, self.mu2, self.mu1, self.mu2])).tolist() == [0, 0, 0, 0, 0, 0], 'classify not working' def test_average(self): cluster1 = DPCluster(0.5, self.mu1, self.sig) cluster3 = DPCluster(0.5, self.mu1, self.sig) cluster5 = DPCluster(0.5, self.mu1, self.sig) cluster7 = DPCluster(0.5, self.mu1, self.sig) cluster2 = DPCluster(0.5, self.mu2, self.sig) cluster4 = DPCluster(0.5, self.mu2, self.sig) cluster6 = DPCluster(0.5, self.mu2, self.sig) cluster8 = DPCluster(0.5, self.mu2, self.sig) mix = DPMixture([ cluster1, cluster2, cluster3, cluster4, cluster5, cluster6, cluster7, cluster8 ], niter=4) avg = mix.average() assert len(avg.clusters) == 2 assert all(avg.mus[0] == self.mu1) assert all(avg.mus[1] == self.mu2) assert all(avg.sigmas[0] == self.sig) assert all(avg.sigmas[1] == self.sig) assert avg.pis[0] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0] assert avg.pis[1] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0] def test_last(self): cluster1 = DPCluster(0.5, self.mu1, self.sig) cluster3 = DPCluster(0.5, self.mu1 + 3, self.sig) cluster5 = DPCluster(0.5, self.mu1 + 5, self.sig) cluster7 = DPCluster(0.5, self.mu1 + 7, self.sig) cluster2 = DPCluster(0.5, self.mu2 + 2, self.sig) cluster4 = DPCluster(0.5, self.mu2 + 4, self.sig) cluster6 = DPCluster(0.5, self.mu2 + 6, self.sig) cluster8 = DPCluster(0.5, self.mu2 + 8, self.sig) mix = DPMixture([ cluster1, cluster2, cluster3, cluster4, cluster5, cluster6, cluster7, cluster8 ], niter=4) new_r = mix.last() assert len(new_r.clusters) == 2 assert all(new_r.clusters[0].mu == cluster7.mu) assert all(new_r.clusters[1].mu == cluster8.mu) new_r = mix.last(2) assert len(new_r.clusters) == 4 assert all(new_r.clusters[0].mu == cluster5.mu) assert all(new_r.clusters[1].mu == cluster6.mu) assert all(new_r.clusters[2].mu == cluster7.mu) assert all(new_r.clusters[3].mu == cluster8.mu) def test_draw(self): x = self.mix.draw(10) assert x.shape[0] == 10, "Number of drawed rows is wrong" assert x.shape[1] == 3, "number of drawed columns is wrong" def test_arithmetic(self): adder = 3 array_adder = array([1, 2, 3]) mat_adder = 2 * eye(3) # add b = self.mix + adder self.assertIsInstance(b, DPMixture, 'integer addition return wrong type') assert_equal(b.mus[0], self.mix.mus[0] + adder, 'integer addition returned wrong value') c = self.mix + array_adder self.assertIsInstance(c, DPMixture, 'array addition return wrong type') assert_array_equal(c.mus[0], self.mix.mus[0] + array_adder, 'array addition returned wrong value') # radd b = adder + self.mix self.assertIsInstance(b, DPMixture, 'integer addition return wrong type') assert_array_equal(b.mus[0], adder + self.mix.mus[0], 'integer addition returned wrong value') c = array_adder + self.mix self.assertIsInstance(c, DPMixture, 'array addition return wrong type') assert_array_equal(c.mus[0], array_adder + self.mix.mus[0], 'array addition returned wrong value') # sub b = self.mix - adder self.assertIsInstance(b, DPMixture, 'integer subtraction return wrong type') assert_array_equal(b.mus[0], self.mix.mus[0] - adder, 'integer subtraction returned wrong value') c = self.mix - array_adder self.assertIsInstance(c, DPMixture, 'array subtraction return wrong type') assert_array_equal(c.mus[0], self.mix.mus[0] - array_adder, 'array subtraction returned wrong value') # rsub b = adder - self.mix self.assertIsInstance(b, DPMixture, 'integer subtraction return wrong type') assert_array_equal(b.mus[0], adder - self.mix.mus[0], 'integer subtraction returned wrong value') c = array_adder - self.mix self.assertIsInstance(c, DPMixture, 'array subtraction return wrong type') assert_array_equal(c.mus[0], array_adder - self.mix.mus[0], 'array subtraction returned wrong value') # mul b = self.mix * adder self.assertIsInstance(b, DPMixture, 'integer multiplication return wrong type') assert_array_equal(b.mus[0], self.mix.mus[0] * adder, 'integer multiplication returned wrong value') c = self.mix * array_adder self.assertIsInstance(c, DPMixture, 'array multiplication return wrong type') assert_array_equal(c.mus[0], dot(self.mix.mus[0], array_adder), 'array multiplication returned wrong value') d = self.mix * mat_adder self.assertIsInstance(d, DPMixture, 'array multiplication return wrong type') assert_array_equal(d.mus[0], dot(self.mix.mus[0], mat_adder), 'array multiplication returned wrong value') # rmul b = adder * self.mix self.assertIsInstance(b, DPMixture, 'integer multiplication return wrong type') assert_array_equal(b.mus[0], adder * self.mix.mus[0], 'integer multiplication returned wrong value') c = array_adder * self.mix self.assertIsInstance(c, DPMixture, 'array multiplication return wrong type') assert_array_equal(c.mus[0], dot(array_adder, self.mix.mus[0]), 'array multiplication returned wrong value') d = mat_adder * self.mix self.assertIsInstance(d, DPMixture, 'array multiplication return wrong type') assert_array_equal(d.mus[0], dot(mat_adder, self.mix.mus[0]), 'array multiplication returned wrong value') assert_array_equal(d.sigmas[0], dot(mat_adder, dot(self.mix.sigmas[0], mat_adder)), 'array multiplication failed') def test_get_item(self): assert_equal(self.mu1, self.mix[0].mu, 'getitem failed') self.mix[0] = self.cluster2 assert_equal(self.mu2, self.mix[0].mu, 'getitem failed') self.mix[0] = self.cluster1 def test_get_iteration(self): self.assertIsInstance(self.mix.get_iteration(2), DPMixture, 'get_iteration failed') self.assertEqual(len(self.mix.get_iteration(2).clusters), 2, 'get_iteration return wrong number of clusters') self.assertIsInstance(self.mix.get_iteration([0, 2]), DPMixture, 'get_iteration failed') self.assertEqual(len(self.mix.get_iteration([0, 2]).clusters), 4, 'get_iteration return wrong number of clusters') def test_enumerate_clusters(self): for i, j in self.mix.enumerate_clusters(): self.assertIsInstance(i, int) self.assertIs( j, self.mix[i], 'failed to return the right cluster when enumerating') def test_enumerate_pis(self): for i, j in self.mix.enumerate_pis(): self.assertIsInstance(i, int) self.assertIs(j, self.mix[i].pi, 'failed to return the right pi when enumerating') def test_enumerate_mus(self): for i, j in self.mix.enumerate_mus(): self.assertIsInstance(i, int) self.assertIs(j, self.mix[i].mu, 'failed to return the right mean when enumerating') def test_enumerate_sigmas(self): for i, j in self.mix.enumerate_sigmas(): self.assertIsInstance(i, int) self.assertIs( j, self.mix[i].sigma, 'failed to return the right covariance when enumerating')
class Dp_mixtureTestCase(unittest.TestCase): def setUp(self): self.mu1 = array([0, 0, 0]) self.sig = eye(3) self.mu2 = array([5, 5, 5]) self.clust1 = DPCluster(.5 / 3, self.mu1, self.sig) self.clust2 = DPCluster(.5 / 3, self.mu2, self.sig) self.clusters = [self.clust1, self.clust2, self.clust1, self.clust2, self.clust1, self.clust2] self.mix = DPMixture(self.clusters, niter=3, identified=True) def tearDown(self): pass def testprob(self): pnt = array([[1, 1, 1]]) print pnt.shape for i in [self.clust1, self.clust2]: print i.prob(pnt) assert i.prob(pnt) <= 1, 'prob of clst %s is > 1' % i assert i.prob(pnt) >= 0, 'prob of clst %s is < 0' % i def testmixprob(self): pnt = array([1, 1, 1]) assert self.mix.prob(pnt)[0] == self.clust1.prob(pnt), 'mixture generates different prob then compoent 1' assert self.mix.prob(pnt)[1] == self.clust2.prob(pnt), 'mixture generates different prob then compoent 2' def testclassify(self): pnt = array([self.mu1, self.mu2]) assert self.mix.classify(pnt)[0] == 0, 'classify classifys mu1 as belonging to something else' assert self.mix.classify(pnt)[1] == 1, 'classify classifys m21 as belonging to something else' def testMakeModal(self): modal = self.mix.make_modal() # modal = ModalDPMixture([self.clst1, self.clst2], # { 0: [0], 1: [1]}, # [self.mu1, self.mu2]) pnt = array([self.mu1, self.mu2]) assert modal.classify(array([self.mu1, self.mu2, self.mu1, self.mu2, self.mu1, self.mu2])).tolist() == [1, 0, 1, 0, 1, 0], 'classify not working' # TODO do actual lookup. # assert self.mix.classify(self.mu1) == modal.classify(self.mu1), 'derived modal mixture is wrong' # assert self.mix.classify(pnt)[0] == modal.classify(pnt)[0], 'derived modal mixture is wrong' # assert self.mix.classify(pnt)[1] == modal.classify(pnt)[1], 'derived modal mixture is wrong' modal = self.mix.make_modal(delta=9) assert modal.classify(array([self.mu1, self.mu2, self.mu1, self.mu2, self.mu1, self.mu2])).tolist() == [0, 0, 0, 0, 0, 0], 'classify not working' def testAverage(self): clst1 = DPCluster(0.5, self.mu1, self.sig) clst3 = DPCluster(0.5, self.mu1, self.sig) clst5 = DPCluster(0.5, self.mu1, self.sig) clst7 = DPCluster(0.5, self.mu1, self.sig) clst2 = DPCluster(0.5, self.mu2, self.sig) clst4 = DPCluster(0.5, self.mu2, self.sig) clst6 = DPCluster(0.5, self.mu2, self.sig) clst8 = DPCluster(0.5, self.mu2, self.sig) mix = DPMixture([clst1, clst2, clst3, clst4, clst5, clst6, clst7, clst8], niter=4) avg = mix.average() assert len(avg.clusters) == 2 assert all(avg.mus[0] == self.mu1) assert all(avg.mus[1] == self.mu2) assert all(avg.sigmas[0] == self.sig) assert all(avg.sigmas[1] == self.sig) assert avg.pis[0] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0] assert avg.pis[1] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0] def testLast(self): clst1 = DPCluster(0.5, self.mu1, self.sig) clst3 = DPCluster(0.5, self.mu1 + 3, self.sig) clst5 = DPCluster(0.5, self.mu1 + 5, self.sig) clst7 = DPCluster(0.5, self.mu1 + 7, self.sig) clst2 = DPCluster(0.5, self.mu2 + 2, self.sig) clst4 = DPCluster(0.5, self.mu2 + 4, self.sig) clst6 = DPCluster(0.5, self.mu2 + 6, self.sig) clst8 = DPCluster(0.5, self.mu2 + 8, self.sig) mix = DPMixture([clst1, clst2, clst3, clst4, clst5, clst6, clst7, clst8], niter=4) new_r = mix.last() assert len(new_r.clusters) == 2 assert all(new_r.clusters[0].mu == clst7.mu) assert all(new_r.clusters[1].mu == clst8.mu) new_r = mix.last(2) assert len(new_r.clusters) == 4 assert all(new_r.clusters[0].mu == clst5.mu) assert all(new_r.clusters[1].mu == clst6.mu) assert all(new_r.clusters[2].mu == clst7.mu) assert all(new_r.clusters[3].mu == clst8.mu) try: new_r = mix.last(10) except ValueError: pass def testDraw(self): x = self.mix.draw(10) assert x.shape[0] == 10, "Number of drawed rows is wrong" assert x.shape[1] == 3, "number of drawed columns is wrong" def testarith(self): adder = 3 array_adder = array([1, 2, 3]) mat_adder = 2 * eye(3) # add b = self.mix + adder self.assertIsInstance(b, DPMixture, 'integer addition return wrong type') assert_equal(b.mus[0], self.mix.mus[0] + adder, 'integer addition returned wrong value') c = self.mix + array_adder self.assertIsInstance(c, DPMixture, 'array addition return wrong type') assert_array_equal(c.mus[0], self.mix.mus[0] + array_adder, 'array addition returned wrong value') # radd b = adder + self.mix self.assertIsInstance(b, DPMixture, 'integer addition return wrong type') assert_array_equal(b.mus[0], adder + self.mix.mus[0], 'integer addition returned wrong value') c = array_adder + self.mix self.assertIsInstance(c, DPMixture, 'array addition return wrong type') assert_array_equal(c.mus[0], array_adder + self.mix.mus[0], 'array addition returned wrong value') # sub b = self.mix - adder self.assertIsInstance(b, DPMixture, 'integer subtraction return wrong type') assert_array_equal(b.mus[0], self.mix.mus[0] - adder, 'integer subtraction returned wrong value') c = self.mix - array_adder self.assertIsInstance(c, DPMixture, 'array subtraction return wrong type') assert_array_equal(c.mus[0], self.mix.mus[0] - array_adder, 'array subtraction returned wrong value') # rsub b = adder - self.mix self.assertIsInstance(b, DPMixture, 'integer subtraction return wrong type') assert_array_equal(b.mus[0], adder - self.mix.mus[0], 'integer subtraction returned wrong value') c = array_adder - self.mix self.assertIsInstance(c, DPMixture, 'array subtraction return wrong type') assert_array_equal(c.mus[0], array_adder - self.mix.mus[0], 'array subtraction returned wrong value') # mul b = self.mix * adder self.assertIsInstance(b, DPMixture, 'integer multiplication return wrong type') assert_array_equal(b.mus[0], self.mix.mus[0] * adder, 'integer multiplication returned wrong value') c = self.mix * array_adder self.assertIsInstance(c, DPMixture, 'array multiplicaton return wrong type') assert_array_equal(c.mus[0], dot(self.mix.mus[0], array_adder), 'array multiplication returned wrong value') d = self.mix * mat_adder self.assertIsInstance(d, DPMixture, 'array multiplicaton return wrong type') assert_array_equal(d.mus[0], dot(self.mix.mus[0], mat_adder), 'array multiplication returned wrong value') # rmul b = adder * self.mix self.assertIsInstance(b, DPMixture, 'integer multiplication return wrong type') assert_array_equal(b.mus[0], adder * self.mix.mus[0], 'integer multiplication returned wrong value') c = array_adder * self.mix self.assertIsInstance(c, DPMixture, 'array multiplication return wrong type') assert_array_equal(c.mus[0], dot(array_adder, self.mix.mus[0]), 'array multiplication returned wrong value') d = mat_adder * self.mix self.assertIsInstance(d, DPMixture, 'array multiplicaton return wrong type') assert_array_equal(d.mus[0], dot(mat_adder, self.mix.mus[0]), 'array multiplication returned wrong value') assert_array_equal(d.sigmas[0], dot(mat_adder, dot(self.mix.sigmas[0], mat_adder)), 'array multiplcation failed') def testgetitem(self): assert_equal(self.mu1, self.mix[0].mu, 'getitem failed') self.mix[0] = self.clust2 assert_equal(self.mu2, self.mix[0].mu, 'getitem failed') self.mix[0] = self.clust1 def testgetiteration(self): self.assertIsInstance(self.mix.get_iteration(2), DPMixture, 'get_iteration failed') self.assertEqual(len(self.mix.get_iteration(2).clusters), 2, 'get_iteration return wrong number of clusters') self.assertIsInstance(self.mix.get_iteration([0, 2]), DPMixture, 'get_iteration failed') self.assertEqual(len(self.mix.get_iteration([0, 2]).clusters), 4, 'get_iteration return wrong number of clusters') def testEnumerateClusters(self): for i, j in self.mix.enumerate_clusters(): self.assertIsInstance(i, int) self.assertIs(j, self.mix[i], 'fialed to return the right cluster when enumerating') def testEnumeratePis(self): for i, j in self.mix.enumerate_pis(): self.assertIsInstance(i, int) self.assertIs(j, self.mix[i].pi, 'fialed to return the right pi when enumerating') def testEnumerateMus(self): for i, j in self.mix.enumerate_mus(): self.assertIsInstance(i, int) self.assertIs(j, self.mix[i].mu, 'fialed to return the right mean when enumerating') def testEnumerateSigmas(self): for i, j in self.mix.enumerate_sigmas(): self.assertIsInstance(i, int) self.assertIs(j, self.mix[i].sigma, 'fialed to return the right covariance when enumerating')
class Dp_mixtureTestCase(unittest.TestCase): def setUp(self): self.mu1 = array([0, 0, 0]) self.sig = eye(3) self.mu2 = array([5, 5, 5]) self.clust1 = DPCluster(.5 / 3, self.mu1, self.sig) self.clust2 = DPCluster(.5 / 3, self.mu2, self.sig) self.clusters = [ self.clust1, self.clust2, self.clust1, self.clust2, self.clust1, self.clust2 ] self.mix = DPMixture(self.clusters, niter=3, identified=True) def tearDown(self): pass def testprob(self): pnt = array([[1, 1, 1]]) print pnt.shape for i in [self.clust1, self.clust2]: print i.prob(pnt) assert i.prob(pnt) <= 1, 'prob of clst %s is > 1' % i assert i.prob(pnt) >= 0, 'prob of clst %s is < 0' % i def testmixprob(self): pnt = array([1, 1, 1]) assert self.mix.prob(pnt)[0] == self.clust1.prob( pnt), 'mixture generates different prob then compoent 1' assert self.mix.prob(pnt)[1] == self.clust2.prob( pnt), 'mixture generates different prob then compoent 2' def testclassify(self): pnt = array([self.mu1, self.mu2]) assert self.mix.classify(pnt)[ 0] == 0, 'classify classifys mu1 as belonging to something else' assert self.mix.classify(pnt)[ 1] == 1, 'classify classifys m21 as belonging to something else' def testMakeModal(self): modal = self.mix.make_modal() # modal = ModalDPMixture([self.clst1, self.clst2], # { 0: [0], 1: [1]}, # [self.mu1, self.mu2]) pnt = array([self.mu1, self.mu2]) assert modal.classify( array([self.mu1, self.mu2, self.mu1, self.mu2, self.mu1, self.mu2])).tolist() in [[1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]], 'classify not working' # TODO do actual lookup. # assert self.mix.classify(self.mu1) == modal.classify(self.mu1), 'derived modal mixture is wrong' # assert self.mix.classify(pnt)[0] == modal.classify(pnt)[0], 'derived modal mixture is wrong' # assert self.mix.classify(pnt)[1] == modal.classify(pnt)[1], 'derived modal mixture is wrong' modal = self.mix.make_modal(delta=9) assert modal.classify( array([self.mu1, self.mu2, self.mu1, self.mu2, self.mu1, self.mu2])).tolist() == [0, 0, 0, 0, 0, 0], 'classify not working' def testAverage(self): clst1 = DPCluster(0.5, self.mu1, self.sig) clst3 = DPCluster(0.5, self.mu1, self.sig) clst5 = DPCluster(0.5, self.mu1, self.sig) clst7 = DPCluster(0.5, self.mu1, self.sig) clst2 = DPCluster(0.5, self.mu2, self.sig) clst4 = DPCluster(0.5, self.mu2, self.sig) clst6 = DPCluster(0.5, self.mu2, self.sig) clst8 = DPCluster(0.5, self.mu2, self.sig) mix = DPMixture( [clst1, clst2, clst3, clst4, clst5, clst6, clst7, clst8], niter=4) avg = mix.average() assert len(avg.clusters) == 2 assert all(avg.mus[0] == self.mu1) assert all(avg.mus[1] == self.mu2) assert all(avg.sigmas[0] == self.sig) assert all(avg.sigmas[1] == self.sig) assert avg.pis[0] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0] assert avg.pis[1] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0] def testLast(self): clst1 = DPCluster(0.5, self.mu1, self.sig) clst3 = DPCluster(0.5, self.mu1 + 3, self.sig) clst5 = DPCluster(0.5, self.mu1 + 5, self.sig) clst7 = DPCluster(0.5, self.mu1 + 7, self.sig) clst2 = DPCluster(0.5, self.mu2 + 2, self.sig) clst4 = DPCluster(0.5, self.mu2 + 4, self.sig) clst6 = DPCluster(0.5, self.mu2 + 6, self.sig) clst8 = DPCluster(0.5, self.mu2 + 8, self.sig) mix = DPMixture( [clst1, clst2, clst3, clst4, clst5, clst6, clst7, clst8], niter=4) new_r = mix.last() assert len(new_r.clusters) == 2 assert all(new_r.clusters[0].mu == clst7.mu) assert all(new_r.clusters[1].mu == clst8.mu) new_r = mix.last(2) assert len(new_r.clusters) == 4 assert all(new_r.clusters[0].mu == clst5.mu) assert all(new_r.clusters[1].mu == clst6.mu) assert all(new_r.clusters[2].mu == clst7.mu) assert all(new_r.clusters[3].mu == clst8.mu) try: new_r = mix.last(10) except ValueError: pass def testDraw(self): x = self.mix.draw(10) assert x.shape[0] == 10, "Number of drawed rows is wrong" assert x.shape[1] == 3, "number of drawed columns is wrong" def testarith(self): adder = 3 array_adder = array([1, 2, 3]) mat_adder = 2 * eye(3) # add b = self.mix + adder self.assertIsInstance(b, DPMixture, 'integer addition return wrong type') assert_equal(b.mus[0], self.mix.mus[0] + adder, 'integer addition returned wrong value') c = self.mix + array_adder self.assertIsInstance(c, DPMixture, 'array addition return wrong type') assert_array_equal(c.mus[0], self.mix.mus[0] + array_adder, 'array addition returned wrong value') # radd b = adder + self.mix self.assertIsInstance(b, DPMixture, 'integer addition return wrong type') assert_array_equal(b.mus[0], adder + self.mix.mus[0], 'integer addition returned wrong value') c = array_adder + self.mix self.assertIsInstance(c, DPMixture, 'array addition return wrong type') assert_array_equal(c.mus[0], array_adder + self.mix.mus[0], 'array addition returned wrong value') # sub b = self.mix - adder self.assertIsInstance(b, DPMixture, 'integer subtraction return wrong type') assert_array_equal(b.mus[0], self.mix.mus[0] - adder, 'integer subtraction returned wrong value') c = self.mix - array_adder self.assertIsInstance(c, DPMixture, 'array subtraction return wrong type') assert_array_equal(c.mus[0], self.mix.mus[0] - array_adder, 'array subtraction returned wrong value') # rsub b = adder - self.mix self.assertIsInstance(b, DPMixture, 'integer subtraction return wrong type') assert_array_equal(b.mus[0], adder - self.mix.mus[0], 'integer subtraction returned wrong value') c = array_adder - self.mix self.assertIsInstance(c, DPMixture, 'array subtraction return wrong type') assert_array_equal(c.mus[0], array_adder - self.mix.mus[0], 'array subtraction returned wrong value') # mul b = self.mix * adder self.assertIsInstance(b, DPMixture, 'integer multiplication return wrong type') assert_array_equal(b.mus[0], self.mix.mus[0] * adder, 'integer multiplication returned wrong value') c = self.mix * array_adder self.assertIsInstance(c, DPMixture, 'array multiplicaton return wrong type') assert_array_equal(c.mus[0], dot(self.mix.mus[0], array_adder), 'array multiplication returned wrong value') d = self.mix * mat_adder self.assertIsInstance(d, DPMixture, 'array multiplicaton return wrong type') assert_array_equal(d.mus[0], dot(self.mix.mus[0], mat_adder), 'array multiplication returned wrong value') # rmul b = adder * self.mix self.assertIsInstance(b, DPMixture, 'integer multiplication return wrong type') assert_array_equal(b.mus[0], adder * self.mix.mus[0], 'integer multiplication returned wrong value') c = array_adder * self.mix self.assertIsInstance(c, DPMixture, 'array multiplication return wrong type') assert_array_equal(c.mus[0], dot(array_adder, self.mix.mus[0]), 'array multiplication returned wrong value') d = mat_adder * self.mix self.assertIsInstance(d, DPMixture, 'array multiplicaton return wrong type') assert_array_equal(d.mus[0], dot(mat_adder, self.mix.mus[0]), 'array multiplication returned wrong value') assert_array_equal(d.sigmas[0], dot(mat_adder, dot(self.mix.sigmas[0], mat_adder)), 'array multiplcation failed') def testgetitem(self): assert_equal(self.mu1, self.mix[0].mu, 'getitem failed') self.mix[0] = self.clust2 assert_equal(self.mu2, self.mix[0].mu, 'getitem failed') self.mix[0] = self.clust1 def testgetiteration(self): self.assertIsInstance(self.mix.get_iteration(2), DPMixture, 'get_iteration failed') self.assertEqual(len(self.mix.get_iteration(2).clusters), 2, 'get_iteration return wrong number of clusters') self.assertIsInstance(self.mix.get_iteration([0, 2]), DPMixture, 'get_iteration failed') self.assertEqual(len(self.mix.get_iteration([0, 2]).clusters), 4, 'get_iteration return wrong number of clusters') def testEnumerateClusters(self): for i, j in self.mix.enumerate_clusters(): self.assertIsInstance(i, int) self.assertIs( j, self.mix[i], 'fialed to return the right cluster when enumerating') def testEnumeratePis(self): for i, j in self.mix.enumerate_pis(): self.assertIsInstance(i, int) self.assertIs(j, self.mix[i].pi, 'fialed to return the right pi when enumerating') def testEnumerateMus(self): for i, j in self.mix.enumerate_mus(): self.assertIsInstance(i, int) self.assertIs(j, self.mix[i].mu, 'fialed to return the right mean when enumerating') def testEnumerateSigmas(self): for i, j in self.mix.enumerate_sigmas(): self.assertIsInstance(i, int) self.assertIs( j, self.mix[i].sigma, 'fialed to return the right covariance when enumerating')
class Dp_mixtureTestCase(unittest.TestCase): def setUp(self): self.mu1 = array([0, 0, 0]) self.sig = eye(3) self.mu2 = array([5, 5, 5]) self.clst1 = DPCluster(.5, self.mu1, self.sig) self.clst2 = DPCluster(.5, self.mu2, self.sig) self.mix = DPMixture([self.clst1, self.clst2]) def tearDown(self): pass def testprob(self): pnt = array([1, 1, 1]) for i in [self.clst1, self.clst2]: assert i.prob(pnt) <= 1, 'prob of clst %s is > 1' % i assert i.prob(pnt) >= 0, 'prob of clst %s is < 0' % i def testmixprob(self): pnt = array([1, 1, 1]) assert self.mix.prob(pnt)[0] == self.clst1.prob( pnt), 'mixture generates different prob then compoent 1' assert self.mix.prob(pnt)[1] == self.clst2.prob( pnt), 'mixture generates different prob then compoent 2' def testclassify(self): pnt = array([self.mu1, self.mu2]) assert self.mix.classify(pnt)[ 0] == 0, 'classify classifys mu1 as belonging to something else' assert self.mix.classify(pnt)[ 1] == 1, 'classify classifys m21 as belonging to something else' def testMakeModal(self): modal = self.mix.make_modal() # modal = ModalDPMixture([self.clst1, self.clst2], # { 0: [0], 1: [1]}, # [self.mu1, self.mu2]) pnt = array([self.mu1, self.mu2]) assert modal.classify( array([self.mu1, self.mu2, self.mu1, self.mu2, self.mu1, self.mu2])).tolist() == [0, 1, 0, 1, 0, 1], 'classify not working' assert self.mix.classify(self.mu1) == modal.classify( self.mu1), 'derived modal mixture is wrong' assert self.mix.classify(pnt)[0] == modal.classify( pnt)[0], 'derived modal mixture is wrong' assert self.mix.classify(pnt)[1] == modal.classify( pnt)[1], 'derived modal mixture is wrong' modal = self.mix.make_modal(delta=9) assert modal.classify( array([self.mu1, self.mu2, self.mu1, self.mu2, self.mu1, self.mu2])).tolist() == [0, 0, 0, 0, 0, 0], 'classify not working' def testAverage(self): clst1 = DPCluster(0.5, self.mu1, self.sig) clst3 = DPCluster(0.5, self.mu1, self.sig) clst5 = DPCluster(0.5, self.mu1, self.sig) clst7 = DPCluster(0.5, self.mu1, self.sig) clst2 = DPCluster(0.5, self.mu2, self.sig) clst4 = DPCluster(0.5, self.mu2, self.sig) clst6 = DPCluster(0.5, self.mu2, self.sig) clst8 = DPCluster(0.5, self.mu2, self.sig) mix = DPMixture( [clst1, clst2, clst3, clst4, clst5, clst6, clst7, clst8], niter=4) avg = mix.average() assert len(avg.clusters) == 2 assert all(avg.mus[0] == self.mu1) assert all(avg.mus[1] == self.mu2) assert all(avg.sigmas[0] == self.sig) assert all(avg.sigmas[1] == self.sig) assert avg.pis[0] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0] assert avg.pis[1] == 0.5, 'pis should be 0.5 but is %f' % avg.pis()[0] def testLast(self): clst1 = DPCluster(0.5, self.mu1, self.sig) clst3 = DPCluster(0.5, self.mu1 + 3, self.sig) clst5 = DPCluster(0.5, self.mu1 + 5, self.sig) clst7 = DPCluster(0.5, self.mu1 + 7, self.sig) clst2 = DPCluster(0.5, self.mu2 + 2, self.sig) clst4 = DPCluster(0.5, self.mu2 + 4, self.sig) clst6 = DPCluster(0.5, self.mu2 + 6, self.sig) clst8 = DPCluster(0.5, self.mu2 + 8, self.sig) mix = DPMixture( [clst1, clst2, clst3, clst4, clst5, clst6, clst7, clst8], niter=4) new_r = mix.last() assert len(new_r.clusters) == 2 assert all(new_r.clusters[0].mu == clst7.mu) assert all(new_r.clusters[1].mu == clst8.mu) new_r = mix.last(2) assert len(new_r.clusters) == 4 assert all(new_r.clusters[0].mu == clst5.mu) assert all(new_r.clusters[1].mu == clst6.mu) assert all(new_r.clusters[2].mu == clst7.mu) assert all(new_r.clusters[3].mu == clst8.mu) try: new_r = mix.last(10) except ValueError: pass def testDraw(self): x = self.mix.draw(10) assert x.shape[0] == 10, "Number of drawed rows is wrong" assert x.shape[1] == 3, "number of drawed columns is wrong" def testarith(self): adder = 3 array_adder = array([1, 2, 3]) # add b = self.mix + adder assert (isinstance(b, DPMixture), 'integer addition return wrong type') assert_equal(b.mus[0], self.mix.mus[0] + adder, 'integer addition returned wrong value') c = self.mix + array_adder assert (isinstance(c, DPMixture), 'array addition return wrong type') assert_equal(c.mus[0], self.mix.mus[0] + array_adder, 'array addition returned wrong value') # radd b = adder + self.mix assert (isinstance(b, DPMixture), 'integer addition return wrong type') assert_equal(b.mus[0], adder + self.mix.mus[0], 'integer addition returned wrong value') c = array_adder + self.mix assert (isinstance(c, DPMixture), 'array addition return wrong type') assert_equal(c.mus[0], array_adder + self.mix.mus[0], 'array addition returned wrong value') # sub b = self.mix - adder assert (isinstance(b, DPMixture), 'integer subtraction return wrong type') assert_equal(b.mus[0], self.mix.mus[0] - adder, 'integer subtraction returned wrong value') c = self.mix - array_adder assert (isinstance(c, DPMixture), 'array subtraction return wrong type') assert_equal(c.mus[0], self.mix.mus[0] - array_adder, 'array subtraction returned wrong value') # rsub b = adder - self.mix assert (isinstance(b, DPMixture), 'integer subtraction return wrong type') assert_equal(b.mus[0], adder - self.mix.mus[0], 'integer subtraction returned wrong value') c = array_adder - self.mix assert (isinstance(c, DPMixture), 'array subtraction return wrong type') assert_equal(c.mus[0], array_adder - self.mix.mus[0], 'array subtraction returned wrong value') # mul b = self.mix * adder assert (isinstance(b, DPMixture), 'integer multiplication return wrong type') assert_equal(b.mus[0], self.mix.mus[0] * adder, 'integer multiplication returned wrong value') c = self.mix * array_adder assert (isinstance(c, DPMixture), 'array multiplicaton return wrong type') assert_equal(c.mus[0], dot(self.mix.mus[0], array_adder), 'array multiplication returned wrong value') # rmul b = adder * self.mix assert (isinstance(b, DPMixture), 'integer multiplication return wrong type') assert_equal(b.mus[0], adder * self.mix.mus[0], 'integer multiplication returned wrong value') c = array_adder * self.mix assert (isinstance(c, DPMixture), 'array multiplication return wrong type') assert_equal(c.mus[0], dot(array_adder, self.mix.mus[0]), 'array multiplication returned wrong value') def testgetitem(self): assert_equal(self.mu1, self.mix[0].mu, 'getitem failed') self.mix[0] = self.clst2 assert_equal(self.mu2, self.mix[0].mu, 'getitem failed') self.mix[0] = self.clst1