Exemplo n.º 1
0
 def test_constructor_two_sequences(self):
     # two sequences with 2 variables (int)
     s = Sequences([[[1, 1, 1], [12, 12, 12]], [[2, 2, 2], [22, 23, 24]]])
     assert s
     s = Sequences([[[1., 1., 1.], [1., 1., 1.]],
                    [[2., 2., 2.], [2., 2., 2.]]])
     assert s
 def test_cluster_limit(self):
     seq1 = Sequences([[1, 2, 3], [1, 3, 1], [4, 5, 6]])
     assert str(Cluster(seq1, "Limit", 1, [2])) == \
         str(seq1.cluster_limit(1, [2], True))
     seqn = Sequences([[[1, 2, 3], [1, 3, 1]], [[4, 5, 6], [7,8,9]]])
     assert str(Cluster(seqn, "Limit", 1, [2, 4, 6])) == \
         str(seqn.cluster_limit(1, [2, 4 ,6], True))
Exemplo n.º 3
0
 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 test1():
    """FIXME markovian_sequences call"""
    seq69 = Sequences(get_shared_data("pin_laricio_7x.seq"))
    a = IndexParameterExtract(seq69, 1929)
    b = IndexParameterExtract(seq69, 1929, 1994)
    c = seq69.index_parameter_extract(1929, -1).markovian_sequences()
    d = seq69.index_parameter_extract(1929, 1994).markovian_sequences()
    assert str(a) == str(c)
    assert str(b) == str(d)
Exemplo n.º 5
0
    def test_index_parameter_type(self):

        seq1 = Sequences([[1., 1, 1], [2., 2, 2.]])
        assert IndexParameterType(seq1) == 'IMPLICIT_TYPE'
        seq1 = Sequences([[1., 1, 1], [2., 2, 2.]], IndexParameterType="TIME")
        assert IndexParameterType(seq1) == 'TIME'
        seq1 = Sequences([[1., 1, 1], [2., 2, 2.]],
                         IndexParameterType="POSITION")
        assert IndexParameterType(seq1) == 'POSITION'
def CorrelationData(index=1):
    """Returns a correlation

    index from 1 to 3"""
    seq66 = Sequences(get_shared_data("laricio_date66.seq"))
    ret = ComputeCorrelation(seq66, index)
    return ret
Exemplo n.º 7
0
 def create_data(self):
     seq0 = Sequences(get_shared_data("chene_sessile_15pa.seq"))
     vec10 = Vectors(seq0)
     vec95 = ValueSelect(vec10, 1, 95)
     vec96 = ValueSelect(vec10, 1, 96)
     vec97 = ValueSelect(vec10, 1, 97)
     return [vec95, vec96, vec97]
def test_select_step():
    """
    #########################################################################
    #
    #  Well-log data; used in Fearnhead and Clifford "On-line Inference for 
    #  Hidden Markov Models via Particle Filters". Measurements of Nuclear-response
    #  of a well-bore over time. Data from O Ruanaidh, J. J. K. and 
    #  Fitzgerald, W. J. (1996). "Numerical Bayesion Methods Applied to Signal 
    #  Processing". New York: Springer.
    #
    #########################################################################
    """
    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)
Exemplo n.º 9
0
def _create_sequences(g):
    """
    0: nothing
    1: Short
    2: Medium
    3: Long


    to be cleaned and added to mtgtools
    """
    from openalea.sequence_analysis import Sequences
    Activate(g)
    apices_ids = [id for id in Components(2, 4) if Class(id) == 'A']
    branch_ids = Sons(2)
    branch_length = [g.property('Branch')[id].length for id in Sons(2)]
    branch_rank = [g.property('Branch')[id].context.rank for id in Sons(2)]
    apices_rank = [
        g.property('Apex')[id].context.rank
        for id in g.components_at_scale(2, 4) if Class(id) == 'A'
    ]
    values = []
    for rank in apices_rank:
        values.append((rank, 0))
    for rank, length in zip(branch_rank, branch_length):
        values.append((rank, convert2LMS(length)))
    import numpy
    dtype = [('index', int), ('length', float)]

    a = numpy.array(values, dtype=dtype)
    new = numpy.sort(a, order='index')
    return Sequences([[[int(x)] for x in new['length']]]), new
def test_transition_count():
    seq = Sequences(str(get_shared_data("wij1.seq")))
    TransitionCount(seq,
                    5,
                    Begin=True,
                    Estimator="MaximumLikelihood",
                    Filename="ASCII")
Exemplo n.º 11
0
    def create_sequence_branch_on_trunk(self):
        """return sequence of the branch category on trunk

        where category are L, M, or S
        """
        var1 = self.get_branch_length_on_trunk()
        from openalea.sequence_analysis.sequences import Sequences
        return Sequences(convert2LMS(var1))
