当前位置: 首页>>代码示例>>Java>>正文


Java SparseDoubleMatrix2D类代码示例

本文整理汇总了Java中cern.colt.matrix.impl.SparseDoubleMatrix2D的典型用法代码示例。如果您正苦于以下问题:Java SparseDoubleMatrix2D类的具体用法?Java SparseDoubleMatrix2D怎么用?Java SparseDoubleMatrix2D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SparseDoubleMatrix2D类属于cern.colt.matrix.impl包,在下文中一共展示了SparseDoubleMatrix2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入依赖的package包/类
public void init()
{
	System.out.println("load matrix");

	load_metapath(metaPaths.get(0));
	if (doc_num == 0) {
		System.exit(0);
	}
	doc_path = new SparseDoubleMatrix2D(doc_num, metaPaths.size());

	for (int i = 0; i < metaPaths.size(); i++)
	{
		if (i % 20 == 0)
			System.err.println("has loaded " + i + " matrix");
		double[] hasInstance = load_metapath(metaPaths.get(i));
		for (int j = 0; j < doc_num; j ++)
			if (hasInstance[j] > 0.01)
				doc_path.setQuick(j, i, hasInstance[j]);
	}
}
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:21,代码来源:calcMI.java

示例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 <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;
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:37,代码来源:GraphMatrixOperations.java

示例3: computeVoltagePotentialMatrix

import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入依赖的package包/类
/**
 * The idea here is based on the metaphor of an electric circuit. We assume
 * that an undirected graph represents the structure of an electrical
 * circuit where each edge has unit resistance. One unit of current is
 * injected into any arbitrary vertex s and one unit of current is extracted
 * from any arbitrary vertex t. The voltage at some vertex i for source
 * vertex s and target vertex t can then be measured according to the
 * equation: V_i^(s,t) = T_is - T-it where T is the voltage potential matrix
 * returned by this method. *
 * 
 * @param graph
 *            an undirected graph representing an electrical circuit
 * @return the voltage potential matrix
 * @see "P. Doyle and J. Snell, 'Random walks and electric networks,', 1989"
 * @see "M. Newman, 'A measure of betweenness centrality based on random walks', pp. 5-7, 2003"
 */
