Search in sources :

Example 1 with SparseDoubleMatrix2D

use of cern.colt.matrix.tdouble.impl.SparseDoubleMatrix2D in project IR_Base by Linda-sunshine.

the class PageRank method constructSparseGraph.

private void constructSparseGraph(ArrayList<_Doc> collection) {
    m_N = collection.size();
    // we need to make this very sparse!
    m_transition = new SparseDoubleMatrix2D(m_N, m_N);
    // construct the connection
    MyPriorityQueue<_RankItem> queue = new MyPriorityQueue<_RankItem>(m_topK);
    for (int i = 0; i < collection.size(); i++) {
        _Doc di = collection.get(i);
        // find k-nearest neighbor
        for (int j = 0; j < collection.size(); j++) {
            if (i != j)
                queue.add(new _RankItem(j, Utils.dotProduct(di, collection.get(j))));
        }
        // transition probability is proportion to similarity
        double sum = 0;
        for (_RankItem item : queue) {
            item.m_value = Math.exp(item.m_value);
            sum += item.m_value;
        }
        // set up the transition
        for (_RankItem item : queue) // i -> j
        m_transition.setQuick(i, item.m_index, item.m_value / sum);
        queue.clear();
    }
}
Also used : structures._RankItem(structures._RankItem) MyPriorityQueue(structures.MyPriorityQueue) structures._Doc(structures._Doc) SparseDoubleMatrix2D(cern.colt.matrix.tdouble.impl.SparseDoubleMatrix2D)

Aggregations

SparseDoubleMatrix2D (cern.colt.matrix.tdouble.impl.SparseDoubleMatrix2D)1 MyPriorityQueue (structures.MyPriorityQueue)1 structures._Doc (structures._Doc)1 structures._RankItem (structures._RankItem)1