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)
    def test_merge_histo(self):
        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"))
       

        meri = Merge(meri1, meri2, meri3, meri4, meri5)
        assert meri
        meri_bis = meri1.merge([meri2, meri3, meri4, meri5])
        assert meri_bis
        assert str(meri)==str(meri_bis)
        Plot(meri)
 def build_data(self):
     vec10 = Vectors(get_shared_data("chene_sessile.vec"))
     vec15 = SelectVariable(vec10, [1, 3, 6], Mode="Reject")
     matrix10 = Compare(vec15, VectorDistance("N", "N", "N"))
     assert 138 == matrix10.nb_row
     assert 138 == matrix10.nb_column
     return matrix10
Пример #4
0
 def build_data(self):
     vec10 = Vectors(get_shared_data("chene_sessile.vec"))
     vec15 = SelectVariable(vec10, [1, 3, 6], Mode="Reject")
     matrix10 = Compare(vec15, VectorDistance("N", "N", "N"))
     assert 138 == matrix10.nb_row
     assert 138 == matrix10.nb_column
     return matrix10
Пример #5
0
    def test_clustering(self):
        vec10 = Vectors(get_shared_data("chene_sessile.vec"))
        vec15 = SelectVariable(vec10, [1, 3, 6], Mode="Reject")

        assert vec15

        matrix10 = Compare(vec15, VectorDistance("N", "N", "N"))

        c1 = Clustering(matrix10, "Partition", 3, Prototypes=[1, 3, 12], Algorithm="Divisive")
        c1_bis = Clustering(matrix10, "Partition", 3, Prototypes=[1, 3, 12], Algorithm="Ordering")

        c2 = Clustering(matrix10, "Hierarchy", Algorithm="Agglomerative")
        c3 = Clustering(matrix10, "Hierarchy", Algorithm="Divisive")
        c4 = Clustering(matrix10, "Hierarchy", Algorithm="Ordering")

        assert c1
        assert c2
        assert c3
        assert c4
        assert ToDistanceMatrix(c1)

        # first argument is the Algorithm
        #  * 0 for agglomerative
        #  * 1 for divisive
        # Second argument is the criterion
        #  * 2 for averaging

        # those 3 tests works on my laptop (TC, April 2009) but not on buildbot
        # assert c2 == matrix10.hierarchical_clustering(0, 2, "test", "test")
        # assert c3 == matrix10.hierarchical_clustering(1, 1, "test", "test")
        # assert c4 == matrix10.hierarchical_clustering(2, 0, "test", "test")

        # 1 for initialisation and 1 for divisive
        assert str(c1) == str(matrix10.partitioning_prototype(3, [1, 3, 12], 1, 1))
        assert str(c1_bis) == str(matrix10.partitioning_prototype(3, [1, 3, 12], 1, 2))
Пример #6
0
    def test_extract_data(self):
        """todo : check if this test makes sense"""
        h = Histogram(str(get_shared_data("meri1.his")))

        e = h.estimate_nonparametric()

        assert e
 def build_data(self):
     vec10 = Vectors(get_shared_data("chene_sessile.vec"))
     vec15 = SelectVariable(vec10, [1, 3, 6], Mode="Reject")
     matrix10 = Compare(vec15, VectorDistance("N", "N", "N"))
     c1 = Clustering(matrix10, "Partition", 3, Prototypes=[1, 3, 12],
                     Algorithm="Divisive")
     return ToDistanceMatrix(c1)
Пример #8
0
    def test_extract_data(self):
        """run and test the extract_data methods"""

        h = Histogram(str(get_shared_data("meri2.his")))
        m = h.estimate_DiscreteMixture("B", "NB")

        d = m.extract_data()
        assert d
    def test_extract_data(self):
        """run and test the extract_data methods"""

        h = Histogram(str(get_shared_data( "meri2.his")))
        m = h.estimate_DiscreteMixture("B", "NB")

        d = m.extract_data()
        assert d
Пример #10
0
    def test_compare_vectors(self):

        vec10 = Vectors(get_shared_data("chene_sessile.vec"))
        vec15 = SelectVariable(vec10, [1, 3, 6], Mode="Reject")
        assert vec15

        matrix10 = Compare(vec15, VectorDistance("N", "N", "N"))
        assert matrix10
        assert str(vec15.compare(VectorDistance("N", "N", "N"),
                                 True)) == str(matrix10)
    def test_compare_vectors(self):

        vec10 = Vectors(get_shared_data("chene_sessile.vec"))
        vec15 = SelectVariable(vec10, [1, 3, 6], Mode="Reject")
        assert vec15

        matrix10 = Compare(vec15, VectorDistance("N", "N", "N"))
        assert matrix10
        assert str(vec15.compare(VectorDistance("N", "N", "N"),
                                 True)) == str(matrix10)
