use of structures._RankItem in project IR_Base by Linda-sunshine.
the class asyncCoRegLR method gradientByR2.
@Override
protected void gradientByR2(_AdaptStruct user) {
_CoRegLRAdaptStruct ui = (_CoRegLRAdaptStruct) user, uj;
for (_RankItem nit : ui.getNeighbors()) {
uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
gradientByR2(ui, uj, nit.m_value);
}
for (_RankItem nit : ui.getReverseNeighbors()) {
uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
gradientByR2(ui, uj, nit.m_value);
}
}
use of structures._RankItem in project IR_Base by Linda-sunshine.
the class asyncCoRegLRFirstOrder method gradientDescent.
@Override
void gradientDescent(_CoRegLRAdaptStruct ui, double initStepSize, double inc) {
// update the current user
super.gradientDescent(ui, initStepSize, inc);
_CoRegLRAdaptStruct uj;
for (_RankItem nit : ui.getNeighbors()) {
uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
super.gradientDescent(uj, initStepSize, inc / 3);
}
for (_RankItem nit : ui.getReverseNeighbors()) {
uj = (_CoRegLRAdaptStruct) m_userList.get(nit.m_index);
super.gradientDescent(uj, initStepSize, inc / 3);
}
}
use of structures._RankItem in project IR_Base by Linda-sunshine.
the class PageRank method constructSparseGraph.
private void constructSparseGraph(ArrayList<_Doc> collection) {
m_N = collection.size();
// we need to make this very sparse!
m_transition = new SparseDoubleMatrix2D(m_N, m_N);
// construct the connection
MyPriorityQueue<_RankItem> queue = new MyPriorityQueue<_RankItem>(m_topK);
for (int i = 0; i < collection.size(); i++) {
_Doc di = collection.get(i);
// find k-nearest neighbor
for (int j = 0; j < collection.size(); j++) {
if (i != j)
queue.add(new _RankItem(j, Utils.dotProduct(di, collection.get(j))));
}
// transition probability is proportion to similarity
double sum = 0;
for (_RankItem item : queue) {
item.m_value = Math.exp(item.m_value);
sum += item.m_value;
}
// set up the transition
for (_RankItem item : queue) // i -> j
m_transition.setQuick(i, item.m_index, item.m_value / sum);
queue.clear();
}
}
use of structures._RankItem in project IR_Base by Linda-sunshine.
the class FeatureSelector method IG.
// Feature Selection -- IG.
public void IG(HashMap<String, _stat> featureStat, int[] classMemberNo) {
m_selectedFeatures.clear();
double classMemberSum = Utils.sumOfArray(classMemberNo);
// I
double[] PrCi = new double[classMemberNo.length];
// II
double[] PrCit = new double[classMemberNo.length];
// III
double[] PrCitNot = new double[classMemberNo.length];
double Prt = 0, PrtNot = 0;
// IG
double Gt = 0;
double PrCiSum = 0, PrCitSum = 0, PrCitNotSum = 0;
// - $sigma$PrCi * log PrCi
for (int i = 0; i < classMemberNo.length; i++) {
PrCi[i] = classMemberNo[i] / classMemberSum;
if (PrCi[i] != 0) {
PrCiSum -= PrCi[i] * Math.log(PrCi[i]);
}
}
for (String f : featureStat.keySet()) {
// Filter the features which have smaller DFs.
int sumDF = Utils.sumOfArray(featureStat.get(f).getDF());
if (sumDF > m_minDF && sumDF < m_maxDF) {
_stat temp = featureStat.get(f);
Prt = Utils.sumOfArray(temp.getDF()) / classMemberSum;
PrtNot = 1 - Prt;
PrCitSum = 0;
PrCitNotSum = 0;
for (int i = 0; i < classMemberNo.length; i++) {
PrCit[i] = ((double) temp.getDF()[i] / classMemberNo[i]) * PrCi[i] / Prt;
PrCitNot[i] = ((double) (classMemberNo[i] - temp.getDF()[i]) / classMemberNo[i]) * PrCi[i] / PrtNot;
if (PrCit[i] != 0) {
PrCitSum += PrCit[i] * Math.log(PrCit[i]);
}
if (PrCitNot[i] != 0) {
PrCitNotSum += PrCitNot[i] * Math.log(PrCi[i]);
}
}
Gt = PrCiSum + PrCitSum + PrCitNotSum;
m_selectedFeatures.add(new _RankItem(f, Gt));
}
}
}
use of structures._RankItem in project IR_Base by Linda-sunshine.
the class FeatureSelector method MI.
// Feature Selection -- MI.
public void MI(HashMap<String, _stat> featureStat, int[] classMemberNo) {
m_selectedFeatures.clear();
double[] PrCi = new double[classMemberNo.length];
double[] ItCi = new double[classMemberNo.length];
double N = Utils.sumOfArray(classMemberNo);
double Iavg = 0;
for (int i = 0; i < classMemberNo.length; i++) PrCi[i] = classMemberNo[i] / N;
for (String f : featureStat.keySet()) {
// Filter the features which have smaller DFs.
int sumDF = Utils.sumOfArray(featureStat.get(f).getDF());
if (sumDF > m_minDF && sumDF < m_maxDF) {
Iavg = 0;
for (int i = 0; i < classMemberNo.length; i++) {
_stat temp = featureStat.get(f);
double A = temp.getDF()[i];
ItCi[i] = Math.log(A * N / classMemberNo[i] * Utils.sumOfArray(temp.getDF()));
Iavg += ItCi[i] * PrCi[i];
}
m_selectedFeatures.add(new _RankItem(f, Iavg));
}
}
}
Aggregations