本文整理了Java中org.apache.mahout.math.Vector.assign()
方法的一些代码示例,展示了Vector.assign()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.assign()
方法的具体详情如下:
包路径:org.apache.mahout.math.Vector
类名称:Vector
方法名:assign
[英]Assign the value to all elements of the receiver
[中]将该值分配给接收器的所有元素
代码示例来源:origin: apache/mahout
@Override
public Vector assign(Vector other) {
delegate.assign(other);
return this;
}
代码示例来源:origin: apache/mahout
@Override
public Vector assign(DoubleFunction function) {
delegate.assign(function);
return this;
}
代码示例来源:origin: apache/mahout
@Override
public Vector assign(Vector other, DoubleDoubleFunction function) {
delegate.assign(other, function);
return this;
}
代码示例来源:origin: apache/mahout
@SuppressWarnings("CloneDoesntCallSuperClone")
@Override
public Vector clone() {
Vector v = new DenseVector(size());
v.assign(this, Functions.PLUS);
return v;
}
代码示例来源:origin: apache/mahout
private static Vector createOptimizedCopy(Vector vector) {
Vector result;
if (vector.isDense()) {
result = vector.like().assign(vector, Functions.SECOND_LEFT_ZERO);
} else {
result = vector.clone();
}
return result;
}
代码示例来源: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 plus(Vector that) {
if (size != that.size()) {
throw new CardinalityException(size, that.size());
}
return createOptimizedCopy().assign(that, Functions.PLUS);
}
代码示例来源:origin: apache/mahout
private static Vector randomVector() {
Vector v = new DenseVector(20);
v.assign(new DoubleFunction() {
private final Random gen = RandomUtils.getRandom();
@Override
public double apply(double arg1) {
return gen.nextDouble();
}
});
return v;
}
}
代码示例来源:origin: apache/mahout
@Test(expected = CardinalityException.class)
public void testAssignDoubleArrayCardinality() {
double[] array = new double[test.size() + 1];
test.assign(array);
}
代码示例来源:origin: apache/mahout
@Test(expected = CardinalityException.class)
public void testAssignVectorCardinality() {
Vector other = new DenseVector(test.size() - 1);
test.assign(other);
}
代码示例来源: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 testAssignDouble() {
test.assign(0);
for (int i = 0; i < test.size(); i++) {
assertEquals("value[" + i + ']', 0.0, test.getQuick(i), EPSILON);
}
}
代码示例来源:origin: apache/mahout
@Test
public void testAssignBinaryFunction2() throws Exception {
test.assign(Functions.PLUS, 4);
for (int i = 0; i < test.size(); i++) {
assertEquals("value[" + i + ']', values[i + 1] + 4, test.getQuick(i), EPSILON);
}
}
代码示例来源:origin: apache/mahout
@Test
public void testAssignBinaryFunction3() throws Exception {
test.assign(new TimesFunction(), 4);
for (int i = 0; i < test.size(); i++) {
assertEquals("value[" + i + ']', values[i + 1] * 4, test.getQuick(i), EPSILON);
}
}
代码示例来源:origin: apache/mahout
@Test
public void testAssignBinaryFunction() {
test.assign(test, Functions.PLUS);
for (int i = 0; i < values.length; i++) {
if (i % 2 == 0) {
assertEquals("get [" + i + ']', 0.0, test.get(i), EPSILON);
} else {
assertEquals("value[" + i + ']', 2 * values[i - 1], test.getQuick(i), EPSILON);
}
}
}
代码示例来源:origin: apache/mahout
@Test
public void testAssignBinaryFunction2() {
test.assign(Functions.plus(4));
for (int i = 0; i < values.length; i++) {
if (i % 2 == 0) {
assertEquals("get [" + i + ']', 4.0, test.get(i), EPSILON);
} else {
assertEquals("value[" + i + ']', values[i - 1] + 4, test.getQuick(i), EPSILON);
}
}
}
代码示例来源:origin: apache/mahout
@Test
public void testAssignBinaryFunction3() {
test.assign(Functions.mult(4));
for (int i = 0; i < values.length; i++) {
if (i % 2 == 0) {
assertEquals("get [" + i + ']', 0.0, test.get(i), EPSILON);
} else {
assertEquals("value[" + i + ']', values[i - 1] * 4, test.getQuick(i), EPSILON);
}
}
}
代码示例来源:origin: apache/mahout
@Test
public void testViewRow() {
Vector row = test.viewRow(1);
assertEquals("row size", 2, row.getNumNondefaultElements());
//create a matrix with an unassigned row 0
Matrix matrix = new SparseMatrix(1, 1);
Vector view = matrix.viewRow(0);
final double value = 1.23;
view.assign(value);
//test whether the update in the view is reflected in the matrix
assertEquals("Matrix value", view.getQuick(0), matrix.getQuick(0, 0), EPSILON);
}
代码示例来源:origin: apache/mahout
@Test
public void randomMatrix() {
Matrix a = new DenseMatrix(60, 60).assign(Functions.random());
QRDecomposition qr = new QRDecomposition(a);
// how close is Q to actually being orthornormal?
double maxIdent = qr.getQ().transpose().times(qr.getQ()).viewDiagonal().assign(Functions.plus(-1)).norm(1);
assertEquals(0, maxIdent, 1.0e-13);
// how close is Q R to the original value of A?
Matrix z = qr.getQ().times(qr.getR()).minus(a);
double maxError = z.aggregate(Functions.MIN, Functions.ABS);
assertEquals(0, maxError, 1.0e-13);
}
内容来源于网络,如有侵权,请联系作者删除!