本文整理了Java中org.apache.mahout.math.Vector.getNumNonZeroElements()
方法的一些代码示例,展示了Vector.getNumNonZeroElements()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.getNumNonZeroElements()
方法的具体详情如下:
包路径:org.apache.mahout.math.Vector
类名称:Vector
方法名:getNumNonZeroElements
[英]Return the number of non zero elements in the vector.
[中]返回向量中非零元素的数量。
代码示例来源:origin: apache/mahout
@Override
public int getNumNonZeroElements() {
// Return the number of nonzeros in the recipient,
// so potentially don't have to go through our iterator
return vector.getNumNonZeroElements();
}
代码示例来源:origin: apache/mahout
@Override
public int getNumNonZeroElements() {
return delegate.getNumNonZeroElements();
}
}
代码示例来源:origin: apache/mahout
@Override
public int getNumNonZeroElements() {
return delegate.getNumNonZeroElements();
}
代码示例来源:origin: apache/mahout
@Override
public Matrix transpose() {
SparseRowMatrix srm = new SparseRowMatrix(columns, rows);
for (int i = 0; i < columns; i++) {
Vector col = columnVectors[i];
if (col.getNumNonZeroElements() > 0)
// this should already be optimized
srm.assignRow(i, col);
}
return srm;
}
代码示例来源:origin: apache/mahout
@Override
public Matrix transpose() {
SparseColumnMatrix scm = new SparseColumnMatrix(columns, rows);
for (int i = 0; i < rows; i++) {
Vector row = rowVectors[i];
if (row.getNumNonZeroElements() > 0) {
scm.assignColumn(i, row);
}
}
return scm;
}
代码示例来源:origin: apache/mahout
@Override
public void testSize() {
assertEquals("size", 3, getTestVector().getNumNonZeroElements());
}
代码示例来源:origin: apache/mahout
@Override
public void testSize() {
assertEquals("size", 3, getTestVector().getNumNonZeroElements());
}
代码示例来源:origin: apache/mahout
@Override
public void testSize() {
assertEquals("size", 3, getTestVector().getNumNonZeroElements());
}
代码示例来源:origin: apache/mahout
Varint.writeUnsignedVarInt(vector.getNumNonZeroElements(), out);
Iterator<Element> iter = vector.nonZeroes().iterator();
if (sequential) {
代码示例来源:origin: apache/mahout
assertEquals(8, vector.getNumNonZeroElements());
assertEquals(7, vector.getNumNonZeroElements());
assertEquals(7, vector.getNumNonZeroElements());
代码示例来源:origin: org.apache.mahout/mahout-math
@Override
public int getNumNonZeroElements() {
return delegate.getNumNonZeroElements();
}
}
代码示例来源:origin: org.apache.mahout/mahout-math
@Override
public int getNumNonZeroElements() {
// Return the number of nonzeros in the recipient,
// so potentially don't have to go through our iterator
return vector.getNumNonZeroElements();
}
代码示例来源:origin: org.apache.mahout/mahout-math
@Override
public Matrix transpose() {
SparseRowMatrix srm = new SparseRowMatrix(columns, rows);
for (int i = 0; i < columns; i++) {
Vector col = columnVectors[i];
if (col.getNumNonZeroElements() > 0)
// this should already be optimized
srm.assignRow(i, col);
}
return srm;
}
代码示例来源:origin: org.apache.mahout/mahout-math
@Override
public Matrix transpose() {
SparseColumnMatrix scm = new SparseColumnMatrix(columns, rows);
for (int i = 0; i < rows; i++) {
Vector row = rowVectors[i];
if (row.getNumNonZeroElements() > 0) {
scm.assignColumn(i, row);
}
}
return scm;
}
代码示例来源:origin: cheng-li/pyramid
public static double density(DataSet dataSet){
int nonZeros = IntStream.range(0,dataSet.getNumDataPoints()).parallel()
.map(i -> dataSet.getRow(i).getNumNonZeroElements())
.sum();
return ((double)nonZeros)/(dataSet.getNumDataPoints()*dataSet.getNumFeatures());
}
代码示例来源:origin: cheng-li/pyramid
public static int[] numOfUsedFeaturesEachClass(LogisticRegression logisticRegression){
int[] numbers = new int[logisticRegression.getNumClasses()];
for (int k=0;k<logisticRegression.getNumClasses();k++){
numbers[k] = logisticRegression.getWeights().getWeightsWithoutBiasForClass(k).getNumNonZeroElements();
}
return numbers;
}
代码示例来源:origin: org.apache.mahout/mahout-mr
@Override
public Vector normalize(Vector vector) {
if (vector.getNumNondefaultElements() == 0) {
return vector;
}
// center non-zero elements
double average = vector.norm(1) / vector.getNumNonZeroElements();
for (Vector.Element e : vector.nonZeroes()) {
e.set(e.get() - average);
}
return super.normalize(vector);
}
}
代码示例来源:origin: org.apache.mahout/mahout-mrlegacy
@Override
public Vector normalize(Vector vector) {
if (vector.getNumNondefaultElements() == 0) {
return vector;
}
// center non-zero elements
double average = vector.norm(1) / vector.getNumNonZeroElements();
for (Vector.Element e : vector.nonZeroes()) {
e.set(e.get() - average);
}
return super.normalize(vector);
}
}
代码示例来源:origin: org.apache.mahout/mahout-core
@Override
public Vector normalize(Vector vector) {
if (vector.getNumNondefaultElements() == 0) {
return vector;
}
// center non-zero elements
double average = vector.norm(1) / vector.getNumNonZeroElements();
for (Vector.Element e : vector.nonZeroes()) {
e.set(e.get() - average);
}
return super.normalize(vector);
}
}
代码示例来源:origin: org.apache.mahout/mahout-mrlegacy
@Test
public void testTraceDictionary() {
StaticWordValueEncoder encoder1 = new StaticWordValueEncoder("first");
StaticWordValueEncoder encoder2 = new StaticWordValueEncoder("second");
Map<String, Set<Integer>> traceDictionary = Maps.newHashMap();
InteractionValueEncoder interactions = new InteractionValueEncoder("interactions", encoder1, encoder2);
interactions.setProbes(1);
interactions.setTraceDictionary(traceDictionary);
Vector v = new DenseVector(10);
interactions.addInteractionToVector("a", "b", 1, v);
assertEquals(1, v.getNumNonZeroElements());
assertEquals(1, traceDictionary.size());
assertEquals("interactions=a:b", getFirst(traceDictionary.keySet(), null));
}
内容来源于网络,如有侵权,请联系作者删除!