def OnlineTensorlearningsingleblock(Choleskysimilaritymatrix, Oldparamtensor,
                                    Oldloadingmatrices, ResponsetensorX,
                                    PredictortensorZ, alpha, M, K,
                                    Coretensorsize, Methodname):
    #All the operations, i.e. the variable change, the update and ALTO application are performed in the function
    #In this function, we assume that ALTO has already been applied to the former parameter tensor and the loading matrices already recovered

    Responsetensor = np.zeros(ResponsetensorX.shape)
    Newparametertensor = np.zeros(Oldparamtensor.shape)
    Listoffactormarices = []
    R = Coretensorsize[0]
    for m in range(M):
        #The parameter change is performed
        Responsetensor[:, :,
                       m] = np.dot(np.linalg.inv(Choleskysimilaritymatrix),
                                   ResponsetensorX[:, :, m])
        #We update the parameter tensor
        Newparametertensor[:, :, m] = (
            1 - alpha) * Oldparamtensor[:, :, m] + alpha * np.dot(
                Responsetensor[:, :, m],
                np.linalg.pinv(PredictortensorZ[:, :, m]))

    if (Methodname == "Online"):
        Setting = "Single"
        [I, J, K] = np.array(Newparametertensor.shape, dtype=int)

        Pre_existingfactors = [
            np.random.normal(loc=0, scale=1 / 2, size=(I, R)),
            np.random.normal(loc=0, scale=1 / 2, size=(J, R)),
            np.random.normal(loc=0, scale=1 / 2, size=(K, R))
        ]
        Pre_existingG_set = np.random.normal(loc=0,
                                             scale=1 / 2,
                                             size=(R, R, R))
        Pre_existingP = [
            np.random.normal(loc=0, scale=1 / 2, size=(I, R)),
            np.random.normal(loc=0, scale=1 / 2, size=(J, R)),
            np.random.normal(loc=0, scale=1 / 2, size=(K, R))
        ]
        Pre_existingQ = [
            np.random.normal(loc=0, scale=1 / 2, size=(R, R)),
            np.random.normal(loc=0, scale=1 / 2, size=(R, R)),
            np.random.normal(loc=0, scale=1 / 2, size=(R, R))
        ]
        Nonnegative = False
        Reprojectornot = True
        Minibatchnumber = []
        step = np.power(10, -18, dtype=float)
        alpha = np.power(10, 2, dtype=float)  #np.power(10,-2,dtype=float)
        theta = np.power(10, -2, dtype=float)
        max_iter = 20
        epsilon = np.power(10, -3, dtype=float)
        period = 2
        nbepochs = 1
        pool = Pool(10)
        Core, Listoffactormarices = CyclicBlocCoordinateTucker_setWithPredefinedEpochs(
            [Newparametertensor], Coretensorsize, Pre_existingfactors,
            [Pre_existingG_set], Pre_existingP, Pre_existingQ, Nonnegative,
            Reprojectornot, Setting, Minibatchnumber, step, alpha, theta,
            max_iter, epsilon, period, nbepochs, pool)
        Newparametertensor = Tensor_matrixproduct(
            tl.tensor(Core[0]),
            Operations_listmatrices(Listoffactormarices, "Tensorize"))

    if (Methodname == "Tucker"):

        Ginit = np.random.normal(loc=0, scale=1 / 2, size=(R, R, R))
        [I, J, K] = np.array(Newparametertensor.shape, dtype=int)
        Reprojectornot = True
        max_iter = 20
        step = np.power(10, -18, dtype=float)
        alpha = np.power(10, 2, dtype=float)
        theta = np.power(10, -2, dtype=float)
        epsilon = np.power(10, -3, dtype=float)
        listoffactorsinit = [
            np.random.normal(loc=0, scale=1, size=(I, R)),
            np.random.normal(loc=0, scale=1 / 2, size=(J, R)),
            np.random.normal(loc=0, scale=1 / 2, size=(K, R))
        ]
        X = Newparametertensor
        Nonnegative = False
        Core, Listoffactormarices, errorlist, nbiter = TuckerBatch(
            X, Coretensorsize, max_iter, listoffactorsinit, Ginit, Nonnegative,
            Reprojectornot, alpha, theta, step, epsilon)
        Newparametertensor = Tensor_matrixproduct(
            tl.tensor(Core),
            Operations_listmatrices(Listoffactormarices, "Tensorize"))

    if (Methodname == "Tucker2"):
        [I, J, K] = np.array(Newparametertensor.shape, dtype=int)
        Ginit = np.random.normal(loc=0, scale=1 / 2, size=(I, R, R))

        Reprojectornot = True
        max_iter = 20
        step = np.power(10, -18, dtype=float)
        alpha = np.power(10, 2, dtype=float)
        theta = np.power(10, -2, dtype=float)
        epsilon = np.power(10, -3, dtype=float)
        listoffactorsinit = [
            np.eye(I),
            np.random.normal(loc=0, scale=1 / 2, size=(J, R)),
            np.random.normal(loc=0, scale=1 / 2, size=(K, R))
        ]
        X = Newparametertensor
        Nonnegative = False
        Core, Listoffactormarices, errorlist, nbiter = TuckerBatch(
            X, Coretensorsize, max_iter, listoffactorsinit, Ginit, Nonnegative,
            Reprojectornot, alpha, theta, step, epsilon)
        Newparametertensor = Tensor_matrixproduct(
            tl.tensor(Core),
            Operations_listmatrices(Listoffactormarices, "Tensorize"))

    #Listoffactormarices: tensor type
    #Newparametertensor: tensor type
    return Newparametertensor, Listoffactormarices