def test_compute_state_sequence():
    from openalea.sequence_analysis import HiddenSemiMarkov
    seq = Sequences(str(get_shared_data("wij1.seq")))
    hsmc0 = HiddenSemiMarkov(str(get_shared_data("wij1.hsc")))
    ComputeStateSequences(seq,
                          hsmc0,
                          Algorithm="ForwardBackward",
                          Characteristics=True)
Exemplo n.º 13
0
 def test_constructor_one_sequence(self):
     # two sequences with 2 variables (int)
     s = Sequences([[1, 1, 1], [2, 2, 2]])
     assert s
     # two sequences with 2 variables (real)
     s = Sequences([[1., 1., 1.], [2., 2., 2.]])
     assert s
     # two sequences with 2 variables mix of (real and int)
     # works because the first one is float so all others are assume to be float as well
     s = Sequences([[1., 1., 1.], [2., 2., 2]])
     assert s
     # here it fails because the first number is int but others may be float
     try:
         s = Sequences([[1, 1., 1.], [2., 2., 2]])
         assert False
     except:
         assert True
Exemplo n.º 14
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
Exemplo n.º 15
0
 def test_spearman(self):
     seq = Sequences(get_shared_data("laricio_date66.seq"))
     ComputeCorrelation(seq, 1, Type="Spearman")
     ComputeCorrelation(seq, 1, 2, Type="Spearman")
     try:
         dummy = 3
         ComputeCorrelation(seq, 1, 2, dummy, Type="Spearman")
     except:
         assert True
Exemplo n.º 16
0
    def build_data(self):
        """todo: check identifier output. should be a list """
        # build a list of 2 sequences with a variable that should be identical
        # to sequences1.seq
        data = Sequences([[
            1, 0, 0, 0, 1, 1, 2, 0, 2, 2, 2, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1,
            1, 1, 0, 1, 2, 2, 2, 1
        ], [0, 0, 0, 1, 1, 0, 2, 0, 2, 2, 2, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0]])
        assert data

        assert data.nb_sequence == 2
        assert data.nb_variable == 1
        assert data.cumul_length == 52
        assert data.max_length == 30

        assert [0, 1] == data.get_identifiers()

        return data
    def build_data(self):
        """todo: check identifier output. should be a list """
        # build a list of 2 sequences with a variable that should be identical
        # to sequences1.seq
        data = Sequences([
                    [1, 0, 0, 0, 1, 1, 2, 0, 2, 2, 2, 1, 1, 0, 1, 0,
                     1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 2, 2, 2, 1],
                    [0, 0, 0, 1, 1, 0, 2, 0, 2, 2 ,2 ,1 ,1 ,1 ,1 ,0 ,1
                     ,0 ,0 ,0 ,0 ,0]])
        assert data

        assert data.nb_sequence == 2
        assert data.nb_variable == 1
        assert data.cumul_length == 52
        assert data.max_length == 30

        assert [0, 1] == data.get_identifiers()

        return data
Exemplo n.º 18
0
 def test_cluster_limit(self):
     seq1 = Sequences([[1, 2, 3], [1, 3, 1], [4, 5, 6]])
     assert str(Cluster(seq1, "Limit", 1, [2])) == \
         str(seq1.cluster_limit(1, [2], True))
     seqn = Sequences([[[1, 2, 3], [1, 3, 1]], [[4, 5, 6], [7, 8, 9]]])
     assert str(Cluster(seqn, "Limit", 1, [2, 4, 6])) == \
         str(seqn.cluster_limit(1, [2, 4 ,6], True))
Exemplo n.º 19
0
 def test_cluster_step(self):
     seq1 = Sequences([[1, 2, 3], [1, 3, 1], [4, 5, 6]])
     assert str(Cluster(seq1, "Step", 1,
                        2)) == str(seq1.cluster_step(1, 2, True))
     seqn = Sequences([[[1, 2, 3], [1, 3, 1]], [[4, 5, 6], [7, 8, 9]]])
     assert str(Cluster(seqn, "Step", 1,
                        2)) == str(seqn.cluster_step(1, 2, True))
