Exemplo n.º 1
0
def test_initialise():
    I,J,K,L = 5,3,2,4
    R = numpy.ones((I,J))
    M = numpy.ones((I,J))
    
    lambdaF = 2*numpy.ones((I,K))
    lambdaS = 3*numpy.ones((K,L))
    lambdaG = 4*numpy.ones((J,L))
    alpha, beta = 3, 1
    priors = { 'alpha':alpha, 'beta':beta, 'lambdaF':lambdaF, 'lambdaS':lambdaS, 'lambdaG':lambdaG }
    
    # First do a random initialisation - we can then only check whether values are correctly initialised
    init_S = 'random'
    init_FG = 'random'
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.initialise(init_S,init_FG)
    
    assert NMTF.tau >= 0.0
    for i,k in itertools.product(xrange(0,I),xrange(0,K)):
        assert NMTF.F[i,k] >= 0.0
    for k,l in itertools.product(xrange(0,K),xrange(0,L)):
        assert NMTF.S[k,l] >= 0.0
    for j,l in itertools.product(xrange(0,J),xrange(0,L)):
        assert NMTF.G[j,l] >= 0.0
        
    # Initialisation of S using random draws from prior
    init_S, init_FG = 'random', 'exp'
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.initialise(init_S,init_FG)
    
    for i,k in itertools.product(xrange(0,I),xrange(0,K)):
        assert NMTF.F[i,k] == 1./lambdaF[i,k]
    for k,l in itertools.product(xrange(0,K),xrange(0,L)):
        assert NMTF.S[k,l] != 1./lambdaS[k,l] # test whether we overwrote the expectation
    for j,l in itertools.product(xrange(0,J),xrange(0,L)):
        assert NMTF.G[j,l] == 1./lambdaG[j,l]
    
    # Initialisation of F and G using random draws from prior
    init_S, init_FG = 'exp', 'random'
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.initialise(init_S,init_FG)
    
    for i,k in itertools.product(xrange(0,I),xrange(0,K)):
        assert NMTF.F[i,k] != 1./lambdaF[i,k] # test whether we overwrote the expectation
    for k,l in itertools.product(xrange(0,K),xrange(0,L)):
        assert NMTF.S[k,l] == 1./lambdaS[k,l]
    for j,l in itertools.product(xrange(0,J),xrange(0,L)):
        assert NMTF.G[j,l] != 1./lambdaG[j,l] # test whether we overwrote the expectation
        
    # Initialisation of F and G using Kmeans
    init_S, init_FG = 'exp', 'kmeans'
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.initialise(init_S,init_FG)
    
    for i,k in itertools.product(xrange(0,I),xrange(0,K)):
        assert NMTF.F[i,k] == 0.2 or NMTF.F[i,k] == 1.2
    for j,l in itertools.product(xrange(0,J),xrange(0,L)):
        assert NMTF.G[j,l] == 0.2 or NMTF.G[j,l] == 1.2
    for k,l in itertools.product(xrange(0,K),xrange(0,L)):
        assert NMTF.S[k,l] == 1./lambdaS[k,l]
Exemplo n.º 2
0
def test_log_likelihood():
    R = numpy.array([[1,2],[3,4]],dtype=float)
    M = numpy.array([[1,1],[0,1]])
    I, J, K, L = 2, 2, 3, 4
    lambdaF = 2*numpy.ones((I,K))
    lambdaS = 3*numpy.ones((K,L))
    lambdaG = 4*numpy.ones((J,L))
    alpha, beta = 3, 1
    priors = { 'alpha':alpha, 'beta':beta, 'lambdaF':lambdaF, 'lambdaS':lambdaS, 'lambdaG':lambdaG }
    
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.F = numpy.ones((I,K))
    NMTF.S = 2*numpy.ones((K,L))
    NMTF.G = 3*numpy.ones((J,L))
    NMTF.tau = 3.
    # expU*expV.T = [[72.]]
    
    log_likelihood = 3./2.*(math.log(3)-math.log(2*math.pi)) - 3./2. * (71**2 + 70**2 + 68**2)
    AIC = -2*log_likelihood + 2*(2*3+3*4+2*4)
    BIC = -2*log_likelihood + (2*3+3*4+2*4)*math.log(3)
    MSE = (71**2+70**2+68**2)/3.
    
    assert log_likelihood == NMTF.quality('loglikelihood')
    assert AIC == NMTF.quality('AIC')
    assert BIC == NMTF.quality('BIC')
    assert MSE == NMTF.quality('MSE')
    with pytest.raises(AssertionError) as error:
        NMTF.quality('FAIL')
    assert str(error.value) == "Unrecognised metric for model quality: FAIL."
Exemplo n.º 3
0
def test_run():
    I, J, K, L = 10, 5, 3, 2
    R = numpy.ones((I, J))
    M = numpy.ones((I, J))
    M[0, 0], M[2, 2], M[3, 1] = 0, 0, 0

    lambdaF = 2 * numpy.ones((I, K))
    lambdaS = 3 * numpy.ones((K, L))
    lambdaG = 4 * numpy.ones((J, L))
    alpha, beta = 3, 1
    priors = {
        'alpha': alpha,
        'beta': beta,
        'lambdaF': lambdaF,
        'lambdaS': lambdaS,
        'lambdaG': lambdaG
    }
    init = 'exp'  #F=1/2,S=1/3,G=1/4

    iterations = 15

    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.initialise(init)
    NMTF.run(iterations)

    assert NMTF.all_tau.shape == (iterations, )
    assert NMTF.all_tau[1] != alpha / float(beta)
Exemplo n.º 4
0
def test_beta_s():
    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.initialise(init_S, init_FG)
    NMTF.tau = 3.
    beta_s = beta + .5 * (12 * (
        11. / 15.)**2)  #F*S = [[1/6+1/6=1/3,..]], F*S*G^T = [[1/15*4=4/15,..]]
    assert abs(NMTF.beta_s() - beta_s) < 0.00000000000001
Exemplo n.º 5
0
def test_compute_statistics():
    R = numpy.array([[1, 2], [3, 4]], dtype=float)
    M = numpy.array([[1, 1], [0, 1]])
    I, J, K, L = 2, 2, 3, 4
    lambdaF = 2 * numpy.ones((I, K))
    lambdaS = 3 * numpy.ones((K, L))
    lambdaG = 4 * numpy.ones((J, L))
    alpha, beta = 3, 1
    priors = {
        'alpha': alpha,
        'beta': beta,
        'lambdaF': lambdaF,
        'lambdaS': lambdaS,
        'lambdaG': lambdaG
    }

    NMTF = nmtf_icm(R, M, K, L, priors)

    R_pred = numpy.array([[500, 550], [1220, 1342]], dtype=float)
    M_pred = numpy.array([[0, 0], [1, 1]])

    MSE_pred = (1217**2 + 1338**2) / 2.0
    R2_pred = 1. - (1217**2 + 1338**2) / (0.5**2 + 0.5**2)  #mean=3.5
    Rp_pred = 61. / (math.sqrt(.5) * math.sqrt(7442.)
                     )  #mean=3.5,var=0.5,mean_pred=1281,var_pred=7442,cov=61

    assert MSE_pred == NMTF.compute_MSE(M_pred, R, R_pred)
    assert R2_pred == NMTF.compute_R2(M_pred, R, R_pred)
    assert Rp_pred == NMTF.compute_Rp(M_pred, R, R_pred)
Exemplo n.º 6
0
def test_predict():
    (I,J,K,L) = (5,3,2,4)
    F = numpy.array([[125.,126.],[126.,126.],[126.,126.],[126.,126.],[126.,126.]])
    S = numpy.array([[84.,84.,84.,84.],[84.,84.,84.,84.]])
    G = numpy.array([[42.,42.,42.,42.],[42.,42.,42.,42.],[42.,42.,42.,42.]])
    taus = [m**2 for m in range(1,10+1)]
    #R_pred = numpy.array([[ 3542112.,  3542112.,  3542112.],[ 3556224.,  3556224.,  3556224.],[ 3556224.,  3556224.,  3556224.],[ 3556224.,  3556224.,  3556224.],[ 3556224.,  3556224.,  3556224.]])
     
    R = numpy.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12],[13,14,15]],dtype=float)
    M = numpy.ones((I,J))
    lambdaF = 2*numpy.ones((I,K))
    lambdaS = 3*numpy.ones((K,L))
    lambdaG = 5*numpy.ones((J,L))
    alpha, beta = 3, 1
    priors = { 'alpha':alpha, 'beta':beta, 'lambdaF':lambdaF, 'lambdaS':lambdaS, 'lambdaG':lambdaG }
    
    M_test = numpy.array([[0,0,1],[0,1,0],[0,0,0],[1,1,0],[0,0,0]]) #R->3,5,10,11, R_pred->3542112,3556224,3556224,3556224
    MSE = ((3.-3542112.)**2 + (5.-3556224.)**2 + (10.-3556224.)**2 + (11.-3556224.)**2) / 4.
    R2 = 1. - ((3.-3542112.)**2 + (5.-3556224.)**2 + (10.-3556224.)**2 + (11.-3556224.)**2) / (4.25**2+2.25**2+2.75**2+3.75**2) #mean=7.25
    Rp = 357. / ( math.sqrt(44.75) * math.sqrt(5292.) ) #mean=7.25,var=44.75, mean_pred=3552696,var_pred=5292, corr=(-4.25*-63 + -2.25*21 + 2.75*21 + 3.75*21)
    
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.F = F
    NMTF.S = S
    NMTF.G = G
    NMTF.all_tau = taus
    performances = NMTF.predict(M_test)
    
    assert performances['MSE'] == MSE
    assert performances['R^2'] == R2
    assert performances['Rp'] == Rp
