#########################################################################
    """
    seq1 = Sequences(str(get_shared_data( "well_log_filtered.seq")))
    Plot(seq1, ViewPoint="Data")
    Plot(seq1)

    SelectStep(seq1, 1000)
    Plot(seq1)

    #Display(seq1, 1, 17, "Gaussian", ViewPoint="SegmentProfile", NbSegmentation=5)
    Plot(seq1, 1, 17, "Gaussian", ViewPoint="SegmentProfile")

    # seq20 = Segmentation(seq1, 1, 20, "Gaussian")
    # seq40 = Segmentation(seq1, 1, 40, "Gaussian")

    # seq20 = Segmentation(seq1, 1, 20, "Mean")
    # seq40 = Segmentation(seq1, 1, 40, "Mean")

    # seq16 = Segmentation(seq1, 1, 16, "Gaussian", NbSegment->"Fixed")

    vec1 = Vectors(seq1)
    Plot(vec1)

    SelectStep(vec1, 1000)
    Plot(vec1)

if __name__ == "__main__":
    runTestClass(TestMerge())
    runTestClass(TestRemoveRun())
    test_compute_state_sequence()
Ejemplo n.º 2
0
        self.sequence = Sequences(get_shared_data("wij1.seq"))

    def _test_estimate(self):
        seq = self.sequence
        # data is a hsm class
        Estimate(seq, "SEMI-MARKOV", "Ordinary")


class Test_Estimate_time_events():
    """test not yet implemented"""
    pass


class Test_Estimate_tops():
    """tests not yet implemented"""
    def __init__(self):
        self.data = TopsData()

    def test_estimate(self):
        Estimate(self.data, MinPosition=1, MaxPosition=10)


if __name__ == "__main__":
    runTestClass(Test_Estimate_HIDDEN_VARIABLE_ORDER_MARKOV())
    runTestClass(Test_Estimate_VARIABLE_ORDER_MARKOV_from_markovian())
    runTestClass(Test_Estimate_VARIABLE_ORDER_MARKOV())
    runTestClass(Test_Estimate_Histogram())
    runTestClass(Test_Estimate_tops())
    runTestClass(Test_Estimate_HIDDEN_SEMI_MARKOV())
    runTestClass(Test_Estimate_SEMI_MARKOV())
    def __init__(self):
        _Cluster.__init__(self)
        self.data = self.create_data()

    def create_data(self):
        data = Sequences(str(get_shared_data('sequences2.seq')))
        return data

    def test_cluster_step(self):
        data = self.data
        mode = True
        cluster1 = data.cluster_step(1, 2, mode)
        cluster2 = Cluster(data, "Step", 1, 2)
        assert str(cluster1) == str(cluster2)

    def test_cluster_limit(self):
        data = self.data
        cluster1 = data.cluster_limit(1, [2 ], True)
        cluster2 = Cluster(data, "Limit", 1, [2])
        assert str(cluster1) == str(cluster2)

if __name__ ==  "__main__":
    runTestClass(TestVectors1())
    runTestClass(TestVectorsn())
    runTestClass(TestSequences1())
    runTestClass(TestSequencesn())
    runTestClass(TestConvolution())
    runTestClass(TestCompound())
    runTestClass(TestHistogram())
Ejemplo n.º 4
0
    def __init__(self):
        _Cluster.__init__(self)
        self.data = self.create_data()

    def create_data(self):
        data = Sequences(str(get_shared_data('sequences2.seq')))
        return data

    def test_cluster_step(self):
        data = self.data
        mode = True
        cluster1 = data.cluster_step(1, 2, mode)
        cluster2 = Cluster(data, "Step", 1, 2)
        assert str(cluster1) == str(cluster2)

    def test_cluster_limit(self):
        data = self.data
        cluster1 = data.cluster_limit(1, [2], True)
        cluster2 = Cluster(data, "Limit", 1, [2])
        assert str(cluster1) == str(cluster2)


if __name__ == "__main__":
    runTestClass(TestVectors1())
    runTestClass(TestVectorsn())
    runTestClass(TestSequences1())
    runTestClass(TestSequencesn())
    runTestClass(TestConvolution())
    runTestClass(TestCompound())
    runTestClass(TestHistogram())
Ejemplo n.º 5
0
        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))


if __name__ == "__main__":
    runTestClass(Test())
            assert True
        try:
            d = Multinomial()
            assert False
        except:
            assert True

    def test_simulation(self):
        """simulate a vector of realizations"""
        d = Uniform(0, 1)
        try:
            import numpy
            l = numpy.zeros(100000)
            for i in range(len(l)):
                l[i] = d.simulation()
            assert ((0 < sum(l)) & (sum(l) < len(l)))
        except:
            pass

    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


if __name__ == "__main__":
    runTestClass(Test())
    runTestClass(TestDistribution())
        """test VarianceAnalysis"""
        # todo: finalise and make method variance_analysis robust.
        vec10 = self.vec10
        va = VarianceAnalysis(vec10, 1, 4, "O")
        assert vec10.variance_analysis(1, 4, 1, "whatever", variance_type['O']) == \
            str(va)
    
        try:
            va = VarianceAnalysis(vec10, 1, 4, "DUMMY")
            assert False
        except:
            assert True

    def test_contingency_table(self):
        """test contingency table"""
        vec10 = self.vec10
        ct = ContingencyTable(vec10, 1, 4)
        assert ct and str(ct)

        ct2 = vec10.contingency_table(1, 4, "what", OutputFormat.ASCII)
        assert ct == ct2

    def test_rank_computation(self):
        vec10 = self.vec10
        ComputeRankCorrelation(vec10, Type="Kendall", FileName="test")
        #ComputeRankCorrelation(vec10, Type="Spearman", FileName="test")

if __name__ == "__main__":
    test = Test()
    runTestClass(test)
        except:
            assert True


    def test_simulation(self):
        """simulate a vector of realizations"""
        d = Uniform(0, 1)
        try:
            import numpy
            l = numpy.zeros(100000)
            for i in range(len(l)):
                l[i] = d.simulation()
            assert((0 < sum(l)) & (sum(l) < len(l)))
        except:
            pass
    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






if __name__ == "__main__":
    runTestClass(Test())
    runTestClass(TestDistribution())
Ejemplo n.º 9
0
        except TypeError:
            assert True


class _TestRegressionKernel():
    def __init__(self):
        self.data = RegressionKernel(4, 0, 10)

    def test_max_value(self):
        assert self.data.max_value == 10

    def test_min_value(self):
        assert self.data.min_value == 0

    def test_get_ident(self):
        assert self.data.ident == 4

    def others_to_be_done(self):
        #there are other methods that need to be tested with an
        #appropriate examples:
        #get_point
        #get_regression_df
        #get_residual_df
        #get_nb_parameter
        #get_parameter
        pass


if __name__ == "__main__":
    runTestClass(TestRegression())
Ejemplo n.º 10
0
        except TypeError:
            assert True


class _TestRegressionKernel:
    def __init__(self):
        self.data = RegressionKernel(4, 0, 10)

    def test_max_value(self):
        assert self.data.max_value == 10

    def test_min_value(self):
        assert self.data.min_value == 0

    def test_get_ident(self):
        assert self.data.ident == 4

    def others_to_be_done(self):
        # there are other methods that need to be tested with an
        # appropriate examples:
        # get_point
        # get_regression_df
        # get_residual_df
        # get_nb_parameter
        # get_parameter
        pass


if __name__ == "__main__":
    runTestClass(TestRegression())
Ejemplo n.º 11
0
        _c1 = Compare(meri1, meri2, meri3, 'N', Filename='result.dat', \
                     Format='SpreadSheet')
        os.remove('result.dat')
        try:
            _c1 = Compare(meri1, meri2, meri3, 'N', Filename='result.dat', \
                         Format='badname')
            assert False
        except ValueError:
            assert True


class TestVectors():
    def __init__(self):
        pass

    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)


if __name__ == "__main__":
    runTestClass(TestHisto())
    runTestClass(TestVectors())
Ejemplo n.º 12
0
class Test_Compare_hsmc_with_sequences(_Compare):
    def __init__(self):
        _Compare.__init__(self)
        self.data = self.create_data()

    def create_data(self):
        hsmc0 = HiddenSemiMarkov(get_shared_data("belren1.hsc"))
        hsmc1 = HiddenSemiMarkov(get_shared_data("elstar1.hsc"))
        seq0 = Sequences(get_shared_data("belren1.seq"))
        seq1 = Sequences(get_shared_data("elstar1.seq"))
        data0 = Estimate(seq0, "HIDDEN_SEMI-MARKOV", hsmc0)
        data1 = Estimate(seq1, "HIDDEN_SEMI-MARKOV", hsmc1)
        return [seq0, seq1, data0, data1]

    def test_compare(self):
        data = self.data
        matrix20 = Compare(Thresholding(data[2],
                                        MinProbability=0.001), data[0],
                           Thresholding(data[3], MinProbability=0.001),
                           data[1], 10000)
        assert matrix20


if __name__ == "__main__":
    runTestClass(Test_Compare_Histograms())
    runTestClass(Test_Compare_Sequences())
    runTestClass(Test_Compare_Sequences_VectorDistance())
    runTestClass(Test_Compare_Vectors_VectorDistance())
    runTestClass(Test_Compare_hsmc_with_sequences())
Ejemplo n.º 13
0
class Test_Compare_hsmc_with_sequences(_Compare):

    def __init__(self):
        _Compare.__init__(self)
        self.data = self.create_data()

    def create_data(self):
        hsmc0 = HiddenSemiMarkov(get_shared_data( "belren1.hsc"))
        hsmc1 = HiddenSemiMarkov(get_shared_data("elstar1.hsc"))
        seq0 = Sequences(get_shared_data( "belren1.seq"))
        seq1 = Sequences(get_shared_data( "elstar1.seq"))
        data0 = Estimate(seq0, "HIDDEN_SEMI-MARKOV", hsmc0)
        data1 = Estimate(seq1, "HIDDEN_SEMI-MARKOV", hsmc1)
        return [seq0, seq1, data0, data1]

    def test_compare(self):
        data = self.data
        matrix20 = Compare(Thresholding(data[2], MinProbability=0.001), data[0],
                           Thresholding(data[3], MinProbability=0.001), data[1],
                           10000)
        assert matrix20


if __name__ ==  "__main__":
    runTestClass(Test_Compare_Histograms())
    runTestClass(Test_Compare_Sequences())
    runTestClass(Test_Compare_Sequences_VectorDistance())
    runTestClass(Test_Compare_Vectors_VectorDistance())
    runTestClass(Test_Compare_hsmc_with_sequences())
        os.remove('result.dat')
        try:
            _c1 = Compare(meri1, meri2, meri3, 'N', Filename='result.dat', \
                         Format='badname')
            assert False
        except ValueError:
            assert True


class TestVectors():

    def __init__(self):
        pass

    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)



if __name__ == "__main__":
    runTestClass(TestHisto())
    runTestClass(TestVectors())
    def test_vector(self):
        v = self.int_vector_data()

        v1 =  SelectVariable(v, 1, Mode="keep")
        v2 =  SelectVariable(v, 2, Mode="Keep")
        v3 =  SelectVariable(v, 3, Mode="Keep")

        merged = MergeVariable(v1, v2, v3)
        merged2 = v1.merge_variable([v2, v3], 1)
        for i in range(3):
            for j in range(3):
                assert merged[i][j] == v[i][j]

        assert str(merged) == str(merged2)



if __name__ == "__main__":
    runTestClass(TestSelectHist())
    runTestClass(TestFit())
    runTestClass(TestShift())
    runTestClass(TestExtractHistogram())
    runTestClass(TestMerge())
    runTestClass(TestMergeVariable())
    runTestClass(TestValueSelect())
    runTestClass(TestSelectVariable())
    runTestClass(TestSelectIndividual())
    runTestClass(TestExtract())
    runTestClass(TestExtractData())
    runTestClass(TestExtractDistribution())
    def __init__(self):
        TestComputeCorrelation.__init__(self)
        self.correlation = self.test_pearson()

    def test_filter(self):
        data = self.correlation
        ComputeWhiteNoiseCorrelation(data, [1, 1, 1])

    def test_order(self):
        data = self.correlation
        ComputeWhiteNoiseCorrelation(data, 1)

    def test_distribution(self):
        data = self.correlation
        ComputeWhiteNoiseCorrelation(data , Distribution("BINOMIAL", 0,4,0.5))

class TestComputePartialAutoCorrelation(Data):

    def __init__(self):
        Data.__init__(self)

    def test_compute_partial_auto_correlation(self):
        ComputePartialAutoCorrelation(self.sequence, 2, MaxLag=5)
        ComputePartialAutoCorrelation(self.sequence, MaxLag=5)


if __name__ == "__main__":
    runTestClass(TestComputeCorrelation())
    runTestClass(TestComputePartialAutoCorrelation())
    runTestClass(TestComputeWhiteNoiseCorrelation())
Ejemplo n.º 17
0
        # todo: finalise and make method variance_analysis robust.
        vec10 = self.vec10
        va = VarianceAnalysis(vec10, 1, 4, "O")
        assert vec10.variance_analysis(1, 4, 1, "whatever", variance_type['O']) == \
            str(va)

        try:
            va = VarianceAnalysis(vec10, 1, 4, "DUMMY")
            assert False
        except:
            assert True

    def test_contingency_table(self):
        """test contingency table"""
        vec10 = self.vec10
        ct = ContingencyTable(vec10, 1, 4)
        assert ct and str(ct)

        ct2 = vec10.contingency_table(1, 4, "what", OutputFormat.ASCII)
        assert ct == ct2

    def test_rank_computation(self):
        vec10 = self.vec10
        ComputeRankCorrelation(vec10, Type="Kendall", FileName="test")
        #ComputeRankCorrelation(vec10, Type="Spearman", FileName="test")


if __name__ == "__main__":
    test = Test()
    runTestClass(test)
    """
    seq1 = Sequences(str(get_shared_data("well_log_filtered.seq")))
    Plot(seq1, ViewPoint="Data")
    Plot(seq1)

    SelectStep(seq1, 1000)
    Plot(seq1)

    #Display(seq1, 1, 17, "Gaussian", ViewPoint="SegmentProfile", NbSegmentation=5)
    Plot(seq1, 1, 17, "Gaussian", ViewPoint="SegmentProfile")

    # seq20 = Segmentation(seq1, 1, 20, "Gaussian")
    # seq40 = Segmentation(seq1, 1, 40, "Gaussian")

    # seq20 = Segmentation(seq1, 1, 20, "Mean")
    # seq40 = Segmentation(seq1, 1, 40, "Mean")

    # seq16 = Segmentation(seq1, 1, 16, "Gaussian", NbSegment->"Fixed")

    vec1 = Vectors(seq1)
    Plot(vec1)

    SelectStep(vec1, 1000)
    Plot(vec1)


