this.preventOverfitting = preventOverfitting;
this.randomNoise = randomNoise;
}
protected void prepareTraining() throws TasteException {
RandomWrapper random = RandomUtils.getRandom();
userVectors = new double[dataModel.getNumUsers()][numFeatures];
itemVectors = new double[dataModel.getNumItems()][numFeatures];
double globalAverage = getAveragePreference();
for (int userIndex = 0; userIndex < userVectors.length; userIndex++) {
userVectors[userIndex][0] = globalAverage;
userVectors[userIndex][USER_BIAS_INDEX] = 0; // will store user bias
userVectors[userIndex][ITEM_BIAS_INDEX] = 1; // corresponding item feature contains item bias
for (int feature = FEATURE_OFFSET; feature < numFeatures; feature++) {
userVectors[userIndex][feature] = random.nextGaussian() * randomNoise;
}
}
for (int itemIndex = 0; itemIndex < itemVectors.length; itemIndex++) {
itemVectors[itemIndex][0] = 1; // corresponding user feature contains global average
itemVectors[itemIndex][USER_BIAS_INDEX] = 1; // corresponding user feature contains user bias
itemVectors[itemIndex][ITEM_BIAS_INDEX] = 0; // will store item bias
for (int feature = FEATURE_OFFSET; feature < numFeatures; feature++) {
itemVectors[itemIndex][feature] = random.nextGaussian() * randomNoise;
}
}
cachePreferences();
shufflePreferences();