Search in sources :

Example 31 with structures._Review

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

the class CLRWithMMB method updateDocMembership.

@Override
public // Override this function since we have different conditions for removing clusters.
void updateDocMembership(_HDPAdaptStruct user, _Review r) {
    int index = -1;
    _HDPThetaStar curThetaStar = r.getHDPThetaStar();
    // remove the current review from the user side.
    user.incHDPThetaStarMemSize(r.getHDPThetaStar(), -1);
    // remove the current review from the theta side.
    // remove the lm stat first before decrease the document count
    curThetaStar.rmLMStat(r.getLMSparse());
    curThetaStar.updateMemCount(-1);
    // No data associated with the cluster
    if (curThetaStar.getMemSize() == 0 && curThetaStar.getTotalEdgeSize() == 0) {
        System.out.println("[Debug]Zero cluster detected in updating doc!");
        // check if every dim gets 0 count in language mode
        LMStatSanityCheck(curThetaStar);
        // recycle the gamma
        m_gamma_e += curThetaStar.getGamma();
        // curThetaStar.resetGamma();
        // swap the disabled theta to the last for later use
        index = findHDPThetaStar(curThetaStar);
        // move it back to \theta*
        swapTheta(m_kBar - 1, index);
        curThetaStar.reset();
        m_kBar--;
    }
}
Also used : structures._HDPThetaStar(structures._HDPThetaStar)

Example 32 with structures._Review

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

the class MTCLRWithMMB method gradientByFunc.

@Override
protected void gradientByFunc(_AdaptStruct u, _Doc review, double weight, double[] g) {
    _Review r = (_Review) review;
    // feature index
    int n;
    int cIndex = r.getHDPThetaStar().getIndex();
    if (cIndex < 0 || cIndex >= m_kBar)
        System.err.println("Error,cannot find the theta star!");
    int offset = m_dim * cIndex;
    int offsetSup = m_dim * m_kBar;
    double delta = weight * (r.getYLabel() - logit(r.getSparse(), r));
    // Bias term.
    // x0=1, each cluster.
    g[offset] -= delta;
    // super model.
    g[offsetSup] -= m_q * delta;
    // Traverse all the feature dimension to calculate the gradient.
    for (_SparseFeature fv : review.getSparse()) {
        n = fv.getIndex() + 1;
        // cluster model.
        g[offset + n] -= delta * fv.getValue();
        // super model.
        g[offsetSup + n] -= delta * fv.getValue() * m_q;
    }
}
Also used : structures._Review(structures._Review) structures._SparseFeature(structures._SparseFeature)

Example 33 with structures._Review

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

the class MTCLinAdaptWithMMB method logit.

// Logit function is different from the father class.
@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] * getSupWeights(0) + Au[m_dim];
    for (_SparseFeature fv : fvs) {
        n = fv.getIndex() + 1;
        k = m_featureGroupMap[n];
        sum += (Au[k] * getSupWeights(n) + Au[m_dim + k]) * fv.getValue();
    }
    return Utils.logistic(sum);
}
Also used : structures._SparseFeature(structures._SparseFeature)

Example 34 with structures._Review

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

the class _MMBAdaptStruct method evaluate.

@Override
public double evaluate(_Doc doc) {
    _Review r = (_Review) doc;
    double prob = 0, sum = 0;
    double[] probs = r.getCluPosterior();
    int n, m, k;
    // not adaptation based
    if (m_dim == 0) {
        for (k = 0; k < probs.length; k++) {
            // need to be fixed: here we assumed binary classification
            sum = Utils.dotProduct(CLRWithMMB.m_hdpThetaStars[k].getModel(), doc.getSparse(), 0);
            if (MTCLRWithMMB.m_supWeights != null && CLRWithDP.m_q != 0)
                sum += CLRWithDP.m_q * Utils.dotProduct(MTCLRWithMMB.m_supWeights, doc.getSparse(), 0);
            // to maintain numerical precision, compute the expectation in log space as well
            if (k == 0)
                prob = probs[k] + Math.log(Utils.logistic(sum));
            else
                prob = Utils.logSum(prob, probs[k] + Math.log(Utils.logistic(sum)));
        }
    } else {
        double[] As;
        for (k = 0; k < probs.length; k++) {
            As = CLRWithMMB.m_hdpThetaStars[k].getModel();
            // Bias term: w_s0*a0+b0.
            sum = As[0] * CLinAdaptWithMMB.m_supWeights[0] + As[m_dim];
            for (_SparseFeature fv : doc.getSparse()) {
                n = fv.getIndex() + 1;
                m = m_featureGroupMap[n];
                sum += (As[m] * CLinAdaptWithMMB.m_supWeights[n] + As[m_dim + m]) * fv.getValue();
            }
            // to maintain numerical precision, compute the expectation in log space as well
            if (k == 0)
                prob = probs[k] + Math.log(Utils.logistic(sum));
            else
                prob = Utils.logSum(prob, probs[k] + Math.log(Utils.logistic(sum)));
        }
    }
    // accumulate the prediction results during sampling procedure
    doc.m_pCount++;
    // >0.5?1:0;
    doc.m_prob += Math.exp(prob);
    return prob;
}
Also used : structures._Review(structures._Review) structures._SparseFeature(structures._SparseFeature)

Example 35 with structures._Review

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

the class ModelAdaptation method constructReverseNeighborhood.

protected int[] constructReverseNeighborhood() {
    // total number of adaptation instances
    int adaptSize = 0;
    // construct the reverse link
    CoAdaptStruct ui, uj;
    for (int i = 0; i < m_userList.size(); i++) {
        ui = (CoAdaptStruct) (m_userList.get(i));
        for (_RankItem nit : ui.getNeighbors()) {
            // uj is a neighbor of ui
            uj = (CoAdaptStruct) (m_userList.get(nit.m_index));
            uj.addReverseNeighbor(i, nit.m_value);
        }
        adaptSize += ui.getAdaptationSize();
    }
    // construct the order of online updating
    ArrayList<_RankItem> userorder = new ArrayList<_RankItem>();
    for (int i = 0; i < m_userList.size(); i++) {
        ui = (CoAdaptStruct) (m_userList.get(i));
        for (_Review r : ui.getReviews()) {
            // reviews in each user is already ordered by time
            if (r.getType() == rType.ADAPTATION) {
                // to be in ascending order
                userorder.add(new _RankItem(i, r.getTimeStamp()));
            }
        }
    }
    Collections.sort(userorder);
    int[] userOrder = new int[adaptSize];
    for (int i = 0; i < adaptSize; i++) userOrder[i] = userorder.get(i).m_index;
    return userOrder;
}
Also used : structures._RankItem(structures._RankItem) structures._Review(structures._Review) ArrayList(java.util.ArrayList)

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