Пример #1
0
print("betaMomentum=", betaMomentum)
print("numIterFixed=", numIterFixed)
print("maxIter=", maxIter)
print("minibatchSize=", minibatchSize)

multitask = False
print("multitask=", multitask)
if not (multitask):
    numTasks = 1
    for ind in trainingDataNegSampling.index:
        a = deepcopy(trainingDataNegSampling.loc[ind, 'itemSet'])
        a = a + [trainingDataNegSampling.loc[ind, 'target']]
        trainingDataNegSampling.at[ind, 'itemSet'] = a

mod = logisticMultiTaskDPP(setName, taskName, rewardName, numItems, numTasks,
                           numTraits, lbda, alpha, eps, betaMomentum,
                           numIterFixed, minibatchSize, maxIter, gradient_cap,
                           random_state)

mod.fit(trainingDataNegSampling, testData_sample)

#np.savetxt(path+"V.txt",mod.V)
#np.savetxt(path+"D.txt",mod.D)
#
#R = np.zeros((numTasks,numTraits))
#for task in range(numTasks):
#    R[task,:] = mod.R[task]
#np.savetxt(path+"R.txt",R)

print("End learning")
print("numTraits:", numTraits)
print("minibatchSize:", minibatchSize)
Пример #2
0
 np.random.seed(123*run)
 data['cv'] = np.random.random(len(data))
 
 trainingData = data.loc[data['cv']<threshold,]
 testData = data.loc[data['cv']>=threshold,]
 testData = testData.loc[(testData['setSize']>1) & (testData['conversion']==1),]
 
 testData['target2'] = -1
 for ind in testData.index:
     testData.loc[ind,'target2'] = testData.loc[ind,'itemSet'][-1]
     testData.at[ind,'itemSet'] = testData.loc[ind,'itemSet'][:-1]
 
 mod = logisticMultiTaskDPP(setName=setName, taskName=taskName, 
                            rewardName=rewardName, numItems=numItems, 
                            numTasks=numTasks, numTraits=numTraits, 
                            lbda=lbda, alpha=alpha, eps=eps, 
                            betaMomentum=betaMomentum, numIterFixed=numIterFixed, 
                            minibatchSize=minibatchSize, maxIter=maxIter, 
                            gradient_cap=gradient_cap, random_state=random_state, 
                            verbose=False)
 
 nCat = len(category)
 numTraits_cat = int(numTraits/nCat)
 nItem_cat = int(numItems/nCat)
 V0 = np.random.normal(scale=0.001,size=(numItems,numTraits))
 R0 = {}
 for i in range(len(category)):
     V0[nItem_cat*i:(nItem_cat*(i+1)),numTraits_cat*i:(numTraits_cat*(i+1))] *= 10
     for task in range(i*nItem_cat,(i+1)*nItem_cat):
         R0[task] = np.random.normal(loc=0.0,scale=0.01,size=numTraits)
         R0[task][numTraits_cat*i:(numTraits_cat*(i+1))] += 1.0