Пример #12
0
    def test_mixture_1(self):
        distributions = ["B", "NB", "NB", "NB"]
        h = Histogram(get_shared_data( "peup2.his"))
        m1 =  h.estimate_mixture(distributions, NbComponent="Estimated")
        assert m1

        types = []
        for d in distributions:
            temp = distribution_identifier_type[d]
            types.append(temp)

        c = h.mixture_estimation2(types, 0, True, True,
                                likelihood_penalty_type['AIC'])

        assert str(c)==str(m1)
Пример #13
0
    def test_clustering(self):
        vec10 = Vectors(get_shared_data("chene_sessile.vec"))
        vec15 = SelectVariable(vec10, [1, 3, 6], Mode="Reject")

        assert vec15

        matrix10 = Compare(vec15, VectorDistance("N", "N", "N"))

        c1 = Clustering(matrix10,
                        "Partition",
                        3,
                        Prototypes=[1, 3, 12],
                        Algorithm="Divisive")
        c1_bis = Clustering(matrix10,
                            "Partition",
                            3,
                            Prototypes=[1, 3, 12],
                            Algorithm="Ordering")

        c2 = Clustering(matrix10, "Hierarchy", Algorithm="Agglomerative")
        c3 = Clustering(matrix10, "Hierarchy", Algorithm="Divisive")
        c4 = Clustering(matrix10, "Hierarchy", Algorithm="Ordering")

        assert c1
        assert c2
        assert c3
        assert c4
        assert ToDistanceMatrix(c1)

        # first argument is the Algorithm
        #  * 0 for agglomerative
        #  * 1 for divisive
        # Second argument is the criterion
        #  * 2 for averaging

        #those 3 tests works on my laptop (TC, April 2009) but not on buildbot
        #assert c2 == matrix10.hierarchical_clustering(0, 2, "test", "test")
        #assert c3 == matrix10.hierarchical_clustering(1, 1, "test", "test")
        #assert c4 == matrix10.hierarchical_clustering(2, 0, "test", "test")

        # 1 for initialisation and 1 for divisive
        assert str(c1) == \
            str(matrix10.partitioning_prototype(3, [1, 3, 12], 1, 1))
        assert str(c1_bis) == \
            str(matrix10.partitioning_prototype(3, [1, 3, 12], 1, 2))
    def test_mixture(self):

        h = Histogram(get_shared_data("meri2.his"))
        mixt = h.estimate_mixture(["B", "NB"])

        assert ExtractHistogram(mixt, "Weight") == \
            mixt.extract_weight()
        assert ExtractHistogram(mixt, "Mixture") == \
            mixt.extract_mixture()
        assert ExtractHistogram(mixt, "Component", 1) == \
            mixt.extract_component(1)
        assert ExtractHistogram(mixt, "Component", 2) == \
            mixt.extract_component(2)

        try:
            ExtractHistogram(mixt, "Component", 3)
            assert False
        except: # Bas distrubition index
            assert True
