def test_constructor_from_dists_failure(self): d1 = Binomial(0, 12, 0.1) d2 = Binomial(0, 12, 0.5) try: _mixt = Mixture(0.1, d1, d2) assert False except TypeError: assert True
def build_data(self): d1 = Binomial(0, 12, 0.1) d2 = Binomial(0, 12, 0.5) d3 = Binomial(0, 12, 0.8) mixt = Mixture(0.1, d1, 0.2, d2, 0.7, d3) assert mixt.nb_component == 3 return mixt
def test_extract(self): """run and test the extract methods""" m = self.data assert m.extract_convolution() == ExtractDistribution(m, "Convolution") assert m.extract(1) == Binomial(0, 10, 0.5) assert m.extract(2) == NegativeBinomial(0, 1, 0.1) assert ExtractDistribution(m, "Elementary", 1) == Binomial(0, 10, 0.5) assert ExtractDistribution(m, "Elementary", 2) == \ NegativeBinomial(0, 1, 0.1)
def build_data(self): d11 = Binomial(0, 12, 0.1) d12 = Binomial(0, 12, 0.5) d13 = Binomial(0, 12, 0.8) d21 = Poisson(0, 18.0) d22 = Poisson(0, 5.0) d23 = Poisson(0, .20) data = _MultivariateMixture([0.1, 0.2, 0.7], [[d11, d21], [d12, d22], [d13, d23]]) assert data.nb_component == 3 assert data.nb_variable == 2 return data
def test_extract_data(self): """run and test the extract_data methods""" m = self.data s = m.simulate(1000) e = s.estimate_convolution(Binomial(0, 10, 0.5), Estimator="Parametric") d = e.extract_data() assert d eprime = Estimate(s, "CONVOLUTION", Binomial(0, 10, 0.5)) # todo: find robust assert ? print eprime.get_mean
def test1(): #ORIGINAL AML stops HERE d11 = Binomial(0, 12, 0.1) d12 = Binomial(2, 13, 0.6) d13 = Binomial(3, 15, 0.9) d21 = Poisson(0, 25.0) d22 = Poisson(0, 5.0) d23 = Poisson(0, 0.2) m = _MultivariateMixture([0.1, 0.2, 0.7], [[d11, d21], [d12, d22], [d13, d23]]) print m #m2 = _MultivariateMixture("mixture_mv1.mixt") #print m2 #print "Egalite des melanges construits par liste ",\ # "de distributions et par fichiers : ", str(str(m)==str(m2)) #m = _MultivariateMixture("mixture_mv_nonparam.mixt") # print m print "Simulation de melanges multivaries : " v = m.simulate(5000) print v Plot(m, variable=1, Title="Simulated mixture") print "Estimation de melanges multivaries ", \ # "d'apres un modele initial : " m_estim_model = v.mixture_estimation(m, 100, [True, True]) extracted_mixture = m_estim_model.extract_mixture(1) extracted_mixture.old_plot(variable=1, Title="Marginal distribution") Plot(m_estim_model, variable=1, Title="Estimated mixture") print "Estimation de melanges multivaries ", \ "d'apres un nombre de composantes : " m_estim_nbcomp = v.mixture_estimation(2, 100, [True, True]) m_estim_nbcomp.plot(variable=1, Title="Estimated mixture") clust_entropy = m_estim_nbcomp.cluster_data(v, True) clust_plain = m_estim_nbcomp.cluster_data(v, False)
def test_simulate2(self): d11 = Binomial(0, 12, 0.1) d12 = Binomial(0, 12, 0.5) d13 = Binomial(0, 12, 0.8) d21 = Poisson(0, 18.0) d22 = Poisson(0, 5.0) d23 = Poisson(0, .20) m = _MultivariateMixture([0.1, 0.2, 0.7], [[d11, d21], [d12, d22], [d13, d23]]) v = m.simulate(5000) assert v m_estim_model = v.mixture_estimation(m, 100, [True, True]) assert m_estim_model m_estim_nbcomp = v.mixture_estimation(2) assert m_estim_nbcomp return m, v
def test_extract_data(self): """todo : check if this test makes sense""" s = self.simulate() #e = Estimate(s, "Compound", Binomial(2, 5, 0.5), "Sum") d = s.extract_sum() assert d _eprime = Estimate(s, "COMPOUND", Binomial(0, 10, 0.5), "Sum")
def test_extract(self): """run and test the extract methods""" m = self.data assert m.extract_compound() == ExtractDistribution(m, "Compound") assert m.extract_sum() == Binomial(2, 5, 0.5) assert m.extract_sum() == ExtractDistribution(m, "Sum") assert m.extract_elementary() == NegativeBinomial(0, 2, 0.5) assert m.extract_elementary() == ExtractDistribution(m, "Elementary")
def test_binomial(self): d = Distribution("BINOMIAL", 0, 10, 0.5) assert list(d.simulate(1000)) assert d.get_sup_bound == 10 assert d.get_inf_bound == 0 assert d.get_probability == 0.5 assert d.get_parameter == -1 assert d.get_ident() == 1 d = Binomial(0, 10, 0.5) assert list(d.simulate(1000)) m = d.simulate(1000).extract_model() assert isinstance(m, _DiscreteParametricModel)
def test_constructor_from_model(self): from openalea.stat_tool.compound import Compound from openalea.stat_tool.mixture import Mixture from openalea.stat_tool.convolution import Convolution from openalea.stat_tool.distribution import Binomial Renewal(Compound(Binomial(0,10,0.5), Binomial(0,10,0.3)), Type="Equilibrium", ObservationTime=20) Renewal(Mixture(0.1, Binomial(0,10,0.5), 0.9, Binomial(0,10,0.3)), Type="Equilibrium", ObservationTime=20) Renewal(Compound(Binomial(0,10,0.5), Binomial(0,10,0.3)), Type="Equilibrium", ObservationTime=20)
def test_extract(self): """run and test the extract methods""" m = self.data assert m.extract_weight() == ExtractDistribution(m, "Weight") assert m.extract_mixture() == ExtractDistribution(m, "Mixture") assert ExtractDistribution(m, "Component", 1) == Binomial(0, 12, 0.1) assert ExtractDistribution(m, "Component", 2) == Binomial(0, 12, 0.5) assert ExtractDistribution(m, "Component", 3) == Binomial(0, 12, 0.8) assert m.extract_component(1) == Binomial(0, 12, 0.1) assert m.extract_component(2) == Binomial(0, 12, 0.5) assert m.extract_component(3) == Binomial(0, 12, 0.8)
def conv_data(self): d1 = Binomial(0, 10, 0.5) d2 = NegativeBinomial(0, 1, 0.1) conv = Convolution(d1, d2) conv_data = conv.simulate(self.N) return conv_data
def test_constructor_from_dists_and_threshold(self): compound1 = self.data compound2 = Compound(Binomial(2, 5, 0.5), NegativeBinomial(0, 2, 0.5), Threshold=0.99999) assert str(compound1) == str(compound2)
def build_data(self): d1 = Binomial(2, 5, 0.5) d2 = NegativeBinomial(0, 2, 0.5) comp = Compound(d1, d2) return comp
def build_data(self): d1 = Binomial(0, 10, 0.5) d2 = NegativeBinomial(0, 1, 0.1) conv = Convolution(d1, d2, d1, d2) conv = Convolution(d1, d2) return conv
def build_data(self): d1 = Binomial(0, 10, 0.5) d2 = Distribution("BINOMIAL", 0, 10, 0.5) assert d1 == d2 return d1
def test_mixture_2(self): h = Histogram(get_shared_data( "peup2.his")) m2 = h.estimate_mixture([Binomial(0, 10, 0.5), "NB"]) assert m2
def conv(self): d1 = Binomial(0, 10, 0.5) d2 = NegativeBinomial(0, 1, 0.1) m = Convolution(d1, d2) return m
def comp(self): d1 = Binomial(2, 5, 0.5) d2 = NegativeBinomial(0, 2, 0.5) c = Compound(d1, d2) return c
def _test_moving_average_and_compound(self): """test to be implemented""" compound = Compound(Binomial(1, 10, 0.5), Binomial(1, 5, 0.4)) Regression(self.vector, "MovingAverage", 1, 2, compound)
def comp_data(self): d1 = Binomial(0, 10, 0.5) d2 = NegativeBinomial(0, 1, 0.1) comp = Compound(d1, d2) comp_data = comp.simulate(self.N) return comp_data
def test_extract_model(self): d = Binomial(0, 10, 0.5) d == d.simulate(1000).extract_model()
def mixt_data(self): d1 = Binomial(0, 10, 0.5) d2 = NegativeBinomial(0, 1, 0.1) mixt = Mixture(0.1, d1, 0.4, d2) mixt_data = mixt.simulate(self.N) return mixt_data