def test_distribution(self):
     seq70 = self.data
     MovingAverage(seq70, Distribution("B", 0, 16, 0.5), BeginEnd=True)
     MovingAverage(seq70,
                   Distribution("B", 0, 16, 0.5),
                   BeginEnd=True,
                   Output="Residual")
Пример #2
0
    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 _test_plot_distribution_set(self):

        d1 = Distribution("B", 2, 18, 0.5)
        d2 = Distribution("NB", 10, 10, 0.5)
        d3 = Distribution("U", 10, 20)

        if DISABLE_PLOT == False:
            Plot(d1, d2, d3)
            d1.old_plot()
    def test_to_histogram(self):

        d = Distribution("NEGATIVE_BINOMIAL", 0, 1, 0.5)
        h = d.simulate(1000)
        d2 = ToDistribution(h)
        assert h and d2

        h2 = ToHistogram(d2)
        assert h2
        assert h == h2
Пример #5
0
    def test_plot_survival(self):

        d1 = Distribution("B", 2, 18, 0.5)

        if DISABLE_PLOT == False:
            d1.plot(ViewPoint="Survival")

        histo1 = Simulate(d1, 200)
        if DISABLE_PLOT == False:
            histo1.plot(ViewPoint="Survival")
    def test_to_histogram(self):

        d = Distribution("NEGATIVE_BINOMIAL", 0, 1, 0.5)
        h = d.simulate(1000)
        d2 = ToDistribution(h)
        assert h and d2

        h2 = ToHistogram(d2)
        assert h2
        assert h == h2
    def test_plot_survival(self):


        d1 = Distribution("B", 2, 18, 0.5)

        if DISABLE_PLOT == False:
            d1.plot(ViewPoint="Survival")

        histo1 = Simulate(d1, 200)
        if DISABLE_PLOT == False:
            histo1.plot(ViewPoint="Survival")
    def test_constructors(self):
        h = Histogram([1, 2, 3, 4, 5, 6, 1, 2, 3])
        assert h

        # from histogram
        dist = Distribution(h)
        assert dist

        #from parametric model
        pm = _DiscreteParametricModel(h)
        dist = Distribution(pm)
        assert dist
    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)
Пример #10
0
    def create_sequence_data(self):

        seq66 = Sequences(get_shared_data("laricio_date66.seq"))
        seq69 = MovingAverage(VariableScaling(seq66, 3, 100),
                              Distribution("B", 0, 6, 0.5),
                              BeginEnd=True,
                              Output="Residual")
        return seq69
Пример #11
0
    def test_plot_parametric_model(self):

        dist1 = Distribution("NB", 0, 3.5, 0.3)
        histo1 = Simulate(dist1, 200)
        if DISABLE_PLOT == False:
            Plot(histo1)
        dist2 = Estimate(histo1, "NB", MinInfBound=0, InfBoundStatus="Fixed")
        if DISABLE_PLOT == False:
            Plot(dist2)
Пример #12
0
def test_output_display_detail():
    d1 = Distribution("B", 2, 19, 0.5)
    print Display(d1)
    print Display(d1, Detail=1)
    print Display(d1, Detail=2)
    try:
        print Display(d1, Detail=3)
        assert False
    except:
        assert ValueError
Пример #13
0
def test_output_display_viewpoint_data():
    from openalea.stat_tool import Vectors
    v = Vectors('data/vectors.vec')
    Display(v, ViewPoint='Data')
    Display(v)
    #ddata viewpoint is dedicated to Vectors or sequences
    try:
        d1 = Distribution("B", 2, 19, 0.5)
        Display(d1, ViewPoint="Data")
        assert False
    except:
        assert True
 def test_multimodial(self):
     """multinomial not yet implemented"""
     try:
         Distribution("MULTINOMIAL", 10)
         assert False
     except:
         assert True
     try:
         d = Multinomial()
         assert False
     except:
         assert True
