Search in sources :

Example 6 with structures._thetaStar

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

the class CLRWithDP method printInfo.

public void printInfo() {
    MyPriorityQueue<_RankItem> clusterRanker = new MyPriorityQueue<_RankItem>(5);
    // clear the statistics
    for (int i = 0; i < m_kBar; i++) {
        m_thetaStars[i].resetCount();
        clusterRanker.add(new _RankItem(i, m_thetaStars[i].getMemSize()));
    }
    // collect statistics across users in adaptation data
    _thetaStar theta = null;
    for (int i = 0; i < m_userList.size(); i++) {
        _DPAdaptStruct user = (_DPAdaptStruct) m_userList.get(i);
        theta = user.getThetaStar();
        for (_Review review : user.getReviews()) {
            if (review.getType() != rType.ADAPTATION)
                // only touch the adaptation data
                continue;
            else if (review.getYLabel() == 1)
                theta.incPosCount();
            else
                theta.incNegCount();
        }
    }
    System.out.print("[Info]Clusters:");
    for (int i = 0; i < m_kBar; i++) System.out.format("%s\t", m_thetaStars[i].showStat());
    System.out.print(String.format("\n[Info]%d Clusters are found in total!\n", m_kBar));
}
Also used : structures._thetaStar(structures._thetaStar) structures._RankItem(structures._RankItem) structures._Review(structures._Review) MyPriorityQueue(structures.MyPriorityQueue)

Example 7 with structures._thetaStar

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

the class CLRWithDP method swapTheta.

protected void swapTheta(int a, int b) {
    _thetaStar cTheta = m_thetaStars[a];
    m_thetaStars[a] = m_thetaStars[b];
    // kBar starts from 0, the size decides how many are valid.
    m_thetaStars[b] = cTheta;
}
Also used : structures._thetaStar(structures._thetaStar)

Example 8 with structures._thetaStar

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

the class CLRWithDP method saveClusterModels.

public void saveClusterModels(String model) {
    PrintWriter writer;
    String filename;
    File dir = new File(model);
    _thetaStar theta;
    double[] weight;
    try {
        if (!dir.exists())
            dir.mkdirs();
        for (int i = 0; i < m_kBar; i++) {
            theta = m_thetaStars[i];
            filename = String.format("%s/%d.classifier", model, theta.getIndex());
            writer = new PrintWriter(new File(filename));
            weight = theta.getModel();
            for (int v = 0; v < weight.length; v++) {
                if (v == weight.length - 1)
                    writer.write(Double.toString(weight[v]));
                else
                    writer.write(weight[v] + ",");
            }
            writer.close();
        }
        writer = new PrintWriter(new File(model + "/ClusterMember.txt"));
        for (_AdaptStruct u : m_userList) {
            _DPAdaptStruct user = (_DPAdaptStruct) u;
            writer.write(user.getUserID() + "\t" + user.getThetaStar().getIndex() + "\n");
        }
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : structures._thetaStar(structures._thetaStar) Classifier.supervised.modelAdaptation._AdaptStruct(Classifier.supervised.modelAdaptation._AdaptStruct) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Aggregations

structures._thetaStar (structures._thetaStar)6 File (java.io.File)2 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 MyPriorityQueue (structures.MyPriorityQueue)2 structures._RankItem (structures._RankItem)2 structures._Review (structures._Review)2 Classifier.supervised.modelAdaptation._AdaptStruct (Classifier.supervised.modelAdaptation._AdaptStruct)1 ArrayList (java.util.ArrayList)1 structures._SparseFeature (structures._SparseFeature)1