Search in sources :

Example 86 with structures._SparseFeature

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

the class WeightedAvgTransAdapt method logit.

@Override
protected // In this logit function, we need to sum over all the neighbors of the current user.
double logit(_SparseFeature[] fvs, _AdaptStruct user) {
    _CoLinAdaptStruct ui = (_CoLinAdaptStruct) user;
    double sum = ui.getSelfSim() * linearFunc(fvs, ui);
    // Traverse all neighbors of the current user.
    for (_RankItem nit : ui.getNeighbors()) {
        _CoLinAdaptStruct uj = (_CoLinAdaptStruct) m_userList.get(nit.m_index);
        sum += nit.m_value * linearFunc(fvs, uj);
    }
    return Utils.logistic(sum);
}
Also used : structures._RankItem(structures._RankItem)

Example 87 with structures._SparseFeature

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

the class CLinAdaptWithDP method logit.

// Logit function is different from the father class.
@Override
protected double logit(_SparseFeature[] fvs, _AdaptStruct u) {
    int k, n;
    double[] Au = ((_DPAdaptStruct) u).getThetaStar().getModel();
    // Bias term: w_s0*a0+b0.
    double value = Au[0] * m_gWeights[0] + Au[m_dim];
    for (_SparseFeature fv : fvs) {
        n = fv.getIndex() + 1;
        k = m_featureGroupMap[n];
        value += (Au[k] * m_gWeights[n] + Au[m_dim + k]) * fv.getValue();
    }
    return Utils.logistic(value);
}
Also used : structures._SparseFeature(structures._SparseFeature)

Example 88 with structures._SparseFeature

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

the class CLinAdaptWithDP method gradientByFunc.

@Override
protected void gradientByFunc(_AdaptStruct u, _Doc review, double weight, double[] g) {
    _DPAdaptStruct user = (_DPAdaptStruct) u;
    // feature index
    int n, k;
    int cIndex = user.getThetaStar().getIndex();
    if (cIndex < 0 || cIndex >= m_kBar)
        System.err.println("Error,cannot find the theta star!");
    int offset = m_dim * 2 * cIndex;
    double delta = (review.getYLabel() - logit(review.getSparse(), user)) * weight;
    if (m_LNormFlag)
        delta /= getAdaptationSize(user);
    // Bias term for individual user.
    // a[0] = ws0*x0; x0=1
    g[offset] -= delta * m_gWeights[0];
    // b[0]
    g[offset + m_dim] -= delta;
    // Traverse all the feature dimension to calculate the gradient for both individual users and super user.
    for (_SparseFeature fv : review.getSparse()) {
        n = fv.getIndex() + 1;
        k = m_featureGroupMap[n];
        // w_si*x_di
        g[offset + k] -= delta * m_gWeights[n] * fv.getValue();
        // x_di
        g[offset + m_dim + k] -= delta * fv.getValue();
    }
}
Also used : structures._SparseFeature(structures._SparseFeature)

Example 89 with structures._SparseFeature

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

the class CLinAdaptWithKmeans method gradientByFunc.

@Override
protected void gradientByFunc(_AdaptStruct u, _Doc review, double weight) {
    _CLinAdaptStruct user = (_CLinAdaptStruct) u;
    // feature index and feature group index
    int n, k;
    int clusterIndex = m_userClusterIndex[user.getId()];
    // general enough to accommodate both LinAdapt and CoLinAdapt
    int iOffset = 2 * m_dim * user.getId();
    int cOffset = 2 * m_dim * (m_userList.size() + clusterIndex);
    int gOffset = 2 * m_dim * (m_userList.size() + m_clusterSize);
    double delta = (review.getYLabel() - logit(review.getSparse(), user));
    if (m_LNormFlag)
        delta /= getAdaptationSize(user);
    // Bias term for individual part.
    // a[0] = w0*x0; x0=1
    m_g[iOffset] -= weight * delta * m_i * m_gWeights[0];
    // b[0]
    m_g[iOffset + m_dim] -= weight * delta * m_i;
    // Bias term for cluster part.
    // a[0] = w0*x0; x0=1
    m_g[cOffset] -= weight * delta * m_c * m_gWeights[0];
    // b[0]
    m_g[cOffset + m_dim] -= weight * delta * m_c;
    // Bias term for global part.
    // a[0] = w0*x0; x0=1
    m_g[gOffset] -= weight * delta * m_u * m_gWeights[0];
    // b[0]
    m_g[gOffset + m_dim] -= weight * delta * m_u;
    // Traverse all the feature dimension to calculate the gradient.
    for (_SparseFeature fv : review.getSparse()) {
        n = fv.getIndex() + 1;
        k = m_featureGroupMap[n];
        // Individual part.
        m_g[iOffset + k] -= weight * delta * m_i * m_gWeights[n] * fv.getValue();
        m_g[iOffset + m_dim + k] -= weight * delta * m_i * fv.getValue();
        // Cluster part.
        m_g[cOffset + k] -= weight * delta * m_c * m_gWeights[n] * fv.getValue();
        m_g[cOffset + m_dim + k] -= weight * delta * m_c * fv.getValue();
        // Global part.
        m_g[gOffset + k] -= weight * delta * m_u * m_gWeights[n] * fv.getValue();
        m_g[gOffset + m_dim + k] -= weight * delta * m_u * fv.getValue();
    }
}
Also used : structures._SparseFeature(structures._SparseFeature)

Example 90 with structures._SparseFeature

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

the class MTCLRWithDP method gradientByFunc.

@Override
protected void gradientByFunc(_AdaptStruct u, _Doc review, double weight, double[] g) {
    _DPAdaptStruct user = (_DPAdaptStruct) u;
    // feature index
    int n;
    int cIndex = user.getThetaStar().getIndex();
    if (cIndex < 0 || cIndex >= m_kBar)
        System.err.println("Error,cannot find the theta star!");
    int offset = m_dim * cIndex, offsetSup = m_dim * m_kBar;
    double delta = weight * (review.getYLabel() - logit(review.getSparse(), user));
    if (m_LNormFlag)
        delta /= getAdaptationSize(user);
    // 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._SparseFeature(structures._SparseFeature)

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