use of structures._HDPThetaStar._Connection in project IR_Base by Linda-sunshine.
the class CLRWithMMB method addConnection.
// add the edge assignment to corresponding cluster
public void addConnection(_MMBAdaptStruct ui, _MMBAdaptStruct uj, int e) {
_HDPThetaStar theta_g, theta_h;
theta_g = ui.getOneNeighbor(uj).getHDPThetaStar();
theta_h = uj.getOneNeighbor(ui).getHDPThetaStar();
theta_g.addConnection(theta_h, e);
theta_h.addConnection(theta_g, e);
}
use of structures._HDPThetaStar._Connection in project IR_Base by Linda-sunshine.
the class CLRWithMMB method saveClusterLanguageModels.
// Save the language models of thetaStars
public void saveClusterLanguageModels(String model) {
PrintWriter writer;
String filename;
File dir = new File(model);
_HDPThetaStar theta;
double[] lm;
try {
if (!dir.exists())
dir.mkdirs();
for (int i = 0; i < m_kBar; i++) {
theta = m_hdpThetaStars[i];
filename = String.format("%s/%d.lm", model, theta.getIndex());
writer = new PrintWriter(new File(filename));
lm = theta.getLMStat();
for (int v = 0; v < lm.length; v++) {
if (v == lm.length - 1)
writer.write(Double.toString(lm[v]));
else
writer.write(lm[v] + ",");
}
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
use of structures._HDPThetaStar._Connection in project IR_Base by Linda-sunshine.
the class CLRWithMMB method rmConnection.
// remove the connection between ui and uj, where i->j \in g, j->i \in h.
public void rmConnection(_MMBAdaptStruct ui, _MMBAdaptStruct uj, int e) {
_HDPThetaStar theta_g, theta_h;
theta_g = ui.getOneNeighbor(uj).getHDPThetaStar();
theta_h = uj.getOneNeighbor(ui).getHDPThetaStar();
theta_g.rmConnection(theta_h, e);
theta_h.rmConnection(theta_g, e);
}
use of structures._HDPThetaStar._Connection in project IR_Base by Linda-sunshine.
the class CLinAdaptWithMMB method loadUsers.
@Override
public void loadUsers(ArrayList<_User> userList) {
m_userList = new ArrayList<_AdaptStruct>();
// Init each user.
for (_User user : userList) {
m_userList.add(new _MMBAdaptStruct(user, m_dim));
}
m_pWeights = new double[m_gWeights.length];
m_indicator = new _HDPThetaStar[m_userList.size()][m_userList.size()];
}
use of structures._HDPThetaStar._Connection in project IR_Base by Linda-sunshine.
the class MTCLinAdaptWithMMB method gradientByFunc.
@Override
protected void gradientByFunc(_AdaptStruct u, _Doc review, double weight, double[] g) {
_Review r = (_Review) review;
_HDPThetaStar theta = r.getHDPThetaStar();
// feature index
int n, k, s;
int cIndex = theta.getIndex();
if (cIndex < 0 || cIndex >= m_kBar)
System.err.println("Error,cannot find the theta star!");
int offset = m_dim * 2 * cIndex, offsetSup = m_dim * 2 * m_kBar;
double[] Au = theta.getModel();
double delta = (review.getYLabel() - logit(review.getSparse(), r)) * weight;
// Bias term for individual user.
// a[0] = ws0*x0; x0=1
g[offset] -= delta * getSupWeights(0);
// b[0]
g[offset + m_dim] -= delta;
// Bias term for super user.
// a_s[0] = a_i0*w_g0*x_d0
g[offsetSup] -= delta * Au[0] * m_gWeights[0];
// b_s[0] = a_i0*x_d0
g[offsetSup + m_dimSup] -= delta * Au[0];
// 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 * getSupWeights(n) * fv.getValue();
// x_di
g[offset + m_dim + k] -= delta * fv.getValue();
s = m_featureGroupMap4SupUsr[n];
// a_i*w_gi*x_di
g[offsetSup + s] -= delta * Au[k] * m_gWeights[n] * fv.getValue();
// a_i*x_di
g[offsetSup + m_dimSup + s] -= delta * Au[k] * fv.getValue();
}
}
Aggregations