本文整理汇总了Java中cern.colt.matrix.DoubleMatrix2D.cardinality方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix2D.cardinality方法的具体用法?Java DoubleMatrix2D.cardinality怎么用?Java DoubleMatrix2D.cardinality使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cern.colt.matrix.DoubleMatrix2D
的用法示例。
在下文中一共展示了DoubleMatrix2D.cardinality方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkIncestConditionParents
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public static SparseDoubleMatrix2D checkIncestConditionParents( DoubleMatrix2D signatureNodeIncestVector,
DoubleMatrix2D functionNodeIncestVector,
SparseDoubleMatrix2D signatureAdjacencyMatrix,
SparseDoubleMatrix2D functionAdjacencyMatrix,
int[] signatureDepths,
int[] functionDepths,
int depth,
SparseDoubleMatrix2D candidateList) {
SparseDoubleMatrix2D signatureSelector = new SparseDoubleMatrix2D(1, signatureDepths.length);
SparseDoubleMatrix2D functionSelector = new SparseDoubleMatrix2D(1, functionDepths.length);
for(int i=0; i<signatureNodeIncestVector.size(); ++i) {
if(signatureNodeIncestVector.get(0, i) == 0.0)
continue;
signatureSelector.assign(0.0);
signatureSelector.set(0, i, 1.0);
DoubleMatrix2D signatureNodeParentVector = Algebra.DEFAULT.mult(signatureSelector, Algebra.DEFAULT.transpose(signatureAdjacencyMatrix));
// only bipartite match on incest parents
for(int iParent = 0; iParent < signatureNodeParentVector.columns(); ++iParent) {
if(signatureNodeParentVector.get(0, iParent) > 0 && signatureDepths[iParent] != depth) {
signatureNodeParentVector.set(0, iParent, 0.0);
}
}
int signatureIncestParentCount = signatureNodeParentVector.cardinality();
for(int j=0; j<functionNodeIncestVector.size(); ++j) {
if(candidateList.get(i, j) == 0.0)
continue;
functionSelector.assign(0.0);
functionSelector.set(0, j, 1.0);
DoubleMatrix2D functionNodeParentVector = Algebra.DEFAULT.mult(functionSelector, Algebra.DEFAULT.transpose(functionAdjacencyMatrix));
// only bipartite match on incest parents
for(int iParent = 0; iParent < functionNodeParentVector.columns(); ++iParent) {
if(functionNodeParentVector.get(0, iParent) > 0 && functionDepths[iParent] != depth) {
functionNodeParentVector.set(0, iParent, 0.0);
}
}
int functionIncestParentCount = functionNodeParentVector.cardinality();
// bipartite matching, if !sufficient
if( candidateList.get(i, j) > 0 && (signatureIncestParentCount > functionIncestParentCount ||
!bipartiteMatchingVector(candidateList, signatureNodeParentVector, functionNodeParentVector, signatureDepths, functionDepths))) {
// remove candidacy
candidateList.set(i, j, 0.0);
}
}
}
return candidateList;
}
示例2: checkPreviouslyVisitedChildren
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public static SparseDoubleMatrix2D checkPreviouslyVisitedChildren( IntArrayList signatureNonZeros,
IntArrayList functionNonZeros,
SparseDoubleMatrix2D signatureAdjacencyMatrix,
SparseDoubleMatrix2D functionAdjacencyMatrix,
int[] signatureDepths,
int[] functionDepths,
SparseDoubleMatrix2D candidateList) {
SparseDoubleMatrix2D signatureSelector = new SparseDoubleMatrix2D(1, signatureDepths.length);
SparseDoubleMatrix2D functionSelector = new SparseDoubleMatrix2D(1, functionDepths.length);
// reduce candidacy based on previously visited children
for(int i=0; i<signatureNonZeros.size(); ++i) {
// for node N, this sets the Nth bit of the vector to 1.0
signatureSelector.assign(0.0);
signatureSelector.set(0, signatureNonZeros.get(i), 1.0);
// get children at depth <= current
DoubleMatrix2D signatureNodeChildVector = Algebra.DEFAULT.mult(signatureSelector, signatureAdjacencyMatrix);
// remove signature node's unvisited children
for(int iChild = 0; iChild < signatureNodeChildVector.columns(); ++iChild) {
if(signatureNodeChildVector.get(0, iChild) > 0 && signatureDepths[iChild] == -1) { // for the oposite conditional && signatureDepths[iChild] <= depth) {
signatureNodeChildVector.set(0, iChild, 0.0);
}
}
int signatureVisitedChildCount = signatureNodeChildVector.cardinality();
for(int j=0; j<functionNonZeros.size(); ++j) {
functionSelector.assign(0.0);
functionSelector.set(0, functionNonZeros.get(j), 1.0);
// get children at depth <= current
DoubleMatrix2D functionNodeChildVector = Algebra.DEFAULT.mult(functionSelector, functionAdjacencyMatrix);
// remove function node's unvisited children
for(int iChild = 0; iChild < functionNodeChildVector.columns(); ++iChild) {
if(functionNodeChildVector.get(0, iChild) > 0 && functionDepths[iChild] == -1) { // for the oposite conditional && functionDepths[iChild] <= depth) {
functionNodeChildVector.set(0, iChild, 0.0);
}
}
int functionVisitedChildCount = functionNodeChildVector.cardinality();
// bipartite matching, if !sufficient
if( candidateList.get(signatureNonZeros.get(i), functionNonZeros.get(j)) > 0 &&
(signatureVisitedChildCount > functionVisitedChildCount ||
!bipartiteMatchingVector(candidateList, signatureNodeChildVector, functionNodeChildVector, signatureDepths, functionDepths))) {
// remove candidacy
candidateList.set(signatureNonZeros.get(i), functionNonZeros.get(j), 0.0);
}
}
}
return candidateList;
}
示例3: normalize
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public void normalize() {
// System.out.println(adjacencyMatrix);
int adjacencyMatrixSize = adjacencyMatrix.columns();
if(adjacencyMatrixSize < 1)
return;
DoubleMatrix2D selector = new SparseDoubleMatrix2D(1, adjacencyMatrixSize);
selector.set(0, 0, 1.0);
// System.out.println(selector);
// get vertices reachable from V0
int cardinality = selector.cardinality();
int lastCardinality = 0;
DoubleDoubleFunction merge = new DoubleDoubleFunction() {
public double apply(double a, double b) {
return (a > 0 || b > 0) ? 1 : 0;
}
};
while(cardinality != lastCardinality) {
lastCardinality = cardinality;
// selector = Algebra.DEFAULT.mult(selector, adjacencyMatrix);
selector.assign(Algebra.DEFAULT.mult(selector, adjacencyMatrix), merge);
// System.out.println(selector);
cardinality = selector.cardinality();
}
// System.out.println(selector);
if(cardinality == adjacencyMatrixSize) {
return;
}
// IntArrayList nonZeros = new IntArrayList();
// IntArrayList unusedInt = new IntArrayList();
// DoubleArrayList unusedDouble = new DoubleArrayList();
// selector.getNonZeros(unusedInt, nonZeros, unusedDouble);
// SparseDoubleMatrix2D reduced = new SparseDoubleMatrix2D(adjacencyMatrix.viewSelection(nonZeros.elements(), nonZeros.elements()).toArray());
SparseDoubleMatrix2D reduced = new SparseDoubleMatrix2D(cardinality, cardinality);
int iCurrentVertex = 0;
for(int i=0; i<adjacencyMatrixSize; ++i) {
if(selector.get(0, i) != 0.0) {
int jCurrentVertex = 0;
for(int j=0; j<adjacencyMatrixSize; ++j) {
if(selector.get(0, j) != 0.0){
reduced.set(iCurrentVertex, jCurrentVertex, adjacencyMatrix.get(i, j));
++jCurrentVertex;
}
}
++iCurrentVertex;
}
}
// System.out.println(reduced);
// System.out.println("=======");
adjacencyMatrix = reduced;
vertexCount = adjacencyMatrix.columns();
edgeCount = adjacencyMatrix.cardinality();
}
示例4: normalize
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public void normalize() {
// System.out.println(adjacencyMatrix);
int adjacencyMatrixSize = adjacencyMatrix.columns();
if(adjacencyMatrixSize < 1)
return;
DoubleMatrix2D selector = new SparseDoubleMatrix2D(1, adjacencyMatrixSize);
selector.set(0, 0, 1.0);
// System.out.println(selector);
// get vertices reachable from V0
int cardinality = selector.cardinality();
int lastCardinality = 0;
DoubleDoubleFunction merge = new DoubleDoubleFunction() {
public double apply(double a, double b) {
return (a > 0 || b > 0) ? 1 : 0;
}
};
while(cardinality != lastCardinality) {
lastCardinality = cardinality;
// selector = Algebra.DEFAULT.mult(selector, adjacencyMatrix);
selector.assign(Algebra.DEFAULT.mult(selector, adjacencyMatrix), merge);
// System.out.println(selector);
cardinality = selector.cardinality();
}
// System.out.println(selector);
if(cardinality == adjacencyMatrixSize) {
return;
}
// IntArrayList nonZeros = new IntArrayList();
// IntArrayList unusedInt = new IntArrayList();
// DoubleArrayList unusedDouble = new DoubleArrayList();
// selector.getNonZeros(unusedInt, nonZeros, unusedDouble);
// SparseDoubleMatrix2D reduced = new SparseDoubleMatrix2D(adjacencyMatrix.viewSelection(nonZeros.elements(), nonZeros.elements()).toArray());
SparseDoubleMatrix2D reduced = new SparseDoubleMatrix2D(cardinality, cardinality);
int iCurrentVertex = 0;
for(int i=0; i<adjacencyMatrixSize; ++i) {
if(selector.get(0, i) != 0.0) {
int jCurrentVertex = 0;
for(int j=0; j<adjacencyMatrixSize; ++j) {
if(selector.get(0, j) != 0.0){
reduced.set(iCurrentVertex, jCurrentVertex, adjacencyMatrix.get(i, j));
++jCurrentVertex;
}
}
++iCurrentVertex;
}
}
// System.out.println(reduced);
// System.out.println("=======");
adjacencyMatrix = reduced;
vertexCount = adjacencyMatrix.columns();
edgeCount = adjacencyMatrix.cardinality();
}
示例5: density
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
* Returns the matrix's fraction of non-zero cells; <tt>A.cardinality() / A.size()</tt>.
*/
public double density(DoubleMatrix2D A) {
return A.cardinality() / (double) A.size();
}