use of structures._Node in project IR_Base by Linda-sunshine.
the class GaussianFieldsByRandomWalk method randomWalkByWeightedSum.
// The random walk algorithm to generate new labels for unlabeled data.
// Take the average of all neighbors as the new label until they converge.
double randomWalkByWeightedSum() {
// construct the sparse graph on the fly every time
double wL = m_alpha, wU = m_beta, acc = 0;
_Node node;
/**
** Construct the C+scale*\Delta matrix and Y vector. ***
*/
for (int i = 0; i < m_U; i++) {
node = m_nodeList[i];
double wijSumU = 0, wijSumL = 0;
double fSumU = 0, fSumL = 0;
/**
**Walk through the top k' unlabeled neighbor for the current data.***
*/
for (_Edge edge : node.m_unlabeledEdges) {
// get the similarity between two nodes.
wijSumU += m_simFlag ? edge.getSimilarity() : 1;
fSumU += m_simFlag ? edge.getSimilarity() * edge.getPred() : edge.getPred();
}
/**
**Walk through the top k labeled neighbor for the current data.***
*/
for (_Edge edge : node.m_labeledEdges) {
// get the similarity between two nodes.
wijSumL += m_simFlag ? edge.getSimilarity() : 1;
fSumL += m_simFlag ? edge.getSimilarity() * edge.getPred() : edge.getPred();
}
node.m_pred = m_eta * (fSumL * wL + fSumU * wU) / (wijSumL * wL + wijSumU * wU) + (1 - m_eta) * node.m_classifierPred;
if (Double.isNaN(node.m_pred)) {
System.out.format("Encounter NaN in random walk!\nfSumL: %.3f, fSumU: %.3f, wijSumL: %.3f, wijSumU: %.3f\n", fSumL, fSumU, wijSumL, wijSumU);
System.exit(-1);
} else if ((int) node.m_label == getLabel(node.m_pred))
acc++;
}
return acc / m_U;
}
use of structures._Node in project IR_Base by Linda-sunshine.
the class GaussianFieldsByRandomWalk method calcMeanVar4OneNode.
public double[] calcMeanVar4OneNode(_Node n) {
double[] stat4OneNode = new double[4];
double sum = 0, mean = 0, var = 0;
_Edge neighbor;
for (int j = 0; j < m_kPrime; j++) {
neighbor = n.m_unlabeledEdges.get(j);
sum += neighbor.getSimilarity();
}
mean = sum / m_kPrime;
// mean of unlabeled neighbors' similarities.
stat4OneNode[0] = mean;
for (int j = 0; j < m_kPrime; j++) {
neighbor = n.m_unlabeledEdges.get(j);
var += (neighbor.getSimilarity() - mean) * (neighbor.getSimilarity() - mean);
}
var = Math.sqrt(var / m_kPrime);
// variance of unlabeled neighbors' similarities.
stat4OneNode[1] = var;
// clear for the calculation of the labeled neighbors.
sum = 0;
// clear for the calculation of the labeled neighbors.
mean = 0;
// clear for the calculation of the labeled neighbors.
var = 0;
for (int j = 0; j < m_k; j++) {
neighbor = n.m_labeledEdges.get(j);
sum += neighbor.getSimilarity();
}
mean = sum / m_k;
// mean of unlabeled neighbors' similarities.
stat4OneNode[2] = mean;
for (int j = 0; j < m_k; j++) {
neighbor = n.m_labeledEdges.get(j);
var += (neighbor.getSimilarity() - mean) * (neighbor.getSimilarity() - mean);
}
var = Math.sqrt(var / m_k);
// variance of unlabeled neighbors' similarities.
stat4OneNode[3] = var;
return stat4OneNode;
}
use of structures._Node in project IR_Base by Linda-sunshine.
the class GaussianFieldsByRandomWalk method randomWalkByMajorityVote.
// Take the majority of all neighbors(k+k') as the new label until they converge.
double randomWalkByMajorityVote() {
// construct the sparse graph on the fly every time
double similarity = 0, acc = 0;
int label;
double wL = m_eta * m_alpha, wU = m_eta * m_beta;
_Node node;
/**
** Construct the C+scale*\Delta matrix and Y vector. ***
*/
for (int i = 0; i < m_U; i++) {
node = m_nodeList[i];
Arrays.fill(m_cProbs, 0);
/**
**Walk through the top k' unlabeled neighbor for the current data.***
*/
for (_Edge edge : node.m_unlabeledEdges) {
// Item n's label.
label = getLabel(edge.getPred());
similarity = edge.getSimilarity();
m_cProbs[label] += m_simFlag ? similarity * wU : wU;
}
/**
**Walk through the top k labeled neighbor for the current data.***
*/
for (_Edge edge : node.m_labeledEdges) {
label = (int) edge.getLabel();
similarity = edge.getSimilarity();
m_cProbs[label] += m_simFlag ? similarity * wL : wL;
}
/**
**Multiple learner's prediction.***
*/
label = (int) node.m_classifierPred;
m_cProbs[label] += 1 - m_eta;
node.m_pred = Utils.argmax(m_cProbs);
if (node.m_label == node.m_pred)
acc++;
}
return acc / m_U;
}
use of structures._Node in project IR_Base by Linda-sunshine.
the class GaussianFieldsByRandomWalk method checkSimilarityVariance.
// Check the mean and variance of the
public void checkSimilarityVariance() {
double[] stat;
double[] avgStat = new double[4];
_Node node;
for (int i = 0; i < m_U; i++) {
node = m_nodeList[i];
stat = calcMeanVar4OneNode(node);
avgStat = addOneNodeStat(avgStat, stat);
}
for (int i = 0; i < avgStat.length; i++) {
avgStat[i] = avgStat[i] / m_U;
}
m_simiStat[m_foldCount++] = avgStat;
}
use of structures._Node in project IR_Base by Linda-sunshine.
the class PairwiseSimCalculator method constructNodes.
void constructNodes() {
_Doc d;
for (int i = m_start; i < m_end; i++) {
d = m_GFObj.getTestDoc(i);
m_GFObj.m_nodeList[i] = new _Node(i, d.getYLabel(), m_GFObj.predict(d));
}
}
Aggregations