use of structures._SparseFeature in project IR_Base by Linda-sunshine.
the class MTRegLR method logit.
// Every user is represented by (u*global + individual)
@Override
protected double logit(_SparseFeature[] fvs, _AdaptStruct user) {
int fid, uOffset, gOffset;
uOffset = (m_featureSize + 1) * user.getId();
gOffset = (m_featureSize + 1) * m_userList.size();
// User bias and Global bias
double sum = m_ws[uOffset] + m_u * m_ws[gOffset];
for (_SparseFeature f : fvs) {
fid = f.getIndex() + 1;
// User model with Global model.
sum += (m_ws[uOffset + fid] + m_u * m_ws[gOffset + fid]) * f.getValue();
}
return Utils.logistic(sum);
}
use of structures._SparseFeature in project IR_Base by Linda-sunshine.
the class RegLR method gradientByFunc.
protected void gradientByFunc(_AdaptStruct user, _Doc review, double weight) {
// feature index
int n;
// general enough to accommodate both LinAdapt and CoLinAdapt
int offset = (m_featureSize + 1) * user.getId();
double delta = weight * (review.getYLabel() - logit(review.getSparse(), user));
if (m_LNormFlag)
delta /= getAdaptationSize(user);
// Bias term.
// a[0] = w0*x0; x0=1
m_g[offset] -= delta;
// Traverse all the feature dimension to calculate the gradient.
for (_SparseFeature fv : review.getSparse()) {
n = fv.getIndex() + 1;
m_g[offset + n] -= delta * fv.getValue();
}
}
use of structures._SparseFeature in project IR_Base by Linda-sunshine.
the class ACCTM method calculate_log_likelihood4Child.
protected double calculate_log_likelihood4Child(_Doc d) {
_ChildDoc cDoc = (_ChildDoc) d;
double docLogLikelihood = 0.0;
// prepare compute the normalizers
_SparseFeature[] fv = cDoc.getSparse();
for (int i = 0; i < fv.length; i++) {
int wid = fv[i].getIndex();
double value = fv[i].getValue();
double wordLogLikelihood = 0;
for (int k = 0; k < number_of_topics; k++) {
double wordPerTopicLikelihood = childWordByTopicProb(k, wid) * childTopicInDocProb(k, cDoc);
wordLogLikelihood += wordPerTopicLikelihood;
}
if (Math.abs(wordLogLikelihood) < 1e-10) {
System.out.println("wordLoglikelihood\t" + wordLogLikelihood);
wordLogLikelihood += 1e-10;
}
wordLogLikelihood = Math.log(wordLogLikelihood);
docLogLikelihood += value * wordLogLikelihood;
}
return docLogLikelihood;
}
use of structures._SparseFeature in project IR_Base by Linda-sunshine.
the class ACCTM_CHard method calculate_log_likelihood4Child.
@Override
protected double calculate_log_likelihood4Child(_Doc d) {
// System.out.println("likelihood in child doc in base with phi");
_ChildDoc4BaseWithPhi cDoc = (_ChildDoc4BaseWithPhi) d;
double docLogLikelihood = 0.0;
double gammaLen = Utils.sumOfArray(m_gamma);
double cDocXSum = Utils.sumOfArray(cDoc.m_xSstat);
// prepare compute the normalizers
_SparseFeature[] fv = cDoc.getSparse();
for (int i = 0; i < fv.length; i++) {
int wid = fv[i].getIndex();
double value = fv[i].getValue();
double wordLogLikelihood = 0;
if (Utils.indexOf(cDoc.m_parentDoc.getSparse(), wid) != -1) {
for (int k = 0; k < number_of_topics; k++) {
double wordPerTopicLikelihood = childWordByTopicProb(k, wid) * childTopicInDocProb(k, cDoc);
wordLogLikelihood += wordPerTopicLikelihood;
}
} else {
for (int k = 0; k < number_of_topics; k++) {
double wordPerTopicLikelihood = childWordByTopicProb(k, wid) * childTopicInDocProb(k, cDoc) * childXInDocProb(0, cDoc) / (cDocXSum + gammaLen);
wordLogLikelihood += wordPerTopicLikelihood;
}
double wordPerTopicLikelihood = childLocalWordByTopicProb(wid, cDoc) * childXInDocProb(1, cDoc) / (cDocXSum + gammaLen);
wordLogLikelihood += wordPerTopicLikelihood;
}
if (Math.abs(wordLogLikelihood) < 1e-10) {
System.out.println("wordLoglikelihood\t" + wordLogLikelihood);
wordLogLikelihood += 1e-10;
}
wordLogLikelihood = Math.log(wordLogLikelihood);
docLogLikelihood += value * wordLogLikelihood;
}
return docLogLikelihood;
}
use of structures._SparseFeature in project IR_Base by Linda-sunshine.
the class ACCTM_CZLR method setFeatures4Word.
protected void setFeatures4Word(ArrayList<_Doc> docList) {
for (_Doc d : docList) {
if (d instanceof _ParentDoc)
continue;
_SparseFeature[] sfs = d.getSparse();
for (_Word w : d.getWords()) {
int wid = w.getIndex();
int wIndex = Utils.indexOf(sfs, wid);
_SparseFeature sf = sfs[wIndex];
w.setFeatures(sf.getValues());
}
}
}
Aggregations