Search in sources :

Example 26 with structures._Review

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

the class CLRWithHDP method calculateClusterProbPerUser.

@Override
protected // Indeed, it is for per review, for inheritance we don't change the function name.
void calculateClusterProbPerUser() {
    double prob, logSum;
    double[] probs;
    if (m_newCluster)
        probs = new double[m_kBar + 1];
    else
        probs = new double[m_kBar];
    _HDPAdaptStruct user;
    _HDPThetaStar curTheta;
    // sample a new cluster parameter first.
    if (m_newCluster) {
        // to make it consistent since we will only use one auxiliary variable
        m_hdpThetaStars[m_kBar].setGamma(m_gamma_e);
        m_G0.sampling(m_hdpThetaStars[m_kBar].getModel());
    }
    for (int i = 0; i < m_userList.size(); i++) {
        user = (_HDPAdaptStruct) m_userList.get(i);
        if (user.getTestSize() == 0)
            continue;
        for (_Review r : user.getReviews()) {
            if (r.getType() != rType.TEST)
                continue;
            for (int k = 0; k < probs.length; k++) {
                curTheta = m_hdpThetaStars[k];
                r.setHDPThetaStar(curTheta);
                prob = calcLogLikelihoodX(r) + Math.log(calcGroupPopularity(user, k, curTheta.getGamma()));
                probs[k] = prob;
            }
            logSum = Utils.logSumOfExponentials(probs);
            for (int k = 0; k < probs.length; k++) probs[k] -= logSum;
            // posterior in log space
            r.setClusterPosterior(probs);
        }
    }
}
Also used : structures._Review(structures._Review) structures._HDPThetaStar(structures._HDPThetaStar)

Example 27 with structures._Review

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

the class CLRWithHDP method calcLogLikelihoodX.

protected double calcLogLikelihoodX(_Review r) {
    if (r.getHDPThetaStar().getLMStat() == null) {
        return r.getL4NewCluster();
    } else {
        double[] Ns = r.getHDPThetaStar().getLMStat();
        double N = Utils.sumOfArray(Ns);
        double n = r.getLMSum();
        _SparseFeature[] fvs = r.getLMSparse();
        double L = Utils.lgamma(m_betaSum + N) - Utils.lgamma(m_betaSum + N + n);
        for (_SparseFeature fv : fvs) {
            L += logGammaDivision((int) fv.getValue(), m_betas[fv.getIndex()], Ns[fv.getIndex()]);
        }
        return L;
    }
}
Also used : structures._SparseFeature(structures._SparseFeature)

Example 28 with structures._Review

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

the class CLRWithHDP method logLikelihood.

@Override
protected double logLikelihood() {
    _HDPAdaptStruct user;
    double fValue = 0;
    // Use instances inside one cluster to update the thetastar.
    for (int i = 0; i < m_userList.size(); i++) {
        user = (_HDPAdaptStruct) m_userList.get(i);
        for (_Review r : user.getReviews()) {
            if (r.getType() == rType.TEST)
                continue;
            fValue -= calcLogLikelihoodY(r);
            // calculate the gradient by the review.
            gradientByFunc(user, r, 1);
        }
    }
    return fValue;
}
Also used : structures._Review(structures._Review)

Example 29 with structures._Review

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

the class CLinAdaptWithHDP method logit.

@Override
protected double logit(_SparseFeature[] fvs, _Review r) {
    int k, n;
    double[] Au = r.getHDPThetaStar().getModel();
    // Bias term: w_s0*a0+b0.
    double sum = Au[0] * m_gWeights[0] + Au[m_dim];
    for (_SparseFeature fv : fvs) {
        n = fv.getIndex() + 1;
        k = m_featureGroupMap[n];
        sum += (Au[k] * m_gWeights[n] + Au[m_dim + k]) * fv.getValue();
    }
    return Utils.logistic(sum);
}
Also used : structures._SparseFeature(structures._SparseFeature)

Example 30 with structures._Review

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

the class CLRWithMMB method accumulateLikelihoodX.

// accumulate the likelihood given by review content
protected double accumulateLikelihoodX() {
    _MMBAdaptStruct user;
    double likelihoodX = 0;
    for (int i = 0; i < m_userList.size(); i++) {
        user = (_MMBAdaptStruct) m_userList.get(i);
        if (user.getAdaptationSize() == 0)
            continue;
        for (_Review r : user.getReviews()) {
            if (r.getType() == rType.TEST)
                // do not touch testing reviews!
                continue;
            likelihoodX += calcLogLikelihoodX(r);
        }
    }
    return likelihoodX;
}
Also used : structures._Review(structures._Review)

Aggregations

structures._Review (structures._Review)44 structures._SparseFeature (structures._SparseFeature)24 structures._HDPThetaStar (structures._HDPThetaStar)9 ArrayList (java.util.ArrayList)8 Feature (Classifier.supervised.liblinear.Feature)6 Classifier.supervised.modelAdaptation._AdaptStruct (Classifier.supervised.modelAdaptation._AdaptStruct)6 structures._PerformanceStat (structures._PerformanceStat)6 IOException (java.io.IOException)5 File (java.io.File)4 structures._User (structures._User)4 FeatureNode (Classifier.supervised.liblinear.FeatureNode)3 Parameter (Classifier.supervised.liblinear.Parameter)3 Problem (Classifier.supervised.liblinear.Problem)3 structures._RankItem (structures._RankItem)3 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 PrintWriter (java.io.PrintWriter)2 MyPriorityQueue (structures.MyPriorityQueue)2 SolverType (Classifier.supervised.liblinear.SolverType)1