Search in sources :

Example 36 with structures._RankItem

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

the class ModelAdaptation method constructReverseNeighborhood.

protected int[] constructReverseNeighborhood() {
    // total number of adaptation instances
    int adaptSize = 0;
    // construct the reverse link
    CoAdaptStruct ui, uj;
    for (int i = 0; i < m_userList.size(); i++) {
        ui = (CoAdaptStruct) (m_userList.get(i));
        for (_RankItem nit : ui.getNeighbors()) {
            // uj is a neighbor of ui
            uj = (CoAdaptStruct) (m_userList.get(nit.m_index));
            uj.addReverseNeighbor(i, nit.m_value);
        }
        adaptSize += ui.getAdaptationSize();
    }
    // construct the order of online updating
    ArrayList<_RankItem> userorder = new ArrayList<_RankItem>();
    for (int i = 0; i < m_userList.size(); i++) {
        ui = (CoAdaptStruct) (m_userList.get(i));
        for (_Review r : ui.getReviews()) {
            // reviews in each user is already ordered by time
            if (r.getType() == rType.ADAPTATION) {
                // to be in ascending order
                userorder.add(new _RankItem(i, r.getTimeStamp()));
            }
        }
    }
    Collections.sort(userorder);
    int[] userOrder = new int[adaptSize];
    for (int i = 0; i < adaptSize; i++) userOrder[i] = userorder.get(i).m_index;
    return userOrder;
}
Also used : structures._RankItem(structures._RankItem) structures._Review(structures._Review) ArrayList(java.util.ArrayList)

Example 37 with structures._RankItem

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

the class CoRegLR method gradientByR2.

// Calculate the gradients for the use in LBFGS.
protected void gradientByR2(_AdaptStruct user) {
    _CoRegLRAdaptStruct ui = (_CoRegLRAdaptStruct) user, uj;
    int vSize = m_featureSize + 1, offseti = vSize * ui.getId(), offsetj;
    double coef, diff;
    for (_RankItem nit : ui.getNeighbors()) {
        uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
        offsetj = vSize * uj.getId();
        coef = 2 * m_eta2 * nit.m_value;
        for (int k = 0; k < vSize; k++) {
            diff = coef * (ui.getPWeight(k) - uj.getPWeight(k));
            // update ui's gradient
            m_g[offseti + k] += diff;
            // update uj's gradient
            m_g[offsetj + k] -= diff;
        }
    }
}
Also used : structures._RankItem(structures._RankItem)

Example 38 with structures._RankItem

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

the class CoRegLR method calculateFuncValue.

@Override
protected double calculateFuncValue(_AdaptStruct u) {
    double fValue = super.calculateFuncValue(u), R2 = 0;
    // R2 regularization
    _CoRegLRAdaptStruct ui = (_CoRegLRAdaptStruct) u, uj;
    for (_RankItem nit : ui.getNeighbors()) {
        uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
        double diff, sum = 0;
        for (int i = 0; i <= m_featureSize; i++) {
            diff = ui.getPWeight(i) - uj.getPWeight(i);
            sum += diff * diff;
        }
        R2 += nit.m_value * sum;
    }
    return fValue + m_eta2 * R2;
}
Also used : structures._RankItem(structures._RankItem)

Example 39 with structures._RankItem

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

the class asyncCoRegLRFirstOrder method gradientByRelatedR1.

// compute gradient for all related user in first order connection (exclude itself)
void gradientByRelatedR1(_CoRegLRAdaptStruct ui) {
    _CoRegLRAdaptStruct uj;
    for (_RankItem nit : ui.getNeighbors()) {
        uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
        gradientByR1(uj);
    }
    for (_RankItem nit : ui.getReverseNeighbors()) {
        uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
        gradientByR1(uj);
    }
}
Also used : structures._RankItem(structures._RankItem)

Example 40 with structures._RankItem

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

the class DCMLDA_test method printTopWord.

protected void printTopWord(int k, String topWordFile) {
    System.out.println("TopWord FilePath:" + topWordFile);
    Arrays.fill(m_sstat, 0);
    for (_Doc d : m_trainSet) {
        for (int i = 0; i < number_of_topics; i++) m_sstat[i] += m_logSpace ? Math.exp(d.m_topics[i]) : d.m_topics[i];
    }
    Utils.L1Normalization(m_sstat);
    try {
        PrintWriter topWordWriter = new PrintWriter(new File(topWordFile));
        for (int i = 0; i < topic_term_probabilty.length; i++) {
            MyPriorityQueue<_RankItem> fVector = new MyPriorityQueue<_RankItem>(k);
            for (int j = 0; j < vocabulary_size; j++) fVector.add(new _RankItem(m_corpus.getFeature(j), topic_term_probabilty[i][j]));
            topWordWriter.format("Topic %d(%.5f):\t", i, m_sstat[i]);
            for (_RankItem it : fVector) topWordWriter.format("%s(%.5f)\t", it.m_name, m_logSpace ? Math.exp(it.m_value) : it.m_value);
            topWordWriter.write("\n");
        }
        topWordWriter.close();
    } catch (Exception ex) {
        System.err.print("File Not Found");
    }
}
Also used : structures._RankItem(structures._RankItem) structures._Doc(structures._Doc) MyPriorityQueue(structures.MyPriorityQueue) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter)

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