Exemplo n.º 7
0
def test_tauG():
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.initialise(init_S,init_FG)
    NMTF.tau = 3.
    # F*S = [[1/3]], (F*S)^2 = [[1/9]], sum_i F*S = [[4/9]]
    tauG = 3.*numpy.array([[4./9.,4./9.,4./9.,4./9.],[4./9.,4./9.,4./9.,4./9.],[4./9.,4./9.,4./9.,4./9.]])
    for j,l in itertools.product(xrange(0,J),xrange(0,L)):
        assert NMTF.tauG(l)[j] == tauG[j,l]
Exemplo n.º 8
0
def test_tauS():
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.initialise(init_S,init_FG)
    NMTF.tau = 3.
    # F outer G = [[1/10]], (F outer G)^2 = [[1/100]], sum (F outer G)^2 = [[12/100]]
    tauS = 3.*numpy.array([[3./25.,3./25.,3./25.,3./25.],[3./25.,3./25.,3./25.,3./25.]])
    for k,l in itertools.product(xrange(0,K),xrange(0,L)):
        assert abs(NMTF.tauS(k,l) - tauS[k,l]) < 0.000000000000001
Exemplo n.º 9
0
def test_tauF():
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.initialise(init_S,init_FG)
    NMTF.tau = 3.
    # S*G.T = [[4/15]], (S*G.T)^2 = [[16/225]], sum_j S*G.T = [[32/225,32/225],[48/225,48/225],[32/225,32/225],[32/225,32/225],[48/225,48/225]]
    tauF = 3.*numpy.array([[32./225.,32./225.],[48./225.,48./225.],[32./225.,32./225.],[32./225.,32./225.],[48./225.,48./225.]])
    for i,k in itertools.product(xrange(0,I),xrange(0,K)):
        assert abs(NMTF.tauF(k)[i] - tauF[i,k]) < 0.000000000000001
Exemplo n.º 10
0
def test_tauS():
    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.initialise(init_S, init_FG)
    NMTF.tau = 3.
    # F outer G = [[1/10]], (F outer G)^2 = [[1/100]], sum (F outer G)^2 = [[12/100]]
    tauS = 3. * numpy.array([[3. / 25., 3. / 25., 3. / 25., 3. / 25.],
                             [3. / 25., 3. / 25., 3. / 25., 3. / 25.]])
    for k, l in itertools.product(xrange(0, K), xrange(0, L)):
        assert abs(NMTF.tauS(k, l) - tauS[k, l]) < 0.000000000000001
Exemplo n.º 11
0
def test_muG():
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.initialise(init_S,init_FG)
    NMTF.tau = 3.
    tauG = 3.*numpy.array([[4./9.,4./9.,4./9.,4./9.],[4./9.,4./9.,4./9.,4./9.],[4./9.,4./9.,4./9.,4./9.]])
    # Rij - Fi*S*Gj + Gjl*(Fi*Sl)) = 11/15 + 1/5 * 1/3 = 12/15 = 4/5
    # (Rij - Fi*S*Gj + Gjl*(Fi*Sl)) * (Fi*Sl) = 4/5 * 1/3 = 4/15
    muG = 1./tauG * ( 3. * numpy.array([[4.*4./15.,4.*4./15.,4.*4./15.,4.*4./15.],[4.*4./15.,4.*4./15.,4.*4./15.,4.*4./15.],[4.*4./15.,4.*4./15.,4.*4./15.,4.*4./15.]]) - lambdaG )
    for j,l in itertools.product(xrange(0,J),xrange(0,L)):
        assert abs(NMTF.muG(tauG[:,l],l)[j] - muG[j,l]) < 0.000000000000001
Exemplo n.º 12
0
def test_muS():
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.initialise(init_S,init_FG)
    NMTF.tau = 3.
    tauS = 3.*numpy.array([[3./25.,3./25.,3./25.,3./25.],[3./25.,3./25.,3./25.,3./25.]])
    # Rij - Fi*S*Gj + Fik*Skl*Gjk = 11/15 + 1/2*1/3*1/5 = 23/30
    # (Rij - Fi*S*Gj + Fik*Skl*Gjk) * Fik*Gjk = 23/30 * 1/10 = 23/300
    muS = 1./tauS * ( 3. * numpy.array([[12*23./300.,12*23./300.,12*23./300.,12*23./300.],[12*23./300.,12*23./300.,12*23./300.,12*23./300.]]) - lambdaS )
    for k,l in itertools.product(xrange(0,K),xrange(0,L)):
        assert abs(NMTF.muS(tauS[k,l],k,l) - muS[k,l]) < 0.000000000000001
Exemplo n.º 13
0
def test_muF():
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.initialise(init_S,init_FG)
    NMTF.tau = 3.
    tauF = 3.*numpy.array([[32./225.,32./225.],[48./225.,48./225.],[32./225.,32./225.],[32./225.,32./225.],[48./225.,48./225.]])
    # Rij - Fi*S*Gj + Fik(Sk*Gj) = 11/15 + 1/2 * 4/15 = 13/15
    # (Rij - Fi*S*Gj + Fik(Sk*Gj)) * (Sk*Gj) = 13/15 * 4/15 = 52/225
    muF = 1./tauF * ( 3. * numpy.array([[2*(52./225.),2*(52./225.)],[3*(52./225.),3*(52./225.)],[2*(52./225.),2*(52./225.)],[2*(52./225.),2*(52./225.)],[3*(52./225.),3*(52./225.)]]) - lambdaF )
    for i,k in itertools.product(xrange(0,I),xrange(0,K)):
        assert abs(NMTF.muF(tauF[:,k],k)[i] - muF[i,k]) < 0.000000000000001
Exemplo n.º 14
0
def test_tauG():
    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.initialise(init_S, init_FG)
    NMTF.tau = 3.
    # F*S = [[1/3]], (F*S)^2 = [[1/9]], sum_i F*S = [[4/9]]
    tauG = 3. * numpy.array([[4. / 9., 4. / 9., 4. / 9., 4. / 9.],
                             [4. / 9., 4. / 9., 4. / 9., 4. / 9.],
                             [4. / 9., 4. / 9., 4. / 9., 4. / 9.]])
    for j, l in itertools.product(xrange(0, J), xrange(0, L)):
        assert NMTF.tauG(l)[j] == tauG[j, l]
Exemplo n.º 15
0
def test_tauF():
    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.initialise(init_S, init_FG)
    NMTF.tau = 3.
    # S*G.T = [[4/15]], (S*G.T)^2 = [[16/225]], sum_j S*G.T = [[32/225,32/225],[48/225,48/225],[32/225,32/225],[32/225,32/225],[48/225,48/225]]
    tauF = 3. * numpy.array([[32. / 225., 32. / 225.], [
        48. / 225., 48. / 225.
    ], [32. / 225., 32. / 225.], [32. / 225., 32. / 225.],
                             [48. / 225., 48. / 225.]])
    for i, k in itertools.product(xrange(0, I), xrange(0, K)):
        assert abs(NMTF.tauF(k)[i] - tauF[i, k]) < 0.000000000000001
Exemplo n.º 16
0
def test_muS():
    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.initialise(init_S, init_FG)
    NMTF.tau = 3.
    tauS = 3. * numpy.array([[3. / 25., 3. / 25., 3. / 25., 3. / 25.],
                             [3. / 25., 3. / 25., 3. / 25., 3. / 25.]])
    # Rij - Fi*S*Gj + Fik*Skl*Gjk = 11/15 + 1/2*1/3*1/5 = 23/30
    # (Rij - Fi*S*Gj + Fik*Skl*Gjk) * Fik*Gjk = 23/30 * 1/10 = 23/300
    muS = 1. / tauS * (3. * numpy.array([[
        12 * 23. / 300., 12 * 23. / 300., 12 * 23. / 300., 12 * 23. / 300.
    ], [12 * 23. / 300., 12 * 23. / 300., 12 * 23. / 300., 12 * 23. / 300.]]) -
                       lambdaS)
    for k, l in itertools.product(xrange(0, K), xrange(0, L)):
        assert abs(NMTF.muS(tauS[k, l], k, l) - muS[k, l]) < 0.000000000000001
