Search in sources :

Example 31 with Classifier.supervised.modelAdaptation._AdaptStruct

use of Classifier.supervised.modelAdaptation._AdaptStruct in project IR_Base by Linda-sunshine.

the class CLRWithHDP method accumulateFeatureCount.

public void accumulateFeatureCount() {
    int cIndex = 0;
    // store the tf count of features in one cluster
    m_tf_count = new int[m_kBar][m_featureSize];
    for (_AdaptStruct user : m_userList) {
        for (_Review r : user.getReviews()) {
            if (r.getType() == rType.ADAPTATION) {
                cIndex = r.getHDPThetaStar().getIndex();
                // aggregate each cluster's word counts
                for (_SparseFeature fv : r.getSparse()) {
                    m_tf_count[cIndex][fv.getIndex()] += fv.getValue();
                }
            }
        }
    }
}
Also used : Classifier.supervised.modelAdaptation._AdaptStruct(Classifier.supervised.modelAdaptation._AdaptStruct) structures._Review(structures._Review) structures._SparseFeature(structures._SparseFeature)

Example 32 with Classifier.supervised.modelAdaptation._AdaptStruct

use of Classifier.supervised.modelAdaptation._AdaptStruct in project IR_Base by Linda-sunshine.

the class CLRWithHDP method initThetaStars.

// Randomly assign user reviews to k user groups.
@Override
public void initThetaStars() {
    initPriorG0();
    _HDPAdaptStruct user;
    double L = 0, beta_sum = Utils.sumOfArray(m_betas), betaSum_lgamma = Utils.lgamma(beta_sum), sum = 0;
    int index;
    for (_AdaptStruct u : m_userList) {
        user = (_HDPAdaptStruct) u;
        for (_Review r : user.getReviews()) {
            // for all reviews pre-compute the likelihood of being generated from a random language model
            L = 0;
            // sum = v*beta+\sum \pi_v(global language model)
            sum = beta_sum;
            // for those v with mij,v=0, frac = \gamma(beta_v)/\gamma(beta_v)=1, log frac = 0
            for (_SparseFeature fv : r.getLMSparse()) {
                index = fv.getIndex();
                sum += fv.getValue();
                // log \gamma(m_v+\pi_v+beta)/\gamma(\pi_v+beta)
                // logGamma(\beta_i) is pre-computed for efficiency
                L += Utils.lgamma(fv.getValue() + m_betas[index]) - Utils.lgamma(m_betas[index]);
            }
            L += betaSum_lgamma - Utils.lgamma(sum);
            r.setL4NewCluster(L);
            if (r.getType() == rType.TEST)
                continue;
            sampleOneInstance(user, r);
        }
    }
}
Also used : Classifier.supervised.modelAdaptation._AdaptStruct(Classifier.supervised.modelAdaptation._AdaptStruct) structures._Review(structures._Review) structures._SparseFeature(structures._SparseFeature)

Example 33 with Classifier.supervised.modelAdaptation._AdaptStruct

use of Classifier.supervised.modelAdaptation._AdaptStruct in project IR_Base by Linda-sunshine.

the class CLRWithHDP method checkTestReviewSize.

// sanity check, how many testing users we have
public void checkTestReviewSize() {
    int test = 0, userCount = 0;
    for (_AdaptStruct u : m_userList) {
        if (u.getAdaptationSize() == 0) {
            test += u.getTestSize();
            userCount++;
        }
    }
    System.out.print(String.format("[Info]test user: %d, test review: %d\n", userCount, test));
}
Also used : Classifier.supervised.modelAdaptation._AdaptStruct(Classifier.supervised.modelAdaptation._AdaptStruct)

Example 34 with Classifier.supervised.modelAdaptation._AdaptStruct

use of Classifier.supervised.modelAdaptation._AdaptStruct in project IR_Base by Linda-sunshine.

the class CLinAdaptWithHDP method loadUsers.

@Override
public void loadUsers(ArrayList<_User> userList) {
    m_userList = new ArrayList<_AdaptStruct>();
    // Init each user.
    for (_User user : userList) m_userList.add(new _HDPAdaptStruct(user, m_dim));
    m_pWeights = new double[m_gWeights.length];
}
Also used : Classifier.supervised.modelAdaptation._AdaptStruct(Classifier.supervised.modelAdaptation._AdaptStruct) structures._User(structures._User)

Aggregations

Classifier.supervised.modelAdaptation._AdaptStruct (Classifier.supervised.modelAdaptation._AdaptStruct)34 structures._User (structures._User)15 File (java.io.File)6 PrintWriter (java.io.PrintWriter)6 structures._Review (structures._Review)6 IOException (java.io.IOException)5 ExceptionWithIflag (LBFGS.LBFGS.ExceptionWithIflag)3 structures._SparseFeature (structures._SparseFeature)3 Feature (Classifier.supervised.liblinear.Feature)2 Parameter (Classifier.supervised.liblinear.Parameter)2 Problem (Classifier.supervised.liblinear.Problem)2 ArrayList (java.util.ArrayList)2 structures._HDPThetaStar (structures._HDPThetaStar)2 structures._PerformanceStat (structures._PerformanceStat)2 FileNotFoundException (java.io.FileNotFoundException)1 HashSet (java.util.HashSet)1 structures._thetaStar (structures._thetaStar)1