@Override public Vector normalize() { return delegate.normalize(); }
@Override public Vector normalize(double power) { return delegate.normalize(power); }
@Override public Vector normalize() { return delegate.normalize(); }
@Override public Vector normalize(double power) { return delegate.normalize(power); }
@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); } }
@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); } } }
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);
assert realEigen != null; realEigen = realEigen.normalize(); state.setRightSingularVector(row, realEigen); double e = eigenVals.get(row) * state.getScaleFactor();
@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); }
@Override public Vector normalize(double power) { return delegate.normalize(power); }
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);
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);
@Override protected void map(IntWritable row, VectorWritable vector, Context context) throws IOException, InterruptedException { context.write(row, new VectorWritable(vector.get().normalize(2))); }
@Override protected void map(IntWritable row, VectorWritable vector, Context context) throws IOException, InterruptedException { context.write(row, new VectorWritable(vector.get().normalize(2))); }
@Override protected void map(IntWritable row, VectorWritable vector, Context context) throws IOException, InterruptedException { context.write(row, new VectorWritable(vector.get().normalize(2))); }
@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(); }
@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(); }
public void renormalize() { for (int x = 0; x < numTopics; x++) { topicTermCounts.assignRow(x, topicTermCounts.viewRow(x).normalize(1)); topicSums.assign(1.0); } }
public void renormalize() { for (int x = 0; x < numTopics; x++) { topicTermCounts.assignRow(x, topicTermCounts.viewRow(x).normalize(1)); topicSums.assign(1.0); } }
@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); } } }