Search in sources :

Example 1 with structures._RankItem

use of structures._RankItem in project IR_Base by Linda-sunshine.

the class asyncCoRegLR method gradientByR2.

@Override
protected void gradientByR2(_AdaptStruct user) {
    _CoRegLRAdaptStruct ui = (_CoRegLRAdaptStruct) user, uj;
    for (_RankItem nit : ui.getNeighbors()) {
        uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
        gradientByR2(ui, uj, nit.m_value);
    }
    for (_RankItem nit : ui.getReverseNeighbors()) {
        uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
        gradientByR2(ui, uj, nit.m_value);
    }
}
Also used : structures._RankItem(structures._RankItem)

Example 2 with structures._RankItem

use of structures._RankItem in project IR_Base by Linda-sunshine.

the class asyncCoRegLRFirstOrder method gradientDescent.

@Override
void gradientDescent(_CoRegLRAdaptStruct ui, double initStepSize, double inc) {
    // update the current user
    super.gradientDescent(ui, initStepSize, inc);
    _CoRegLRAdaptStruct uj;
    for (_RankItem nit : ui.getNeighbors()) {
        uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
        super.gradientDescent(uj, initStepSize, inc / 3);
    }
    for (_RankItem nit : ui.getReverseNeighbors()) {
        uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
        super.gradientDescent(uj, initStepSize, inc / 3);
    }
}
Also used : structures._RankItem(structures._RankItem)

Example 3 with structures._RankItem

use of structures._RankItem 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)

Example 4 with structures._RankItem

use of structures._RankItem in project IR_Base by Linda-sunshine.

the class FeatureSelector method IG.

// Feature Selection -- IG.
public void IG(HashMap<String, _stat> featureStat, int[] classMemberNo) {
    m_selectedFeatures.clear();
    double classMemberSum = Utils.sumOfArray(classMemberNo);
    // I
    double[] PrCi = new double[classMemberNo.length];
    // II
    double[] PrCit = new double[classMemberNo.length];
    // III
    double[] PrCitNot = new double[classMemberNo.length];
    double Prt = 0, PrtNot = 0;
    // IG
    double Gt = 0;
    double PrCiSum = 0, PrCitSum = 0, PrCitNotSum = 0;
    // - $sigma$PrCi * log PrCi
    for (int i = 0; i < classMemberNo.length; i++) {
        PrCi[i] = classMemberNo[i] / classMemberSum;
        if (PrCi[i] != 0) {
            PrCiSum -= PrCi[i] * Math.log(PrCi[i]);
        }
    }
    for (String f : featureStat.keySet()) {
        // Filter the features which have smaller DFs.
        int sumDF = Utils.sumOfArray(featureStat.get(f).getDF());
        if (sumDF > m_minDF && sumDF < m_maxDF) {
            _stat temp = featureStat.get(f);
            Prt = Utils.sumOfArray(temp.getDF()) / classMemberSum;
            PrtNot = 1 - Prt;
            PrCitSum = 0;
            PrCitNotSum = 0;
            for (int i = 0; i < classMemberNo.length; i++) {
                PrCit[i] = ((double) temp.getDF()[i] / classMemberNo[i]) * PrCi[i] / Prt;
                PrCitNot[i] = ((double) (classMemberNo[i] - temp.getDF()[i]) / classMemberNo[i]) * PrCi[i] / PrtNot;
                if (PrCit[i] != 0) {
                    PrCitSum += PrCit[i] * Math.log(PrCit[i]);
                }
                if (PrCitNot[i] != 0) {
                    PrCitNotSum += PrCitNot[i] * Math.log(PrCi[i]);
                }
            }
            Gt = PrCiSum + PrCitSum + PrCitNotSum;
            m_selectedFeatures.add(new _RankItem(f, Gt));
        }
    }
}
Also used : structures._stat(structures._stat) structures._RankItem(structures._RankItem)

Example 5 with structures._RankItem

use of structures._RankItem in project IR_Base by Linda-sunshine.

the class FeatureSelector method MI.

// Feature Selection -- MI.
public void MI(HashMap<String, _stat> featureStat, int[] classMemberNo) {
    m_selectedFeatures.clear();
    double[] PrCi = new double[classMemberNo.length];
    double[] ItCi = new double[classMemberNo.length];
    double N = Utils.sumOfArray(classMemberNo);
    double Iavg = 0;
    for (int i = 0; i < classMemberNo.length; i++) PrCi[i] = classMemberNo[i] / N;
    for (String f : featureStat.keySet()) {
        // Filter the features which have smaller DFs.
        int sumDF = Utils.sumOfArray(featureStat.get(f).getDF());
        if (sumDF > m_minDF && sumDF < m_maxDF) {
            Iavg = 0;
            for (int i = 0; i < classMemberNo.length; i++) {
                _stat temp = featureStat.get(f);
                double A = temp.getDF()[i];
                ItCi[i] = Math.log(A * N / classMemberNo[i] * Utils.sumOfArray(temp.getDF()));
                Iavg += ItCi[i] * PrCi[i];
            }
            m_selectedFeatures.add(new _RankItem(f, Iavg));
        }
    }
}
Also used : structures._stat(structures._stat) structures._RankItem(structures._RankItem)

Aggregations

structures._RankItem (structures._RankItem)66 MyPriorityQueue (structures.MyPriorityQueue)39 File (java.io.File)27 PrintWriter (java.io.PrintWriter)27 structures._Doc (structures._Doc)25 FileNotFoundException (java.io.FileNotFoundException)20 structures._ParentDoc4DCM (structures._ParentDoc4DCM)3 structures._Review (structures._Review)3 structures._SparseFeature (structures._SparseFeature)3 structures._stat (structures._stat)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 structures._Doc4DCMLDA (structures._Doc4DCMLDA)2 SparseDoubleMatrix2D (cern.colt.matrix.tdouble.impl.SparseDoubleMatrix2D)1 structures._HDPThetaStar (structures._HDPThetaStar)1 structures._Node (structures._Node)1 structures._QUPair (structures._QUPair)1 structures._Query (structures._Query)1 structures._Stn (structures._Stn)1 structures._thetaStar (structures._thetaStar)1