Exemplo n.º 17
0
def test_predict():
    (I, J, K, L) = (5, 3, 2, 4)
    F = numpy.array([[125., 126.], [126., 126.], [126., 126.], [126., 126.],
                     [126., 126.]])
    S = numpy.array([[84., 84., 84., 84.], [84., 84., 84., 84.]])
    G = numpy.array([[42., 42., 42., 42.], [42., 42., 42., 42.],
                     [42., 42., 42., 42.]])
    taus = [m**2 for m in range(1, 10 + 1)]
    #R_pred = numpy.array([[ 3542112.,  3542112.,  3542112.],[ 3556224.,  3556224.,  3556224.],[ 3556224.,  3556224.,  3556224.],[ 3556224.,  3556224.,  3556224.],[ 3556224.,  3556224.,  3556224.]])

    R = numpy.array(
        [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]],
        dtype=float)
    M = numpy.ones((I, J))
    lambdaF = 2 * numpy.ones((I, K))
    lambdaS = 3 * numpy.ones((K, L))
    lambdaG = 5 * numpy.ones((J, L))
    alpha, beta = 3, 1
    priors = {
        'alpha': alpha,
        'beta': beta,
        'lambdaF': lambdaF,
        'lambdaS': lambdaS,
        'lambdaG': lambdaG
    }

    M_test = numpy.array(
        [[0, 0, 1], [0, 1, 0], [0, 0, 0], [1, 1, 0],
         [0, 0, 0]])  #R->3,5,10,11, R_pred->3542112,3556224,3556224,3556224
    MSE = ((3. - 3542112.)**2 + (5. - 3556224.)**2 + (10. - 3556224.)**2 +
           (11. - 3556224.)**2) / 4.
    R2 = 1. - ((3. - 3542112.)**2 + (5. - 3556224.)**2 + (10. - 3556224.)**2 +
               (11. - 3556224.)**2) / (4.25**2 + 2.25**2 + 2.75**2 + 3.75**2
                                       )  #mean=7.25
    Rp = 357. / (
        math.sqrt(44.75) * math.sqrt(5292.)
    )  #mean=7.25,var=44.75, mean_pred=3552696,var_pred=5292, corr=(-4.25*-63 + -2.25*21 + 2.75*21 + 3.75*21)

    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.F = F
    NMTF.S = S
    NMTF.G = G
    NMTF.all_tau = taus
    performances = NMTF.predict(M_test)

    assert performances['MSE'] == MSE
    assert performances['R^2'] == R2
    assert performances['Rp'] == Rp
Exemplo n.º 18
0
def test_muG():
    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.initialise(init_S, init_FG)
    NMTF.tau = 3.
    tauG = 3. * numpy.array([[4. / 9., 4. / 9., 4. / 9., 4. / 9.],
                             [4. / 9., 4. / 9., 4. / 9., 4. / 9.],
                             [4. / 9., 4. / 9., 4. / 9., 4. / 9.]])
    # Rij - Fi*S*Gj + Gjl*(Fi*Sl)) = 11/15 + 1/5 * 1/3 = 12/15 = 4/5
    # (Rij - Fi*S*Gj + Gjl*(Fi*Sl)) * (Fi*Sl) = 4/5 * 1/3 = 4/15
    muG = 1. / tauG * (3. * numpy.array(
        [[4. * 4. / 15., 4. * 4. / 15., 4. * 4. / 15., 4. * 4. / 15.],
         [4. * 4. / 15., 4. * 4. / 15., 4. * 4. / 15., 4. * 4. / 15.],
         [4. * 4. / 15., 4. * 4. / 15., 4. * 4. / 15., 4. * 4. / 15.]]) -
                       lambdaG)
    for j, l in itertools.product(xrange(0, J), xrange(0, L)):
        assert abs(NMTF.muG(tauG[:, l], l)[j] - muG[j, l]) < 0.000000000000001
Exemplo n.º 19
0
def test_muF():
    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.initialise(init_S, init_FG)
    NMTF.tau = 3.
    tauF = 3. * numpy.array([[32. / 225., 32. / 225.], [
        48. / 225., 48. / 225.
    ], [32. / 225., 32. / 225.], [32. / 225., 32. / 225.],
                             [48. / 225., 48. / 225.]])
    # Rij - Fi*S*Gj + Fik(Sk*Gj) = 11/15 + 1/2 * 4/15 = 13/15
    # (Rij - Fi*S*Gj + Fik(Sk*Gj)) * (Sk*Gj) = 13/15 * 4/15 = 52/225
    muF = 1. / tauF * (3. * numpy.array(
        [[2 * (52. / 225.), 2 *
          (52. / 225.)], [3 * (52. / 225.), 3 *
                          (52. / 225.)], [2 * (52. / 225.), 2 * (52. / 225.)],
         [2 * (52. / 225.), 2 *
          (52. / 225.)], [3 * (52. / 225.), 3 * (52. / 225.)]]) - lambdaF)
    for i, k in itertools.product(xrange(0, I), xrange(0, K)):
        assert abs(NMTF.muF(tauF[:, k], k)[i] - muF[i, k]) < 0.000000000000001
Exemplo n.º 20
0
def test_run():
    I,J,K,L = 10,5,3,2
    R = numpy.ones((I,J))
    M = numpy.ones((I,J))
    M[0,0], M[2,2], M[3,1] = 0, 0, 0
    
    lambdaF = 2*numpy.ones((I,K))
    lambdaS = 3*numpy.ones((K,L))
    lambdaG = 4*numpy.ones((J,L))
    alpha, beta = 3, 1
    priors = { 'alpha':alpha, 'beta':beta, 'lambdaF':lambdaF, 'lambdaS':lambdaS, 'lambdaG':lambdaG }
    init = 'exp' #F=1/2,S=1/3,G=1/4
    
    iterations = 15
    
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.initialise(init)
    NMTF.run(iterations)
    
    assert NMTF.all_tau.shape == (iterations,)
    assert NMTF.all_tau[1] != alpha/float(beta)
Exemplo n.º 21
0
def test_compute_statistics():
    R = numpy.array([[1,2],[3,4]],dtype=float)
    M = numpy.array([[1,1],[0,1]])
    I, J, K, L = 2, 2, 3, 4
    lambdaF = 2*numpy.ones((I,K))
    lambdaS = 3*numpy.ones((K,L))
    lambdaG = 4*numpy.ones((J,L))
    alpha, beta = 3, 1
    priors = { 'alpha':alpha, 'beta':beta, 'lambdaF':lambdaF, 'lambdaS':lambdaS, 'lambdaG':lambdaG }
    
    NMTF = nmtf_icm(R,M,K,L,priors)
    
    R_pred = numpy.array([[500,550],[1220,1342]],dtype=float)
    M_pred = numpy.array([[0,0],[1,1]])
    
    MSE_pred = (1217**2 + 1338**2) / 2.0
    R2_pred = 1. - (1217**2+1338**2)/(0.5**2+0.5**2) #mean=3.5
    Rp_pred = 61. / ( math.sqrt(.5) * math.sqrt(7442.) ) #mean=3.5,var=0.5,mean_pred=1281,var_pred=7442,cov=61
    
    assert MSE_pred == NMTF.compute_MSE(M_pred,R,R_pred)
    assert R2_pred == NMTF.compute_R2(M_pred,R,R_pred)
    assert Rp_pred == NMTF.compute_Rp(M_pred,R,R_pred)
Exemplo n.º 22
0
def test_log_likelihood():
    R = numpy.array([[1, 2], [3, 4]], dtype=float)
    M = numpy.array([[1, 1], [0, 1]])
    I, J, K, L = 2, 2, 3, 4
    lambdaF = 2 * numpy.ones((I, K))
    lambdaS = 3 * numpy.ones((K, L))
    lambdaG = 4 * numpy.ones((J, L))
    alpha, beta = 3, 1
    priors = {
        'alpha': alpha,
        'beta': beta,
        'lambdaF': lambdaF,
        'lambdaS': lambdaS,
        'lambdaG': lambdaG
    }

    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.F = numpy.ones((I, K))
    NMTF.S = 2 * numpy.ones((K, L))
    NMTF.G = 3 * numpy.ones((J, L))
    NMTF.tau = 3.
    # expU*expV.T = [[72.]]

    log_likelihood = 3. / 2. * (math.log(3) - math.log(
        2 * math.pi)) - 3. / 2. * (71**2 + 70**2 + 68**2)
    AIC = -2 * log_likelihood + 2 * (2 * 3 + 3 * 4 + 2 * 4)
    BIC = -2 * log_likelihood + (2 * 3 + 3 * 4 + 2 * 4) * math.log(3)
    MSE = (71**2 + 70**2 + 68**2) / 3.

    assert log_likelihood == NMTF.quality('loglikelihood')
    assert AIC == NMTF.quality('AIC')
    assert BIC == NMTF.quality('BIC')
    assert MSE == NMTF.quality('MSE')
    with pytest.raises(AssertionError) as error:
        NMTF.quality('FAIL')
    assert str(error.value) == "Unrecognised metric for model quality: FAIL."
