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