本文整理了Java中org.apache.mahout.math.Vector.iterator()
方法的一些代码示例,展示了Vector.iterator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.iterator()
方法的具体详情如下:
包路径:org.apache.mahout.math.Vector
类名称:Vector
方法名:iterator
[英]Iterates over all elements
代码示例来源:origin: cloudera/mahout
private AllIterator() {
it = vector.iterator();
}
代码示例来源:origin: cloudera/mahout
@Override
public Iterator<Element> iterator() {
return delegate.iterator();
}
代码示例来源:origin: cloudera/mahout
public Iterator<Element> iterator() {
return new AbstractIterator<Element>() {
private final Iterator<Element> i = vector.iterator();
代码示例来源:origin: org.apache.mahout/mahout-utils
public static void vectorToCSVString(Vector vector,
boolean namesAsComments,
Appendable bldr) throws IOException {
if (namesAsComments && vector instanceof NamedVector){
bldr.append('#').append(((NamedVector) vector).getName()).append('\n');
}
Iterator<Vector.Element> iter = vector.iterator();
boolean first = true;
while (iter.hasNext()) {
if (first) {
first = false;
} else {
bldr.append(',');
}
Vector.Element elt = iter.next();
bldr.append(String.valueOf(elt.get()));
}
bldr.append('\n');
}
代码示例来源:origin: cloudera/mahout
private static void doTestIterators(Vector vector, Collection<Integer> expectedIndices) {
expectedIndices = new HashSet<Integer>(expectedIndices);
Iterator<Vector.Element> allIterator = vector.iterator();
int index = 0;
while (allIterator.hasNext()) {
Vector.Element element = allIterator.next();
assertEquals(index, element.index());
if (expectedIndices.contains(index)) {
assertEquals((double) index * 2, element.get(), EPSILON);
} else {
assertEquals(0.0, element.get(), EPSILON);
}
index++;
}
Iterator<Vector.Element> nonZeroIterator = vector.iterateNonZero();
while (nonZeroIterator.hasNext()) {
Vector.Element element = nonZeroIterator.next();
index = element.index();
assertTrue(expectedIndices.contains(index));
assertEquals((double) index * 2, element.get(), EPSILON);
expectedIndices.remove(index);
}
assertTrue(expectedIndices.isEmpty());
}
代码示例来源:origin: cloudera/mahout
@Test
public void testIteratorSet() {
Vector clone = test.clone();
Iterator<Vector.Element> it = clone.iterateNonZero();
while (it.hasNext()) {
Vector.Element e = it.next();
e.set(e.get() * 2.0);
}
it = clone.iterateNonZero();
while (it.hasNext()) {
Vector.Element e = it.next();
assertEquals(test.get(e.index()) * 2.0, e.get(), EPSILON);
}
clone = test.clone();
it = clone.iterator();
while (it.hasNext()) {
Vector.Element e = it.next();
e.set(e.get() * 2.0);
}
it = clone.iterator();
while (it.hasNext()) {
Vector.Element e = it.next();
assertEquals(test.get(e.index()) * 2.0, e.get(), EPSILON);
}
}
代码示例来源:origin: cloudera/mahout
@Test
public void testIterator() {
Iterator<Vector.Element> iterator = test.iterateNonZero();
checkIterator(iterator, gold);
iterator = test.iterator();
checkIterator(iterator, gold);
double[] doubles = {0.0, 5.0, 0, 3.0};
RandomAccessSparseVector zeros = new RandomAccessSparseVector(doubles.length);
for (int i = 0; i < doubles.length; i++) {
zeros.setQuick(i, doubles[i]);
}
iterator = zeros.iterateNonZero();
checkIterator(iterator, doubles);
iterator = zeros.iterator();
checkIterator(iterator, doubles);
doubles = new double[]{0.0, 0.0, 0, 0.0};
zeros = new RandomAccessSparseVector(doubles.length);
for (int i = 0; i < doubles.length; i++) {
zeros.setQuick(i, doubles[i]);
}
iterator = zeros.iterateNonZero();
checkIterator(iterator, doubles);
iterator = zeros.iterator();
checkIterator(iterator, doubles);
}
代码示例来源:origin: cloudera/mahout
assertEquals("mutation via setQuick() fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON);
Iterator<Vector.Element> it = v.iterator();
while (it.hasNext()) {
Vector.Element e = it.next();
内容来源于网络,如有侵权,请联系作者删除!