def executeOneSetting(tensor, density, roundId, para): logger.info('density=%.2f, %2d-round starts.'%(density, roundId + 1)) (numUser, numService, numTime) = tensor.shape # remove the entries of data to generate trainTensor and testTensor (trainTensor, testTensor) = evallib.removeTensor(tensor, density, roundId, para) # invocation to the prediction function startTime = time.clock() # to record the running time for one round predictedTensor = Average.predict(trainTensor, para) runningTime = float(time.clock() - startTime) / numTime # evaluate the prediction error for sliceId in xrange(numTime): testMatrix = testTensor[:, :, sliceId] predictedMatrix = predictedTensor[:, :, sliceId] (testVecX, testVecY) = np.where(testMatrix) testVec = testMatrix[testVecX, testVecY] predVec = predictedMatrix[testVecX, testVecY] evalResult = evallib.errMetric(testVec, predVec, para['metrics']) result = (evalResult, runningTime) # dump the result at each density outFile = '%s%s_%s_result_%02d_%.2f_round%02d.tmp'%(para['outPath'], para['dataName'], para['dataType'], sliceId + 1, density, roundId + 1) evallib.dumpresult(outFile, result) logger.info('density=%.2f, %2d-round done.'%(density, roundId + 1)) logger.info('----------------------------------------------')
def executeOneSetting(matrix, density, roundId, sliceId, para): (numUser, numService) = matrix.shape dim = para['dimension'] # remove data entries to generate trainMatrix and testMatrix seedID = roundId + sliceId * 100 (trainMatrix, testMatrix) = evallib.removeEntries(matrix, density, seedID) (testVecX, testVecY) = np.where(testMatrix) testVec = testMatrix[testVecX, testVecY] # invocation to the prediction function startTime = time.clock() predictedMatrix = PMF.predict(trainMatrix, para) runningTime = float(time.clock() - startTime) # evaluate the prediction error predVec = predictedMatrix[testVecX, testVecY] evalResult = evallib.errMetric(testVec, predVec, para['metrics']) result = (evalResult, runningTime) # dump the result at each density outFile = '%s%s_%s_result_%02d_%.2f_round%02d.tmp' % ( para['outPath'], para['dataName'], para['dataType'], sliceId + 1, density, roundId + 1) evallib.dumpresult(outFile, result) logger.info('density=%.2f, sliceId=%02d, %2d-round done.'\ %(density, sliceId + 1, roundId + 1))
def executeOneSetting(tensor, density, roundId, para): logger.info('density=%.2f, %2d-round starts.' % (density, roundId + 1)) (numUser, numService, numTime) = tensor.shape dim = para['dimension'] # remove the entries of data to generate trainTensor and testTensor (trainTensor, testTensor) = evallib.removeTensor(tensor, density, roundId, para) # invocation to the prediction function startTime = time.clock() # to record the running time for one round predictedTensor = NTF.predict(trainTensor, para) runningTime = float(time.clock() - startTime) / numTime # evaluate the prediction error for sliceId in xrange(numTime): testMatrix = testTensor[:, :, sliceId] predictedMatrix = predictedTensor[:, :, sliceId] (testVecX, testVecY) = np.where(testMatrix) testVec = testMatrix[testVecX, testVecY] predVec = predictedMatrix[testVecX, testVecY] evalResult = evallib.errMetric(testVec, predVec, para['metrics']) result = (evalResult, runningTime) # dump the result at each density outFile = '%s%s_%s_result_%02d_%.2f_round%02d.tmp' % ( para['outPath'], para['dataName'], para['dataType'], sliceId + 1, density, roundId + 1) evallib.dumpresult(outFile, result) logger.info('density=%.2f, %2d-round done.' % (density, roundId + 1)) logger.info('----------------------------------------------')
def executeOneSetting(matrix, density, roundId, sliceId, para): (numUser, numService) = matrix.shape dim = para['dimension'] # remove data entries to generate trainMatrix and testMatrix seedID = roundId + sliceId * 100 (trainMatrix, testMatrix) = evallib.removeEntries(matrix, density, seedID) (testVecX, testVecY) = np.where(testMatrix) testVec = testMatrix[testVecX, testVecY] # invocation to the prediction function startTime = time.clock() predictedMatrix = PMF.predict(trainMatrix, para) runningTime = float(time.clock() - startTime) # evaluate the prediction error predVec = predictedMatrix[testVecX, testVecY] evalResult = evallib.errMetric(testVec, predVec, para['metrics']) result = (evalResult, runningTime) # dump the result at each density outFile = '%s%s_%s_result_%02d_%.2f_round%02d.tmp'%(para['outPath'], para['dataName'], para['dataType'], sliceId + 1, density, roundId + 1) evallib.dumpresult(outFile, result) logger.info('density=%.2f, sliceId=%02d, %2d-round done.'\ %(density, sliceId + 1, roundId + 1))