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