本文整理了Java中org.apache.mahout.math.Vector.clone()
方法的一些代码示例,展示了Vector.clone()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.clone()
方法的具体详情如下:
包路径:org.apache.mahout.math.Vector
类名称:Vector
方法名:clone
[英]Return a copy of the recipient
[中]返回收件人的副本
代码示例来源:origin: apache/mahout
@SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
@Override
public Vector clone() {
DelegatingVector r;
try {
r = (DelegatingVector) super.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException("Clone not supported for DelegatingVector, shouldn't be possible");
}
// delegate points to original without this
r.delegate = delegate.clone();
return r;
}
代码示例来源:origin: apache/mahout
@Override
public Vector clone() {
VectorView r = (VectorView) super.clone();
r.vector = vector.clone();
r.offset = offset;
return r;
}
代码示例来源:origin: apache/mahout
@SuppressWarnings("CloneDoesntCallSuperClone")
@Override
public NamedVector clone() {
return new NamedVector(delegate.clone(), name);
}
代码示例来源:origin: apache/mahout
@Override
public Matrix clone() {
SparseColumnMatrix clone = (SparseColumnMatrix) super.clone();
clone.columnVectors = new Vector[columnVectors.length];
for (int i = 0; i < columnVectors.length; i++) {
clone.columnVectors[i] = columnVectors[i].clone();
}
return clone;
}
代码示例来源:origin: apache/mahout
@Override
public Matrix clone() {
SparseRowMatrix clone = (SparseRowMatrix) super.clone();
clone.rowVectors = new Vector[rowVectors.length];
for (int i = 0; i < rowVectors.length; i++) {
clone.rowVectors[i] = rowVectors[i].clone();
}
return clone;
}
代码示例来源:origin: apache/mahout
public SparseMatrix(int rows, int columns, Map<Integer, Vector> rowVectors, boolean shallow) {
// Why this is passing in a map? iterating it is pretty inefficient as opposed to simple lists...
super(rows, columns);
this.rowVectors = new Int2ObjectOpenHashMap<>();
if (shallow) {
for (Map.Entry<Integer, Vector> entry : rowVectors.entrySet()) {
this.rowVectors.put(entry.getKey().intValue(), entry.getValue());
}
} else {
for (Map.Entry<Integer, Vector> entry : rowVectors.entrySet()) {
this.rowVectors.put(entry.getKey().intValue(), entry.getValue().clone());
}
}
}
代码示例来源:origin: apache/mahout
@Override
public synchronized EigenStatus verify(VectorIterable corpus, Vector vector) {
if (!finished && !started) { // not yet started or finished, so start!
status = new EigenStatus(-1, 0);
Vector vectorCopy = vector.clone();
threadPool.execute(new VerifierRunnable(corpus, vectorCopy));
started = true;
}
if (finished) {
finished = false;
}
return status;
}
代码示例来源:origin: apache/mahout
public SparseColumnMatrix(int rows, int columns, Vector[] columnVectors, boolean shallow) {
super(rows, columns);
if (shallow) {
this.columnVectors = columnVectors;
} else {
this.columnVectors = columnVectors.clone();
for (int col = 0; col < columnSize(); col++) {
this.columnVectors[col] = this.columnVectors[col].clone();
}
}
}
代码示例来源: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
public SparseRowMatrix(int rows, int columns, Vector[] vectors, boolean shallowCopy, boolean randomAccess) {
super(rows, columns);
this.randomAccessRows = randomAccess;
this.rowVectors = vectors.clone();
for (int row = 0; row < rows; row++) {
if (vectors[row] == null) {
// TODO: this can't be right to change the argument
vectors[row] = randomAccess
? new RandomAccessSparseVector(numCols(), 10)
: new SequentialAccessSparseVector(numCols(), 10);
}
this.rowVectors[row] = shallowCopy ? vectors[row] : vectors[row].clone();
}
}
代码示例来源:origin: apache/mahout
private OpenIntObjectHashMap<Vector> asRowVectors(Matrix matrix) {
OpenIntObjectHashMap<Vector> rows = new OpenIntObjectHashMap<>();
for (int row = 0; row < matrix.numRows(); row++) {
rows.put(row, matrix.viewRow(row).clone());
}
return rows;
}
代码示例来源:origin: apache/mahout
Vector other = m.viewRow(r.nextInt(numRows));
if (other != null && other.getLengthSquared() > 0) {
m.assignRow(c, other.clone());
代码示例来源: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 testCopy() throws Exception {
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 testDot2() {
Vector test2 = test.clone();
test2.set(1, 0.0);
test2.set(3, 0.0);
assertEquals(3.3 * 3.3, test2.dot(test), EPSILON);
}
代码示例来源:origin: apache/mahout
@Override
public Matrix assign(Matrix other, DoubleDoubleFunction function) {
//TODO generalize to other kinds of functions
if (Functions.PLUS.equals(function) && other instanceof SparseMatrix) {
int rows = rowSize();
if (rows != other.rowSize()) {
throw new CardinalityException(rows, other.rowSize());
}
int columns = columnSize();
if (columns != other.columnSize()) {
throw new CardinalityException(columns, other.columnSize());
}
SparseMatrix otherSparse = (SparseMatrix) other;
for(ObjectIterator<Entry<Vector>> fastIterator = otherSparse.rowVectors.int2ObjectEntrySet().fastIterator();
fastIterator.hasNext();) {
final Entry<Vector> entry = fastIterator.next();
final int rowIndex = entry.getIntKey();
Vector row = rowVectors.get(rowIndex);
if (row == null) {
rowVectors.put(rowIndex, entry.getValue().clone());
} else {
row.assign(entry.getValue(), Functions.PLUS);
}
}
return this;
} else {
return super.assign(other, function);
}
}
代码示例来源:origin: apache/mahout
@Test
public void testIteratorSet() {
Vector clone = test.clone();
for (Element e : clone.nonZeroes()) {
e.set(e.get() * 2.0);
}
for (Element e : clone.nonZeroes()) {
assertEquals(test.get(e.index()) * 2.0, e.get(), EPSILON);
}
clone = test.clone();
for (Element e : clone.all()) {
e.set(e.get() * 2.0);
}
for (Element e : clone.all()) {
assertEquals(test.get(e.index()) * 2.0, e.get(), EPSILON);
}
}
代码示例来源:origin: apache/mahout
if (currentState.getActivationDenominatorSquared() == 0) {
pseudoEigen.assign(trainingVector, new PlusMult(1));
currentState.setHelperVector(currentState.currentTrainingProjection().clone());
double helperNorm = currentState.getHelperVector().norm(2);
currentState.setActivationDenominatorSquared(trainingVectorNorm * trainingVectorNorm - helperNorm * helperNorm);
代码示例来源:origin: apache/mahout
Vector v3 = v1.clone();
代码示例来源:origin: org.apache.mahout/mahout-core
protected AbstractCluster(Vector point, int id2) {
setNumObservations(0);
setTotalObservations(0);
setCenter(point.clone());
setRadius(center.like());
setS0(0);
setS1(center.like());
setS2(center.like());
this.id = id2;
}
内容来源于网络,如有侵权,请联系作者删除!