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);
}
}
}
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;
}
}
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;
}
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);
}
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;
}
Aggregations