Пример #15
0
    def _test_plot_distribution_set(self):

        d1 = Distribution("B", 2, 18, 0.5)
        d2 = Distribution("NB", 10, 10, 0.5)
        d3 = Distribution("U", 10, 20)

        if DISABLE_PLOT == False:
            Plot(d1, d2, d3)
            d1.old_plot()
    def test_neg_binomial(self):

        d = Distribution("NEGATIVE_BINOMIAL", 0, 1, 0.5)
        assert list(d.simulate(1000))
        assert d.get_sup_bound == -1
        assert d.get_inf_bound == 0
        assert d.get_probability == 0.5
        assert d.get_parameter == 1
        assert d.get_ident() == 3
        d = NegativeBinomial(0, 1, 0.5)
        assert list(d.simulate(1000))

        m = d.simulate(1000).extract_model()
        assert isinstance(m, _DiscreteParametricModel)
    def test_uniform(self):

        d = Distribution("UNIFORM", 0, 10)
        assert list(d.simulate(1000))
        assert d.get_sup_bound == 10
        assert d.get_inf_bound == 0
        assert d.get_probability == -1
        assert d.get_parameter == -1
        assert d.get_ident() == 4

        d = Uniform(0, 10)
        assert list(d.simulate(1000))

        m = d.simulate(1000).extract_model()
        assert isinstance(m, _DiscreteParametricModel)
    def test_poisson(self):

        d = Distribution("POISSON", 0, 2)
        assert list(d.simulate(1000))
        assert d.get_sup_bound == -1
        assert d.get_inf_bound == 0
        assert d.get_probability == -1
        assert d.get_parameter == 2
        assert d.get_ident() == 2

        d = Poisson(0, 2)
        assert list(d.simulate(1000))

        m = d.simulate(1000).extract_model()
        assert isinstance(m, _DiscreteParametricModel)
    def test_neg_binomial(self):

        d = Distribution("NEGATIVE_BINOMIAL", 0, 1, 0.5)
        assert list(d.simulate(1000))
        assert d.get_sup_bound == -1
        assert d.get_inf_bound == 0
        assert d.get_probability == 0.5
        assert d.get_parameter == 1
        assert d.get_ident() == 3
        d = NegativeBinomial(0, 1, 0.5)
        assert list(d.simulate(1000))

        m = d.simulate(1000).extract_model()
        assert isinstance(m, _DiscreteParametricModel)
    def test_poisson(self):

        d = Distribution("POISSON", 0, 2)
        assert list(d.simulate(1000))
        assert d.get_sup_bound == -1
        assert d.get_inf_bound == 0
        assert d.get_probability == -1
        assert d.get_parameter == 2
        assert d.get_ident() == 2

        d = Poisson(0, 2)
        assert list(d.simulate(1000))

        m = d.simulate(1000).extract_model()
        assert isinstance(m, _DiscreteParametricModel)
    def test_uniform(self):

        d = Distribution("UNIFORM", 0, 10)
        assert list(d.simulate(1000))
        assert d.get_sup_bound == 10
        assert d.get_inf_bound == 0
        assert d.get_probability == -1
        assert d.get_parameter == -1
        assert d.get_ident() == 4

        d = Uniform(0, 10)
        assert list(d.simulate(1000))

        m = d.simulate(1000).extract_model()
        assert isinstance(m, _DiscreteParametricModel)
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)
Пример #23
0
def test_output_plot_viewpoint_survival():
    d1 = Distribution("B", 2, 19, 0.5)
    Plot(d1)
    Plot(d1, ViewPoint='Survival')
Пример #24
0
def test_output_display_viewpoint_survival():
    d1 = Distribution("B", 2, 19, 0.5)
    print Display(d1, ViewPoint="Survival")
    convol1 = Convolution("data/convolution1.conv")
    print Display(convol1, ViewPoint="Survival")
Пример #25
0
def test_simulate_distribution():
    c = Distribution("data/distribution1.dist")
    s1 = Simulate(c, 1000)
    assert s1
 def test_getters(self):
     dist = Distribution(Histogram([1, 1, 1, 2, 2, 2, 3, 3, 3]))
     assert dist.get_mean == 2
     assert 0.3333 < dist.get_max < 0.3334
     assert dist.get_mean == 2
     assert 0.6666 < dist.get_variance < 0.6667
Пример #27
0
 def test_distribution(self):
     data = self.correlation
     ComputeWhiteNoiseCorrelation(data, Distribution("BINOMIAL", 0, 4, 0.5))
 def build_data(self):
     d1 = Binomial(0, 10, 0.5)
     d2 = Distribution("BINOMIAL", 0, 10, 0.5)
     assert d1 == d2
     return d1
 def test_fit_histogram(self):
     meri5 = Histogram(get_shared_data( "meri5.his"))
     dist1 = Fit(meri5, Distribution("B", 0, 10, 0.437879))
     dist2 = meri5.fit(Distribution("B", 0, 10, 0.437879))
     assert str(dist1)==str(dist2)
 def test_constructor_failure(self):
     try:
         _h = Distribution("Whatever", 1, 1)
         assert False
     except KeyError:
         assert True