本文整理汇总了Java中cern.colt.matrix.impl.SparseDoubleMatrix2D.set方法的典型用法代码示例。如果您正苦于以下问题:Java SparseDoubleMatrix2D.set方法的具体用法?Java SparseDoubleMatrix2D.set怎么用?Java SparseDoubleMatrix2D.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cern.colt.matrix.impl.SparseDoubleMatrix2D
的用法示例。
在下文中一共展示了SparseDoubleMatrix2D.set方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: graphToSparseMatrix
import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入方法依赖的package包/类
/**
* Returns a SparseDoubleMatrix2D whose entries represent the edge weights for the
* edges in <code>g</code>, as specified by <code>nev</code>.
*
* <p>The <code>(i,j)</code> entry of the matrix returned will be equal to the sum
* of the weights of the edges connecting the vertex with index <code>i</code> to
* <code>j</code>.
*
* <p>If <code>nev</code> is <code>null</code>, then a constant edge weight of 1 is used.
*
* @param g
* @param nev
*/
public static <V,E> SparseDoubleMatrix2D graphToSparseMatrix(Graph<V,E> g, Map<E,Number> nev)
{
if (nev == null)
nev = new ConstantMap<E,Number>(1);
int numVertices = g.getVertexCount();
SparseDoubleMatrix2D matrix = new SparseDoubleMatrix2D(numVertices,
numVertices);
BidiMap<V,Integer> indexer = Indexer.<V>create(g.getVertices());
int i=0;
for(V v : g.getVertices())
{
for (E e : g.getOutEdges(v))
{
V w = g.getOpposite(v,e);
int j = indexer.get(w);
matrix.set(i, j, matrix.getQuick(i,j) + nev.get(e).doubleValue());
}
i++;
}
return matrix;
}
示例2: graphToSparseMatrix
import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入方法依赖的package包/类
/**
* Returns a SparseDoubleMatrix2D whose entries represent the edge weights for the
* edges in <code>g</code>, as specified by <code>nev</code>.
*
* <p>The <code>(i,j)</code> entry of the matrix returned will be equal to the sum
* of the weights of the edges connecting the vertex with index <code>i</code> to
* <code>j</code>.
*
* <p>If <code>nev</code> is <code>null</code>, then a constant edge weight of 1 is used.
*
* @param g
* @param nev
*/
public static SparseDoubleMatrix2D graphToSparseMatrix(Graph g, NumberEdgeValue nev)
{
if (nev == null)
nev = new ConstantEdgeValue(1);
int numVertices = g.getVertices().size();
SparseDoubleMatrix2D matrix = new SparseDoubleMatrix2D(numVertices,
numVertices);
Indexer id = Indexer.getIndexer(g);
for (int i = 0; i < numVertices; i++)
{
Vertex v = (Vertex)id.getVertex(i);
for (Iterator o_iter = v.getOutEdges().iterator(); o_iter.hasNext(); )
{
Edge e = (Edge)o_iter.next();
Vertex w = e.getOpposite(v);
int j = id.getIndex(w);
matrix.set(i, j, matrix.getQuick(i,j) + nev.getNumber(e).doubleValue());
}
}
return matrix;
}
示例3: load
import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入方法依赖的package包/类
private void load(File similarities, File preferences, int base) throws IOException {
// Load preferences
List<Double> prefs = loadPreferences(preferences);
this.n = prefs.size();
// Similarity matrix
s = new SparseDoubleMatrix2D(n, n);
int c = 0;
for (Double p: prefs) {
s.set(c, c, p);
c++;
}
// Load similarities
int simCount = 0;
String line;
BufferedReader reader = new BufferedReader(new FileReader(similarities));
while ((line = reader.readLine()) != null) {
List<String> tokens = getTokens(line, delimiters);
int i = Integer.parseInt(tokens.get(0)) - base;
int j = Integer.parseInt(tokens.get(1)) - base;
Double v = Double.parseDouble(tokens.get(2));
s.set(i, j, v);
simCount++;
}
reader.close();
double full = 100d * (simCount + n) / (n * n);
Logger.info("[Loader] Loaded %d similarities, matrix is %f%% populated", simCount, full);
}
示例4: checkIncestConditionParents
import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入方法依赖的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;
}
示例5: checkPreviouslyVisitedChildren
import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入方法依赖的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;
}
示例6: reduceCandidateList
import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入方法依赖的package包/类
public static SparseDoubleMatrix2D reduceCandidateList(IntArrayList signatureNonZeros, IntArrayList functionNonZeros, SparseDoubleMatrix2D candidateList) {
// reduce
for(int i=0; i<signatureNonZeros.size(); ++i) {
// find nodes with only one possible candidate
if(candidateList.viewRow(signatureNonZeros.get(i)).cardinality() == 1) {
int nonZero = -1;
for(int j=0; j<functionNonZeros.size(); ++j) {
if(candidateList.get(signatureNonZeros.get(i), functionNonZeros.get(j)) != 0.0) {
nonZero = functionNonZeros.get(j);
break;
}
}
if(nonZero == -1){
System.out.println("REDUCE LOOP IS BROKEN - J NOT FOUND");
System.out.println(signatureNonZeros);
System.out.println(functionNonZeros);
System.out.println(candidateList);
System.out.println();
break;
}
// remove candidacy of other nodes since it /has/ to be that one node
for(int x=0; x<signatureNonZeros.size(); ++x) {
if(x != i) {
candidateList.set(signatureNonZeros.get(x), nonZero, 0.0);
}
}
}
}
return candidateList;
}
示例7: normalize
import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入方法依赖的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();
}
示例8: normalize
import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入方法依赖的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();
}
示例9: createVertexDegreeDiagonalMatrix
import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入方法依赖的package包/类
/**
* Returns a diagonal matrix whose diagonal entries contain the degree for
* the corresponding node.
*
* <p>NOTE: the vertices will be traversed in the order given by the graph's vertex
* collection. If you want to be assured of a particular ordering, use a graph
* implementation that guarantees such an ordering (see the implementations with {@code Ordered}
* or {@code Sorted} in their name).
*
* @return SparseDoubleMatrix2D
*/
public static <V,E> SparseDoubleMatrix2D createVertexDegreeDiagonalMatrix(Graph<V,E> graph)
{
int numVertices = graph.getVertexCount();
SparseDoubleMatrix2D matrix = new SparseDoubleMatrix2D(numVertices,
numVertices);
int i = 0;
for (V v : graph.getVertices())
{
matrix.set(i, i, graph.degree(v));
i++;
}
return matrix;
}
示例10: createVertexDegreeDiagonalMatrix
import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入方法依赖的package包/类
/**
* Returns a diagonal matrix whose diagonal entries contain the degree for
* the corresponding node.
*
* @return SparseDoubleMatrix2D
*/
public static SparseDoubleMatrix2D createVertexDegreeDiagonalMatrix(Graph G)
{
int numVertices = G.getVertices().size();
SparseDoubleMatrix2D matrix = new SparseDoubleMatrix2D(numVertices,
numVertices);
Indexer id = Indexer.getIndexer(G);
for (Iterator v_iter = G.getVertices().iterator(); v_iter.hasNext();)
{
Vertex v = (Vertex) v_iter.next();
matrix.set(id.getIndex(v), id.getIndex(v), v.degree());
}
return matrix;
}
示例11: scanMethodSubgraph
import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入方法依赖的package包/类
public static boolean scanMethodSubgraph(SparseDoubleMatrix2D signatureAdjacencyMatrix, SparseDoubleMatrix2D functionAdjacencyMatrix){
// System.out.println("DEPTH: " + 0);
// System.out.println(signatureAdjacencyMatrix);
// System.out.println(functionAdjacencyMatrix);
int signatureNodeCount = signatureAdjacencyMatrix.rows();
int functionNodeCount = functionAdjacencyMatrix.rows();
SparseDoubleMatrix2D candidateList = new SparseDoubleMatrix2D(signatureNodeCount, functionNodeCount);
int[] signatureDepths = new int[signatureNodeCount];
int[] functionDepths = new int[functionNodeCount];
for(int functionEntry=0; functionEntry<functionNodeCount; ++functionEntry) {
// arrays for tracking depths
// function finds all nodes with no branches to them
// first node (entry point) is always set at depth 0
// System.out.println(functionEntry);
candidateList.assign(0);
Arrays.fill(signatureDepths, -1);
Arrays.fill(functionDepths, -1);
signatureDepths[0] = 0;
functionDepths[functionEntry] = 0;
// all nodes at depth 0 go into this vector
SparseDoubleMatrix2D signatureVector = new SparseDoubleMatrix2D(1, signatureNodeCount);
SparseDoubleMatrix2D functionVector = new SparseDoubleMatrix2D(1, functionNodeCount);
// First node should be always be an entry point
signatureVector.set(0, 0, 1.0);
functionVector.set(0, functionEntry, 1.0);
// get total children at depth 0+1
// check function has sufficient nodes to satisfy sig at this depth
// System.out.println("\t" + Algebra.DEFAULT.mult(signatureVector, signatureAdjacencyMatrix).cardinality());
// System.out.println("\t" + Algebra.DEFAULT.mult(functionVector, functionAdjacencyMatrix).cardinality());
if(Algebra.DEFAULT.mult(signatureVector, signatureAdjacencyMatrix).cardinality() >
Algebra.DEFAULT.mult(functionVector, functionAdjacencyMatrix).cardinality()) {
// System.out.println("Insufficient function basic blocks at depth 1 to satisfy signature!");
continue;
}
// build candidate list
candidateList.set(0, functionEntry, 1.0);
// check bipartite match
if(!bipartiteMatchingDepth(candidateList, signatureDepths, functionDepths, 0)) {
// System.out.println("BIPARTITE MATCHING FAILED!");
continue;
}
// check children recursively
if(bfsCompare(candidateList, signatureAdjacencyMatrix, functionAdjacencyMatrix, signatureDepths, functionDepths, 1)) {
return true;
}
// System.out.println();
}
return false;
}