Exemplo n.º 20
0
    def test_constructors(self):
        # heterogeneous or homogeneous type
        seq1 = Sequences([1, 2, 3, 4])
        seq1 = Sequences([1, 2, 3, 4.])
        assert seq1.nb_sequence == 1
        assert seq1.nb_variable == 1

        # single sequence multivariate
        seq2 = Sequences([[1, 2], [3, 4], [5, 6]])
        assert seq2.nb_sequence == 1
        assert seq2.nb_variable == 2
        #ambiguous case (length>5)
        seq2 = Sequences([[1, 2, 3, 4, 5, 6], [3, 4, 3, 4, 5, 6],
                          [5, 6, 4, 5, 6, 7]])
        assert seq2.nb_sequence == 3
        assert seq2.nb_variable == 1

        # univariates sequences
        seq3 = Sequences([[1, 2], [3, 4], [5, 6, 7]])
        assert seq3.nb_sequence == 3
        assert seq3.nb_variable == 1

        # general case
        seq4 = Sequences([[[1, 2], [3, 4]], [[21, 22], [23, 24]],
                          [[31, 32], [33, 34], [35, 36]]])
        assert seq4.nb_sequence == 3
        assert seq4.nb_variable == 2

        seq4 = Sequences([[[1, 2], [3, 4]], [[21, 22], [23, 24]],
                          [[31, 32], [33, 34], [35, 36]]],
                         VertexIdentifiers=[[1, 2], [3, 4], [5, 6, 7]],
                         Identifiers=[1, 2, 3])

        seq4 = Sequences([[[1, 2], [3, 4]], [[21, 22], [23, 24]],
                          [[31, 32], [33, 34], [35, 36]]],
                         IndexParameterType="POSITION",
                         IndexParameter=[[0, 1, 10], [2, 3, 11], [4, 5, 6,
                                                                  12]])

        seq4 = Sequences([[[1, 2], [3, 4]], [[21, 22], [23, 24]],
                          [[31, 32], [33, 34], [35, 36]]],
                         IndexParameterType="TIME",
                         IndexParameter=[[0, 1], [2, 3], [4, 5, 6]])
 def test_cluster_step(self):
     seq1 = Sequences([[1, 2, 3], [1, 3, 1], [4, 5, 6]])
     assert str(Cluster(seq1, "Step", 1, 2)) == str(seq1.cluster_step(1, 2, True))
     seqn = Sequences([[[1, 2, 3], [1, 3, 1]], [[4, 5, 6], [7,8,9]]])
     assert str(Cluster(seqn, "Step", 1, 2)) == str(seqn.cluster_step(1, 2, True))
Exemplo n.º 22
0
 def build_seqn(self):
     s = Sequences([[[1, 1, 1], [12, 12, 12]], [[2, 2, 2], [22, 23, 24]]])
     return s
Exemplo n.º 23
0
 def build_seq1(self):
     s = Sequences([[1, 1, 1], [2, 2, 2]])
     return s
 def _test_sequences_2(self):
     seq1 = Sequences(str(get_shared_data("sequences2.seq")))
     seq2 = seq1.remove_run(1, 0, "e", 2)
     seq3 = RemoveRun(seq1, 1, 0, "e", 2)
     assert str(seq3) == str(seq2)
 def __init__(self):
     self.data = Sequences(str(get_shared_data("sequences1.seq")))
Exemplo n.º 26
0
 def build_seq_wrong_identifiers(self):
     try:
         s = Sequences([[1, 1, 1], [2, 2, 2]], Identifiers=[-1, 1])
         assert False
     except:
         assert True
Exemplo n.º 27
0
 def create_data(self):
     seq = Sequences(get_shared_data('sequences1.seq'))
     return seq
Exemplo n.º 28
0
def test_get_shared_data():
    from openalea.sequence_analysis.sequences import Sequences
    seq = Sequences(str(get_shared_data('wij1.seq')))
Exemplo n.º 29
0
 def create_data(self):
     seq = Sequences(get_shared_data('dupreziana_a1.seq'))
     return seq
Exemplo n.º 30
0
 def test_split(self):
     #markovian sequences
     data = Sequences(str(get_shared_data('vanille_m.seq')))
     Split(data, 2)
Exemplo n.º 31
0
 def create_data(self):
     data = Sequences(str(get_shared_data('sequences2.seq')))
     return data
Exemplo n.º 32
0
 def test_initial_run(self):
     from openalea.sequence_analysis import ComputeInitialRun
     #markovian sequences
     data = Sequences(str(get_shared_data('vanille_m.seq')))
     ComputeInitialRun(data)
 def _test_sequences_2(self):
     seq1 = Sequences(str(get_shared_data("sequences2.seq")))
     seq2 = seq1.remove_run(1, 0,"e",2)
     seq3 = RemoveRun(seq1,1, 0,"e",2)
     assert str(seq3)==str(seq2)
Exemplo n.º 34
0
    def build_data(self):
        seq = Sequences(str(get_shared_data("belren1.seq")))
        vom = Estimate(seq, "VARIABLE_ORDER_MARKOV", "Ordinary",
                        MaxOrder=4, GlobalInitialTransition=False)

        return vom