Search in sources :

Example 51 with structures._SparseFeature

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);
}
Also used : structures._SparseFeature(structures._SparseFeature)

Example 52 with structures._SparseFeature

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();
    }
}
Also used : structures._SparseFeature(structures._SparseFeature)

Example 53 with structures._SparseFeature

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;
}
Also used : structures._ChildDoc(structures._ChildDoc) structures._SparseFeature(structures._SparseFeature)

Example 54 with structures._SparseFeature

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;
}
Also used : structures._ChildDoc4BaseWithPhi(structures._ChildDoc4BaseWithPhi) structures._SparseFeature(structures._SparseFeature)

Example 55 with structures._SparseFeature

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());
        }
    }
}
Also used : structures._Doc(structures._Doc) structures._ParentDoc(structures._ParentDoc) structures._SparseFeature(structures._SparseFeature) structures._Word(structures._Word)

Aggregations

structures._SparseFeature (structures._SparseFeature)94 structures._ChildDoc (structures._ChildDoc)14 structures._Doc (structures._Doc)14 structures._Review (structures._Review)14 HashMap (java.util.HashMap)7 structures._ParentDoc (structures._ParentDoc)7 structures._Stn (structures._Stn)7 Feature (Classifier.supervised.liblinear.Feature)6 FeatureNode (Classifier.supervised.liblinear.FeatureNode)6 structures._RankItem (structures._RankItem)5 File (java.io.File)3 PrintWriter (java.io.PrintWriter)3 Classifier.supervised.modelAdaptation._AdaptStruct (Classifier.supervised.modelAdaptation._AdaptStruct)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 structures._ChildDoc4BaseWithPhi (structures._ChildDoc4BaseWithPhi)2 structures._HDPThetaStar (structures._HDPThetaStar)2