import model
import numpy as np
import datasetReader as df
import main

# Number of traces loaded T
T = 1
# Generate traces
traces_factory = df.DatasetFactory()
traces_factory.createDataset(T)
traces = traces_factory.traces

P0 = np.matrix("[ .02 0;"
                "0 0 0.5;"
                "0 0 0]")

P1 = np.matrix("[0.1 0 0;"
                "0 0.5 0;"
                "0 0 0.9]")

M = np.matrix("[0.25 0 0;"
                "0 0.23 0;"
                "0 0 0.85]")



def backward_likelihood(i, trace):
    N = model.N
    M = len( trace )
    likelihoods = np.ones((N, 1))

    if i < M:
        P = main.randomization(P0, model.uniformization_rate, trace[i][0])
        # P = stored_p_values[i, :, :]
        likelihoods = np.multiply(
            P.dot( model.P1 ).dot( backward_likelihood(i+1, trace) ),
            model.M[:, trace[i][1]] )

        if likelihoods.sum() != 0:
            likelihoods = likelihoods / likelihoods.sum()

    return likelihoods
[((9, 17, 9, 36), 'datasetReader.DatasetFactory', 'df.DatasetFactory', ({}, {}), '()', True, 'import datasetReader as df\n'), ((13, 5, 15, 25), 'numpy.matrix', 'np.matrix', ({(13, 15, 15, 24): '"""[ .02 0;0 0 0.5;0 0 0]"""'}, {}), "('[ .02 0;0 0 0.5;0 0 0]')", True, 'import numpy as np\n'), ((17, 5, 19, 27), 'numpy.matrix', 'np.matrix', ({(17, 15, 19, 26): '"""[0.1 0 0;0 0.5 0;0 0 0.9]"""'}, {}), "('[0.1 0 0;0 0.5 0;0 0 0.9]')", True, 'import numpy as np\n'), ((21, 4, 23, 28), 'numpy.matrix', 'np.matrix', ({(21, 14, 23, 27): '"""[0.25 0 0;0 0.23 0;0 0 0.85]"""'}, {}), "('[0.25 0 0;0 0.23 0;0 0 0.85]')", True, 'import numpy as np\n'), ((30, 18, 30, 33), 'numpy.ones', 'np.ones', ({(30, 26, 30, 32): '(N, 1)'}, {}), '((N, 1))', True, 'import numpy as np\n'), ((33, 12, 33, 74), 'main.randomization', 'main.randomization', ({(33, 31, 33, 33): 'P0', (33, 35, 33, 60): 'model.uniformization_rate', (33, 62, 33, 73): 'trace[i][0]'}, {}), '(P0, model.uniformization_rate, trace[i][0])', False, 'import main\n')]