def test():
    vec10 = Vectors(get_shared_data('chene_sessile.vec'))
    vec15 = SelectVariable(vec10, [1, 3, 6], Mode="Reject")
    vec9596 = ValueSelect(vec10, 1, 1995, 1996)

    # computation of a distance matrix using a standardization procedure

    matrix10 = Compare(vec15, VectorDistance("N", "N", "N"))
    Plot(matrix10)
    # clustering using a partitioning method

    cluster = Clustering(matrix10, "Partition", 5)
    Plot(cluster)
    Display(Clustering(matrix10, "Partition", 2))

    vec151 = SelectIndividual(vec10,  \
        [69, 48, 41, 44, 32, 47, 81, 95, 11, 36, 75, 108, 56, 83, 38, 98
        , 113, 134, 110, 101, 77, 35, 74, 80, 50, 24, 89, 128, 5, 45, 8,
        116, 119, 132, 61, 78, 53, 29, 131, 65, 90, 96, 104, 20, 86, 66,
        42, 68, 125, 14, 23, 54, 33, 26, 71, 129, 102, 51, 70, 111, 138,
        19, 127, 62, 117, 137, 2, 28, 17])
    vec152 = SelectIndividual(vec10, \
        [100, 13, 133, 105, 72, 9, 93, 109, 30, 115, 63, 7, 55, 37, 15,
        114, 106, 46, 73, 18, 3, 87, 58, 43, 60, 76, 52, 6, 39, 31, 12, 
        99, 121, 123, 22, 79, 94, 88, 21, 97, 25, 40, 57, 136, 67, 49, 10, 
        4, 120, 92, 27, 91, 64, 124, 16, 130, 84, 107, 126, 103, 122, 112, 
        59, 1, 82, 34, 135, 118, 85])

    Plot(ExtractHistogram(vec151, 4), ExtractHistogram(vec152, 4))

    matrix11 = Compare(vec15, VectorDistance("N", "O", "N"))

    Clustering(matrix10, "Hierarchy", Algorithm="Agglomerative")
    Clustering(matrix10, "Hierarchy", Algorithm="Divisive")

    vec16 = SelectVariable(vec9596, [1, 3], Mode="Reject")
    matrix12 = Compare(vec16, VectorDistance("N", "N", "N", "N"))
    matrix13 = Compare(vec16, VectorDistance("N", "O", "N", "N"))
def test():
    vec10 = Vectors(get_shared_data('chene_sessile.vec'))
    vec15 = SelectVariable(vec10, [1, 3, 6], Mode="Reject")
    vec9596 = ValueSelect(vec10, 1, 1995, 1996)

    # computation of a distance matrix using a standardization procedure

    matrix10 = Compare(vec15, VectorDistance("N", "N", "N"))
    Plot(matrix10)
    # clustering using a partitioning method

    cluster = Clustering(matrix10, "Partition", 5)
    Plot(cluster)
    Display(Clustering(matrix10, "Partition", 2))

    vec151 = SelectIndividual(vec10,  \
        [69, 48, 41, 44, 32, 47, 81, 95, 11, 36, 75, 108, 56, 83, 38, 98
        , 113, 134, 110, 101, 77, 35, 74, 80, 50, 24, 89, 128, 5, 45, 8,
        116, 119, 132, 61, 78, 53, 29, 131, 65, 90, 96, 104, 20, 86, 66,
        42, 68, 125, 14, 23, 54, 33, 26, 71, 129, 102, 51, 70, 111, 138,
        19, 127, 62, 117, 137, 2, 28, 17])
    vec152 = SelectIndividual(vec10, \
        [100, 13, 133, 105, 72, 9, 93, 109, 30, 115, 63, 7, 55, 37, 15,
        114, 106, 46, 73, 18, 3, 87, 58, 43, 60, 76, 52, 6, 39, 31, 12,
        99, 121, 123, 22, 79, 94, 88, 21, 97, 25, 40, 57, 136, 67, 49, 10,
        4, 120, 92, 27, 91, 64, 124, 16, 130, 84, 107, 126, 103, 122, 112,
        59, 1, 82, 34, 135, 118, 85])

    Plot(ExtractHistogram(vec151, 4), ExtractHistogram(vec152, 4))

    matrix11 = Compare(vec15, VectorDistance("N", "O", "N"))

    Clustering(matrix10, "Hierarchy", Algorithm="Agglomerative")
    Clustering(matrix10, "Hierarchy", Algorithm="Divisive")

    vec16 = SelectVariable(vec9596, [1, 3], Mode="Reject")
    matrix12 = Compare(vec16, VectorDistance("N", "N", "N", "N"))
    matrix13 = Compare(vec16, VectorDistance("N", "O", "N", "N"))
