use of structures._RankItem in project IR_Base by Linda-sunshine.
the class ModelAdaptation method constructReverseNeighborhood.
protected int[] constructReverseNeighborhood() {
// total number of adaptation instances
int adaptSize = 0;
// construct the reverse link
CoAdaptStruct ui, uj;
for (int i = 0; i < m_userList.size(); i++) {
ui = (CoAdaptStruct) (m_userList.get(i));
for (_RankItem nit : ui.getNeighbors()) {
// uj is a neighbor of ui
uj = (CoAdaptStruct) (m_userList.get(nit.m_index));
uj.addReverseNeighbor(i, nit.m_value);
}
adaptSize += ui.getAdaptationSize();
}
// construct the order of online updating
ArrayList<_RankItem> userorder = new ArrayList<_RankItem>();
for (int i = 0; i < m_userList.size(); i++) {
ui = (CoAdaptStruct) (m_userList.get(i));
for (_Review r : ui.getReviews()) {
// reviews in each user is already ordered by time
if (r.getType() == rType.ADAPTATION) {
// to be in ascending order
userorder.add(new _RankItem(i, r.getTimeStamp()));
}
}
}
Collections.sort(userorder);
int[] userOrder = new int[adaptSize];
for (int i = 0; i < adaptSize; i++) userOrder[i] = userorder.get(i).m_index;
return userOrder;
}
use of structures._RankItem in project IR_Base by Linda-sunshine.
the class CoRegLR method gradientByR2.
// Calculate the gradients for the use in LBFGS.
protected void gradientByR2(_AdaptStruct user) {
_CoRegLRAdaptStruct ui = (_CoRegLRAdaptStruct) user, uj;
int vSize = m_featureSize + 1, offseti = vSize * ui.getId(), offsetj;
double coef, diff;
for (_RankItem nit : ui.getNeighbors()) {
uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
offsetj = vSize * uj.getId();
coef = 2 * m_eta2 * nit.m_value;
for (int k = 0; k < vSize; k++) {
diff = coef * (ui.getPWeight(k) - uj.getPWeight(k));
// update ui's gradient
m_g[offseti + k] += diff;
// update uj's gradient
m_g[offsetj + k] -= diff;
}
}
}
use of structures._RankItem in project IR_Base by Linda-sunshine.
the class CoRegLR method calculateFuncValue.
@Override
protected double calculateFuncValue(_AdaptStruct u) {
double fValue = super.calculateFuncValue(u), R2 = 0;
// R2 regularization
_CoRegLRAdaptStruct ui = (_CoRegLRAdaptStruct) u, uj;
for (_RankItem nit : ui.getNeighbors()) {
uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
double diff, sum = 0;
for (int i = 0; i <= m_featureSize; i++) {
diff = ui.getPWeight(i) - uj.getPWeight(i);
sum += diff * diff;
}
R2 += nit.m_value * sum;
}
return fValue + m_eta2 * R2;
}
use of structures._RankItem in project IR_Base by Linda-sunshine.
the class asyncCoRegLRFirstOrder method gradientByRelatedR1.
// compute gradient for all related user in first order connection (exclude itself)
void gradientByRelatedR1(_CoRegLRAdaptStruct ui) {
_CoRegLRAdaptStruct uj;
for (_RankItem nit : ui.getNeighbors()) {
uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
gradientByR1(uj);
}
for (_RankItem nit : ui.getReverseNeighbors()) {
uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
gradientByR1(uj);
}
}
use of structures._RankItem in project IR_Base by Linda-sunshine.
the class DCMLDA_test method printTopWord.
protected void printTopWord(int k, String topWordFile) {
System.out.println("TopWord FilePath:" + topWordFile);
Arrays.fill(m_sstat, 0);
for (_Doc d : m_trainSet) {
for (int i = 0; i < number_of_topics; i++) m_sstat[i] += m_logSpace ? Math.exp(d.m_topics[i]) : d.m_topics[i];
}
Utils.L1Normalization(m_sstat);
try {
PrintWriter topWordWriter = new PrintWriter(new File(topWordFile));
for (int i = 0; i < topic_term_probabilty.length; i++) {
MyPriorityQueue<_RankItem> fVector = new MyPriorityQueue<_RankItem>(k);
for (int j = 0; j < vocabulary_size; j++) fVector.add(new _RankItem(m_corpus.getFeature(j), topic_term_probabilty[i][j]));
topWordWriter.format("Topic %d(%.5f):\t", i, m_sstat[i]);
for (_RankItem it : fVector) topWordWriter.format("%s(%.5f)\t", it.m_name, m_logSpace ? Math.exp(it.m_value) : it.m_value);
topWordWriter.write("\n");
}
topWordWriter.close();
} catch (Exception ex) {
System.err.print("File Not Found");
}
}
Aggregations