use of Classifier.supervised.modelAdaptation._AdaptStruct in project IR_Base by Linda-sunshine.
the class LinAdapt method loadUsers.
// Initialize the weights of the transformation matrix.
@Override
public void loadUsers(ArrayList<_User> userList) {
m_userList = new ArrayList<_AdaptStruct>();
for (_User user : userList) m_userList.add(new _LinAdaptStruct(user, m_dim));
m_pWeights = new double[m_gWeights.length];
}
use of Classifier.supervised.modelAdaptation._AdaptStruct in project IR_Base by Linda-sunshine.
the class WeightedAvgAdapt method constructUserList.
@Override
void constructUserList(ArrayList<_User> userList) {
int vSize = m_dim;
// step 1: create space
m_userList = new ArrayList<_AdaptStruct>();
for (int i = 0; i < userList.size(); i++) {
_User user = userList.get(i);
// we will not create transformation matrix for this user
m_userList.add(new _CoLinAdaptStruct(user, -1, i, m_topK));
// Initiate user weights with global weights.
user.setModel(m_gWeights);
}
m_pWeights = new double[m_gWeights.length];
// huge space consumption
_CoLinAdaptStruct.sharedA = new double[getVSize()];
// step 2: copy each user's weights to shared A(weights) in _CoLinAdaptStruct
for (int i = 0; i < m_userList.size(); i++) System.arraycopy(m_gWeights, 0, _CoLinAdaptStruct.sharedA, vSize * i, vSize);
}
use of Classifier.supervised.modelAdaptation._AdaptStruct in project IR_Base by Linda-sunshine.
the class CLRWithDP method trainTrace.
// added by Lin for tracking trace.
public double trainTrace(String data, int iter) {
m_numberOfIterations = iter;
System.out.println(toString());
double delta = 0, lastLikelihood = 0, curLikelihood = 0;
int count = 0;
// clear user performance and init cluster assignment
init();
// Burn in period.
while (count++ < m_burnIn) {
calculate_E_step();
lastLikelihood = calculate_M_step();
}
try {
String traceFile = String.format("%s_iter_%d_burnin_%d_thin_%d.txt", data, iter, m_burnIn, m_thinning);
PrintWriter writer = new PrintWriter(new File(traceFile));
// EM iteration.
for (int i = 0; i < m_numberOfIterations; i++) {
// Cluster assignment, thinning to reduce auto-correlation.
calculate_E_step();
// Optimize the parameters
curLikelihood = calculate_M_step();
delta = (lastLikelihood - curLikelihood) / curLikelihood;
if (i % m_thinning == 0) {
evaluateModel();
test();
for (_AdaptStruct u : m_userList) u.getPerfStat().clear();
}
writer.write(String.format("%.5f\t%.5f\t%d\t%.5f\t%.5f\n", curLikelihood, delta, m_kBar, m_perf[0], m_perf[1]));
printInfo();
System.out.print(String.format("[Info]Step %d: likelihood: %.4f, Delta_likelihood: %.3f\n", i, curLikelihood, delta));
if (Math.abs(delta) < m_converge)
break;
lastLikelihood = curLikelihood;
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
// we do not want to miss the last sample?!
evaluateModel();
setPersonalizedModel();
return curLikelihood;
}
use of Classifier.supervised.modelAdaptation._AdaptStruct in project IR_Base by Linda-sunshine.
the class CLRWithDP method saveClusterModels.
public void saveClusterModels(String model) {
PrintWriter writer;
String filename;
File dir = new File(model);
_thetaStar theta;
double[] weight;
try {
if (!dir.exists())
dir.mkdirs();
for (int i = 0; i < m_kBar; i++) {
theta = m_thetaStars[i];
filename = String.format("%s/%d.classifier", model, theta.getIndex());
writer = new PrintWriter(new File(filename));
weight = theta.getModel();
for (int v = 0; v < weight.length; v++) {
if (v == weight.length - 1)
writer.write(Double.toString(weight[v]));
else
writer.write(weight[v] + ",");
}
writer.close();
}
writer = new PrintWriter(new File(model + "/ClusterMember.txt"));
for (_AdaptStruct u : m_userList) {
_DPAdaptStruct user = (_DPAdaptStruct) u;
writer.write(user.getUserID() + "\t" + user.getThetaStar().getIndex() + "\n");
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of Classifier.supervised.modelAdaptation._AdaptStruct in project IR_Base by Linda-sunshine.
the class CLinAdaptWithKmeans method loadUsers.
// Initialize the weights of the transformation matrix.
@Override
public void loadUsers(ArrayList<_User> userList) {
int totalUserSize = userList.size();
// step 1: create space
m_userList = new ArrayList<_AdaptStruct>();
for (int i = 0; i < userList.size(); i++) {
_User user = userList.get(i);
m_userList.add(new _CLinAdaptStruct(user, m_dim, i, totalUserSize, m_clusterSize));
}
m_pWeights = new double[m_gWeights.length];
// step1: init the shared A: individual + cluster + global
_CLinAdaptStruct.sharedA = new double[getVSize()];
for (int i = 0; i < m_userList.size() + m_clusterSize; i++) {
for (int j = 0; j < m_dim; j++) {
_CLinAdaptStruct.sharedA[i * m_dim * 2 + j] = 1;
}
}
}
Aggregations