def Reconstruction(Originalimage, patchsize, Rank, alpha, theta, val, pool):

    [I, J] = np.array(Originalimage.shape, dtype=int)
    Listrestauration = []
    n0 = np.min([I, J])
    Imrestored = np.zeros((I, J))
    #nbx=int(np.floor(n0/patchsize))
    nbpatches = int(np.floor(n0 / patchsize))
    Setofpatches = np.zeros((patchsize, patchsize, nbpatches))
    mask = Definemasksingleslice2d(Originalimage, val)
    Setofpatches = Patch_extractionallslices2d(Originalimage, mask, patchsize,
                                               val)
    Xtrain_set = []
    for l in range(nbpatches):
        Xtrain_set.append(tl.tensor(Setofpatches[:, :, l]))
    max_iter = 50  #00
    period = 3
    Nonnegative = True  #"Orthogonal"#False#True#(done)

    epsilon = np.power(10, -3, dtype=float)
    step = np.power(10, -6, dtype=float)  #np.power(10,-7,dtype=float)
    Setting = "Single"
    nbepochs = 1  #5
    Reprojectornot = False
    Minibatchsize = []
    Pre_existingfactors = []
    Coretensorsize = [Rank, Rank]
    penaltylasso = alpha * theta
    Pre_existingG_settrain = []

    for l in range(nbpatches):

        Pre_existingG_settrain.append(
            tl.tensor(
                np.maximum(
                    np.random.normal(loc=0, scale=1, size=Coretensorsize), 0)))

    Pre_existingfactors = [
        tl.tensor(
            np.maximum(
                np.random.normal(loc=0,
                                 scale=1,
                                 size=(patchsize, Coretensorsize[0])), 0)),
        tl.tensor(
            np.maximum(
                np.random.normal(loc=0,
                                 scale=1,
                                 size=(patchsize, Coretensorsize[1])), 0))
    ]

    Pre_existingP = [
        tl.tensor(
            np.random.normal(loc=0,
                             scale=1,
                             size=(patchsize, Coretensorsize[0]))),
        tl.tensor(
            np.random.normal(loc=0,
                             scale=1,
                             size=(patchsize, Coretensorsize[1])))
    ]

    Pre_existingQ = [
        tl.tensor(
            np.random.normal(loc=0,
                             scale=1,
                             size=(Coretensorsize[0], Coretensorsize[0]))),
        tl.tensor(
            np.random.normal(loc=0,
                             scale=1,
                             size=(Coretensorsize[1], Coretensorsize[1])))
    ]

    start_timetraining = time.clock()
    Dictionarymatrices, listobjectivefunctionvalues, Objectivefunction_per_epoch, Time_per_epoch = CyclicBlocCoordinateTucker_setWithPredefinedEpochs(
        Xtrain_set, Coretensorsize, Pre_existingfactors,
        Pre_existingG_settrain, backendchoice, Pre_existingP, Pre_existingQ,
        Nonnegative, Reprojectornot, Setting, Minibatchsize, step, alpha,
        theta, max_iter, epsilon, period, nbepochs, pool)
    end_timetraining = time.clock()

    Runningtime = end_timetraining - start_timetraining
    print("The running time is")
    print(Runningtime)
    pdb.set_trace()

    adress = '/Users/Traoreabraham/Desktop/OnlineTensorDictionaryLearning/Inpaintingproblem/ImageInpainting/Objectivefunctions/OnlinesingleObjectivefunctionnonegative' + str(
        Rank)

    #adress='/home/scr/etu/sil821/traorabr/ImageInpainting/Objectivefunctions/OnlinesingleObjectivefunctionunconstrained'+str(Rank)
    np.savez_compressed(adress,
                        Objectivefunction=listobjectivefunctionvalues,
                        Objectivefunctionperepoch=Objectivefunction_per_epoch,
                        Timeperepoch=Time_per_epoch)

    Dm = list(Dictionarymatrices)

    Dictionarymatricesconverted = Operations_listmatrices(
        Dictionarymatrices, "Arrayconversion")

    mask = Definemasksingleslice2d(Originalimage, val)
    #plt.imshow(mask)
    #plt.show()
    #pdb.set_trace()
    for i in range(nbpatches):
        for j in range(nbpatches):
            #indx=np.array(np.linspace(i*patchsize+1,(i+1)*patchsize,patchsize),dtype=int)
            #indy=np.array(np.linspace(j*patchsize+1,(j+1)*patchsize,patchsize),dtype=int)

            #pdb.set_trace()
            #patchmask=mask[i*patchsize+1:(i+1)*patchsize,j*patchsize+1:(j+1)*patchsize]#[indx,indy]
            #Aux=Originalimage[i*patchsize+1:(i+1)*patchsize,j*patchsize+1:(j+1)*patchsize,:]#[indx,indy,:]
            patchmask = mask[i * patchsize:(i + 1) * patchsize,
                             j * patchsize:(j + 1) * patchsize]  #[indx,indy]
            #plt.imshow(patchmask)
            #plt.show()
            #print(patchmask)

            Aux = Originalimage[i * patchsize:(i + 1) * patchsize, j *
                                patchsize:(j + 1) * patchsize]  #[indx,indy,:]
            Aux = np.resize(Aux, np.size(Aux))
            #patchmask=Repetition(patchmask,K)
            Auxmask = np.resize(patchmask, np.size(patchmask))
            Ind = np.where(Auxmask != val)[0]  #np.nonzero(Auxmask)[0]

            yy = Aux[Ind]
            Dictionarymatrix = np.kron(Dictionarymatricesconverted[0],
                                       Dictionarymatricesconverted[1])
            Dma = Dictionarymatrix[Ind, :]
            clf = linear_model.Lasso(alpha=penaltylasso,
                                     fit_intercept=False,
                                     positive=True)  #fit_intercept=False
            #print(Dma.shape)
            #print(yy.shape)
            clf.fit(Dma, yy)
            #print(clf.coef_.shape)
            #pdb.set_trace()
            Activationcoeff = np.reshape(clf.coef_, (Rank, Rank))

            Restore = Tensor_matrixproduct(Activationcoeff, Dm)
            Restore = mxnet_backend.to_numpy(Restore)
            #plt.imshow(Originalimage[i*patchsize:(i+1)*patchsize,j*patchsize:(j+1)*patchsize,:])
            #plt.show()
            #plt.imshow(Restore)
            #plt.show()

            Listrestauration.append(Restore)
            #plt.imshow(Restore)
            #plt.show()
            #plt.imshow(Originalimage[i*patchsize:(i+1)*patchsize,j*patchsize:(j+1)*patchsize,:])
            #plt.show()
            #pdb.set_trace()
            #print(np.argwhere(Restore==0))
            #print(i*patchsize)
            #print((i+1)*patchsize)
            #print(j*patchsize)
            #print((j+1)*patchsize)
            Imrestored[i * patchsize:(i + 1) * patchsize,
                       j * patchsize:(j + 1) * patchsize] = Restore
            #print(Restore)
            #pdb.set_trace()
            #print("The values of i and j are")
            #print(i,j)
    return Imrestored, Listrestauration, listobjectivefunctionvalues, Objectivefunction_per_epoch