def test():
    """Mixture tests from exploratory.aml
    #
    #  Frequency distributions
    #
    #  Objective: Analyzing the number of nodes of growth units in selected architectural
    #                 position considering the respective roles of preformation and neoformation,
    #
    #  Methods: comparison tests, one-way variance analysis,
    #           estimation of finite mixture of distributions.
    #
    #  Wild cherry tree: number of nodes per growth unit (GU)
    #
    #  Data: Dominique Fournier
    #
    #  meri1.his: order 1,
    #  meri1.his: order 2,
    #  meri1.his: order 3, GU 1,
    #  meri1.his: order 3, GU 2,
    #  meri5.his: short shoots.
    #
    #
    #  Poplar: number of nodes per growth unit
    #
    #  Data: Yves Caraglio and Herve Rey
    #
    #  peup1.his: order 2,
    #  peup2.his: order 3,
    #  peup3.his: order 4,
    #  peup4.his: order 5,
    #  peup5.his: order 3, GU 4,
    #  peup6.his: order 3, acrotony.
    #
    #########################################################################
    """

    plot.DISABLE_PLOT = DISABLE_PLOT
    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"))
    

    Plot(meri1, meri2, meri3, meri4, meri5)
    Compare(meri1, meri2, meri3, meri4, meri5, "N")


    ComparisonTest("F", meri1, meri2)
    ComparisonTest("T", meri1, meri2)
    ComparisonTest("W", meri1, meri2)

    ComparisonTest("F", meri1, meri3)
    ComparisonTest("T", meri1, meri3)
    ComparisonTest("W", meri1, meri3)

    # Estimation of a mixture of two distributions assuming a first
    # sub-population of GUs made only of a preformed part and a second
    # sub-population made of both a preformed part and a neoformed part

    _mixt1 = Estimate(meri2, "MIXTURE", "B", "B")

    meri = Merge(meri1, meri2, meri3, meri4, meri5)

    # model selection approach: estimation of both the mixture parameters and
    # the number of components"""

    mixt2 = Estimate(meri, "MIXTURE", "B", "B", "B", "B",
                     NbComponent="Estimated")
    mixt2 = Estimate(meri, "MIXTURE", "NB", "NB")
    Plot(mixt2)
    Plot(ExtractDistribution(mixt2, "Mixture"))
    Plot(ExtractDistribution(mixt2, "Component", 1),
         ExtractDistribution(mixt2, "Component", 2))
    Display(mixt2)

    _mixt_data = ExtractData(mixt2)

    dist5 = Estimate(meri5, "BINOMIAL")
    Display(dist5, Detail=2)
    Plot(dist5)

    histo5 = Simulate(dist5, 100)
    Display(histo5, Detail=2)
    Plot(histo5)

    peup1 = Histogram(get_shared_data( "peup1.his"))
    peup2 = Histogram(get_shared_data( "peup2.his"))
    peup3 = Histogram(get_shared_data( "peup3.his"))
    peup4 = Histogram(get_shared_data( "peup4.his"))
    peup5 = Histogram(get_shared_data( "peup5.his"))
    peup6 = Histogram(get_shared_data( "peup6.his"))


    _mixt10 = Estimate(peup2, "MIXTURE", "B", "NB", "NB", "NB",
                      NbComponent="Estimated")

    peup = Merge(peup1, peup2, peup3, peup4, peup5, peup6)

    _histo1 = Shift(peup, -1)
    _histo2 = Cluster(peup, "Information", 0.8)
    _histo3 = Cluster(peup, "Step", 10)
    histo4 = Cluster(peup, "Limit", [13, 24])
    Display(histo4, Detail=2)
    Plot(histo4)

    _mixt11 = Estimate(peup, "MIXTURE", "B", "NB", "NB", "NB",
                      NbComponent="Estimated")

    _mixt11 = Estimate(peup, "MIXTURE", "B", "NB")
Пример #18
0
 def test_binomial(self):
     """BINOMIAL Distribution"""
     h = Histogram(get_shared_data("meri5.his"))
     assert h.estimate_parametric('B')
Пример #19
0
# transformation of histograms, extraction/filter

histo2 = Cluster(fagus, "Step", 2)
histo3 = Cluster(fagus, "Information", 0.8)
histo4 = Cluster(fagus, "Limit", [2, 4, 6, 8, 10])
histo5 = Transcode(fagus, [1, 2, 2, 3, 3, 4, 4, 5])
#Display(histo5, Detail=2)

histo7 = Shift(fagus, -2)

histo8 = ValueSelect(fagus, 2, 8)

dist3 = Estimate(fagus, "B")

# comparison of histograms
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"))

# Compare(meri1, meri2, meri3, meri4, meri5, "N", FileName="ASCII/meri.cmp")
Compare(meri1, meri2, meri3, meri4, meri5, "O")

ComparisonTest("F", meri1, meri2)
ComparisonTest("T", meri1, meri2)
ComparisonTest("W", meri1, meri2)

# fit of a known distribution to an  histogram

