org.lenskit.transform.quantize.Quantizer类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(59)

本文整理了Java中org.lenskit.transform.quantize.Quantizer类的一些代码示例,展示了Quantizer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Quantizer类的具体详情如下:
包路径:org.lenskit.transform.quantize.Quantizer
类名称:Quantizer

Quantizer介绍

[英]Quantize real values into discrete values. Used to do things like map floating point ratings or predictions to discrete rating values. By default, if there is a preference domain available, a PreferenceDomainQuantizer will be used to implement this interface.
[中]将实值量化为离散值。用于将浮点评级或预测映射到离散评级值。默认情况下,如果有可用的首选域,将使用PreferenceDomainQuantizer来实现此接口。

代码示例

代码示例来源:origin: lenskit/lenskit

@Test
  public void testHalfStars() {
    Quantizer q = new PreferenceDomainQuantizer(domain);
    assertThat(q.getCount(), equalTo(10));
    assertThat(q.getIndexValue(q.index(4.9)), closeTo(5.0, 1.0e-6));
    assertThat(q.getIndexValue(q.index(4.7)), closeTo(4.5, 1.0e-6));
    assertThat(q.getIndexValue(q.index(3.42)), closeTo(3.5, 1.0e-6));
    assertThat(q.quantize(4.9), closeTo(5.0, 1.0e-6));
    assertThat(q.quantize(4.7), closeTo(4.5, 1.0e-6));
    assertThat(q.quantize(3.42), closeTo(3.5, 1.0e-6));
  }
}

代码示例来源:origin: lenskit/lenskit

@Nonnull
  @Override
  public ResultMap predictWithDetails(long user, @Nonnull Collection<Long> items) {
    ResultMap scores = itemScorer.scoreWithDetails(user, items);
    List<Result> results = new ArrayList<>();
    for (Result raw: scores) {
      int idx = quantizer.index(raw.getScore());
      double score = quantizer.getIndexValue(idx);
      results.add(Results.rescore(raw, score));
    }
    return Results.newResultMap(results);
  }
}

代码示例来源:origin: lenskit/lenskit

@Override
public double similarity(Long2DoubleMap vec1, Long2DoubleMap vec2) {
  MutualInformationAccumulator accum = new MutualInformationAccumulator(quantizer.getCount());
  for (Long2DoubleMap.Entry e: vec1.long2DoubleEntrySet()) {
    long k = e.getLongKey();
    if (vec2.containsKey(k)) {
      accum.count(quantizer.index(e.getDoubleValue()),
            quantizer.index(vec2.get(k)));
    }
  }
  return accum.getMutualInformation();
}

代码示例来源:origin: lenskit/lenskit

@Test
  public void testSomeElements() {
    Quantizer q = new ValueArrayQuantizer(new double[]{1.0, 2.0, 3.0, 4.0, 5.0});
    assertThat(q.getCount(), equalTo(5));
    assertThat(q.getIndexValue(0), equalTo(1.0));
    assertThat(q.index(2.5), equalTo(2));
    assertThat(q.index(5.0), equalTo(4));
    assertThat(q.index(1.73), equalTo(1));
  }
}

代码示例来源:origin: lenskit/lenskit

long iid = rating.getLongKey();
double score = scores.get(iid);
int r = quantizer.index(rating.getDoubleValue());

代码示例来源:origin: lenskit/lenskit

