use of structures._RankItem in project IR_Base by Linda-sunshine.
the class CoLinAdaptWithDiffFeatureGroups method calculateFuncValue.
// There is still issue in calculating R2 since we don't know which set to use for a user.
@Override
protected double calculateFuncValue(_AdaptStruct u) {
double fValue = super.calculateFuncValue(u), R1 = 0, R2 = 0, diffA, diffB;
_CoLinAdaptDiffFvGroupsStruct ui = (_CoLinAdaptDiffFvGroupsStruct) u, uj;
// Add R1 for another class.
for (int i = 0; i < m_dimB; i++) {
// (a[i]-1)^2
R1 += m_eta1 * (ui.getScalingB(i) - 1) * (ui.getScalingB(i) - 1);
// b[i]^2
R1 += m_eta2 * ui.getShiftingB(i) * ui.getShiftingB(i);
}
// R2 regularization
for (_RankItem nit : ui.getNeighbors()) {
uj = (_CoLinAdaptDiffFvGroupsStruct) m_userList.get(nit.m_index);
diffA = 0;
diffB = 0;
// We also need to sum over the other set of parameters.
for (int k = 0; k < m_dimB; k++) {
diffA += (ui.getScalingB(k) - uj.getScalingB(k)) * (ui.getScalingB(k) - uj.getScalingB(k));
diffB += (ui.getShiftingB(k) - uj.getShiftingB(k)) * (ui.getShiftingB(k) - uj.getShiftingB(k));
}
R2 += nit.m_value * (m_eta3 * diffA + m_eta4 * diffB);
}
return fValue + R1 + R2;
}
use of structures._RankItem in project IR_Base by Linda-sunshine.
the class CoLinAdaptWithNeighborhoodLearning method constructXijs.
// Construct all training instances.
public void constructXijs() {
// Index of neighbors.
int j = 0;
_CoLinAdaptStruct ui;
m_xijs = new double[m_topK * m_userList.size()][];
for (int i = 0; i < m_userList.size(); i++) {
ui = (_CoLinAdaptStruct) m_userList.get(i);
j = 0;
// Traverse all neighbors.
for (_RankItem nit : ui.getNeighbors()) {
// Construct the training instance.
m_xijs[m_topK * i + j] = constructXij(ui.getUser(), m_userList.get(nit.m_index).getUser());
j++;
}
}
}
use of structures._RankItem in project IR_Base by Linda-sunshine.
the class MTCoLinAdapt method calculateFuncValue.
@Override
protected // Calculate the function value of the new added instance.
double calculateFuncValue(_AdaptStruct u) {
double fValue = super.calculateFuncValue(u), R2 = 0, diffA, diffB;
// R2 regularization
_CoLinAdaptStruct ui = (_CoLinAdaptStruct) u, uj;
for (_RankItem nit : ui.getNeighbors()) {
uj = (_CoLinAdaptStruct) m_userList.get(nit.m_index);
diffA = 0;
diffB = 0;
for (int k = 0; k < m_dim; k++) {
diffA += (ui.getScaling(k) - uj.getScaling(k)) * (ui.getScaling(k) - uj.getScaling(k));
diffB += (ui.getShifting(k) - uj.getShifting(k)) * (ui.getShifting(k) - uj.getShifting(k));
}
R2 += nit.m_value * (m_eta3 * diffA + m_eta4 * diffB);
}
return fValue + R2;
}
use of structures._RankItem in project IR_Base by Linda-sunshine.
the class WeightedAvgAdapt method setPersonalizedModel.
@Override
public void setPersonalizedModel() {
_CoLinAdaptStruct ui;
double[] pWeights;
int offset;
for (int i = 0; i < m_userList.size(); i++) {
ui = (_CoLinAdaptStruct) m_userList.get(i);
pWeights = ui.getPWeights();
offset = i * m_dim;
for (int n = 0; n < m_dim; n++) pWeights[n] = ui.getSelfSim() * _CoLinAdaptStruct.sharedA[offset + n];
// traverse all the neighbors
for (_RankItem nit : ui.getNeighbors()) {
// get neighbor's index
offset = nit.m_index * m_dim;
for (int n = 0; n < m_dim; n++) pWeights[n] += nit.m_value * _CoLinAdaptStruct.sharedA[offset + n];
}
}
}
use of structures._RankItem in project IR_Base by Linda-sunshine.
the class WeightedAvgTransAdapt method gradientByFunc.
// shared gradient calculation by batch and online updating
@Override
protected void gradientByFunc(_AdaptStruct u, _Doc review, double weight) {
_CoLinAdaptStruct ui = (_CoLinAdaptStruct) u;
int n, k, offsetj;
// general enough to accommodate both LinAdapt and CoLinAdapt
int offset = m_dim * ui.getId();
double delta = weight * (review.getYLabel() - logit(review.getSparse(), ui));
if (m_LNormFlag)
delta /= getAdaptationSize(ui);
// Current user's info: Bias term + other features.
// \theta_{ii}*w_g[0]*x_0 and x_0=1
m_g[offset] -= delta * ui.getSelfSim() * m_gWeights[0];
// \theta_{ii}*x_0
m_g[offset + m_dim] -= delta * ui.getSelfSim();
for (_SparseFeature fv : review.getSparse()) {
n = fv.getIndex() + 1;
k = m_featureGroupMap[n];
// \theta_{ii}*x_d
m_g[offset + k] -= delta * ui.getSelfSim() * m_gWeights[n] * fv.getValue();
m_g[offset + k + m_dim] -= delta * ui.getSelfSim() * fv.getValue();
}
// Neighbors' info: Bias term + other features.
for (_RankItem nit : ui.getNeighbors()) {
offsetj = 2 * m_dim * nit.m_index;
// Bias term.
// neighbors' bias term.
m_g[offsetj] -= delta * nit.m_value * m_gWeights[0];
m_g[offsetj + m_dim] -= delta * nit.m_value;
for (_SparseFeature fv : review.getSparse()) {
n = fv.getIndex() + 1;
k = m_featureGroupMap[n];
// neighbors' other features.
m_g[offsetj + k] -= delta * nit.m_value * m_gWeights[n] * fv.getValue();
m_g[offsetj + m_dim + k] -= delta * nit.m_value * fv.getValue();
}
}
}
Aggregations