dist5 = Fit(meri5, Distribution("B", 0, 10, 0.437879))
def test():
    """Mixture tests from exploratory.aml
    #
    #  Frequency distributions
    #
    #  Objective: Analyzing the number of nodes of growth units in selected architectural
    #                 position considering the respective roles of preformation and neoformation,
    #
    #  Methods: comparison tests, one-way variance analysis,
    #           estimation of finite mixture of distributions.
    #
    #  Wild cherry tree: number of nodes per growth unit (GU)
    #
    #  Data: Dominique Fournier
    #
    #  meri1.his: order 1,
    #  meri1.his: order 2,
    #  meri1.his: order 3, GU 1,
    #  meri1.his: order 3, GU 2,
    #  meri5.his: short shoots.
    #
    #
    #  Poplar: number of nodes per growth unit
    #
    #  Data: Yves Caraglio and Herve Rey
    #
    #  peup1.his: order 2,
    #  peup2.his: order 3,
    #  peup3.his: order 4,
    #  peup4.his: order 5,
    #  peup5.his: order 3, GU 4,
    #  peup6.his: order 3, acrotony.
    #
    #########################################################################
    """

    plot.DISABLE_PLOT = DISABLE_PLOT
    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"))

    Plot(meri1, meri2, meri3, meri4, meri5)
    Compare(meri1, meri2, meri3, meri4, meri5, "N")

    ComparisonTest("F", meri1, meri2)
    ComparisonTest("T", meri1, meri2)
    ComparisonTest("W", meri1, meri2)

    ComparisonTest("F", meri1, meri3)
    ComparisonTest("T", meri1, meri3)
    ComparisonTest("W", meri1, meri3)

    # Estimation of a mixture of two distributions assuming a first
    # sub-population of GUs made only of a preformed part and a second
    # sub-population made of both a preformed part and a neoformed part

    _mixt1 = Estimate(meri2, "MIXTURE", "B", "B")

    meri = Merge(meri1, meri2, meri3, meri4, meri5)

    # model selection approach: estimation of both the mixture parameters and
    # the number of components"""

    mixt2 = Estimate(meri,
                     "MIXTURE",
                     "B",
                     "B",
                     "B",
                     "B",
                     NbComponent="Estimated")
    mixt2 = Estimate(meri, "MIXTURE", "NB", "NB")
    Plot(mixt2)
    Plot(ExtractDistribution(mixt2, "Mixture"))
    Plot(ExtractDistribution(mixt2, "Component", 1),
         ExtractDistribution(mixt2, "Component", 2))
    Display(mixt2)

    _mixt_data = ExtractData(mixt2)

    dist5 = Estimate(meri5, "BINOMIAL")
    Display(dist5, Detail=2)
    Plot(dist5)

    histo5 = Simulate(dist5, 100)
    Display(histo5, Detail=2)
    Plot(histo5)

    peup1 = Histogram(get_shared_data("peup1.his"))
    peup2 = Histogram(get_shared_data("peup2.his"))
    peup3 = Histogram(get_shared_data("peup3.his"))
    peup4 = Histogram(get_shared_data("peup4.his"))
    peup5 = Histogram(get_shared_data("peup5.his"))
    peup6 = Histogram(get_shared_data("peup6.his"))

    _mixt10 = Estimate(peup2,
                       "MIXTURE",
                       "B",
                       "NB",
                       "NB",
                       "NB",
                       NbComponent="Estimated")

    peup = Merge(peup1, peup2, peup3, peup4, peup5, peup6)

    _histo1 = Shift(peup, -1)
    _histo2 = Cluster(peup, "Information", 0.8)
    _histo3 = Cluster(peup, "Step", 10)
    histo4 = Cluster(peup, "Limit", [13, 24])
    Display(histo4, Detail=2)
    Plot(histo4)

    _mixt11 = Estimate(peup,
                       "MIXTURE",
                       "B",
                       "NB",
                       "NB",
                       "NB",
                       NbComponent="Estimated")

    _mixt11 = Estimate(peup, "MIXTURE", "B", "NB")