double pred = quantizer.getIndexValue(mlIdx);
if (includeDetails) {
  results.add(new FullResult(baseResults.get(item), pred,

代码示例来源:origin: lenskit/lenskit

/**
 * The constructor of OrdRecParameter.
 * It use the quantized values of rating to initialize t1 and beta.
 * Each threshold is initialized as the mean of two contiguous rating values.
 * Since the index of quantizer is always an successive non-negative integer
 * begin from 0, so t1 will initialize as 0.5, and the interval between two
 * thresholds will be 1.
 * @param qtz The quantizer for ratings
 */
OrdRecModel(Quantizer qtz) {
  qtzValues = qtz.getValues();
  levelCount = qtzValues.getDimension();
  t1 = (qtzValues.getEntry(0) + qtzValues.getEntry(1))/2;
  beta = new ArrayRealVector(levelCount - 2);
  double tr = t1;
  for (int i = 1; i <= beta.getDimension(); i++) {
    double trnext = (qtzValues.getEntry(i) + qtzValues.getEntry(i + 1)) * 0.5;
    beta.setEntry(i - 1, Math.log(trnext - tr));
    tr = trnext;
  }
}

代码示例来源:origin: lenskit/lenskit

@Test
public void testFindSingle() {
  Quantizer q = new ValueArrayQuantizer(new double[]{5.0});
  assertThat(q.getCount(), equalTo(1));
  assertThat(q.getIndexValue(0), equalTo(5.0));
  assertThat(q.index(2.5), equalTo(0));
  assertThat(q.index(5.0), equalTo(0));
}

代码示例来源:origin: org.grouplens.lenskit/lenskit-predict

private void quantize(MutableSparseVector scores) {
  for (VectorEntry e: scores) {
    scores.set(e, quantizer.getIndexValue(quantizer.index(e.getValue())));
  }
}

代码示例来源:origin: org.lenskit/lenskit-core

@Override
public double similarity(Long2DoubleMap vec1, Long2DoubleMap vec2) {
  MutualInformationAccumulator accum = new MutualInformationAccumulator(quantizer.getCount());
  for (Long2DoubleMap.Entry e: vec1.long2DoubleEntrySet()) {
    long k = e.getLongKey();
    if (vec2.containsKey(k)) {
      accum.count(quantizer.index(e.getDoubleValue()),
            quantizer.index(vec2.get(k)));
    }
  }
  return accum.getMutualInformation();
}

代码示例来源:origin: org.grouplens.lenskit/lenskit-predict

long iid = rating.getKey();
double score = scores.get(iid);
int r = quantizer.index(rating.getValue());

代码示例来源:origin: org.grouplens.lenskit/lenskit-predict

double pred = quantizer.getIndexValue(mlIdx);
if (includeDetails) {
  results.add(new FullResult(baseResults.get(item), pred,

代码示例来源:origin: org.grouplens.lenskit/lenskit-predict

/**
 * The constructor of OrdRecParameter.
 * It use the quantized values of rating to initialize t1 and beta.
 * Each threshold is initialized as the mean of two contiguous rating values.
 * Since the index of quantizer is always an successive non-negative integer
 * begin from 0, so t1 will initialize as 0.5, and the interval between two
 * thresholds will be 1.
 * @param qtz The quantizer for ratings
 */
OrdRecModel(Quantizer qtz) {
  qtzValues = qtz.getValues();
  levelCount = qtzValues.getDimension();
  t1 = (qtzValues.getEntry(0) + qtzValues.getEntry(1))/2;
  beta = new ArrayRealVector(levelCount - 2);
  double tr = t1;
  for (int i = 1; i <= beta.getDimension(); i++) {
    double trnext = (qtzValues.getEntry(i) + qtzValues.getEntry(i + 1)) * 0.5;
    beta.setEntry(i - 1, Math.log(trnext - tr));
    tr = trnext;
  }
}

代码示例来源:origin: org.grouplens.lenskit/lenskit-predict

@Nonnull
  @Override
  public ResultMap predictWithDetails(long user, @Nonnull Collection<Long> items) {
    ResultMap scores = itemScorer.scoreWithDetails(user, items);
    List<Result> results = new ArrayList<>();
    for (Result raw: scores) {
      int idx = quantizer.index(raw.getScore());
      double score = quantizer.getIndexValue(idx);
      results.add(Results.rescore(raw, score));
    }
    return Results.newResultMap(results);
  }
}

相关文章

微信公众号

最新文章

更多