当前位置: 首页>>代码示例>>Java>>正文


Java SimpleRatingPreferencesReader类代码示例

本文整理汇总了Java中org.ranksys.formats.preference.SimpleRatingPreferencesReader的典型用法代码示例。如果您正苦于以下问题:Java SimpleRatingPreferencesReader类的具体用法?Java SimpleRatingPreferencesReader怎么用?Java SimpleRatingPreferencesReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SimpleRatingPreferencesReader类属于org.ranksys.formats.preference包,在下文中一共展示了SimpleRatingPreferencesReader类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.ranksys.formats.preference.SimpleRatingPreferencesReader; //导入依赖的package包/类
public static void main(String[] args) throws IOException, ClassNotFoundException {
    String userPath = args[0];
    String itemPath = args[1];
    String dataPath = args[2];

    // READING USER, ITEM AND RATINGS FILES
    FastUserIndex<Long> users = SimpleFastUserIndex.load(UsersReader.read(userPath, lp));
    FastItemIndex<Long> items = SimpleFastItemIndex.load(ItemsReader.read(itemPath, lp));
    FastPreferenceData<Long, Long> simpleData = SimpleFastPreferenceData.load(SimpleRatingPreferencesReader.get().read(dataPath, lp, lp), users, items);

    // CREATING A COMPRESSED PREFERENCE DATA
    CODEC<int[]> uCodec = new IntegratedFORVBCODEC();
    CODEC<int[]> iCodec = new IntegratedFORVBCODEC();
    // We assume here that the ratings are 1-5 stars
    CODEC<byte[]> vCodec = new FixedLengthBitStreamCODEC(3);
    FastPreferenceData<Long, Long> codecData = new RatingCODECPreferenceData<>(simpleData, users, items, uCodec, iCodec, vCodec);

    // PRINTING COMPRESSION STATISTICS
    System.out.println(uCodec.stats()[0] + "\t" + uCodec.stats()[1]);
    System.out.println(iCodec.stats()[0] + "\t" + iCodec.stats()[1]);
    System.out.println(vCodec.stats()[0] + "\t" + vCodec.stats()[1]);
    System.out.println(codecData.numPreferences());
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:24,代码来源:CompressionExample.java

示例2: main

import org.ranksys.formats.preference.SimpleRatingPreferencesReader; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
    String userPath = args[0];
    String itemPath = args[1];
    String featurePath = args[2];
    String trainDataPath = args[3];
    String testDataPath = args[4];
    String featureDataPath = args[5];

    FastUserIndex<Long> userIndex = SimpleFastUserIndex.load(UsersReader.read(userPath, lp));
    FastItemIndex<Long> itemIndex = SimpleFastItemIndex.load(ItemsReader.read(itemPath, lp));
    FastFeatureIndex<String> featureIndex = SimpleFastFeatureIndex.load(FeatsReader.read(featurePath, sp));
    FastPreferenceData<Long, Long> trainData = SimpleFastPreferenceData.load(SimpleRatingPreferencesReader.get().read(trainDataPath, lp, lp), userIndex, itemIndex);
    FastPreferenceData<Long, Long> testData = SimpleFastPreferenceData.load(SimpleRatingPreferencesReader.get().read(testDataPath, lp, lp), userIndex, itemIndex);
    FastFeatureData<Long, String, Double> featureData = SimpleFastFeatureData.load(SimpleFeaturesReader.get().read(featureDataPath, lp, sp), itemIndex, featureIndex);

    int numIter = 100;

    Factorization<Long, Long> factorization = new CPLSAFactorizer<Long, Long, String>(numIter, featureData).factorize(trainData);
    Recommender<Long, Long> recommender = new MFRecommender<>(userIndex, itemIndex, factorization);

    Set<Long> targetUsers = testData.getUsersWithPreferences().collect(Collectors.toSet());
    RecommendationFormat<Long, Long> format = new SimpleRecommendationFormat<>(lp, lp);
    Function<Long, IntPredicate> filter = FastFilters.notInTrain(trainData);
    int maxLength = 100;
    RecommenderRunner<Long, Long> runner = new FastFilterRecommenderRunner<>(userIndex, itemIndex, targetUsers.stream(), filter, maxLength);

    System.out.println("Running cPLSA recommender");
    try (RecommendationFormat.Writer<Long, Long> writer = format.getWriter("cplsa")) {
        runner.run(recommender, writer);
    }
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:32,代码来源:CPLSARecommenderExample.java

示例3: main

import org.ranksys.formats.preference.SimpleRatingPreferencesReader; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    String userPath = args[0];
    String itemPath = args[1];
    String featurePath = args[2];
    String trainDataPath = args[3];
    String featureDataPath = args[4];
    String recIn = args[5];

    double lambda = 0.5;
    int cutoff = 100;
    int numIter = 100;

    FastUserIndex<Long> userIndex = SimpleFastUserIndex.load(UsersReader.read(userPath, lp));
    FastItemIndex<Long> itemIndex = SimpleFastItemIndex.load(ItemsReader.read(itemPath, lp));
    FastFeatureIndex<String> featureIndex = SimpleFastFeatureIndex.load(FeatsReader.read(featurePath, sp));
    FastPreferenceData<Long, Long> trainData = SimpleFastPreferenceData.load(SimpleRatingPreferencesReader.get().read(trainDataPath, lp, lp), userIndex, itemIndex);
    FastFeatureData<Long, String, Double> featureData = SimpleFastFeatureData.load(SimpleFeaturesReader.get().read(featureDataPath, lp, sp), itemIndex, featureIndex);

    CPLSAIAFactorizationModelFactory<Long, Long, String> cPLSAModel = new CPLSAIAFactorizationModelFactory<>(numIter, trainData,featureData);
    Reranker<Long, Long> reranker = new XQuAD<>(cPLSAModel.getAspectModel(), lambda, cutoff, true);

    RecommendationFormat<Long, Long> format = new SimpleRecommendationFormat<>(lp, lp);

    System.out.println("Running xQuAD with cPLSA aspect model");
    String recOut = String.format("%s_xQuAD_cplsa_%.1f", recIn, lambda);
    try (RecommendationFormat.Writer<Long, Long> writer = format.getWriter(recOut)) {
        format.getReader(recIn).readAll()
                .map(rec -> reranker.rerankRecommendation(rec, cutoff))
                .forEach(Unchecked.consumer(writer::write));
    }
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:32,代码来源:CPLSARerankerExample.java

示例4: run

import org.ranksys.formats.preference.SimpleRatingPreferencesReader; //导入依赖的package包/类
@Override
  public TemporalDataModelIF<Long, Long> run(final RUN_OPTIONS opts) throws RecommenderException, IOException {
      if (isAlreadyRecommended()) {
          return null;
      }

      String trainDataPath = getProperties().getProperty(RecommendationRunner.TRAINING_SET);
      String testDataPath = getProperties().getProperty(RecommendationRunner.TEST_SET);
      String userPath = getProperties().getProperty(RecommendationRunner.USER_INDEX);
      String itemPath = getProperties().getProperty(RecommendationRunner.ITEM_INDEX);

PreferenceData<Long, Long> dataTotal = null;
if ((userPath == null) ||  (itemPath == null)){
	PreferenceData<Long, Long> dataTrain = SimplePreferenceData.load(SimpleRatingPreferencesReader.get().read(trainDataPath, Parsers.lp, Parsers.lp));
	PreferenceData<Long, Long> dataTest = SimplePreferenceData.load(SimpleRatingPreferencesReader.get().read(testDataPath, Parsers.lp, Parsers.lp));
	dataTotal = new ConcatPreferenceData<>(dataTrain, dataTest);
}

      FastUserIndex<Long> userIndex = null;
if (userPath != null){
	userIndex = SimpleFastUserIndex.load(UsersReader.read(userPath, Parsers.lp));
}else{
	userIndex = SimpleFastUserIndex.load(dataTotal.getAllUsers());
}
      FastItemIndex<Long> itemIndex = null;
if (itemPath != null){
	itemIndex = SimpleFastItemIndex.load(ItemsReader.read(itemPath, Parsers.lp));
}else{
	itemIndex = SimpleFastItemIndex.load(dataTotal.getAllItems());
}
      FastPreferenceData<Long, Long> trainData = SimpleFastPreferenceData.load(SimpleRatingPreferencesReader.get().read(trainDataPath, Parsers.lp, Parsers.lp), userIndex, itemIndex);
      FastPreferenceData<Long, Long> testData = SimpleFastPreferenceData.load(SimpleRatingPreferencesReader.get().read(testDataPath, Parsers.lp, Parsers.lp), userIndex, itemIndex);

      return runRanksysRecommender(opts, userIndex, itemIndex, trainData, testData);
  }
 
开发者ID:recommenders,项目名称:rival,代码行数:36,代码来源:RanksysRecommenderRunner.java

示例5: main

import org.ranksys.formats.preference.SimpleRatingPreferencesReader; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    String trainDataPath = args[0];
    String testDataPath = args[1];
    String featurePath = args[2];
    String recIn = args[3];
    Double threshold = Double.parseDouble(args[4]);

    // USER - ITEM - RATING files for train and test
    PreferenceData<Long, Long> trainData = SimplePreferenceData.load(SimpleRatingPreferencesReader.get().read(trainDataPath, lp, lp));
    PreferenceData<Long, Long> testData = SimplePreferenceData.load(SimpleRatingPreferencesReader.get().read(testDataPath, lp, lp));
    PreferenceData<Long, Long> totalData = new ConcatPreferenceData<>(trainData, testData);
    // EVALUATED AT CUTOFF 10
    int cutoff = 10;
    // ITEM - FEATURE file
    FeatureData<Long, String, Double> featureData = SimpleFeatureData.load(SimpleFeaturesReader.get().read(featurePath, lp, sp));
    // COSINE DISTANCE
    ItemDistanceModel<Long> dist = new CosineFeatureItemDistanceModel<>(featureData);
    // BINARY RELEVANCE
    BinaryRelevanceModel<Long, Long> binRel = new BinaryRelevanceModel<>(false, testData, threshold);
    // NO RELEVANCE
    NoRelevanceModel<Long, Long> norel = new NoRelevanceModel<>();
    // NO RANKING DISCOUNT
    RankingDiscountModel disc = new NoDiscountModel();
    // INTENT MODEL
    IntentModel<Long, Long, String> intentModel = new FeatureIntentModel<>(totalData, featureData);

    Map<String, SystemMetric<Long, Long>> sysMetrics = new HashMap<>();

    ////////////////////////
    // INDIVIDUAL METRICS //
    ////////////////////////
    Map<String, RecommendationMetric<Long, Long>> recMetrics = new HashMap<>();

    // PRECISION
    recMetrics.put("prec", new Precision<>(cutoff, binRel));
    // RECALL
    recMetrics.put("recall", new Recall<>(cutoff, binRel));
    // nDCG
    recMetrics.put("ndcg", new NDCG<>(cutoff, new NDCG.NDCGRelevanceModel<>(false, testData, threshold)));
    // EILD
    recMetrics.put("eild", new EILD<>(cutoff, dist, norel, disc));
    // EPC
    recMetrics.put("epc", new EPC<>(cutoff, new PCItemNovelty<>(trainData), norel, disc));
    // EFD
    recMetrics.put("efd", new EFD<>(cutoff, new FDItemNovelty<>(trainData), norel, disc));
    // EPD
    recMetrics.put("epd", new EPD<>(cutoff, new PDItemNovelty<>(false, trainData, dist), norel, disc));
    // ERR-IA
    recMetrics.put("err-ia", new ERRIA<>(cutoff, intentModel, new ERRIA.ERRRelevanceModel<>(false, testData, threshold)));
    // alpha-nDCG
    recMetrics.put("a-ndcg", new AlphaNDCG<>(cutoff, 0.5, featureData, binRel));

    // AVERAGE VALUES OF RECOMMENDATION METRICS FOR ITEMS IN TEST
    int numUsers = testData.numUsersWithPreferences();
    recMetrics.forEach((name, metric) -> sysMetrics.put(name, new AverageRecommendationMetric<>(metric, numUsers)));

    ////////////////////
    // SYSTEM METRICS //
    ////////////////////
    sysMetrics.put("aggrdiv", new AggregateDiversityMetric<>(cutoff, norel));
    int numItems = totalData.numItemsWithPreferences();
    sysMetrics.put("gini", new GiniIndex<>(cutoff, numItems));

    RecommendationFormat<Long, Long> format = new SimpleRecommendationFormat<>(lp, lp);

    format.getReader(recIn).readAll().forEach(rec -> sysMetrics.values().forEach(metric -> metric.add(rec)));

    sysMetrics.forEach((name, metric) -> System.out.println(name + "\t" + metric.evaluate()));
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:70,代码来源:MetricExample.java


注:本文中的org.ranksys.formats.preference.SimpleRatingPreferencesReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。