public static <V,E> DoubleMatrix2D computeVoltagePotentialMatrix(
        UndirectedGraph<V,E> graph)
{
    int numVertices = graph.getVertexCount();
    //create adjacency matrix from graph
    DoubleMatrix2D A = GraphMatrixOperations.graphToSparseMatrix(graph,
            null);
    //create diagonal matrix of vertex degrees
    DoubleMatrix2D D = GraphMatrixOperations
            .createVertexDegreeDiagonalMatrix(graph);
    DoubleMatrix2D temp = new SparseDoubleMatrix2D(numVertices - 1,
            numVertices - 1);
    //compute D - A except for last row and column
    for (int i = 0; i < numVertices - 1; i++)
    {
        for (int j = 0; j < numVertices - 1; j++)
        {
            temp.set(i, j, D.get(i, j) - A.get(i, j));
        }
    }
    Algebra algebra = new Algebra();
    DoubleMatrix2D tempInverse = algebra.inverse(temp);
    DoubleMatrix2D T = new SparseDoubleMatrix2D(numVertices, numVertices);
    //compute "voltage" matrix
    for (int i = 0; i < numVertices - 1; i++)
    {
        for (int j = 0; j < numVertices - 1; j++)
        {
            T.set(i, j, tempInverse.get(i, j));
        }
    }
    return T;
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:50,代码来源:GraphMatrixOperations.java

示例4: testUpdateScoreInMatrix_forFirstTime

import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入依赖的package包/类
@Test
public void testUpdateScoreInMatrix_forFirstTime() throws Exception {
    SparseDoubleMatrix2D matrix2D = new SparseDoubleMatrix2D(100, 100);
    List<Integer> members = Arrays.asList(4, 8, 19, 5, 27);
    int recordId = 19;
    Block block = PowerMockito.mock(Block.class);
    PowerMockito.when(block.getMembers()).thenReturn(members);
    PowerMockito.when(block.getMemberScore(Mockito.eq(recordId))).thenReturn((float) 888);
    PowerMockito.when(block.getMemberProbability(Mockito.eq(recordId))).thenReturn((float) 0.456);

    Whitebox.invokeMethod(classUnderTest, "updateScoreInMatrix", matrix2D, recordId, block, CellType.PROBABILITY);

    for (Integer member : members) {
        if (recordId != member) {
            int rawIndex = Whitebox.invokeMethod(classUnderTest, "getMatrixPosFromRecordID", recordId);
            int colIndex = Whitebox.invokeMethod(classUnderTest, "getMatrixPosFromRecordID", member);
            MatcherAssert.assertThat(matrix2D.getQuick(rawIndex, colIndex), closeTo(0.456, 0.0001));
        }
    }
}
 
开发者ID:sapirgolan,项目名称:MFIBlocking,代码行数:21,代码来源:MeasurLogicTest.java

示例5: testUpdateScoreInMatrix_cellsNotAffected

import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入依赖的package包/类
@Test
public void testUpdateScoreInMatrix_cellsNotAffected() throws Exception {
    SparseDoubleMatrix2D matrix2D = new SparseDoubleMatrix2D(100, 100);
    List<Integer> members = Arrays.asList(4, 8, 19, 5, 27);
    int recordId = 19;
    Block block = PowerMockito.mock(Block.class);
    PowerMockito.when(block.getMembers()).thenReturn(members);
    PowerMockito.when(block.getMemberScore(Mockito.eq(recordId))).thenReturn((float) 0.999);
    PowerMockito.when(block.getMemberProbability(Mockito.eq(recordId))).thenReturn((float) 0.456);

    Whitebox.invokeMethod(classUnderTest, "updateScoreInMatrix", matrix2D, recordId, block, CellType.PROBABILITY);
    for (int someMember = 1; someMember <= 100; someMember++) {
        if (!members.contains(someMember)) {
            int rawIndex = Whitebox.invokeMethod(classUnderTest, "getMatrixPosFromRecordID", recordId);
            int colIndex = Whitebox.invokeMethod(classUnderTest, "getMatrixPosFromRecordID", someMember);
            MatcherAssert.assertThat(matrix2D.getQuick(rawIndex, colIndex), closeTo(0.0, 0.000001));
        }
    }
}
 
开发者ID:sapirgolan,项目名称:MFIBlocking,代码行数:20,代码来源:MeasurLogicTest.java

示例6: testUpdateScoreInMatrix_forSecondTime

import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入依赖的package包/类
@Test
public void testUpdateScoreInMatrix_forSecondTime() throws Exception {
    SparseDoubleMatrix2D matrix2D = new SparseDoubleMatrix2D(100, 100);
    int recordId = 19;
    List<Integer> members = Arrays.asList(4, 8, 19, 5, 27);
    Block block = PowerMockito.mock(Block.class);
    PowerMockito.when(block.getMembers()).thenReturn(members);
    PowerMockito.when(block.getMemberScore(Mockito.eq(recordId))).thenReturn((float) 0.92);
    PowerMockito.when(block.getMemberProbability(Mockito.eq(recordId))).thenReturn((float) 0.32);

    Whitebox.invokeMethod(classUnderTest, "updateScoreInMatrix", matrix2D, recordId, block, CellType.PROBABILITY);
    members = Arrays.asList(19, 5, 27);
    Whitebox.invokeMethod(classUnderTest, "updateScoreInMatrix", matrix2D, recordId, block, CellType.PROBABILITY);

    int rawIndex = Whitebox.invokeMethod(classUnderTest, "getMatrixPosFromRecordID", recordId);
    int colIndex = Whitebox.invokeMethod(classUnderTest, "getMatrixPosFromRecordID", 5);
    MatcherAssert.assertThat(matrix2D.getQuick(rawIndex, colIndex), closeTo(0.64, 0.0001));
    colIndex = Whitebox.invokeMethod(classUnderTest, "getMatrixPosFromRecordID", 27);
    MatcherAssert.assertThat(matrix2D.getQuick(rawIndex, colIndex), closeTo(0.64, 0.0001));
}
 
开发者ID:sapirgolan,项目名称:MFIBlocking,代码行数:21,代码来源:MeasurLogicTest.java

示例7: 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;
}
 
