Пример #1
0
 def approximateCP(Xin):
     print re
     print alpha
     print Ls
     print beta
     As = alg.RRMFCP(Xin,re,beta,Ls,alpha)
     Xs = alg.expand(I,As)
     return Xs
Пример #2
0
def testL():
    """
    過去の遺産
    """
    s = 100
    size = [s, s, s]
    rank = 4
    rank_estimate = 15

    alpha = 0.1
    beta = 0.00

    while True:
        #X = alg.randomTensorOfNorm(size,rank,0.05)
        dat = benchmark.Bonnie()
        X = dat["X"]
        L = dat["L"]

        #X = X - mean(X)
        #X = X + min(X.reshape(prod(X.shape)))
        print "norm:", norm(X)

        originalNorm = norm(X)
        X = X / norm(X)
        #X = X+0.1

        print[det(l) for l in L]
        return
        print X.shape

        #As = alg.RRMFCP(X,rank_estimate,alpha,[L,None,None],beta)
        As = alg.RRMFCP(X, rank_estimate, beta, L, alpha)
        #As = cpold.RRMFCP(X,rank_estimate,alpha)

        print "finished"

        I = alg.createUnitTensor(len(size), rank_estimate)
        Result = alg.expand(I, As)

        #vint = vectorize(int)
        #Result = vint(Result*originalNorm+0.5) / originalNorm
        #Result = sign(vint(Result))

        #benchmark.SaveImage(X.reshape(151*2,151*19),"Sugar")
        #benchmark.SaveImage(Result.reshape(151*2,151*19),"Est_Sugar")
        #benchmark.SaveImage(abs(X-Result).reshape(151*2,151*19),"Diff_Sugar")
        #Result = Result / norm(Result)

        #print "original \n", X
        print "estimated \n", abs(X - Result)
        print "error \n", norm(X - Result)
        #print As[0]
        raw_input()
Пример #3
0
def testCP():
    s = 100 
    size = [s,s,s]
    rank = 4
    rank_estimate = 5
   
    alpha = 0.1
    beta = 0.0001

    while True:
        #X = alg.randomTensorOfNorm(size,rank,0.05)
        #dat = benchmark.ThreeDNoseData()
        #dat = benchmark.RandomSmallTensor()
        dat = benchmark.Flow_Injection()
        #dat = benchmark.Bonnie()
        #dat = benchmark.Artificial()
        X = dat["X"]
        L = dat["L"]

        #X = X - mean(X)
        #X = X + min(X.reshape(prod(X.shape)))
        print "norm:",norm(X)
        X = X / norm(X)
        #X = X+0.1
        
        L = [None,None,None]
        print X.shape

        #As = alg.RRMFCP(X,rank_estimate,alpha,[L,None,None],beta)
        As = alg.RRMFCP(X,rank_estimate,beta,L,alpha)
        #As = cpold.RRMFCP(X,rank_estimate,alpha)

        print "finished"
        
        I = alg.createUnitTensor(len(size),rank_estimate)
        Result = alg.expand(I,As)

        benchmark.SaveImage(X,"Flow")
        benchmark.SaveImage(Result,"Est_Flow")
        #Result = Result / norm(Result)
        
        #print "original \n", X
        #print "estimated \n",Result
        print "error \n", norm(X - Result)
        #print As[0]
        raw_input()
Пример #4
0
 def approximate(Xin):
     As = alg.RRMFCP(Xin,rank_estimate,beta,Ls,alpha,Ps,Ds)
     Xs = alg.expand(I,As)
     return Xs
Пример #5
0
def testCP():
    """
    CP分解テスト
    """
    s = 100
    size = [s, s, s]
    rank = 10
    rank_estimate = 15

    alpha = 0.1
    beta = 0.00

    #X = alg.randomTensorOfNorm(size,rank,0.05)
    #dat = benchmark.ThreeDNoseData()
    dat = benchmark.RandomSmallTensor()
    #dat = benchmark.Flow_Injection()
    #dat = benchmark.Bonnie()
    #dat = benchmark.Enron()
    #dat = benchmark.Sugar()
    #dat = benchmark.Artificial()
    while True:
        X = dat["X"]
        L = dat["L"]

        #X = X - mean(X)
        #X = X + min(X.reshape(prod(X.shape)))
        print "norm:", norm(X)

        originalNorm = norm(X)
        X = X / norm(X)
        #X = X+0.1

        L = [None, None, None]
        print X.shape

        #As = alg.RRMFCP(X,rank_estimate,alpha,[L,None,None],beta)
        start = datetime.datetime.today()
        As = alg.RRMFCP(X, rank_estimate, beta, L, alpha)
        end = datetime.datetime.today()
        #As = cpold.RRMFCP(X,rank_estimate,alpha)

        print "finished"
        print end - start

        I = alg.createUnitTensor(len(size), rank_estimate)
        Result = alg.expand(I, As)

        #vint = vectorize(int)
        #Result = vint(Result*originalNorm+0.5) / originalNorm
        #Result = sign(vint(Result))

        #benchmark.SaveImage(X.reshape(151*2,151*19),"Sugar")
        #benchmark.SaveImage(Result.reshape(151*2,151*19),"Est_Sugar")
        #benchmark.SaveImage(abs(X-Result).reshape(151*2,151*19),"Diff_Sugar")
        #Result = Result / norm(Result)

        #print "original \n", X
        #print "estimated \n",abs(X-Result)
        print "error \n", norm(X - Result)
        #print As[0]
        raw_input()
Пример #6
0
 def approximate(Xin):
     As = alg.RRMFCP(Xin, rank_estimate, alpha)
     Xs = alg.expand(I, As)
     return Xs