def test_merge_correlation():
    c1 = CorrelationData(1)
    c2 = CorrelationData(2)
    c3 = CorrelationData(3)
    c = Merge(c1,c2,c3)
    c_bis = c1.merge([c2,c3])
    assert str(c)==str(c_bis)
    c.plot()
    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 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_merge_vectors(self):

        v1 = self.int_vector_data()
        b = [[2, 78, 45],
             [6, 2, 122],
             [3, 4, 31],]
        v2 = Vectors(b)

        v = Merge(v1, v2)
        assert v

        a = v1.merge([v2])
        b = v2.merge([v1])
        assert str(a)==str(b)

        assert str(a)==str(v)
        Plot(v)
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")
def test_merge_tops():
    t1 = TopsData()
    t2 = TopsData()
    t = Merge(t1, t2)
    t.plot()
def _test_merge_semi_markov_data():
    sm1 = SemiMarkovData()
    sm2 = SemiMarkovData()
    sm = Merge(sm1, sm2)
def test_merge_sequences():
    from test_sequences import Test as sequences_data
    sequences = sequences_data()
    data = sequences.build_data()
    assert Merge(data, data)
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 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)