def test():
    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"))


    Plot(meri1, meri2, meri3, meri4, meri5)
    Compare(meri1, meri2, meri3, meri4, meri5, "N")


    ComparisonTest("F", meri1, meri2)
    ComparisonTest("T", meri1, meri2)
    ComparisonTest("W", meri1, meri2)

    ComparisonTest("F", meri1, meri3)
    ComparisonTest("T", meri1, meri3)
    ComparisonTest("W", meri1, meri3)

    # Estimation of a mixture of two distributions assuming a first
    # sub-population of GUs made only of a preformed part and a second
    # sub-population made of both a preformed part and a neoformed part


    _mixt1 = Estimate(meri2, "MIXTURE", "B", "B")

    meri = Merge(meri1, meri2, meri3, meri4, meri5)

    #model selection approach: estimation of both the mixture parameters and
    # the number of components

    mixt2 = Estimate(meri, "MIXTURE", "B", "B", "B", "B",
                     NbComponent="Estimated")
    mixt2 = Estimate(meri, "MIXTURE", "NB", "NB")
    Plot(mixt2)
    Plot(ExtractDistribution(mixt2, "Mixture"))

    print type(ExtractDistribution(mixt2, "Component", 1))


    Plot(ExtractDistribution(mixt2, "Component", 1),
         ExtractDistribution(mixt2, "Component", 2))
    Display(mixt2)

    _mixt_data = ExtractData(mixt2)

    dist5 = Estimate(meri5, "BINOMIAL")
    Display(dist5, Detail=2)
    Plot(dist5)

    histo5 = Simulate(dist5, 100)
    Display(histo5, Detail=2)
    Plot(histo5)


    peup1 = Histogram(get_shared_data( "peup1.his"))
    peup2 = Histogram(get_shared_data( "peup2.his"))
    peup3 = Histogram(get_shared_data( "peup3.his"))
    peup4 = Histogram(get_shared_data( "peup4.his"))
    peup5 = Histogram(get_shared_data( "peup5.his"))
    peup6 = Histogram(get_shared_data( "peup6.his"))

    _mixt10 = Estimate(peup2, "MIXTURE", "B", "NB", "NB", "NB",
                       NbComponent="Estimated")

    peup = Merge(peup1, peup2, peup3, peup4, peup5, peup6)

    _histo1 = Shift(peup, -1)
    _histo2 = Cluster(peup, "Information", 0.8)
    _histo3 = Cluster(peup, "Step", 10)
    histo4 = Cluster(peup, "Limit", [13, 24])
    Display(histo4, Detail=2)
    Plot(histo4)


    _mixt11 = Estimate(peup, "MIXTURE", "B", "NB", "NB", "NB",
                       NbComponent="Estimated")
    _mixt11 = Estimate(peup, "MIXTURE", "B", "NB")
Пример #22
0
 def get_mixture_2(self):
     """create another mixture data"""
     h = Histogram(get_shared_data("meri2.his"))
     m = h.estimate_mixture("B", "NB")
     return m
    def test_histo_extract_data(self):

        h = Histogram(get_shared_data("meri2.his"))
        mixt = h.estimate_mixture(["B", "NB"])
        assert ExtractData(mixt)
        assert mixt.extract_data() == ExtractData(mixt)
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)
 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 build_data_2(self):
     return Vectors(get_shared_data("chene_sessile.vec"))
# transformation of histograms, extraction/filter

histo2 = Cluster(fagus, "Step", 2)
histo3 = Cluster(fagus, "Information", 0.8)
histo4 = Cluster(fagus, "Limit", [2, 4, 6, 8, 10])
histo5 = Transcode(fagus, [1, 2, 2, 3, 3, 4, 4, 5])
#Display(histo5, Detail=2)

histo7 = Shift(fagus, -2)

histo8 = ValueSelect(fagus, 2, 8)

dist3 = Estimate(fagus, "B")

# comparison of histograms
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"))


# Compare(meri1, meri2, meri3, meri4, meri5, "N", FileName="ASCII/meri.cmp")
Compare(meri1, meri2, meri3, meri4, meri5, "O")

ComparisonTest("F", meri1, meri2)
ComparisonTest("T", meri1, meri2)
ComparisonTest("W", meri1, meri2)

# fit of a known distribution to an  histogram
Пример #28
0
 def __init__(self):
     self.meri1 = Histogram(get_shared_data("meri1.his"))
     self.meri2 = Histogram(get_shared_data("meri1.his"))
     self.meri3 = Histogram(get_shared_data("meri1.his"))
Пример #29
0
 def test_mixture_2(self):
     h = Histogram(get_shared_data( "peup2.his"))
     m2 = h.estimate_mixture([Binomial(0, 10, 0.5), "NB"])
     assert m2
