本文整理了Java中org.apache.mahout.math.Vector.normalize()
方法的一些代码示例,展示了Vector.normalize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.normalize()
方法的具体详情如下:
包路径:org.apache.mahout.math.Vector
类名称:Vector
方法名:normalize
[英]Return a new vector containing the normalized (L_2 norm) values of the recipient
[中]返回一个新向量,其中包含收件人的标准化(L_2 norm)值
代码示例来源:origin: apache/mahout
@Override
public Vector normalize() {
return delegate.normalize();
}
代码示例来源:origin: apache/mahout
@Override
public Vector normalize(double power) {
return delegate.normalize(power);
}
代码示例来源:origin: apache/mahout
@Override
public Vector normalize() {
return delegate.normalize();
}
代码示例来源:origin: apache/mahout
@Override
public Vector normalize(double power) {
return delegate.normalize(power);
}
代码示例来源:origin: apache/mahout
@Test
public void testNormalize() throws Exception {
Vector res = test.normalize();
double mag = Math.sqrt(1.1 * 1.1 + 2.2 * 2.2 + 3.3 * 3.3);
for (int i = 0; i < test.size(); i++) {
assertEquals("dot", values[OFFSET + i] / mag, res.get(i), EPSILON);
}
}
代码示例来源:origin: apache/mahout
@Test
public void testNormalize() {
Vector val = test.normalize();
double mag = Math.sqrt(1.1 * 1.1 + 2.2 * 2.2 + 3.3 * 3.3);
for (int i = 0; i < test.size(); i++) {
if (i % 2 == 0) {
assertEquals("get [" + i + ']', 0.0, val.get(i), EPSILON);
} else {
assertEquals("dot", values[i/2] / mag, val.get(i), EPSILON);
}
}
}
代码示例来源:origin: apache/mahout
vec1.setQuick(1, 2);
vec1.setQuick(2, 3);
Vector norm = vec1.normalize();
assertNotNull("norm1 is null and it shouldn't be", norm);
vec2.setQuick(1, 2);
vec2.setQuick(2, 3);
Vector norm2 = vec2.normalize();
assertNotNull("norm1 is null and it shouldn't be", norm2);
norm = vec1.normalize(2);
assertEquals(expected, norm);
norm2 = vec2.normalize(2);
assertEquals(expected, norm2);
norm = vec1.normalize(1);
norm2 = vec2.normalize(1);
expected.setQuick(0, 1.0 / 6);
expected.setQuick(1, 2.0 / 6);
assertEquals(expected, norm);
assertEquals(expected, norm2);
norm = vec1.normalize(3);
norm = vec1.normalize(Double.POSITIVE_INFINITY);
norm2 = vec2.normalize(Double.POSITIVE_INFINITY);
norm = vec1.normalize(0);
代码示例来源:origin: apache/mahout
assert realEigen != null;
realEigen = realEigen.normalize();
state.setRightSingularVector(row, realEigen);
double e = eigenVals.get(row) * state.getScaleFactor();
代码示例来源:origin: apache/mahout
@Test
public void testProjection() {
Vector v1 = new DenseVector(10).assign(Functions.random());
WeightedVector v2 = new WeightedVector(v1, v1, 31);
assertEquals(v1.dot(v1), v2.getWeight(), 1.0e-13);
assertEquals(31, v2.getIndex());
Matrix y = new DenseMatrix(10, 4).assign(Functions.random());
Matrix q = new QRDecomposition(y.viewPart(0, 10, 0, 3)).getQ();
Vector nullSpace = y.viewColumn(3).minus(q.times(q.transpose().times(y.viewColumn(3))));
WeightedVector v3 = new WeightedVector(q.viewColumn(0).plus(q.viewColumn(1)), nullSpace, 1);
assertEquals(0, v3.getWeight(), 1.0e-13);
Vector qx = q.viewColumn(0).plus(q.viewColumn(1)).normalize();
WeightedVector v4 = new WeightedVector(qx, q.viewColumn(0), 2);
assertEquals(Math.sqrt(0.5), v4.getWeight(), 1.0e-13);
WeightedVector v5 = WeightedVector.project(q.viewColumn(0), qx);
assertEquals(Math.sqrt(0.5), v5.getWeight(), 1.0e-13);
}
代码示例来源:origin: org.apache.mahout/mahout-math
@Override
public Vector normalize(double power) {
return delegate.normalize(power);
}
代码示例来源:origin: apache/mahout
assertEquals(dv1.maxValueIndex(), v1.maxValueIndex());
Vector nv1 = v1.normalize();
assertEquals(0, dv1.normalize().getDistanceSquared(nv1), FUZZ);
nv1 = v1.normalize(1);
assertEquals(0, dv1.getDistanceSquared(v1), FUZZ);
assertEquals(1, nv1.norm(1), FUZZ);
assertEquals(0, dv1.normalize(1).getDistanceSquared(nv1), FUZZ);
代码示例来源:origin: apache/mahout
assertEquals("mutation via v.getElement().set() fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON);
v.normalize();
expected = lengthSquaredSlowly(v);
assertEquals("mutation via normalize() fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON);
v.normalize(1.0);
expected = lengthSquaredSlowly(v);
assertEquals("mutation via normalize(double) fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON);
代码示例来源:origin: org.apache.mahout/mahout-mrlegacy
@Override
protected void map(IntWritable row, VectorWritable vector, Context context)
throws IOException, InterruptedException {
context.write(row, new VectorWritable(vector.get().normalize(2)));
}
代码示例来源:origin: org.apache.mahout/mahout-mr
@Override
protected void map(IntWritable row, VectorWritable vector, Context context)
throws IOException, InterruptedException {
context.write(row, new VectorWritable(vector.get().normalize(2)));
}
代码示例来源:origin: org.apache.mahout/mahout-core
@Override
protected void map(IntWritable row, VectorWritable vector, Context context)
throws IOException, InterruptedException {
context.write(row, new VectorWritable(vector.get().normalize(2)));
}
代码示例来源:origin: org.apache.mahout/mahout-mrlegacy
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
for (int x = 0; x < numTopics; x++) {
String v = dictionary != null
? vectorToSortedString(topicTermCounts.viewRow(x).normalize(1), dictionary)
: topicTermCounts.viewRow(x).asFormatString();
buf.append(v).append('\n');
}
return buf.toString();
}
代码示例来源:origin: org.apache.mahout/mahout-mr
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
for (int x = 0; x < numTopics; x++) {
String v = dictionary != null
? vectorToSortedString(topicTermCounts.viewRow(x).normalize(1), dictionary)
: topicTermCounts.viewRow(x).asFormatString();
buf.append(v).append('\n');
}
return buf.toString();
}
代码示例来源:origin: org.apache.mahout/mahout-core
public void renormalize() {
for (int x = 0; x < numTopics; x++) {
topicTermCounts.assignRow(x, topicTermCounts.viewRow(x).normalize(1));
topicSums.assign(1.0);
}
}
代码示例来源:origin: org.apache.mahout/mahout-mr
public void renormalize() {
for (int x = 0; x < numTopics; x++) {
topicTermCounts.assignRow(x, topicTermCounts.viewRow(x).normalize(1));
topicSums.assign(1.0);
}
}
代码示例来源:origin: cloudera/mahout
@Test
public void testNormalize() {
Vector val = test.normalize();
double mag = Math.sqrt(1.1 * 1.1 + 2.2 * 2.2 + 3.3 * 3.3);
for (int i = 0; i < test.size(); i++) {
if (i % 2 == 0) {
assertEquals("get [" + i + ']', 0.0, val.get(i), EPSILON);
} else {
assertEquals("dot", values[i/2] / mag, val.get(i), EPSILON);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!