if __name__ == "__main__":
    runTestClass(TestMerge())
    runTestClass(TestRemoveRun())
    test_compute_state_sequence()
Ejemplo n.º 19
0
    def __init__(self):
        TestComputeCorrelation.__init__(self)
        self.correlation = self.test_pearson()

    def test_filter(self):
        data = self.correlation
        ComputeWhiteNoiseCorrelation(data, [1, 1, 1])

    def test_order(self):
        data = self.correlation
        ComputeWhiteNoiseCorrelation(data, 1)

    def test_distribution(self):
        data = self.correlation
        ComputeWhiteNoiseCorrelation(data, Distribution("BINOMIAL", 0, 4, 0.5))


class TestComputePartialAutoCorrelation(Data):
    def __init__(self):
        Data.__init__(self)

    def test_compute_partial_auto_correlation(self):
        ComputePartialAutoCorrelation(self.sequence, 2, MaxLag=5)
        ComputePartialAutoCorrelation(self.sequence, MaxLag=5)


if __name__ == "__main__":
    runTestClass(TestComputeCorrelation())
    runTestClass(TestComputePartialAutoCorrelation())
    runTestClass(TestComputeWhiteNoiseCorrelation())
        # assert str(a)==str(b)

    def test_extract(self):
        pass
        self.data.extract(1, 1, 1)

    def test_extract_data(self):
        self.data.extract_data()