Exemplo n.º 23
0
def test_alpha_s():
    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.initialise(init_S, init_FG)
    NMTF.tau = 3.
    alpha_s = alpha + 6.
    assert NMTF.alpha_s() == alpha_s
Exemplo n.º 24
0
def test_initialise():
    I, J, K, L = 5, 3, 2, 4
    R = numpy.ones((I, J))
    M = numpy.ones((I, J))

    lambdaF = 2 * numpy.ones((I, K))
    lambdaS = 3 * numpy.ones((K, L))
    lambdaG = 4 * numpy.ones((J, L))
    alpha, beta = 3, 1
    priors = {
        'alpha': alpha,
        'beta': beta,
        'lambdaF': lambdaF,
        'lambdaS': lambdaS,
        'lambdaG': lambdaG
    }

    # First do a random initialisation - we can then only check whether values are correctly initialised
    init_S = 'random'
    init_FG = 'random'
    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.initialise(init_S, init_FG)

    assert NMTF.tau >= 0.0
    for i, k in itertools.product(xrange(0, I), xrange(0, K)):
        assert NMTF.F[i, k] >= 0.0
    for k, l in itertools.product(xrange(0, K), xrange(0, L)):
        assert NMTF.S[k, l] >= 0.0
    for j, l in itertools.product(xrange(0, J), xrange(0, L)):
        assert NMTF.G[j, l] >= 0.0

    # Initialisation of S using random draws from prior
    init_S, init_FG = 'random', 'exp'
    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.initialise(init_S, init_FG)

    for i, k in itertools.product(xrange(0, I), xrange(0, K)):
        assert NMTF.F[i, k] == 1. / lambdaF[i, k]
    for k, l in itertools.product(xrange(0, K), xrange(0, L)):
        assert NMTF.S[k, l] != 1. / lambdaS[
            k, l]  # test whether we overwrote the expectation
    for j, l in itertools.product(xrange(0, J), xrange(0, L)):
        assert NMTF.G[j, l] == 1. / lambdaG[j, l]

    # Initialisation of F and G using random draws from prior
    init_S, init_FG = 'exp', 'random'
    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.initialise(init_S, init_FG)

    for i, k in itertools.product(xrange(0, I), xrange(0, K)):
        assert NMTF.F[i, k] != 1. / lambdaF[
            i, k]  # test whether we overwrote the expectation
    for k, l in itertools.product(xrange(0, K), xrange(0, L)):
        assert NMTF.S[k, l] == 1. / lambdaS[k, l]
    for j, l in itertools.product(xrange(0, J), xrange(0, L)):
        assert NMTF.G[j, l] != 1. / lambdaG[
            j, l]  # test whether we overwrote the expectation

    # Initialisation of F and G using Kmeans
    init_S, init_FG = 'exp', 'kmeans'
    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.initialise(init_S, init_FG)

    for i, k in itertools.product(xrange(0, I), xrange(0, K)):
        assert NMTF.F[i, k] == 0.2 or NMTF.F[i, k] == 1.2
    for j, l in itertools.product(xrange(0, J), xrange(0, L)):
        assert NMTF.G[j, l] == 0.2 or NMTF.G[j, l] == 1.2
    for k, l in itertools.product(xrange(0, K), xrange(0, L)):
        assert NMTF.S[k, l] == 1. / lambdaS[k, l]
Exemplo n.º 25
0

# We now run the VB algorithm on each of the M's for each fraction.
all_performances = {metric:[] for metric in metrics} 
average_performances = {metric:[] for metric in metrics} # averaged over repeats
for (fraction,Ms,Ms_test) in zip(fractions_unknown,all_Ms,all_Ms_test):
    print "Trying fraction %s." % fraction
    
    # Run the algorithm <repeats> times and store all the performances
    for metric in metrics:
        all_performances[metric].append([])
    for (repeat,M,M_test) in zip(range(0,repeats),Ms,Ms_test):
        print "Repeat %s of fraction %s." % (repeat+1, fraction)
    
        # Run the VB algorithm
        NMTF = nmtf_icm(R,M,K,L,priors)
        NMTF.initialise(init_S,init_FG)
        NMTF.run(iterations,minimum_TN=minimum_TN)
    
        # Measure the performances
        performances = NMTF.predict(M_test)
        for metric in metrics:
            # Add this metric's performance to the list of <repeat> performances for this fraction
            all_performances[metric][-1].append(performances[metric])
    
    # Compute the average across attempts
    for metric in metrics:
        average_performances[metric].append(sum(all_performances[metric][-1])/repeats)
        

print "repeats=%s \nfractions_unknown = %s \nall_performances = %s \naverage_performances = %s" % \
Exemplo n.º 26
0
def test_alpha_s():
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.initialise(init_S,init_FG)
    NMTF.tau = 3.
    alpha_s = alpha + 6.
    assert NMTF.alpha_s() == alpha_s
Exemplo n.º 27
0
def test_beta_s():
    NMTF = nmtf_icm(R,M,K,L,priors)
    NMTF.initialise(init_S,init_FG)
    NMTF.tau = 3.
    beta_s = beta + .5*(12*(11./15.)**2) #F*S = [[1/6+1/6=1/3,..]], F*S*G^T = [[1/15*4=4/15,..]]
    assert abs(NMTF.beta_s() - beta_s) < 0.00000000000001
Exemplo n.º 28
0
def test_init():
    # Test getting an exception when R and M are different sizes, and when R is not a 2D array.
    R1 = numpy.ones(3)
    M = numpy.ones((2,3))
    I,J,K,L = 5,3,1,2
    lambdaF = numpy.ones((I,K))
    lambdaS = numpy.ones((K,L))
    lambdaG = numpy.ones((J,L))
    alpha, beta = 3, 1    
    priors = { 'alpha':alpha, 'beta':beta, 'lambdaF':lambdaF, 'lambdaS':lambdaS, 'lambdaG':lambdaG }
    
    with pytest.raises(AssertionError) as error:
        nmtf_icm(R1,M,K,L,priors)
    assert str(error.value) == "Input matrix R is not a two-dimensional array, but instead 1-dimensional."
    
    R2 = numpy.ones((4,3,2))
    with pytest.raises(AssertionError) as error:
        nmtf_icm(R2,M,K,L,priors)
    assert str(error.value) == "Input matrix R is not a two-dimensional array, but instead 3-dimensional."
    
    R3 = numpy.ones((3,2))
    with pytest.raises(AssertionError) as error:
        nmtf_icm(R3,M,K,L,priors)
    assert str(error.value) == "Input matrix R is not of the same size as the indicator matrix M: (3, 2) and (2, 3) respectively."
    
    # Similarly for lambdaF, lambdaS, lambdaG
    I,J,K,L = 2,3,1,2
    R4 = numpy.ones((2,3))
    lambdaF = numpy.ones((2+1,1))
    priors = { 'alpha':alpha, 'beta':beta, 'lambdaF':lambdaF, 'lambdaS':lambdaS, 'lambdaG':lambdaG }
    with pytest.raises(AssertionError) as error:
        nmtf_icm(R4,M,K,L,priors)
    assert str(error.value) == "Prior matrix lambdaF has the wrong shape: (3, 1) instead of (2, 1)."
    
    lambdaF = numpy.ones((2,1))
    lambdaS = numpy.ones((1+1,2+1))
    priors = { 'alpha':alpha, 'beta':beta, 'lambdaF':lambdaF, 'lambdaS':lambdaS, 'lambdaG':lambdaG }
    with pytest.raises(AssertionError) as error:
        nmtf_icm(R4,M,K,L,priors)
    assert str(error.value) == "Prior matrix lambdaS has the wrong shape: (2, 3) instead of (1, 2)."
    
    lambdaS = numpy.ones((1,2))
    lambdaG = numpy.ones((3,2+1))
    priors = { 'alpha':alpha, 'beta':beta, 'lambdaF':lambdaF, 'lambdaS':lambdaS, 'lambdaG':lambdaG }
    with pytest.raises(AssertionError) as error:
        nmtf_icm(R4,M,K,L,priors)
    assert str(error.value) == "Prior matrix lambdaG has the wrong shape: (3, 3) instead of (3, 2)."
    
    # Test getting an exception if a row or column is entirely unknown
    lambdaF = numpy.ones((I,K))
    lambdaS = numpy.ones((K,L))
    lambdaG = numpy.ones((J,L))
    M1 = [[1,1,1],[0,0,0]]
    M2 = [[1,1,0],[1,0,0]]
    priors = { 'alpha':alpha, 'beta':beta, 'lambdaF':lambdaF, 'lambdaS':lambdaS, 'lambdaG':lambdaG }
    
    with pytest.raises(AssertionError) as error:
        nmtf_icm(R4,M1,K,L,priors)
    assert str(error.value) == "Fully unobserved row in R, row 1."
    with pytest.raises(AssertionError) as error:
        nmtf_icm(R4,M2,K,L,priors)
    assert str(error.value) == "Fully unobserved column in R, column 2."
    
    # Finally, a successful case
    I,J,K,L = 3,2,2,2
    R5 = 2*numpy.ones((I,J))
    lambdaF = numpy.ones((I,K))
    lambdaS = numpy.ones((K,L))
    lambdaG = numpy.ones((J,L))
    M = numpy.ones((I,J))
    priors = { 'alpha':alpha, 'beta':beta, 'lambdaF':lambdaF, 'lambdaS':lambdaS, 'lambdaG':lambdaG }
    NMTF = nmtf_icm(R5,M,K,L,priors)
    
    assert numpy.array_equal(NMTF.R,R5)
    assert numpy.array_equal(NMTF.M,M)
    assert NMTF.I == I
    assert NMTF.J == J
    assert NMTF.K == K
    assert NMTF.L == L
    assert NMTF.size_Omega == I*J
    assert NMTF.alpha == alpha
    assert NMTF.beta == beta
    assert numpy.array_equal(NMTF.lambdaF,lambdaF)
    assert numpy.array_equal(NMTF.lambdaS,lambdaS)
    assert numpy.array_equal(NMTF.lambdaG,lambdaG)
    
    # Test when lambdaF S G are integers
    I,J,K,L = 3,2,2,2
    R5 = 2*numpy.ones((I,J))
    lambdaF = 3
    lambdaS = 4
    lambdaG = 5
    M = numpy.ones((I,J))
    priors = { 'alpha':alpha, 'beta':beta, 'lambdaF':lambdaF, 'lambdaS':lambdaS, 'lambdaG':lambdaG }
    NMTF = nmtf_icm(R5,M,K,L,priors)
    
    assert numpy.array_equal(NMTF.R,R5)
    assert numpy.array_equal(NMTF.M,M)
    assert NMTF.I == I
    assert NMTF.J == J
    assert NMTF.K == K
    assert NMTF.L == L
    assert NMTF.size_Omega == I*J
    assert NMTF.alpha == alpha
    assert NMTF.beta == beta
    assert numpy.array_equal(NMTF.lambdaF,3*numpy.ones((I,K)))
    assert numpy.array_equal(NMTF.lambdaS,4*numpy.ones((K,L)))
    assert numpy.array_equal(NMTF.lambdaG,5*numpy.ones((J,L)))