开发者ID:markus1978,项目名称:clickwatch,代码行数:35,代码来源:GraphMatrixOperations.java

示例8: exportGraph

import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入依赖的package包/类
@Override
public void exportGraph() {
	try {
		initialiseOut();
		Map<WeightedEdge, Number> map = new HashMap<WeightedEdge, Number>();
		Graph<Agent, WeightedEdge> graph = tradeNetworkReport.getGraph();
		for(WeightedEdge edge : graph.getEdges()) {
			map.put(edge, edge.getValue());
		}
		SparseDoubleMatrix2D matrix = GraphMatrixOperations
				.graphToSparseMatrix(this.tradeNetworkReport.getGraph(),
						map);
		for (int i = 0; i < matrix.rows(); i++) {
			for (int j = 0; j < matrix.columns(); j++) {
				out.newData(matrix.get(i, j));
			}
			out.endRecord();
		}
		out.close();
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:phelps-sg,项目名称:jasa,代码行数:24,代码来源:AdjacencyMatrixTradeNetworkGraphExporter.java

示例9: laplacianScore

import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入依赖的package包/类
public int[] laplacianScore(int numK, String type, double[] weights) {
		if (this.fMat == null) {
			logger.warning("No feature loaded");
			return null;
		}
		System.out.println("computeLaplacian");
		computeLaplacian(numK, type);
		DoubleMatrix2D diagSum = new SparseDoubleMatrix2D(fMat.rows(), fMat.rows()); 
		for (int i = 0; i < fMat.rows(); ++i) {
			diagSum.setQuick(i, i, sumRow[i]);
		}
		diagSum.trimToSize();

		DenseDoubleMatrix1D  onesVector = new DenseDoubleMatrix1D (fMat.rows());
		onesVector.assign(1);
		DenseDoubleMatrix1D  zerosVector = new DenseDoubleMatrix1D (fMat.rows());
		zerosVector.assign(0);

		// f = f - \frac{f^T D 1}{1^T D 1} 1
		System.out.println("compute weight");
//		DoubleMatrix1D[] trans_vec = new DoubleMatrix1D[fMat.columns()];
//		for (int i = 0; i < fMat.columns(); i++)
//		{
//			trans_vec[i] = fMat.viewColumn(i).copy();
//		}
		for (int i = 0; i < fMat.columns(); ++i) {
			if (i % 100 == 0)
				System.out.println("have handle " + i + " feature");
			DoubleMatrix1D colVector = null;
//			colVector = trans_vec[i];
			colVector = fMat.viewColumn(i).copy();
			DoubleMatrix1D tempVector = null;
			
			// potential problem: diagSum.zMult(onesVector, tempVector) will lead tempVector as null!!
			tempVector = diagSum.zMult(onesVector, tempVector);
			double temp1 = colVector.zDotProduct(tempVector);
			double temp2 = onesVector.zDotProduct(onesVector);
			
			for (int j = 0; j < colVector.size(); ++j) {
				double temp3 = colVector.getQuick(j);
				double temp4 = temp3 - temp1/temp2;
				colVector.setQuick(j, temp4);
			}
			
			Laplacian.zMult(colVector, tempVector);
			temp1 = colVector.zDotProduct(tempVector);
			diagSum.zMult(colVector, tempVector);
			temp2 = colVector.zDotProduct(tempVector);
			
			lScore.insert(i, temp1/(temp2+Double.MIN_VALUE));
			weights[i] = temp1/(temp2+Double.MIN_VALUE);
		}
		int[] sortedIndices = MaxHeap.heapSort(lScore);
		//reverse array
//		sortedIndices = lScore.getIndices();
//		double[] scores = lScore.getValues();
//		for (double score: scores)
//				System.out.print(score + " ");
//		System.out.println();
		return sortedIndices;
		
	}
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:63,代码来源:LaplacianScore.java

示例10: inverseSparse

import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入依赖的package包/类
static public List<DoubleMatrix1D> inverseSparse(List<DoubleMatrix1D> A) {
	
	// TODO: optimize this code
	
	List<DoubleMatrix1D> C = null;
	
	DoubleMatrix2D A1 = new SparseDoubleMatrix2D(A.size(), A.get(0).size());
	for (int i = 0; i < A.size(); ++i) {
		DoubleMatrix1D vector = A.get(i);
		for (int j = 0; j < vector.size(); ++j ) {
			A1.set(i, j, vector.get(j));
		}
	}
	double tol = 0.001;
	for (int i = 0; i < A.size(); ++i) {
		A1.set(i, i, A1.get(i, i) + tol);
	}
	Algebra algebra = new Algebra();
	DoubleMatrix2D C1 = algebra.inverse(A1);
	
	C = new ArrayList<DoubleMatrix1D>();
	for (int i = 0; i < A.size(); ++i) {
		C.add(new ColtSparseVector(A.get(0).size()));
	}
	for (int i = 0; i < C1.rows(); ++i) {
		for (int j = 0; j < C1.columns(); ++j ) {
			C.get(i).set(j, C1.get(i, j));
		}
	}
	return C;
}
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:32,代码来源:Matrix2DUtil.java

示例11: multiplyMatrix

import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入依赖的package包/类
static DoubleMatrix2D multiplyMatrix(DoubleMatrix2D A, DoubleMatrix2D B) {
        DoubleMatrix2D C = new SparseDoubleMatrix2D(A.rows(), B.columns());
        A.zMult(B, C);
        return C;
}
 
开发者ID:santiontanon,项目名称:RHOG,代码行数:6,代码来源:KashimaKernelSparse.java

示例12: 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);
}
 