"""
hsm.nb_output_process
hsm.ascii_write
hsm.divergence_computation
hsm.simulation_histogram
hsm.extract_histogram
hsm.simulation_markovian_sequences
hsm.file_ascii_write
hsm.get_forward
hsm.simulation_nb_sequences
hsm.get_plotable
hsm.get_semi_markov_data
hsm.state_sequence_computation
hsm.get_state_subtype
hsm.nb_iterator
"""


if __name__ == "__main__":
    runTestClass(Test())
    def _test_estimate(self):
        seq = self.sequence
        # data is a hsm class
        Estimate(seq, "SEMI-MARKOV", "Ordinary")


class Test_Estimate_time_events():
    """test not yet implemented"""
    pass

class Test_Estimate_tops():
    """tests not yet implemented"""

    def __init__(self):
        self.data = TopsData()

    def test_estimate(self):
        Estimate(self.data, MinPosition=1, MaxPosition=10)



if __name__ == "__main__":
    runTestClass(Test_Estimate_HIDDEN_VARIABLE_ORDER_MARKOV())
    runTestClass(Test_Estimate_VARIABLE_ORDER_MARKOV_from_markovian())
    runTestClass(Test_Estimate_VARIABLE_ORDER_MARKOV())
    runTestClass(Test_Estimate_Histogram())
    runTestClass(Test_Estimate_tops())
    runTestClass(Test_Estimate_HIDDEN_SEMI_MARKOV())
    runTestClass(Test_Estimate_SEMI_MARKOV())