Пример #30
0
 def get_mixture_2(self):
     """create another mixture data"""
     h = Histogram(get_shared_data("meri2.his"))
     m = h.estimate_mixture("B", "NB")
     return m
 def hist_data(self):
     h = Histogram(get_shared_data( "meri2.his"))
     return h
 def __init__(self):
     self.meri1 = Histogram(get_shared_data("meri1.his"))
     self.meri2 = Histogram(get_shared_data("meri1.his"))
     self.meri3 = Histogram(get_shared_data("meri1.his"))
Пример #33
0
 def build_data_2(self):
     return Vectors(get_shared_data("chene_sessile.vec"))
Пример #34
0
 def __init__(self):
     interface.__init__(self,
                        self.build_data(),
                        str(get_shared_data("peup1.his")),
                        Histogram)
Пример #35
0
 def test_nonparametric(self):
     h = Histogram(get_shared_data("meri1.his"))
     e =  h.estimate_nonparametric()
     assert e
Пример #36
0
    def test_container(self):
        """ container / iterator"""
        h = Histogram(str(get_shared_data("meri1.his")))

        assert h[0] == 0
        assert h[10] == 1
Пример #37
0
 def test_nb(self):
     """NegativeBinomial"""
     h = Histogram(get_shared_data("peup2.his"))
     assert h.estimate_parametric('NB')
 def test_value_select_float(self):
     meri1 = Histogram(get_shared_data("meri1.his"))
     # note keep=False is equivalent to Mode=keep,is this correct ?
     assert str(ValueSelect(meri1, 0, 10, Mode="Keep"))==\
         str(meri1.value_select( min=0, max=10, keep=True))
def test():
    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"))

    Plot(meri1, meri2, meri3, meri4, meri5)
    Compare(meri1, meri2, meri3, meri4, meri5, "N")

    ComparisonTest("F", meri1, meri2)
    ComparisonTest("T", meri1, meri2)
    ComparisonTest("W", meri1, meri2)

    ComparisonTest("F", meri1, meri3)
    ComparisonTest("T", meri1, meri3)
    ComparisonTest("W", meri1, meri3)

    # Estimation of a mixture of two distributions assuming a first
    # sub-population of GUs made only of a preformed part and a second
    # sub-population made of both a preformed part and a neoformed part

    _mixt1 = Estimate(meri2, "MIXTURE", "B", "B")

    meri = Merge(meri1, meri2, meri3, meri4, meri5)

    #model selection approach: estimation of both the mixture parameters and
    # the number of components

    mixt2 = Estimate(meri,
                     "MIXTURE",
                     "B",
                     "B",
                     "B",
                     "B",
                     NbComponent="Estimated")
    mixt2 = Estimate(meri, "MIXTURE", "NB", "NB")
    Plot(mixt2)
    Plot(ExtractDistribution(mixt2, "Mixture"))

    print type(ExtractDistribution(mixt2, "Component", 1))

    Plot(ExtractDistribution(mixt2, "Component", 1),
         ExtractDistribution(mixt2, "Component", 2))
    Display(mixt2)

    _mixt_data = ExtractData(mixt2)

    dist5 = Estimate(meri5, "BINOMIAL")
    Display(dist5, Detail=2)
    Plot(dist5)

    histo5 = Simulate(dist5, 100)
    Display(histo5, Detail=2)
    Plot(histo5)

    peup1 = Histogram(get_shared_data("peup1.his"))
    peup2 = Histogram(get_shared_data("peup2.his"))
    peup3 = Histogram(get_shared_data("peup3.his"))
    peup4 = Histogram(get_shared_data("peup4.his"))
    peup5 = Histogram(get_shared_data("peup5.his"))
    peup6 = Histogram(get_shared_data("peup6.his"))

    _mixt10 = Estimate(peup2,
                       "MIXTURE",
                       "B",
                       "NB",
                       "NB",
                       "NB",
                       NbComponent="Estimated")

    peup = Merge(peup1, peup2, peup3, peup4, peup5, peup6)

    _histo1 = Shift(peup, -1)
    _histo2 = Cluster(peup, "Information", 0.8)
    _histo3 = Cluster(peup, "Step", 10)
    histo4 = Cluster(peup, "Limit", [13, 24])
    Display(histo4, Detail=2)
    Plot(histo4)

    _mixt11 = Estimate(peup,
                       "MIXTURE",
                       "B",
                       "NB",
                       "NB",
                       "NB",
                       NbComponent="Estimated")
    _mixt11 = Estimate(peup, "MIXTURE", "B", "NB")