Exemple #3
0
def Reconstruction(Originalimage,patchsize,Coretensorsize,alpha,theta,val,pool):
    
    [I,J,K]=np.array(Originalimage.shape,dtype=int)
    Listrestauration=[]
    n0=np.min([I,J])
    Imrestored=np.zeros((I,J,K))
    nbpatches=int(np.floor(n0/patchsize)) 
    Setofpatches=np.zeros((patchsize,patchsize,3,nbpatches))
    slicenumber=0
    mask=Definemasksingleslice(Originalimage,val,slicenumber)
    Setofpatches=Patch_extractionallslices(Originalimage,mask,patchsize,val)
    Xtrain_set=[]
    for l in range(nbpatches):
        Xtrain_set.append(tl.tensor(Setofpatches[:,:,:,l]))
    max_iter=100
    period=3
    Nonnegative=True
 
    epsilon=np.power(10,-3,dtype=float)
    step=np.power(10,-6,dtype=float)
    Setting="Single"
    nbepochs=10
    Reprojectornot=False
    Minibatchsize=[]
    Pre_existingfactors=[]

    penaltylasso=alpha*theta
    Pre_existingG_settrain=[]
    
    for l in range(nbpatches):
        
        Pre_existingG_settrain.append(tl.tensor(np.maximum(np.random.normal(loc=0,scale=1/4,size=Coretensorsize),0)))

    Pre_existingfactors=[tl.tensor(np.maximum(np.random.normal(loc=0,scale=1/4,size=(patchsize,Coretensorsize[0])),0)),tl.tensor(np.maximum(np.random.normal(loc=0,scale=1/4,size=(patchsize,Coretensorsize[1])),0)),tl.tensor(np.maximum(np.random.normal(loc=0,scale=1/4,size=(K,Coretensorsize[2])),0))]
    
    Pre_existingP=[tl.tensor(np.random.normal(loc=0,scale=2,size=(patchsize,Coretensorsize[0]))),tl.tensor(np.random.normal(loc=0,scale=2,size=(patchsize,Coretensorsize[1]))),tl.tensor(np.random.normal(loc=0,scale=2,size=(K,Coretensorsize[2])))]
    
    Pre_existingQ=[tl.tensor(np.random.normal(loc=0,scale=2,size=(Coretensorsize[0],Coretensorsize[0]))),tl.tensor(np.random.normal(loc=0,scale=2,size=(Coretensorsize[1],Coretensorsize[1]))),tl.tensor(np.random.normal(loc=0,scale=2,size=(Coretensorsize[2],Coretensorsize[2])))]
        
 
    Dictionarymatrices,listobjectivefunctionvalues,Objectivefunction_per_epoch=CyclicBlocCoordinateTucker_setWithPredefinedEpochs(Xtrain_set,Coretensorsize,Pre_existingfactors,Pre_existingG_settrain,backendchoice,Pre_existingP,Pre_existingQ,Nonnegative,Reprojectornot,Setting,Minibatchsize,step,alpha,theta,max_iter,epsilon,period,nbepochs,pool)
    
    Dm=list(Dictionarymatrices)
    
    Dictionarymatricesconverted=Operations_listmatrices(Dictionarymatrices,"Arrayconversion")
    
    mask=Definemasksingleslice(Originalimage,val,0)
    for i in range(nbpatches):
        for j in range(nbpatches):
            
            patchmask=mask[i*patchsize:(i+1)*patchsize,j*patchsize:(j+1)*patchsize]#[indx,indy]         

            
            Aux=Originalimage[i*patchsize:(i+1)*patchsize,j*patchsize:(j+1)*patchsize,:]#[indx,indy,:]            
            Aux=np.resize(Aux,np.size(Aux))        
            patchmask=Repetition(patchmask,K)
            Auxmask=np.resize(patchmask,np.size(patchmask))
            Ind=np.where(Auxmask!=val)[0]      #np.nonzero(Auxmask)[0]
            
            yy=Aux[Ind]
            Dictionarymatrix=np.kron(Dictionarymatricesconverted[0],Dictionarymatricesconverted[1])
            Dictionarymatrix=np.kron(Dictionarymatrix,Dictionarymatricesconverted[2])
            Dma=Dictionarymatrix[Ind,:]
            clf=linear_model.Lasso(alpha=penaltylasso,fit_intercept=False,positive=True)#fit_intercept=False
            
            clf.fit(Dma,yy)

            Activationcoeff=np.reshape(clf.coef_,Coretensorsize)
            
            Restore=Tensor_matrixproduct(Activationcoeff,Dm)
            Restore=mxnet_backend.to_numpy(Restore)

            Listrestauration.append(Restore)

    return Imrestored,Listrestauration    
        