开发者ID:lovro-i,项目名称:apro,代码行数:34,代码来源:DSVProvider.java

示例13: getA

import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入依赖的package包/类
@Override
public DoubleMatrix2D getA() {
  SparseDoubleMatrix2D a = new SparseDoubleMatrix2D(n, n);
  for (Group group: groups) {
    for (int i=0; i<group.size; i++) {
      int len = group.lengths[i];
      int k;
      for (int j=0; j<len; j++) {
        k = group.indices[i][j];
        a.setQuick(i+group.startIndex, k, group.a[i][j]);
      }
    }
  }
  return a;
}
 
开发者ID:lovro-i,项目名称:apro,代码行数:16,代码来源:Apro.java

示例14: ColtSparseDoubleMatrix2D

import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入依赖的package包/类
public ColtSparseDoubleMatrix2D(Matrix source) {
	super(source.getRowCount(), source.getColumnCount());
	this.matrix = new SparseDoubleMatrix2D((int) source.getRowCount(), (int) source.getColumnCount());
	for (long[] c : source.availableCoordinates()) {
		setDouble(source.getAsDouble(c), c);
	}
	if (source.getMetaData() != null) {
		setMetaData(source.getMetaData().clone());
	}
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:11,代码来源:ColtSparseDoubleMatrix2D.java

示例15: plus

import cern.colt.matrix.impl.SparseDoubleMatrix2D; //导入依赖的package包/类
public Matrix plus(double value) {
	Matrix result = new ColtSparseDoubleMatrix2D((SparseDoubleMatrix2D) matrix.copy().assign(Functions.plus(value)));
	MapMatrix<String, Object> a = getMetaData();
	if (a != null) {
		result.setMetaData(a.clone());
	}
	return result;
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:9,代码来源:ColtSparseDoubleMatrix2D.java


注:本文中的cern.colt.matrix.impl.SparseDoubleMatrix2D类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。