Exemplo n.º 29
0
# Load in data
R = numpy.loadtxt(input_folder + "R.txt")
M = numpy.ones((I, J))

# Run the VB algorithm, <repeats> times
times_repeats = []
performances_repeats = []
for i in range(0, repeats):
    # Set all the seeds
    numpy.random.seed(3)
    random.seed(4)
    scipy.random.seed(5)

    # Run the classifier
    NMTF = nmtf_icm(R, M, K, L, priors)
    NMTF.initialise(init_S=init_S, init_FG=init_FG)
    NMTF.run(iterations, minimum_TN=minimum_TN)

    # Extract the performances and timestamps across all iterations
    times_repeats.append(NMTF.all_times)
    performances_repeats.append(NMTF.all_performances)

# Check whether seed worked: all performances should be the same
assert all([numpy.array_equal(performances, performances_repeats[0]) for performances in performances_repeats]), \
    "Seed went wrong - performances not the same across repeats!"

# Print out the performances, and the average times
icm_all_times_average = list(numpy.average(times_repeats, axis=0))
icm_all_performances = performances_repeats[0]
Exemplo n.º 30
0
def test_init():
    # Test getting an exception when R and M are different sizes, and when R is not a 2D array.
    R1 = numpy.ones(3)
    M = numpy.ones((2, 3))
    I, J, K, L = 5, 3, 1, 2
    lambdaF = numpy.ones((I, K))
    lambdaS = numpy.ones((K, L))
    lambdaG = numpy.ones((J, L))
    alpha, beta = 3, 1
    priors = {
        'alpha': alpha,
        'beta': beta,
        'lambdaF': lambdaF,
        'lambdaS': lambdaS,
        'lambdaG': lambdaG
    }

    with pytest.raises(AssertionError) as error:
        nmtf_icm(R1, M, K, L, priors)
    assert str(
        error.value
    ) == "Input matrix R is not a two-dimensional array, but instead 1-dimensional."

    R2 = numpy.ones((4, 3, 2))
    with pytest.raises(AssertionError) as error:
        nmtf_icm(R2, M, K, L, priors)
    assert str(
        error.value
    ) == "Input matrix R is not a two-dimensional array, but instead 3-dimensional."

    R3 = numpy.ones((3, 2))
    with pytest.raises(AssertionError) as error:
        nmtf_icm(R3, M, K, L, priors)
    assert str(
        error.value
    ) == "Input matrix R is not of the same size as the indicator matrix M: (3, 2) and (2, 3) respectively."

    # Similarly for lambdaF, lambdaS, lambdaG
    I, J, K, L = 2, 3, 1, 2
    R4 = numpy.ones((2, 3))
    lambdaF = numpy.ones((2 + 1, 1))
    priors = {
        'alpha': alpha,
        'beta': beta,
        'lambdaF': lambdaF,
        'lambdaS': lambdaS,
        'lambdaG': lambdaG
    }
    with pytest.raises(AssertionError) as error:
        nmtf_icm(R4, M, K, L, priors)
    assert str(
        error.value
    ) == "Prior matrix lambdaF has the wrong shape: (3, 1) instead of (2, 1)."

    lambdaF = numpy.ones((2, 1))
    lambdaS = numpy.ones((1 + 1, 2 + 1))
    priors = {
        'alpha': alpha,
        'beta': beta,
        'lambdaF': lambdaF,
        'lambdaS': lambdaS,
        'lambdaG': lambdaG
    }
    with pytest.raises(AssertionError) as error:
        nmtf_icm(R4, M, K, L, priors)
    assert str(
        error.value
    ) == "Prior matrix lambdaS has the wrong shape: (2, 3) instead of (1, 2)."

    lambdaS = numpy.ones((1, 2))
    lambdaG = numpy.ones((3, 2 + 1))
    priors = {
        'alpha': alpha,
        'beta': beta,
        'lambdaF': lambdaF,
        'lambdaS': lambdaS,
        'lambdaG': lambdaG
    }
    with pytest.raises(AssertionError) as error:
        nmtf_icm(R4, M, K, L, priors)
    assert str(
        error.value
    ) == "Prior matrix lambdaG has the wrong shape: (3, 3) instead of (3, 2)."

    # Test getting an exception if a row or column is entirely unknown
    lambdaF = numpy.ones((I, K))
    lambdaS = numpy.ones((K, L))
    lambdaG = numpy.ones((J, L))
    M1 = [[1, 1, 1], [0, 0, 0]]
    M2 = [[1, 1, 0], [1, 0, 0]]
    priors = {
        'alpha': alpha,
        'beta': beta,
        'lambdaF': lambdaF,
        'lambdaS': lambdaS,
        'lambdaG': lambdaG
    }

    with pytest.raises(AssertionError) as error:
        nmtf_icm(R4, M1, K, L, priors)
    assert str(error.value) == "Fully unobserved row in R, row 1."
    with pytest.raises(AssertionError) as error:
        nmtf_icm(R4, M2, K, L, priors)
    assert str(error.value) == "Fully unobserved column in R, column 2."

    # Finally, a successful case
    I, J, K, L = 3, 2, 2, 2
    R5 = 2 * numpy.ones((I, J))
    lambdaF = numpy.ones((I, K))
    lambdaS = numpy.ones((K, L))
    lambdaG = numpy.ones((J, L))
    M = numpy.ones((I, J))
    priors = {
        'alpha': alpha,
        'beta': beta,
        'lambdaF': lambdaF,
        'lambdaS': lambdaS,
        'lambdaG': lambdaG
    }
    NMTF = nmtf_icm(R5, M, K, L, priors)

    assert numpy.array_equal(NMTF.R, R5)
    assert numpy.array_equal(NMTF.M, M)
    assert NMTF.I == I
    assert NMTF.J == J
    assert NMTF.K == K
    assert NMTF.L == L
    assert NMTF.size_Omega == I * J
    assert NMTF.alpha == alpha
    assert NMTF.beta == beta
    assert numpy.array_equal(NMTF.lambdaF, lambdaF)
    assert numpy.array_equal(NMTF.lambdaS, lambdaS)
    assert numpy.array_equal(NMTF.lambdaG, lambdaG)

    # Test when lambdaF S G are integers
    I, J, K, L = 3, 2, 2, 2
    R5 = 2 * numpy.ones((I, J))
    lambdaF = 3
    lambdaS = 4
    lambdaG = 5
    M = numpy.ones((I, J))
    priors = {
        'alpha': alpha,
        'beta': beta,
        'lambdaF': lambdaF,
        'lambdaS': lambdaS,
        'lambdaG': lambdaG
    }
    NMTF = nmtf_icm(R5, M, K, L, priors)

    assert numpy.array_equal(NMTF.R, R5)
    assert numpy.array_equal(NMTF.M, M)
    assert NMTF.I == I
    assert NMTF.J == J
    assert NMTF.K == K
    assert NMTF.L == L
    assert NMTF.size_Omega == I * J
    assert NMTF.alpha == alpha
    assert NMTF.beta == beta
    assert numpy.array_equal(NMTF.lambdaF, 3 * numpy.ones((I, K)))
    assert numpy.array_equal(NMTF.lambdaS, 4 * numpy.ones((K, L)))
    assert numpy.array_equal(NMTF.lambdaG, 5 * numpy.ones((J, L)))