#val=255   #value which allows to define the missing pixels
#ratio=0.4 #ratio of missing pixels
#Hyperspectralimg=np.array(Image.open("Lena.png"))
#[W,H,K]=np.array(Hyperspectralimg.shape,dtype=int)
#Hyperspectralimg=Hyperspectralimg+np.maximum(np.random.normal(loc=0,scale=1,size=(W,H,K)),0)/10
#plt.imshow(Hyperspectralimgpixelsdropped)
#plt.show()
#pdb.set_trace()
#patchsize=16
#Rank=16
#alpha=0.001
#theta=0.1
#[width,length,spectralbands]=np.array(Hyperspectralimg.shape,dtype=int)
#Commonsize=np.min(np.array([width,length,spectralbands]))
#Corentensorsize=[int(Rank),int(Rank),int(Rank)]
#pool=Pool(20)
#Imrestored,Listrestauration=Reconstruction(Hyperspectralimgpixelsdropped,patchsize,Corentensorsize,alpha,theta,val,pool)
#pdb.set_trace()
            
            
            
def Reconstruction(Originalimage, patchsize, Coretensorsize, alpha, theta,
                   pool):

    [I, J, K] = np.array(Originalimage.shape, dtype=int)
    Listrestauration = []
    n0 = np.min([I, J])
    Imrestored = np.zeros((I, J, K))
    nbpatches = int(np.floor(n0 / patchsize))
    Setofpatches = np.zeros((patchsize, patchsize, 3, nbpatches))

    Setofpatches = Patch_extractionallslices(Originalimage, patchsize)
    Xtrain_set = []
    for l in range(nbpatches):
        Xtrain_set.append(tl.tensor(Setofpatches[:, :, :, l]))
    max_iter = 5
    period = 20
    Nonnegative = False

    epsilon = np.power(10, -3, dtype=float)
    step = np.power(10, -5, dtype=float)
    Setting = "Single"
    nbepochs = 1
    Reprojectornot = False
    Minibatchsize = []
    Pre_existingfactors = []

    Pre_existingG_settrain = []

    for l in range(nbpatches):

        Pre_existingG_settrain.append(
            tl.tensor(
                np.maximum(
                    np.random.normal(loc=0, scale=1, size=Coretensorsize), 0)))

    Pre_existingfactors = [
        tl.tensor(
            np.maximum(
                np.random.normal(loc=0,
                                 scale=1,
                                 size=(patchsize, Coretensorsize[0])), 0)),
        tl.tensor(
            np.maximum(
                np.random.normal(loc=0,
                                 scale=1 / 4,
                                 size=(patchsize, Coretensorsize[1])), 0)),
        tl.tensor(
            np.maximum(
                np.random.normal(loc=0,
                                 scale=1 / 4,
                                 size=(K, Coretensorsize[2])), 0))
    ]

    Pre_existingP = [
        tl.tensor(
            np.random.normal(loc=0,
                             scale=1,
                             size=(patchsize, Coretensorsize[0]))),
        tl.tensor(
            np.random.normal(loc=0,
                             scale=1,
                             size=(patchsize, Coretensorsize[1]))),
        tl.tensor(np.random.normal(loc=0, scale=1,
                                   size=(K, Coretensorsize[2])))
    ]

    Pre_existingQ = [
        tl.tensor(
            np.random.normal(loc=0,
                             scale=1,
                             size=(Coretensorsize[0], Coretensorsize[0]))),
        tl.tensor(
            np.random.normal(loc=0,
                             scale=2,
                             size=(Coretensorsize[1], Coretensorsize[1]))),
        tl.tensor(
            np.random.normal(loc=0,
                             scale=1,
                             size=(Coretensorsize[2], Coretensorsize[2])))
    ]

    Dictionarymatrices, listobjectivefunctionvalues, Objectivefunction_per_epoch = CyclicBlocCoordinateTucker_setWithPredefinedEpochs(
        Xtrain_set, Coretensorsize, Pre_existingfactors,
        Pre_existingG_settrain, backendchoice, Pre_existingP, Pre_existingQ,
        Nonnegative, Reprojectornot, Setting, Minibatchsize, step, alpha,
        theta, max_iter, epsilon, period, nbepochs, pool)

    #Dm=list(Dictionarymatrices)

    #Dictionarymatricesconverted=Operations_listmatrices(Dictionarymatrices,"Arrayconversion")
    #pdb.set_trace()

    Nonnegative = False
    for i in range(nbpatches):
        for j in range(nbpatches):

            Noisypatch = Originalimage[i * patchsize:(i + 1) * patchsize,
                                       j * patchsize:(j + 1) * patchsize, :]

            G_init = tl.tensor(
                np.random.normal(loc=0, scale=1, size=Coretensorsize))

            Activationcoeff = Sparse_code(Noisypatch, G_init,
                                          Dictionarymatrices, Nonnegative,
                                          step, max_iter, alpha, theta,
                                          epsilon)[0]

            Restore = Tensor_matrixproduct(Activationcoeff, Dictionarymatrices)

            Imrestored[i * patchsize:(i + 1) * patchsize,
                       j * patchsize:(j + 1) * patchsize, :] = Restore
            #pdb.set_trace()
            #Aux=np.resize(Aux,np.size(Aux))
            #patchmask=Repetition(patchmask,K)
            #Auxmask=np.resize(patchmask,np.size(patchmask))
            #Ind=np.where(Auxmask!=val)[0]      #np.nonzero(Auxmask)[0]

            #yy=Aux#[Ind]
            #Dictionarymatrix=np.kron(Dictionarymatricesconverted[0],Dictionarymatricesconverted[1])
            #Dictionarymatrix=np.kron(Dictionarymatrix,Dictionarymatricesconverted[2])
            #Dma=Dictionarymatrix
            #pdb.set_trace()

            #clf=linear_model.Lasso(alpha=penaltylasso,fit_intercept=False,positive=False)#fit_intercept=False

            #clf.fit(Dma,yy)

            #Activationcoeff=np.reshape(clf.coef_,Coretensorsize)

            #Restore=Tensor_matrixproduct(Activationcoeff,Dm)
            #Restore=mxnet_backend.to_numpy(Restore)

            Listrestauration.append(Restore)

    return Imrestored, Listrestauration
