Skip to content

Commit b0c6c4f

Browse files
committed
Code tidying
1 parent 2eb49b8 commit b0c6c4f

8 files changed

Lines changed: 85 additions & 348 deletions

File tree

src/main/java/edu/virginia/uvacluster/internal/Graph.java

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ private String getRootName() {
4747

4848
//returns a set of node names in the form "Statistic: Feature (TotalBins)"
4949
public Set<String> loadModelFrom(CyNetwork network) {
50-
System.out.println("----------------LOAD MODEL FROM CYTOSCAPE NETWORK ----------------");
5150
Set<String> features = new HashSet<String>();
5251
Map<CyNode, List<Node>> nodeMap = new HashMap<CyNode, List<Node>>();
5352
List<CyNode> originLevel = new ArrayList<CyNode>(),
@@ -74,11 +73,9 @@ public Set<String> loadModelFrom(CyNetwork network) {
7473
for (CyNode origin: originLevel) {
7574
nodesVisited.add(origin);
7675
destinationLevel.removeAll(network.getNeighborList(origin, Type.OUTGOING)); //to prevent duplicates
77-
// System.out.println("Size of destination level: " + destinationLevel.size());
7876
destinationLevel.addAll(network.getNeighborList(origin, Type.OUTGOING));
7977
for (CyNode destination: destinationLevel) {
8078

81-
// System.out.println("Origin: " + origin.getSUID() + ", Destination: " + destination.getSUID());
8279
parentNumNodes.clear();
8380
parentNumNodesVisited.clear();
8481
for (CyNode parent: network.getNeighborList(destination, Type.INCOMING)) {
@@ -100,46 +97,24 @@ public Set<String> loadModelFrom(CyNetwork network) {
10097
featureDesc = spacesPattern.matcher(featureDesc).replaceAll(" ").trim();
10198
features.add(nodeName);
10299
newNodes = toNodeBins;
103-
// for (Integer numNodes: parentNumNodes) {newNodes *= numNodes;}
104100
nodesPerBin = newNodes/toNodeBins;
105101
for (int i = 0; i < newNodes; i++) {
106-
// System.out.println("newNodes: " + newNodes);
107102
//Order of bins in list is important, note integer division
108-
// System.out.println("Graph size before: " + this.getRoot().getChildren().size() + " -- node being added: " + featureDesc + " (" + (i/nodesPerBin) + "/" + toNodeBins + ")");
109-
110103
Node currentNode = new Node(featureDesc, new Bin((i/nodesPerBin)+1,toNodeBins));
111-
// printNode(currentNode);
112104
nodeMap.get(destination).add(new Node(featureDesc, new Bin((i/nodesPerBin)+1,toNodeBins)));
113-
// System.out.println("Graph size after: " + this.getRoot().getChildren().size());
114105
}
115106
}
116107

117108
//create edges for internal origin nodes
118109
fromNodes = nodeMap.get(origin);
119110
toNodes = nodeMap.get(destination);
120-
for (Integer parentNodesVisited: parentNumNodesVisited) {reps *= parentNodesVisited;}
121-
// System.out.println("Reps - 1: " + reps);
122-
reps /= fromNodes.size();
123-
// System.out.println("Reps - 2: " + reps);
124111

125112
for (Node fromNode : fromNodes) {
126113
for (Node toNode : toNodes) {
127114
fromNode.addChild(toNode);
128115
}
129116
}
130-
// for (int toNode = 0, fromNode = 0, i = 0; toNode < toNodes.size(); toNode++) {
131-
// System.out.println("Reps - 3: " + reps);
132-
// System.out.println("FROM");
133-
// printNode(fromNodes.get(fromNode));
134-
// System.out.println("TO");
135-
// printNode(toNodes.get(toNode));
136-
// if (i == reps) {
137-
// fromNode = (fromNode + 1)%fromNodes.size();
138-
// i = 0;
139-
// }
140-
// fromNodes.get(fromNode).addChild(toNodes.get(toNode));
141-
// i++;
142-
// }
117+
143118
}
144119
}
145120
} while (destinationLevel.size() > 0);
@@ -304,59 +279,25 @@ public ArrayList<Child> getChildFeatures(Child c, HashSet<String> visitedChildre
304279

305280
public void trainBins(List<Cluster> clusters) {
306281
// trainBinning() gets the range of each feature
307-
// System.out.println("Before trainBinning: the size of the graph is: " + this.getRoot().getChildren().size());
308282
for (Cluster cluster: clusters) {
309283
cluster.trainBinning();
310-
// System.out.println("After trainBinning: the size of the graph is: " + this.getRoot().getChildren().size());
311284
}
312-
System.out.println("Cluster train binning complete");
313285
}
314286

315287
public void trainOn(List<Cluster> clusters) {
316-
System.out.println("Start training on clusters");
317-
// System.out.println("----PRINTING FEATURE NETWORK------");
318-
// printNetwork();
319288
Map<String, Bin> featureMap;
320289
List<Child> currentLevel = new ArrayList<Child>();
321290
List<Child> nextLevel = new ArrayList<Child>();
322291

323292
for (Cluster cluster: clusters) {
324293
featureMap = cluster.getBinMap();
325-
// for (String feature: featureMap.keySet()) {
326-
// System.out.println("For cluster " + cluster.getSUID() + ":");
327-
// System.out.println("\tFeature= " + feature + "\tBin=" + featureMap.get(feature).number);
328-
// }
329-
// System.out.println("Cluster: " + cluster.getSUID());
330-
// featureMap = cluster.getNewBinMap();
331-
// System.out.println("In trainOn: the size of the featureMap for cluster " + cluster.getSUID() + " is: " + featureMap.size());
332-
// System.out.println("In trainOn: the size of the graph is: " + this.getRoot().getChildren().size());
333294
nextLevel.addAll(root.getChildren());
334295

335296
for (Child child : getRootFeatures()) {
336297
System.out.println(child.getName());
337298
child.addTo(featureMap.get(child.getName()).number);
338299
}
339-
340-
341-
// scanGraph(featureMap);
342-
// do {
343-
// currentLevel.clear();
344-
// currentLevel.addAll(nextLevel);
345-
// nextLevel.clear();
346-
// for (Child child: currentLevel) {
347-
//// System.out.println("in child: currentLevel -- CHILD = " + child.getName());
348-
// nextLevel.removeAll(child.getChildren());
349-
// nextLevel.addAll(child.getChildren());
350-
// child.addTo(featureMap.get(child.getName()).number);
351-
// }
352-
// } while(nextLevel.size() > 0);
353300
}
354-
355-
// for (Child child : getRootFeatures()) {
356-
// System.out.println(child.getName() + " #" + child.getNode().getBin() + " : " + child.count);
357-
// }
358-
359-
System.out.println("Done training on clusters");
360301
}
361302

362303
public double score(Cluster cluster) {
@@ -372,11 +313,6 @@ public double score(Cluster cluster) {
372313
score *= child.score(features.get(child.getName()).number);
373314
}
374315
}
375-
// System.out.println("\t\t" + cluster.getSUID() + ": " + score);
376-
// for (Child child: root.getChildren()) {
377-
// score *= child.score(features.get(child.getName()).number);
378-
// score *= childScore(child, cluster);
379-
// }
380316
return score;
381317
}
382318

@@ -396,17 +332,10 @@ public double childScore(Child child, Cluster cluster) {
396332

397333
public void printNode(Node n) {
398334
System.out.println("Children of the node: " + n.getDisplayName());
399-
// for (Child c : n.children) {
400-
// printChild(c);
401-
// }
402335
}
403336

404337
public void printChild(Child c) {
405338
System.out.println("\t\t" + c.getName());
406-
// for (Child c2 : c.getChildren()) {
407-
// System.out.print("Children of the child node: " + c.getName());
408-
// printChild(c2);
409-
// }
410339
}
411340

412341
private void resetGraph() {root.reset();}
@@ -415,10 +344,7 @@ private void scanGraph(Map<String, Bin> features) {
415344
List<Child> currentLevel = new ArrayList<Child>();
416345
List<Child> nextLevel = new ArrayList<Child>();
417346
nextLevel.addAll(root.getChildren());
418-
// System.out.println("About to reset graph");
419-
// System.out.println("The name of the root node is: " + root.getDisplayName());
420347
resetGraph();
421-
// System.out.println("In scanGraph: reset graph done");
422348
root.activate();
423349
do {
424350
currentLevel.clear();
@@ -464,9 +390,7 @@ public Child addChild(Node n) {
464390
}
465391
public void reset() {
466392
active = false;
467-
// System.out.println("The node " + getDisplayName() + " has size " + children.size());
468393
for (Child child: children) {
469-
// System.out.println("The child about to be reset is: " + child.getName());
470394
child.reset();
471395
}
472396
}
@@ -500,7 +424,6 @@ public void addTo(int bin) {
500424
// if (node.parentsActive()) {
501425
if (node.getBin() == bin) {
502426
count++;
503-
// System.out.println(this.getName() + " # " + bin + " : " + count);
504427
}
505428
totalSamples++;
506429
probability = ((double)count + 1.0) / ((double)totalSamples + (double)node.getTotalBins());
@@ -511,7 +434,6 @@ public double score(int bin) {
511434
double score = 1;
512435
if (node.parentsActive()) {
513436
if(node.getBin() == bin) {
514-
// System.out.println("\t\tChild.score-Scoring on " + this.getName() + " - bin #" + node.getBin() + ": score = score*" + probability);
515437
score = probability;
516438
}
517439
}

0 commit comments

Comments
 (0)