org.apache.mahout.math.Vector.zSum()方法的使用及代码示例

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

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

Vector.zSum介绍

[英]Return the sum of all the elements of the receiver
[中]返回接收器所有元素的总和

代码示例

代码示例来源:origin: apache/mahout

@Override
public double zSum() {
 return delegate.zSum();
}

代码示例来源:origin: apache/mahout

@Override
public double zSum() {
 return delegate.zSum();
}

代码示例来源:origin: apache/mahout

@Override
 public double apply(Vector v) {
  return v.zSum();
 }
}).zSum(), total, EPSILON);

代码示例来源:origin: apache/mahout

@Override
 public double apply(Vector v) {
  return v.zSum();
 }
});

代码示例来源:origin: apache/mahout

@Override
 public double apply(Vector v) {
  return v.zSum();
 }
});

代码示例来源:origin: apache/mahout

@Test
public void testZSum() {
 double expected = 0;
 for (double value : values) {
  expected += value;
 }
 assertEquals("wrong zSum", expected, test.zSum(), EPSILON);
}

代码示例来源:origin: apache/mahout

@Test
public void testZSum() {
 double expected = 0;
 for (int i = OFFSET; i < OFFSET + CARDINALITY; i++) {
  expected += values[i];
 }
 assertEquals("wrong zSum", expected, test.zSum(), EPSILON);
}

代码示例来源:origin: apache/mahout

@Test
public void testAggregate() {
 double total = test.aggregate(Functions.PLUS, Functions.IDENTITY);
 assertEquals(test.aggregateRows(new VectorFunction() {
  @Override
  public double apply(Vector v) {
   return v.zSum();
  }
 }).zSum(), total, EPSILON);
}

代码示例来源:origin: apache/mahout

@Test
public void testAggregateCols() {
 Vector v = test.aggregateColumns(new VectorFunction() {
  @Override
  public double apply(Vector v) {
   return v.zSum();
  }
 });
 for (int i = 0; i < test.numCols(); i++) {
  assertEquals(test.viewColumn(i).zSum(), v.get(i), EPSILON);
 }
}

代码示例来源:origin: apache/mahout

@Test
public void testAggregateRows() {
 Vector v = test.aggregateRows(new VectorFunction() {
  @Override
  public double apply(Vector v) {
   return v.zSum();
  }
 });
 for (int i = 0; i < test.numRows(); i++) {
  assertEquals(test.viewRow(i).zSum(), v.get(i), EPSILON);
 }
}

代码示例来源:origin: apache/mahout

@Test
public void testIterators() {
 final T v0 = vectorToTest(20);
 double sum = 0;
 int elements = 0;
 int nonZero = 0;
 for (Element element : v0.all()) {
  elements++;
  sum += element.get();
  if (element.get() != 0) {
   nonZero++;
  }
 }
 int nonZeroIterated = Iterables.size(v0.nonZeroes());
 assertEquals(20, elements);
 assertEquals(v0.size(), elements);
 assertEquals(nonZeroIterated, nonZero);
 assertEquals(v0.zSum(), sum, 0);
}

代码示例来源:origin: apache/mahout

assertEquals(i * i, m.viewRow(i).zSum(), 0);
assertEquals(i * i, m.viewRow(i).get(i), 0);
assertEquals(i * i, m.viewColumn(i).zSum(), 0);
assertEquals(i * i, m.viewColumn(i).get(i), 0);

代码示例来源:origin: apache/mahout

@Test
public void testIterators() {
 int[] pivot = pivot();
 int[] unpivot = unpivot();
 Vector v = randomVector();
 PermutedVectorView pvv = new PermutedVectorView(v, pivot);
 // check a simple operation and thus an iterator
 assertEquals(v.zSum(), pvv.zSum(), 0);
 assertEquals(v.getNumNondefaultElements(), pvv.getNumNondefaultElements());
 v.set(11, 0);
 assertEquals(v.getNumNondefaultElements(), pvv.getNumNondefaultElements());
 Iterator<Vector.Element> vi = pvv.iterator();
 int i = 0;
 while (vi.hasNext()) {
  Vector.Element e = vi.next();
  assertEquals("Index " + i, i, pivot[e.index()]);
  assertEquals("Reverse Index " + i, unpivot[i], e.index());
  assertEquals("Self-value " + i, e.get(), pvv.get(e.index()), 0);
  // note that we iterate in the original vector order
  assertEquals("Value " + i, v.get(i), e.get(), 0);
  i++;
 }
}

代码示例来源:origin: apache/mahout

assertEquals(dv1.norm(2), v1.norm(2), FUZZ);
assertEquals(dv1.zSum(), v1.zSum(), FUZZ);
assertEquals(3.1 * v1.size(), v1.assign(3.1).zSum(), FUZZ);
assertEquals(0, v1.plus(-3.1).norm(1), FUZZ);
v1.assign(dv1);
assertEquals(0, v1.getDistanceSquared(dv1), FUZZ);
assertEquals(dv1.zSum() - dv1.size() * 3.4, v1.assign(Functions.minus(3.4)).zSum(), FUZZ);
assertEquals(dv1.zSum() - dv1.size() * 4.5, v1.assign(Functions.MINUS, 1.1).zSum(), FUZZ);
v1.assign(dv1);
assertEquals(dv1.dot(dv2), v1.aggregate(v2, Functions.PLUS, Functions.MULT), FUZZ);
assertEquals(dv1.viewPart(5, 10).zSum(), v1.viewPart(5, 10).zSum(), FUZZ);

代码示例来源:origin: org.apache.mahout/mahout-mrlegacy

@Override
public double getAverageStd() {
 if (s0 == 0.0) {
  return 0.0;
 } else {
  return std.zSum() / std.size();
 }
}

代码示例来源:origin: org.apache.mahout/mahout-mr

@Override
 protected void map(IntWritable key, VectorWritable row, Context context) 
  throws IOException, InterruptedException {
  // store the sum
  IntDoublePairWritable store = new IntDoublePairWritable(key.get(), row.get().zSum());
  context.write(NullWritable.get(), store);
 }
}

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

@Override
 protected void map(IntWritable key, VectorWritable row, Context context) 
  throws IOException, InterruptedException {
  // store the sum
  IntDoublePairWritable store = new IntDoublePairWritable(key.get(), row.get().zSum());
  context.write(NullWritable.get(), store);
 }
}

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

protected AbstractThetaTrainer(Vector weightsPerFeature, Vector weightsPerLabel, double alphaI) {
 Preconditions.checkNotNull(weightsPerFeature);
 Preconditions.checkNotNull(weightsPerLabel);
 this.weightsPerFeature = weightsPerFeature;
 this.weightsPerLabel = weightsPerLabel;
 this.alphaI = alphaI;
 perLabelThetaNormalizer = weightsPerLabel.like();
 totalWeightSum = weightsPerLabel.zSum();
 numFeatures = weightsPerFeature.getNumNondefaultElements();
}

代码示例来源:origin: org.apache.mahout/mahout-mrlegacy

@Override
 public double apply(Vector v) {
  return v.zSum() / v.size();
 }
});

代码示例来源:origin: org.apache.mahout/mahout-mrlegacy

@Override
public Vector classify(Vector data, ClusterClassifier prior) {
 List<Cluster> models = prior.getModels();
 int i = 0;
 Vector pdfs = new DenseVector(models.size());
 for (Cluster model : models) {
  pdfs.set(i++, model.pdf(new VectorWritable(data)));
 }
 return pdfs.assign(new TimesFunction(), 1.0 / pdfs.zSum());
}

相关文章