def test_plot_mixture_data(self): mixt1 = Mixture(0.6, Distribution("B", 2, 18, 0.5), 0.4, Distribution("NB", 10, 10, 0.5)) mixt_histo1 = Simulate(mixt1, 200) if DISABLE_PLOT == False: mixt1.plot() mixt_histo1.plot()
def get_mixture(self): """create a mixture data""" d1 = Uniform(0, 10) d2 = Uniform(10, 20) d3 = Uniform(20, 30) m = Mixture(0.1, d1, 0.2, d2, 0.7, d3) return m
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_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_merge(self): mixt1 = Mixture(0.6, Distribution("B", 2, 18, 0.5), 0.4, Distribution("NB", 10, 10, 0.5)) mixt_histo1 = Simulate(mixt1, 200) histo10 = mixt_histo1.extract_component(1) histo11 = mixt_histo1.extract_component(2) histo12 = Merge(histo10, histo11) assert histo12 Plot(histo12)
def test_simulate_mixture(): m = Mixture("data/mixture1.mixt") s1 = Simulate(m, 1000) assert s1
def mixt(self): d1 = Uniform(0, 10) d2 = Uniform(10, 20) d3 = Uniform(20, 30) m = Mixture(0.1, d1, 0.2, d2, 0.7, d3) return m
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
def test2(): """finite mixture of discrete distributions""" mixt1 = Mixture("data//mixture1.mixt") mixt1 = Mixture(0.6, Distribution("B", 2, 18, 0.5), 0.4, Distribution("NB", 10, 10, 0.5)) mixt_histo1 = Simulate(mixt1, 200) Plot(mixt_histo1) # extraction of histograms/frequency distributions corresponding # to a given mixture component # (i.e. elementary distributions which are combined by mixture) histo10 = ExtractHistogram(mixt_histo1, "Component", 1) histo11 = ExtractHistogram(mixt_histo1, "Component", 2) _histo12 = Merge(histo10, histo11) _histo13 = ExtractHistogram(mixt_histo1, "Weight") # estimation mixt2 = Estimate(mixt_histo1, "MIXTURE", "B", "NB", MinInfBound=0, InfBoundStatus="Fixed", DistInfBoundStatus="Fixed") _mixt_histo2 = ExtractData(mixt2) _histo14 = ExtractHistogram(ExtractData(mixt2), "Component", 1) _histo15 = ToHistogram(ExtractDistribution(mixt2, "Component", 1)) # estimation and selection of the number of components meri1 = Histogram(get_shared_data("meri1.his")) meri2 = Histogram(get_shared_data("meri2.his")) meri3 = Histogram(get_shared_data("meri3.his")) meri4 = Histogram(get_shared_data("meri4.his")) meri5 = Histogram(get_shared_data("meri5.his")) #mixt3 = Estimate(meri1, "MIXTURE", Distribution("B", 6, 7, 0.5), "B") mixt3 = Estimate(meri1, "MIXTURE", "B", "B") Plot(mixt3) # NbComponent="Fixed" (default) / "Estimated" # Penalty="AIC"/ "AICc" / "BIC" / "BICc" (default), option # valide if NbComponent="Estimated" meri = Merge(meri1, meri2, meri3, meri4, meri5) mixt2 = Estimate(meri, "MIXTURE", "B", "B", "B", "B", NbComponent="Estimated", Penalty="BIC") Display(mixt2, Detail=2) dist_mixt = ExtractDistribution(mixt2, "Mixture") Plot(dist_mixt)