def ExperimentToyGeneral(etavalues, Nonnegative, Numberofexamples,
                         Minibatchsize, max_iter, step, alpha, theta, nbepochs,
                         randomarray, trainratio, period, pool):
    L = len(etavalues)
    Nbmean = len(randomarray)

    RMSEminibatch = np.zeros(L)

    StdminibatchRMSE = np.zeros(L)

    Fittingminibatch = np.zeros(L)

    MREminibatch = np.zeros(L)

    Stdminibatchfitting = np.zeros(L)

    Stdminibatchmre = np.zeros(L)

    for l in range(L):
        eta = etavalues[l]

        Stdminibatchrmselist = []

        Stdminibatchfittlist = []

        Stdminibatchmrelist = []

        for k in range(len(randomarray)):

            m = randomarray[k]

            print("The noise number is")
            print(k + 1)

            X_set = GenerateTensorsNonnegative(Numberofexamples, eta, m)
            print("Point I")
            Xtrain_set, Xtest_set = Split_into_two_subsets(X_set, trainratio)
            Xtrain = np.zeros((len(Xtrain_set), 30, 40, 50))
            Xtest = np.zeros((len(Xtest_set), 30, 40, 50))
            for t in range(len(Xtrain_set)):
                Xtrain[t, :, :, :] = Xtrain_set[t]
            for t in range(len(Xtest_set)):
                Xtest[t, :, :, :] = Xtest_set[t]

            Xtest_set = Operations_listmatrices(Xtest_set, "Tensorize")
            print("Point II")
            epsilon = np.power(10, -15, dtype=float)

            Coretensorsize = np.array(
                [len(Xtrain_set), eta, eta, eta]
            )  # The first dimensions must be equal for mathematical coherence purpose
            Ginittrain = np.random.normal(
                loc=0, scale=1 / 100, size=([len(Xtrain_set), eta, eta, eta]))

            Ginittest = np.random.normal(loc=0,
                                         scale=1 / 100,
                                         size=(len(Xtest_set), eta, eta, eta))
            Reprojectornot = False

            Pre_existingG_settrain = []
            for n in range(len(Xtrain_set)):
                Pre_existingG_settrain.append(
                    np.maximum(Ginittrain[n, :, :, :], 0))

            Pre_existingG_settest = []
            for n in range(len(Xtest_set)):
                Pre_existingG_settest.append(
                    np.maximum(Ginittest[n, :, :, :], 0))

            Ltest = len(Xtest_set)

            Pre_existingfactors = [
                np.maximum(
                    np.random.normal(loc=0, scale=1 / 10, size=(30, eta)), 0),
                np.maximum(
                    np.random.normal(loc=0, scale=1 / 10, size=(40, eta)), 0),
                np.maximum(
                    np.random.normal(loc=0, scale=1 / 10, size=(50, eta)), 0)
            ]
            Pre_existingP = [
                np.maximum(
                    np.random.normal(loc=0, scale=1 / 10, size=(30, eta)), 0),
                np.maximum(
                    np.random.normal(loc=0, scale=1 / 10, size=(40, eta)), 0),
                np.maximum(
                    np.random.normal(loc=0, scale=1 / 10, size=(50, eta)), 0)
            ]
            Pre_existingQ = [
                np.maximum(
                    np.random.normal(loc=0, scale=1 / 10, size=(eta, eta)), 0),
                np.maximum(
                    np.random.normal(loc=0, scale=1 / 10, size=(eta, eta)), 0),
                np.maximum(
                    np.random.normal(loc=0, scale=1 / 10, size=(eta, eta)), 0)
            ]

            Coretensorsize = np.array([eta, eta, eta])

            Setting = "MiniBatch"
            print("Point IV")
            listoffactorsresult3 = CyclicBlocCoordinateTucker_setWithPredefinedEpochs(
                Xtrain_set, Coretensorsize, Pre_existingfactors,
                Pre_existingG_settrain, Pre_existingP, Pre_existingQ,
                Nonnegative, Reprojectornot, Setting, Minibatchsize, step,
                alpha, theta, max_iter, epsilon, period, nbepochs, pool)

            Gtest3 = Sparse_coding(Xtest_set, Pre_existingG_settest,
                                   listoffactorsresult3, Nonnegative, Setting,
                                   step, max_iter, alpha, theta, epsilon, pool)
            error3 = Error(Xtest_set, Gtest3, listoffactorsresult3,
                           "MiniBatch", pool)
            fittingerror3 = error3 / Ltest
            rmse3 = np.sqrt(error3 / Ltest)
            mreminibatch = Mean_relative_error(
                Xtest_set, Gtest3,
                Operations_listmatrices(listoffactorsresult3, "Tensorize"),
                "MiniBatch", pool)

            RMSEminibatch[l] = RMSEminibatch[l] + rmse3

            Fittingminibatch[l] = Fittingminibatch[l] + fittingerror3

            MREminibatch[l] = MREminibatch[l] + mreminibatch

            Stdminibatchrmselist.append(rmse3)

            Stdminibatchfittlist.append(fittingerror3)

            Stdminibatchmrelist.append(mreminibatch)

        print("The value of eta is")
        print(eta)

        RMSEminibatch[l] = RMSEminibatch[l] / Nbmean

        print("The root mean sqaure errors RMSEs are")
        print(RMSEminibatch[l])
        StdminibatchRMSE[l] = np.std(np.array(Stdminibatchrmselist))
        print("The standard deviations associated to the RMSEs are")

        print(StdminibatchRMSE[l])

        Fittingminibatch[l] = Fittingminibatch[l] / Nbmean

        print("The fitting errors FEs are")

        print(Fittingminibatch[l])

        Stdminibatchfitting[l] = np.std(np.array(Stdminibatchfittlist))

        print("The standard deviations associated to the FEs are")

        print(Stdminibatchfitting[l])

        MREminibatch[l] = MREminibatch[l] / Nbmean

        print("The mean relative errors MRE are")

        print(MREminibatch[l])

        Stdminibatchmre[l] = np.std(Stdminibatchmrelist)

        print("The standard deviation associated to the MREs are")
        print(Stdminibatchmre[l])

        pdb.set_trace()

    return RMSEminibatch, StdminibatchRMSE, Fittingminibatch, Stdminibatchfitting, MREminibatch, Stdminibatchmre