Java Code Examples for com.jstarcraft.ai.data.DataInstance#setQuantityMark()
The following examples show how to use
com.jstarcraft.ai.data.DataInstance#setQuantityMark() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemClusterModel.java From jstarcraft-rns with Apache License 2.0 | 6 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); float value = 0F; for (int topicIndex = 0; topicIndex < factorSize; topicIndex++) { float topicProbability = itemTopicProbabilities.getValue(itemIndex, topicIndex); // probability float topicValue = 0F; for (Entry<Float, Integer> entry : scoreIndexes.entrySet()) { float score = entry.getKey(); float probability = topicScoreMatrix.getValue(topicIndex, entry.getValue()); topicValue += score * probability; } value += topicProbability * topicValue; } instance.setQuantityMark(value); }
Example 2
Source File: BHFreeRankingModel.java From jstarcraft-rns with Apache License 2.0 | 6 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); float value = 0F; for (Entry<Float, Integer> entry : scoreIndexes.entrySet()) { float score = entry.getKey(); float probability = 0F; for (int userTopic = 0; userTopic < userTopicSize; userTopic++) { for (int itemTopic = 0; itemTopic < itemTopicSize; itemTopic++) { probability += user2TopicProbabilities.getValue(userIndex, userTopic) * userTopic2ItemTopicProbabilities.getValue(userTopic, itemTopic) * userTopic2ItemTopicItemSums[userTopic][itemTopic][itemIndex] * userTopic2ItemTopicScoreProbabilities[userTopic][itemTopic][entry.getValue()]; } } value += score * probability; } instance.setQuantityMark(value); }
Example 3
Source File: AspectModelRatingModel.java From jstarcraft-rns with Apache License 2.0 | 6 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); float value = 0F; float denominator = 0F; for (int topicIndex = 0; topicIndex < factorSize; topicIndex++) { float weight = topicProbabilities.getValue(topicIndex) * userProbabilities.getValue(topicIndex, userIndex) * itemProbabilities.getValue(topicIndex, itemIndex); denominator += weight; value += weight * meanProbabilities.getValue(topicIndex); } value = value / denominator; if (Float.isNaN(value)) { value = meanScore; } instance.setQuantityMark(value); }
Example 4
Source File: SVDPlusPlusModel.java From jstarcraft-rns with Apache License 2.0 | 6 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); SparseVector userVector = scoreMatrix.getRowVector(userIndex); // TODO 此处需要重构,取消DenseVector. DenseVector factorVector = DenseVector.valueOf(factorSize); // sum of implicit feedback factors of userIdx with weight Math.sqrt(1.0 // / userItemsList.get(userIdx).size()) for (VectorScalar term : userVector) { factorVector.addVector(factorMatrix.getRowVector(term.getIndex())); } float scale = (float) Math.sqrt(userVector.getElementSize()); if (scale > 0F) { factorVector.scaleValues(1F / scale); } instance.setQuantityMark(predict(userIndex, itemIndex, factorVector)); }
Example 5
Source File: DeepFMModel.java From jstarcraft-rns with Apache License 2.0 | 5 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); float value = outputData.getFloat(userIndex, itemIndex); instance.setQuantityMark(value); }
Example 6
Source File: MovieDataConfigurer.java From jstarcraft-example with Apache License 2.0 | 5 votes |
/** * 装配数据模型 * * @param movieDataSpace * @return */ @Bean("movieDataModule") DataModule getMovieDataModule(DataSpace movieDataSpace, List<MovieUser> movieUsers, List<MovieItem> movieItems) throws Exception { TreeMap<Integer, String> configuration = new TreeMap<>(); configuration.put(1, "user"); configuration.put(2, "item"); configuration.put(3, "score"); configuration.put(4, "instant"); DataModule dataModule = movieDataSpace.makeDenseModule("score", configuration, 1000000); File file = new File("data/ml-100k/u.data"); CSVFormat format = CSVFormat.DEFAULT.withDelimiter('\t'); DataConverter<InputStream> convertor = new CsvConverter(format, movieDataSpace.getQualityAttributes(), movieDataSpace.getQuantityAttributes()); try (InputStream stream = new FileInputStream(file)) { convertor.convert(dataModule, stream); } int userDimension = dataModule.getQualityInner("user"); int itemDimension = dataModule.getQualityInner("item"); int scoreDimension = dataModule.getQuantityInner("score"); for (DataInstance instance : dataModule) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); instance.setQuantityMark(instance.getQuantityFeature(scoreDimension)); movieUsers.get(userIndex).click(itemIndex); } return dataModule; }
Example 7
Source File: LDAModel.java From jstarcraft-rns with Apache License 2.0 | 5 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); DefaultScalar scalar = DefaultScalar.getInstance(); DenseVector userVector = userTopicProbabilities.getRowVector(userIndex); DenseVector itemVector = topicItemProbabilities.getColumnVector(itemIndex); instance.setQuantityMark(scalar.dotProduct(userVector, itemVector).getValue()); }
Example 8
Source File: DeepCrossModel.java From jstarcraft-rns with Apache License 2.0 | 5 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); float value = outputData.getValue(userIndex, itemIndex); instance.setQuantityMark(value); }
Example 9
Source File: RankVFCDModel.java From jstarcraft-rns with Apache License 2.0 | 5 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); DefaultScalar scalar = DefaultScalar.getInstance(); float score = 0F; if (scoreMatrix.getColumnVector(itemIndex).getElementSize() == 0) { score = scalar.dotProduct(userFactors.getRowVector(userIndex), factorMatrix.getColumnVector(itemIndex)).getValue(); } else { score = scalar.dotProduct(userFactors.getRowVector(userIndex), explicitItemFactors.getRowVector(itemIndex)).getValue(); } instance.setQuantityMark(score); }
Example 10
Source File: SLIMModel.java From jstarcraft-rns with Apache License 2.0 | 5 votes |
/** * predict a specific ranking score for user userIdx on item itemIdx. * * @param userIndex user index * @param itemIndex item index * @return predictive ranking score for user userIdx on item itemIdx * @throws ModelException if error occurs */ @Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); int[] neighbors = itemNeighbors[itemIndex]; if (neighbors == null) { instance.setQuantityMark(0F); return; } instance.setQuantityMark(predict(userIndex, itemIndex, neighbors, -1)); }
Example 11
Source File: HMMModel.java From jstarcraft-rns with Apache License 2.0 | 5 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); float score = 0F; for (int state = 0; state < numberOfStates; state++) { score += Math.exp(norms.getValue(userIndex, state) - viewProbabilities.getValue(state, itemIndex)); } score = 1F - score; instance.setQuantityMark(score); }
Example 12
Source File: AspectModelRankingModel.java From jstarcraft-rns with Apache License 2.0 | 5 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); float value = 0F; for (int topicIndex = 0; topicIndex < factorSize; topicIndex++) { value += userProbabilities.getValue(topicIndex, userIndex) * itemProbabilities.getValue(topicIndex, itemIndex) * topicProbabilities.getValue(topicIndex); } instance.setQuantityMark(value); }
Example 13
Source File: TopicMFMTModel.java From jstarcraft-rns with Apache License 2.0 | 4 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); instance.setQuantityMark(predict(userIndex, itemIndex)); }
Example 14
Source File: ZeroRuleRegressor.java From jstarcraft-ai with Apache License 2.0 | 4 votes |
@Override public void predict(DataInstance instance, DataInstance... contexts) { instance.setQuantityMark(quantity); }
Example 15
Source File: WBPRModel.java From jstarcraft-rns with Apache License 2.0 | 4 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); instance.setQuantityMark(predict(userIndex, itemIndex)); }
Example 16
Source File: ASVDPlusPlusModel.java From jstarcraft-rns with Apache License 2.0 | 4 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); instance.setQuantityMark(predict(userIndex, itemIndex)); }
Example 17
Source File: UserAverageModel.java From jstarcraft-rns with Apache License 2.0 | 4 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); instance.setQuantityMark(userMeans[userIndex]); }
Example 18
Source File: CDAEModel.java From jstarcraft-rns with Apache License 2.0 | 4 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); instance.setQuantityMark(outputData.getValue(userIndex, itemIndex)); }
Example 19
Source File: VBPRModel.java From jstarcraft-rns with Apache License 2.0 | 4 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); instance.setQuantityMark(predict(userIndex, itemIndex, featureVector.getValue(itemIndex), factorMatrix.getColumnVector(itemIndex))); }
Example 20
Source File: TopicMFATModel.java From jstarcraft-rns with Apache License 2.0 | 4 votes |
@Override public void predict(DataInstance instance) { int userIndex = instance.getQualityFeature(userDimension); int itemIndex = instance.getQualityFeature(itemDimension); instance.setQuantityMark(predict(userIndex, itemIndex)); }