Exemplo n.º 31
0
standardised = False #standardised Sanger or unstandardised

iterations = 1000
I, J, K, L = 622,139,10,5

init_S = 'random' #'exp' #
init_FG = 'kmeans' #'exp' #

alpha, beta = 1., 1.
lambdaF = numpy.ones((I,K))/10.
lambdaS = numpy.ones((K,L))/10.
lambdaG = numpy.ones((J,L))/10.
priors = { 'alpha':alpha, 'beta':beta, 'lambdaF':lambdaF, 'lambdaS':lambdaS, 'lambdaG':lambdaG }

# Load in data
(_,X_min,M,_,_,_,_) = load_Sanger(standardised=standardised)

# Run the Gibbs sampler
NMTF = nmtf_icm(X_min,M,K,L,priors)
NMTF.initialise(init_S=init_S,init_FG=init_FG)
NMTF.run(iterations)

# Plot the tau expectation values to check convergence
plt.plot(NMTF.all_tau)

# Print the performances across iterations (MSE)
print "icm_all_performances = %s" % NMTF.all_performances['MSE']

'''
icm_all_performances = [12.344568776419457, 4.4034219943879798, 3.2821276964929229, 2.998220149205125, 2.8988371999811116, 2.8524264541971407, 2.8253326411553701, 2.807046745849969, 2.7936389471827248, 2.7832523842906554, 2.7749015167978763, 2.7679496038659059, 2.7619929726078727, 2.7567689394925501, 2.7520971403819456, 2.7478465851867884, 2.7439135016671057, 2.7402187129573821, 2.7367048989387417, 2.7333318131129372, 2.730067034968092, 2.7268781576582617, 2.7237453873967961, 2.7206570703148594, 2.7175952959795313, 2.7146536624027049, 2.7118902387197164, 2.7091464682739153, 2.7064083754841572, 2.7037985930028943, 2.7012387192414855, 2.6986857820255321, 2.6961281372882513, 2.6935621778047487, 2.6909864864718842, 2.6883979212858198, 2.6857935983454855, 2.6831722298833895, 2.6805323379555195, 2.6778718795590435, 2.675188498861734, 2.6724804137549625, 2.6697463820313918, 2.666984624745008, 2.664192107222402, 2.6613685777297098, 2.6585119799929942, 2.6556201560980548, 2.6526967278013833, 2.6497365382415414, 2.6467394973638996, 2.6437038337149517, 2.6406240651800896, 2.6374960190613255, 2.6343186001498484, 2.631089042053913, 2.6278043542315657, 2.6244629981011594, 2.621061698439815, 2.6175965788762232, 2.6140450783208444, 2.6106590004855046, 2.6074302921812564, 2.604218216638531, 2.6010029988258503, 2.5977728717827042, 2.5945231775615594, 2.5912518958277655, 2.5879602509856481, 2.5846450047113199, 2.5813070112419965, 2.5779473563334632, 2.5745638954492072, 2.5711571024585331, 2.5677265439590506, 2.5642717325061617, 2.5607979646768868, 2.557354904046095, 2.5539048601408396, 2.55044400769577, 2.5469722134081842, 2.5434900944213514, 2.5400074909333532, 2.5365228951487198, 2.5330364470831772, 2.5295497897092107, 2.5260649146876175, 2.5225843653864715, 2.5191103757669264, 2.5156456431660437, 2.512198663003065, 2.5087793568155958, 2.5053818546968643, 2.5020088930623827, 2.4986718350061587, 2.4953696728725561, 2.49210656334661, 2.4888829903438281, 2.4856962847329238, 2.4825545907939213, 2.4794592707211383, 2.4764096616210014, 2.4734067689939119, 2.4704508295329619, 2.4676079461819702, 2.4648178563943546, 2.4620574686450847, 2.4593395256061719, 2.4566593777085952, 2.4540171690007009, 2.4514118221616203, 2.448859086552023, 2.446344427655093, 2.4438623375406152, 2.4414104358378044, 2.4389869122194687, 2.4365915960555733, 2.4342275064192718, 2.4318917221756733, 2.4295815568000441, 2.4272951182027946, 2.4250316686554747, 2.4227936983215814, 2.4205790261504596, 2.4183863299440462, 2.4162139261267117, 2.4140642163862789, 2.4119370373738183, 2.4098321870406441, 2.407752798162877, 2.4056998770300071, 2.403680026051525, 2.4016819131056728, 2.3997232487244284, 2.3977723535494069, 2.395840368024746, 2.3939270175870955, 2.3920326488815373, 2.3901584305010317, 2.3883041705094166, 2.386469866686459, 2.3846594884903034, 2.3828736981068901, 2.3811159004135258, 2.3793773824256896, 2.3776582059286606, 2.3759531844471655, 2.3742649331907169, 2.3725953615169022, 2.3709448909356272, 2.3693134276578767, 2.3676998324001541, 2.366104447968989, 2.3645269759033631, 2.3629668178701277, 2.361425162365697, 2.3599012594435567, 2.3583789537328363, 2.3568808328303459, 2.3554068031555158, 2.3539547864711663, 2.3525234628278358, 2.3511115610419209, 2.3497181999207082, 2.3483426544331785, 2.3469866711892267, 2.3456438941605278, 2.3443221043834215, 2.3430199400941718, 2.3417365485506156, 2.3404707038070236, 2.3392214989809661, 2.3379883502516532, 2.3367705022196601, 2.3355707598402708, 2.3343895921705027, 2.3332207223889867, 2.3320655823775018, 2.3309237818312636, 2.329794977953866, 2.3286788776794745, 2.3275749351623647, 2.3264828765794028, 2.3254023710499094, 2.3243331250355017, 2.3232748694677836, 2.3222273035433108, 2.3211912919337085, 2.3201677349568306, 2.3191544175298651, 2.3181509795473447, 2.317157186430721, 2.3161727485827708, 2.3151975008150907, 2.3142311514958838, 2.3132735124424118, 2.3123242941857014, 2.3113835553453654, 2.3104507834001189, 2.3095258164709778, 2.3086085841134287, 2.3076990347326785, 2.3067970899581822, 2.3059026425942353, 2.3050166564486037, 2.3041380315771347, 2.3032665361623952, 2.3024019814459948, 2.3015443201014043, 2.300693462891362, 2.2998493317719513, 2.299011829068967, 2.2981808584761345, 2.2973563318152888, 2.2965381791797008, 2.2957263297045731, 2.2949206944809957, 2.2941212073904951, 2.2933270475282286, 2.2925391660792651, 2.2917585040668431, 2.2909839582919016, 2.2902153346010437, 2.2894525378296247, 2.2886954667309554, 2.2879440216135687, 2.2871981772673879, 2.2864577985907428, 2.2857227871937043, 2.2849930723004661, 2.2842685826596316, 2.2835492427248645, 2.2828349754167103, 2.2821257118520624, 2.2814213835246777, 2.2807219141255062, 2.2800272483776438, 2.279337319279588, 2.2786520700758226, 2.2779714321382194, 2.2772953401942515, 2.2766237272615517, 2.2759546958145842, 2.2752882752469232, 2.2746263006645111, 2.2739686855441374, 2.2733148416279509, 2.2726645856563437, 2.2720181109867803, 2.2713753958320329, 2.2707363916238776, 2.2701016227612154, 2.2694706781702911, 2.2688434434005447, 2.268219889671542, 2.2675999598429337, 2.2669836009251059, 2.2663709488461659, 2.2657619176071808, 2.2651563052177472, 2.264554059081997, 2.2639544300462502, 2.2633575850060641, 2.2627636539187881, 2.2621726826569279, 2.2615846951629757, 2.2609997260136421, 2.2604178655186078, 2.2598391267013875, 2.2592634336145481, 2.2586907297445142, 2.2581209610912314, 2.2575526677926296, 2.2569873515301282, 2.2564248560602587, 2.2558650302096495, 2.2553078256459025, 2.2547532891231628, 2.2542014737785956, 2.2536521965750564, 2.2531054231077072, 2.2525611144951134, 2.252019235598449, 2.2514797386797745, 2.2509425899141022, 2.2504077311733455, 2.24987515052654, 2.2493448153950855, 2.2488166713591897, 2.2482906816559969, 2.2477668052276902, 2.2472450036698919, 2.246725241947154, 2.2462074876893361, 2.2456917093038551, 2.2451780068855571, 2.2446661555566942, 2.2441558610603356, 2.2436474332721041, 2.2431408737971013, 2.2426361189282051, 2.2421331773422981, 2.2416320349663112, 2.2411327516719384, 2.2406350717489203, 2.2401391511108626, 2.2396449852555786, 2.2391525492654045, 2.2386618114465282, 2.2381727550203259, 2.237685361659576, 2.2371996125187241, 2.2367154888052552, 2.2362329716399851, 2.2357520438904093, 2.2352726988033407, 2.2347952001891951, 2.234322812175221, 2.233851969124252, 2.2333826438423805, 2.2329148166413857, 2.2324484788439185, 2.2319836551574794, 2.2315203223935822, 2.2310584830009907, 2.2305981974292908, 2.2301404052220088, 2.2296843281374819, 2.2292296547579133, 2.2287764496540845, 2.2283277780409891, 2.227880474441736, 2.2274345257257444, 2.2269899161215361, 2.2265466615954237, 2.2261047341779054, 2.2256641072048886, 2.2252247765594717, 2.2247867430705703, 2.2243500105268055, 2.2239145412720389, 2.2234803315786364, 2.2230474135333478, 2.2226160021072796, 2.222186088331334, 2.2217572978693565, 2.2213296734327725, 2.2209032273300111, 2.2204780027991817, 2.2200542064173248, 2.2196316962688947, 2.2192104210044556, 2.218790363125283, 2.2183715175271899, 2.2179538805005925, 2.217537448739197, 2.2171222047282382, 2.2167081553527028, 2.2162952225708494, 2.215883401113564, 2.2154727218199683, 2.2150631936631822, 2.2146548498249703, 2.214247747909881, 2.2138418829074125, 2.2134372207966511, 2.2130338067833679, 2.2126316419041956, 2.2122306900289193, 2.2118309409086296, 2.211432389236712, 2.2110359358204534, 2.2106414361180802, 2.2102481321662255, 2.2098560263871558, 2.2094651026951957, 2.2090753563216214, 2.2086867857466577, 2.2082993921214675, 2.2079133164110414, 2.207528792984172, 2.2071451800877924, 2.2067626814042054, 2.2063813783800703, 2.2060012923821954, 2.2056224463809571, 2.2052448476888307, 2.2048684949040491, 2.2044933858864657, 2.2041195191781733, 2.2037468939900675, 2.2033758250965834, 2.2030071332799439, 2.202639668230097, 2.2022734416146741, 2.2019084659003876, 2.2015447477698529, 2.2011823106593473, 2.2008211376832176, 2.2004612279502789, 2.2001025822106963, 2.1997452048444961, 2.1993890969879906, 2.1990342573742505, 2.1986806867180331, 2.1983283866852643, 2.197975772403157, 2.1976229344031841, 2.1972713818267144, 2.1969211339328258, 2.196572210262973, 2.1962246123779434, 2.195878188749679, 2.1955330291083266, 2.1951889694382314, 2.1948467231634723, 2.1945061327836535, 2.1941670794065442, 2.1938295126188385, 2.1934934094078899, 2.1931587688148717, 2.1928255801290595, 2.1924938378487506, 2.1921635349932411, 2.1918346633522336, 2.1915072191018634, 2.1911811971609332, 2.1908565969810074, 2.1905334193793307, 2.1902116625294967, 2.1898913483063862, 2.1895724700840202, 2.1892549067550435, 2.1889387617856539, 2.18862466610683, 2.1883122472302476, 2.1880013606584781, 2.1876919446804246, 2.1873839798493435, 2.1870774383016349, 2.1867723548387898, 2.1864687961947475, 2.1861666451344677, 2.1858658924779029, 2.1855665333446268, 2.1852683664878132, 2.1849695806596894, 2.1846721820859618, 2.1843761883490771, 2.1840816051900416, 2.1837884296763481, 2.1834966598619139, 2.1832062940595653, 2.1829171060839001, 2.1826289699939943, 2.1823422395264638, 2.1820569224217801, 2.1817730171895979, 2.1814905217776408, 2.1812094336673291, 2.1809297508871315, 2.1806514854912784, 2.1803746335378604, 2.1800991822257743, 2.179825124834943, 2.1795524568838087, 2.1792811748437355, 2.1790112754087705, 2.1787427764721627, 2.1784756902443858, 2.1782100395752941, 2.1779457660880142, 2.1776828588399502, 2.1774213130608553, 2.1771611244097104, 2.1769022875462216, 2.1766445663911433, 2.1763878603729583, 2.1761324941356959, 2.1758784915304781, 2.1756258312341985, 2.17537450577916, 2.1751245080514696, 2.1748758329661517, 2.174628474994893, 2.174382431769966, 2.1741377054144508, 2.1738943060375764, 2.1736522560281677, 2.173411984821735, 2.1731729830378761, 2.1729352561937429, 2.1726989188245112, 2.1724638741169735, 2.1722301078752482, 2.1719976388103439, 2.1717664649588317, 2.1715366786863246, 2.1713082375866248, 2.1710810468715791, 2.1708550996600438, 2.1706303913455098, 2.1704069164448234, 2.1701846689269644, 2.1699636423092166, 2.1697438298239624, 2.1695252245521477, 2.1693078195996214, 2.1690916171071359, 2.1688766086262841, 2.1686627824732803, 2.1684501310229498, 2.1682386478251718, 2.1680283272100334, 2.1678191676409315, 2.167611161521922, 2.1674043012477529, 2.1672003426004665, 2.1669979614445372, 2.1667967173332623, 2.1665965938722231, 2.1663975919358212, 2.1661997150299452, 2.1660029435252364, 2.1658072659137155, 2.165612673862126, 2.1654191601255754, 2.1652267189139245, 2.1650353442066703, 2.1648450287015932, 2.1646557653543681, 2.1644675471336532, 2.164280367021385, 2.1640942180131177, 2.1639087140170408, 2.163722617366358, 2.1635375354767064, 2.1633534757733743, 2.1631704309715092, 2.1629883975906359, 2.1628073959377376, 2.1626274165504769, 2.1624484412240346, 2.1622704599369644, 2.1620934647324588, 2.1619174476363017, 2.1617424020282558, 2.1615683215689709, 2.1613952000276058, 2.1612230312174545, 2.1610518089881867, 2.1608815271952122, 2.160712179727251, 2.1605437604761004, 2.1603762631245491, 2.1602096799711776, 2.1600440048157017, 2.1598792303307537, 2.1597153493694647, 2.1595523554046672, 2.1593902417198354, 2.1592290018528892, 2.1590686326596082, 2.15890912597943, 2.1587504752983784, 2.1585926744684083, 2.1584357162472263, 2.1582795941275541, 2.1581243016062062, 2.1579698320305241, 2.1578161793428636, 2.1576633388116599, 2.1575113035726243, 2.1573600662600114, 2.1572096200021322, 2.1570599581911352, 2.1569110742978554, 2.1567629619026416, 2.1566156146395961, 2.1564690261906994, 2.1563231902787532, 2.1561781006584249, 2.1560337549050335, 2.1558901454991739, 2.1557472641070969, 2.155605104748211, 2.1554636822788611, 2.1553229731865917, 2.1551829701170764, 2.1550436665281261, 2.1549050561680727, 2.1547671325584346, 2.1546298886141528, 2.1544933245072411, 2.1543574314041498, 2.1542222018139636, 2.1540876293684668, 2.1539536814164655, 2.1538193774072263, 2.1536857220625318, 2.1535527109749997, 2.153420346820885, 2.1532887378451457, 2.1531578193746892, 2.153027518711554, 2.1528978260871821, 2.1527687393477066, 2.1526402669967557, 2.1525123975425005, 2.1523851192602184, 2.1522584303463144, 2.1521323223554316, 2.1520067891155916, 2.1518818251287666, 2.151757425457741, 2.1516335906866195, 2.1515103211472497, 2.1513876052989485, 2.1512654361764305, 2.1511438081592056, 2.1510227160502211, 2.1509021548039073, 2.1507821194239987, 2.1506627758549075, 2.1505440714742172, 2.1504258759391792, 2.1503081847791461, 2.1501909934053316, 2.1500742971882882, 2.1499580915091587, 2.1498423717781447, 2.1497271334462229, 2.1496123719911697, 2.1494980829304589, 2.1493853647882721, 2.149273419859969, 2.1491619409810809, 2.1490509166257281, 2.1489403414402939, 2.1488302106559809, 2.148720524604665, 2.1486112770713941, 2.1485024598320526, 2.1483940688128715, 2.1482861000127658, 2.1481785494252961, 2.1480714134513521, 2.1479646881272196, 2.1478583688277859, 2.1477524514291022, 2.1476469319385241, 2.1475418064515788, 2.1474370953857749, 2.1473328140692391, 2.1472289210459299, 2.1471254101297723, 2.1470222768429035, 2.1469195173949451, 2.1468171281445132, 2.146715105537881, 2.1466134461266684, 2.1465121463571584, 2.146411202602895, 2.1463106110051147, 2.1462103685517704, 2.1461104718302257, 2.1460109174451523, 2.1459117018969134, 2.1458128217072239, 2.1457142735656936, 2.1456160262208286, 2.1455180902019158, 2.1454204687765017, 2.1453231615767723, 2.1452261674645703, 2.1451294923304833, 2.1450331479164637, 2.1449371191220554, 2.1448413989633353, 2.1447459830140425, 2.1446508677304821, 2.1445560500118308, 2.1444615268122438, 2.1443672951130428, 2.1442733519358419, 2.1441796943332063, 2.1440863195240296, 2.1439932264019381, 2.143900412077083, 2.1438078736887083, 2.1437156083336921, 2.1436236131933173, 2.1435318854721608, 2.1434404224080286, 2.1433492212761465, 2.1432582793866413, 2.1431675940838568, 2.1430771627448992, 2.1429869827793451, 2.1428970516282302, 2.1428073667632073, 2.1427179338076159, 2.1426287623988887, 2.1425398328670577, 2.1424511419216996, 2.1423626902501312, 2.1422744750624441, 2.1421864933256565, 2.1420987409568899, 2.1420112155177793, 2.1419237136419911, 2.1418363868252328, 2.1417493187723018, 2.1416624813008571, 2.1415758708613093, 2.1414894932735278, 2.1414033405268276, 2.1413174080268536, 2.1412316929832849, 2.1411461929320796, 2.1410609054810386, 2.1409758282968765, 2.1408909597610695, 2.140806310796703, 2.1407218765955554, 2.1406376496264996, 2.1405536271811529, 2.1404698065241301, 2.1403860558589822, 2.1403020000974462, 2.1402181409137251, 2.1401344730467859, 2.1400509985124052, 2.1399677146686642, 2.1398846195423245, 2.1398017114230043, 2.1397189887410186, 2.1396364497775662, 2.1395540930872032, 2.1394719174246406, 2.1393899212861616, 2.1393081031888794, 2.1392264617563814, 2.1391449956412667, 2.1390637035053519, 2.1389825840094652, 2.1389016358245017, 2.1388208575736378, 2.138740247876683, 2.13865980534908, 2.1385795286041493, 2.1384994162532869, 2.1384194669059227, 2.1383396791694693, 2.1382600516528432, 2.1381805829817675, 2.1381012717679631, 2.1380221166144824, 2.1379431161157099, 2.1378642688629346, 2.1377855734461528, 2.1377070284428275, 2.1376286324938234, 2.1375500233288367, 2.1374715988438475, 2.1373934960068444, 2.1373157177081814, 2.1372382471287543, 2.1371610704034891, 2.1370841767532371, 2.1370075570663909, 2.1369312024474705, 2.1368551026029747, 2.1367792488014405, 2.1367036351155444, 2.1366282804094743, 2.136553155190803, 2.1364782498162636, 2.1364035575784444, 2.13632907264848, 2.1362547895807626, 2.1361807032211924, 2.1361068086699881, 2.1360331012657352, 2.1359595765769446, 2.1358862307283548, 2.135813057298579, 2.1357400462281455, 2.1356672032344086, 2.1355945228248463, 2.1355220013611724, 2.1354496353681154, 2.1353774405815815, 2.1353054238105798, 2.1352335523199377, 2.1351618219183126, 2.1350902303347077, 2.1350187757340908, 2.1349474591392021, 2.134876278095533, 2.1348052285146442, 2.1347343080227192, 2.1346635144339898, 2.1345928456092524, 2.1345222994591126, 2.1344518739375862, 2.1343815670446542, 2.134311376831123, 2.1342413013928287, 2.1341713388694235, 2.1341014874460345, 2.1340317453517801, 2.1339621108581985, 2.133892582277729, 2.133823157963771, 2.1337538360735917, 2.1336846149935664, 2.1336154933613765, 2.1335464695190005, 2.1334775428987274, 2.1334087190347972, 2.1333399918080858, 2.1332713588945578, 2.133202817051989, 2.1331343693174714, 2.1330660130269883, 2.1329977458127249, 2.1329295659407865, 2.1328614719001293, 2.1327934624020584, 2.1327255367691196, 2.1326576933048771, 2.1325899307899356, 2.1325222481244888, 2.1324546437883543, 2.1323871165908672, 2.1323196653728456, 2.1322522908785033, 2.1321850358603545, 2.1321178552393647, 2.1320507473141301, 2.1319837107402777, 2.1319167443604106, 2.1318498480519388, 2.1317830209510307, 2.1317162606901596, 2.1316495662818054, 2.131582937301193, 2.1315163730397373, 2.1314498723997071, 2.1313834344650693, 2.13131705837871, 2.1312507438523594, 2.1311844901072572, 2.1311182959709498, 2.1310521605394208, 2.1309860829568854, 2.1309200624052504, 2.130854098085404, 2.1307881892070792, 2.1307223349942803, 2.1306565346840767, 2.1305907875407653, 2.1305250904202402, 2.1304593990874734, 2.1303937593689914, 2.1303281705100749, 2.1302626317117466, 2.1301971554824881, 2.1301317314694814, 2.1300663562802695, 2.1300010281465465, 2.1299357458873449, 2.129870508621178, 2.1298053156199894, 2.12974016623463, 2.1296750602693018, 2.1296099971741294, 2.1295449761358056, 2.1294799965419582, 2.1294150575547457, 2.1293501585353898, 2.129285298993592, 2.1292204789386844, 2.1291556977067367, 2.1290909546946852, 2.1290262493176324, 2.128961580935365, 2.1288969489091758, 2.1288323527470534, 2.128767791883075, 2.1287032657662319, 2.1286387738423143, 2.1285743155603374, 2.1285098903735142, 2.1284454977398561, 2.1283811371224202, 2.1283168079893966, 2.1282525098145006, 2.1281882420765497, 2.1281240042655347, 2.1280597958846093, 2.1279956164108396, 2.1279314653444841, 2.1278673421909708, 2.1278032463751613, 2.127739177395501, 2.1276751347663705, 2.1276111180068833, 2.1275471266381736, 2.1274831601904971, 2.1274192182005747, 2.127355300210684, 2.1272914057680055, 2.1272275344245988, 2.1271636857366985, 2.1270998605511369, 2.1270360573267242, 2.1269722753940674, 2.1269085142820212, 2.1268447735417704, 2.12678105274101, 2.1267173514521396, 2.126653669253519, 2.126590005732981, 2.1265263604857756, 2.1264627331135766, 2.1263991232235582, 2.1263355304278559, 2.1262719543432529, 2.1262083946299355, 2.1261448509325636, 2.1260813228081843, 2.1260178098977094, 2.1259543118419555, 2.125890828282714, 2.1258273588638041, 2.1257639032315865, 2.1257004610350703, 2.1256370318316007, 2.1255736167152475, 2.1255102152270489, 2.1254468261611263, 2.1253834487748744, 2.1253200825434058, 2.12525672704164, 2.125193381707716, 2.1251300463185476, 2.1250667205344924, 2.1250034040687162, 2.1249400966107088, 2.1248767978460155, 2.1248135074658325, 2.1247502251663875, 2.1246869506467125, 2.1246236837254964, 2.124560424256595, 2.1244971719191086, 2.1244339264648078, 2.1243706884422631, 2.1243074582052466, 2.1242442344748937, 2.1241810169021509, 2.1241178051420744, 2.1240545987794524, 2.1239913975659261, 2.1239282011842353, 2.1238650093406295, 2.1238018217485268, 2.1237386381278882, 2.1236754582037349, 2.1236122817082248, 2.1235491083698719, 2.1234859379232156, 2.1234227703203219, 2.1233596085829269, 2.1232964523709135, 2.1232332975906445, 2.1231701440828208, 2.1231069916498875, 2.1230438401018632, 2.1229806928920674, 2.1229175505543241, 2.1228544108855418, 2.1227912741849182, 2.1227281429597946, 2.1226650178552684, 2.1226018986471122, 2.122538785097853, 2.1224756769007738, 2.1224125737313217, 2.1223494752687668, 2.1222863812054378, 2.1222232912520553, 2.1221602051341142, 2.1220971225918546, 2.1220340434110097, 2.1219709673571425, 2.121907894191426, 2.1218448242947376]
'''