本文整理了Java中org.apache.mahout.math.Vector.size()
方法的一些代码示例,展示了Vector.size()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.size()
方法的具体详情如下:
包路径:org.apache.mahout.math.Vector
类名称:Vector
方法名:size
[英]Return the cardinality of the recipient (the maximum number of values)
[中]返回收件人的基数(最大值数)
代码示例来源:origin: apache/mahout
@Override
public double aggregate(Vector other, DoubleDoubleFunction aggregator, DoubleDoubleFunction combiner) {
Preconditions.checkArgument(size == other.size(), "Vector sizes differ");
if (size == 0) {
return 0;
}
return VectorBinaryAggregate.aggregateBest(this, other, aggregator, combiner);
}
代码示例来源:origin: apache/mahout
@Override
public double dot(Vector x) {
if (size != x.size()) {
throw new CardinalityException(size, x.size());
}
if (this == x) {
return getLengthSquared();
}
return aggregate(x, Functions.PLUS, Functions.MULT);
}
代码示例来源:origin: apache/mahout
@Override
public Vector plus(Vector that) {
if (size != that.size()) {
throw new CardinalityException(size, that.size());
}
return createOptimizedCopy().assign(that, Functions.PLUS);
}
代码示例来源:origin: apache/mahout
@Override
public Matrix timesRight(Matrix that) {
if (that.numRows() != diagonal.size()) {
throw new IllegalArgumentException("Incompatible number of rows in the right operand of matrix multiplication.");
}
Matrix m = that.like();
for (int row = 0; row < diagonal.size(); row++) {
m.assignRow(row, that.viewRow(row).times(diagonal.getQuick(row)));
}
return m;
}
代码示例来源:origin: apache/mahout
public static void writeVector(DataOutput out, Vector vector, boolean laxPrecision) throws IOException {
byte flags = flags(vector, laxPrecision);
writeVectorFlagsAndSize(out, flags, vector.size());
writeVectorContents(out, vector, flags);
}
代码示例来源:origin: apache/mahout
@Override
public Vector times(Vector that) {
if (size != that.size()) {
throw new CardinalityException(size, that.size());
}
if (this.getNumNondefaultElements() <= that.getNumNondefaultElements()) {
return createOptimizedCopy(this).assign(that, Functions.MULT);
} else {
return createOptimizedCopy(that).assign(this, Functions.MULT);
}
}
代码示例来源:origin: apache/mahout
@Override
public Vector assign(Vector other) {
if (size() != other.size()) {
throw new CardinalityException(size(), other.size());
}
values.clear();
for (Element e : other.nonZeroes()) {
setQuick(e.index(), e.get());
}
return this;
}
代码示例来源:origin: apache/mahout
@Test
public void testLike() {
Vector other = test.like();
assertTrue("not like", test.getClass().isAssignableFrom(other.getClass()));
assertEquals("size", test.size(), other.size());
}
代码示例来源:origin: apache/mahout
public RandomAccessSparseVector(Vector other) {
this(other.size(), other.getNumNondefaultElements());
for (Element e : other.nonZeroes()) {
values.put(e.index(), e.get());
}
}
代码示例来源:origin: apache/mahout
@Test(expected = CardinalityException.class)
public void testAssignDoubleArrayCardinality() {
double[] array = new double[test.size() + 1];
test.assign(array);
}
代码示例来源:origin: apache/mahout
@Test
public void testPlusDouble() {
Vector val = test.plus(1);
assertEquals("size", test.size(), val.size());
for (int i = 0; i < test.size(); i++) {
if (i % 2 == 0) {
assertEquals("get [" + i + ']', 1.0, val.get(i), EPSILON);
} else {
assertEquals("get [" + i + ']', values[i/2] + 1.0, val.get(i), EPSILON);
}
}
}
代码示例来源:origin: apache/mahout
@Test
public void testTimesVector() {
Vector val = test.times(test);
assertEquals("size", test.size(), val.size());
for (int i = 0; i < test.size(); i++) {
if (i % 2 == 0) {
assertEquals("get [" + i + ']', 0.0, val.get(i), EPSILON);
} else {
assertEquals("get [" + i + ']', values[i/2] * values[i/2], val.get(i), EPSILON);
}
}
}
代码示例来源:origin: apache/mahout
@Test
public void testMinus() throws Exception {
Vector val = test.minus(test);
assertEquals("size", 3, val.size());
for (int i = 0; i < test.size(); i++) {
assertEquals("get [" + i + ']', 0.0, val.get(i), EPSILON);
}
}
代码示例来源:origin: apache/mahout
@Test
public void testPlusDouble() throws Exception {
Vector val = test.plus(1);
assertEquals("size", 3, val.size());
for (int i = 0; i < test.size(); i++) {
assertEquals("get [" + i + ']', values[OFFSET + i] + 1, val.get(i), EPSILON);
}
}
代码示例来源:origin: apache/mahout
private static void assertVectorEquals(Vector expected, Vector actual, double epsilon) {
assertEquals(expected.size(), actual.size());
for (Element x : expected.all()) {
assertEquals(x.get(), actual.get(x.index()), epsilon);
}
}
代码示例来源:origin: apache/mahout
@Test(expected = CardinalityException.class)
public void testAssignVectorCardinality() {
Vector other = new DenseVector(test.size() - 1);
test.assign(other);
}
代码示例来源:origin: apache/mahout
@Test
public void testAssignDoubleArray() {
double[] array = new double[test.size()];
test.assign(array);
for (int i = 0; i < values.length; i++) {
assertEquals("value[" + i + ']', 0.0, test.getQuick(i), EPSILON);
}
}
代码示例来源:origin: apache/mahout
@Test
public void testCopy() {
Vector copy = test.clone();
for (int i = 0; i < test.size(); i++) {
assertEquals("copy [" + i + ']', test.get(i), copy.get(i), EPSILON);
}
}
代码示例来源:origin: apache/mahout
@Test
public void testViewPart() {
Vector part = test.viewPart(1, 2);
assertEquals("part size", 2, part.getNumNondefaultElements());
for (int i = 0; i < part.size(); i++) {
assertEquals("part[" + i + ']', test.get(i+1), part.get(i), EPSILON);
}
}
代码示例来源:origin: apache/mahout
@Test
public void testGetDistanceSquared() {
Vector other = new RandomAccessSparseVector(test.size());
other.set(1, -2);
other.set(2, -5);
other.set(3, -9);
other.set(4, 1);
double expected = test.minus(other).getLengthSquared();
assertTrue("a.getDistanceSquared(b) != a.minus(b).getLengthSquared",
Math.abs(expected - test.getDistanceSquared(other)) < 10.0E-7);
}
内容来源于网络,如有侵权,请联系作者删除!