Skip to content

Commit 6074177

Browse files
committed
Updated panel layout
1 parent d37cbd4 commit 6074177

7 files changed

Lines changed: 156 additions & 98 deletions

File tree

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ public void trainOn(List<Cluster> clusters) {
332332
// System.out.println("In trainOn: the size of the graph is: " + this.getRoot().getChildren().size());
333333
nextLevel.addAll(root.getChildren());
334334

335-
336335
for (Child child : getRootFeatures()) {
337336
child.addTo(featureMap.get(child.getName()).number);
338337
}
@@ -351,6 +350,11 @@ public void trainOn(List<Cluster> clusters) {
351350
// }
352351
// } while(nextLevel.size() > 0);
353352
}
353+
354+
// for (Child child : getRootFeatures()) {
355+
// System.out.println(child.getName() + " #" + child.getNode().getBin() + " : " + child.count);
356+
// }
357+
354358
System.out.println("Done training on clusters");
355359
}
356360

@@ -360,8 +364,12 @@ public double score(Cluster cluster) {
360364

361365
scanGraph(features);
362366
for (Child child : getRootFeatures()) {
363-
if (features.get(child.getName()).number < 0)
364-
score *= child.score(features.get(child.getName()).number);
367+
if (features.get(child.getName()).number < 0) {
368+
// Value for the feature is outside the bins
369+
score *= child.scoreValOutsideRange();
370+
} else {
371+
score *= child.score(features.get(child.getName()).number);
372+
}
365373
}
366374
// System.out.println("\t\t" + cluster.getSUID() + ": " + score);
367375
// for (Child child: root.getChildren()) {
@@ -490,8 +498,8 @@ public Child(Node x) {
490498
public void addTo(int bin) {
491499
// if (node.parentsActive()) {
492500
if (node.getBin() == bin) {
493-
// System.out.println("\t\tJust added to " + this.getName() + " - bin # " + bin);
494501
count++;
502+
// System.out.println(this.getName() + " # " + bin + " : " + count);
495503
}
496504
totalSamples++;
497505
probability = ((double)count + 1.0) / ((double)totalSamples + (double)node.getTotalBins());
@@ -508,6 +516,13 @@ public double score(int bin) {
508516
}
509517
return score;
510518
}
519+
520+
public double scoreValOutsideRange() {
521+
totalSamples++;
522+
return 1.0 / ((double)totalSamples + (double)node.getTotalBins());
523+
}
524+
525+
511526
public void activate(int bin) {
512527
if (node.parentsActive()) {
513528
if (node.getBin() == bin) {

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

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.awt.FlowLayout;
77
import java.awt.GridBagConstraints;
88
import java.awt.GridBagLayout;
9+
import java.awt.GridLayout;
910
import java.awt.Insets;
1011
import java.awt.event.ActionEvent;
1112
import java.awt.event.ActionListener;
@@ -380,15 +381,20 @@ public JPanel createAdvancedTrainParams() {
380381
layout.setHorizontalGroup(
381382
layout.createSequentialGroup()
382383
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
384+
.addComponent(clusterPriorLabel)
383385
.addComponent(negativeExamplesLabel)
384386
.addComponent(ignoreMissingLabel))
385387
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
388+
.addComponent(clusterPrior)
386389
.addComponent(negativeExamples)
387390
.addComponent(ignoreMissing))
388391
);
389392

390393
layout.setVerticalGroup(
391394
layout.createSequentialGroup()
395+
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
396+
.addComponent(clusterPriorLabel)
397+
.addComponent(clusterPrior))
392398
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
393399
.addComponent(negativeExamplesLabel)
394400
.addComponent(negativeExamples))
@@ -414,28 +420,20 @@ public JPanel createAdvancedScoreParams() {
414420
// Minimum acceptable score
415421
minScoreThreshold = new JTextField("0");
416422
minScoreThresholdLabel = new JLabel("Minimum Complex Score");
417-
418-
clusterPrior = new JTextField("1E-4");
419-
clusterPriorLabel = new JLabel("Cluster Probability Prior");
420423

421424
layout.setHorizontalGroup(
422425
layout.createSequentialGroup()
423426
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
424-
.addComponent(minScoreThresholdLabel)
425-
.addComponent(clusterPriorLabel))
427+
.addComponent(minScoreThresholdLabel))
426428
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
427-
.addComponent(minScoreThreshold)
428-
.addComponent(clusterPrior))
429+
.addComponent(minScoreThreshold))
429430
);
430431

431432
layout.setVerticalGroup(
432433
layout.createSequentialGroup()
433434
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
434435
.addComponent(minScoreThresholdLabel)
435436
.addComponent(minScoreThreshold))
436-
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
437-
.addComponent(clusterPriorLabel)
438-
.addComponent(clusterPrior))
439437
);
440438

441439
}
@@ -706,15 +704,22 @@ public void actionPerformed(ActionEvent e)
706704
gbc.gridy = 0;
707705
scorePanel.add(weightScoreOption, gbc);
708706
gbc.gridy = 1;
709-
scorePanel.add(trainedModelOption, gbc);
710-
gbc.gridy = 2;
711707
scorePanel.add(learningScoreOption, gbc);
708+
gbc.gridy = 2;
709+
scorePanel.add(outerTrainPanel, gbc);
712710
gbc.gridy = 3;
713-
scorePanel.add(trainedModel, gbc);
711+
scorePanel.add(trainedModelOption, gbc);
714712
gbc.gridy = 4;
715-
scorePanel.add(outerTrainPanel, gbc);
716-
gbc.gridy = 5;
717-
scorePanel.add(advancedScorePanel, gbc);
713+
scorePanel.add(trainedModel, gbc);
714+
715+
JPanel minScorePanel = new JPanel(new GridLayout(1, 0));
716+
minScorePanel.add(minScoreThresholdLabel, gbc);
717+
minScorePanel.add(minScoreThreshold, gbc);
718+
minScorePanel.setAlignmentX(CENTER_ALIGNMENT);
719+
720+
gbc.gridy = 5;
721+
scorePanel.add(minScorePanel, gbc);
722+
// scorePanel.add(advancedScorePanel, gbc);
718723
outerTrainPanel.setVisible(false);
719724
trainedModel.setVisible(false);
720725
scoringButtons.add(weightScoreOption);
@@ -759,6 +764,10 @@ public JPanel createTrainPanel() {
759764
// }
760765
// });
761766

767+
// Prior probability for cluster
768+
clusterPrior = new JTextField("1E-4");
769+
clusterPriorLabel = new JLabel("Cluster Probability Prior");
770+
762771
// Train the Default (Built-in) Model?
763772
trainDefaultModel = new JRadioButton("Train the built-in template");
764773
trainDefaultModel.addActionListener(new ActionListener() {
@@ -769,7 +778,6 @@ public void actionPerformed(ActionEvent e)
769778
modelPanel.setVisible(false);
770779
trainingFilePanel.setVisible(true);
771780

772-
clusterPrior.setEnabled(true);
773781
negativeExamples.setEnabled(true);
774782
ignoreMissing.setEnabled(true);
775783
}
@@ -786,7 +794,6 @@ public void actionPerformed(ActionEvent e)
786794
modelPanel.setVisible(true);
787795
trainingFilePanel.setVisible(true);
788796

789-
clusterPrior.setEnabled(true);
790797
negativeExamples.setEnabled(true);
791798
ignoreMissing.setEnabled(true);
792799
}

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,25 @@ public void run(TaskMonitor taskMonitor) throws Exception {
8181
//Add results to session for display and presentation
8282
taskMonitor.setProgress(0.9);
8383
taskMonitor.setStatusMessage("Returning Results...");
84-
System.out.println("Adding " + results.size() + " Result Networks via manager...");
84+
// System.out.println("Adding " + results.size() + " Result Networks via manager...");
8585
resultComplexes = new ArrayList<Cluster>();
86-
for (Cluster result: results) {
87-
88-
resultComplexes.add(result);
89-
90-
// Sort the results by their score
91-
Collections.sort(resultComplexes, new Comparator<Cluster>() {
92-
@Override
93-
public int compare(Cluster c1, Cluster c2) {
94-
try {
95-
return ~Double.compare(model.score(c1), model.score(c2));
96-
} catch (Exception e) {
97-
return 0;
98-
}
99-
}
100-
});
101-
86+
for (Cluster result: results) {
87+
resultComplexes.add(result);
10288
}
10389

104-
// Get the top 10 results sorted by score
90+
// Sort the results by their score
91+
Collections.sort(resultComplexes, new Comparator<Cluster>() {
92+
@Override
93+
public int compare(Cluster c1, Cluster c2) {
94+
try {
95+
return ~Double.compare(model.score(c1), model.score(c2));
96+
} catch (Exception e) {
97+
return 0;
98+
}
99+
}
100+
});
101+
102+
// Get the top N results sorted by score
105103
ArrayList<Cluster> networkResults = new ArrayList<Cluster>(userInput.numResults);
106104
if (resultComplexes.size() < userInput.numResults) {
107105
networkResults.addAll(resultComplexes);

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,20 @@ public void run() {
3838
if ((! (cluster.searchComplete || x.searchComplete)) &&
3939
(cluster.getSUID() != x.getSUID()) &&
4040
(getOverlapRatio(cluster,x) > input.overlapLimit)) {
41-
cluster.searchComplete = true;
41+
double score1 = 0.0, score2 = 0.0;
42+
try {
43+
score1 = ClusterScore.score(cluster, model);
44+
score2 = ClusterScore.score(x, model);
45+
} catch (Exception e) {
46+
// TODO Auto-generated catch block
47+
e.printStackTrace();
48+
}
49+
// Deactivate the complex with the lower score
50+
if (score1 > score2) {
51+
x.searchComplete = true;
52+
} else {
53+
cluster.searchComplete = true;
54+
}
4255
}
4356
}
4457
}

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

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ public List<CySubNetwork> generateNegativeExamples(int numExamples, List<CySubNe
162162
}
163163

164164
exponent = getSizeDistributionExponent(positiveExampleSizes);
165-
System.out.println("Exp: " + exponent);
165+
// System.out.println("Exp: " + exponent);
166166

167167
for(i = 0; i < sizeDistributionValues.length; i++) {
168168
sizeDistributionValues[i] = (1/(Math.pow((i + minSize), exponent)));
169-
System.out.println("sizeDistributionValues[" + i + "] : " + sizeDistributionValues[i]);
169+
// System.out.println("sizeDistributionValues[" + i + "] : " + sizeDistributionValues[i]);
170170
sizeDistributionTotal = sizeDistributionTotal + sizeDistributionValues[i];
171171
}
172172

@@ -177,16 +177,20 @@ public List<CySubNetwork> generateNegativeExamples(int numExamples, List<CySubNe
177177

178178
System.out.println("Generating negative examples");
179179
for(i = 0; i < sizeDistributionRatios.length; i++) {
180+
int failedIterations = 0;
180181
// System.out.println("sizeDistributionRatios[" + i + "] : " + sizeDistributionRatios[i]);
181182
for (int x = 0; x < Math.round(sizeDistributionRatios[i] * numExamples); x++) {
182-
System.out.println("x: " + x);
183+
// System.out.println("x: " + x);
183184
example = genNegativeExample(i + minSize, positiveExamples);
184185
if ((example != null) && (example.getNodeCount() >= (i + minSize))) {
185186
negativeExamples.add(example);
186187
}
187188
else {
188189
rootNetwork.removeSubNetwork(example);
189-
x--;
190+
if (! (failedIterations > positiveExamples.size()) ) {
191+
x--;
192+
}
193+
failedIterations++;
190194
}
191195
}
192196
}
@@ -283,42 +287,63 @@ public void train(List<CySubNetwork> positiveExamples, List<CySubNetwork> negati
283287
System.out.println("Entered TRAIN");
284288
List<Cluster> posExamples = new ArrayList<Cluster>(), negExamples = new ArrayList<Cluster>();
285289
for(CySubNetwork pos: positiveExamples) {posExamples.add(new Cluster(features, pos)); }
290+
for(CySubNetwork neg: negativeExamples) {negExamples.add(new Cluster(features, neg));}
291+
286292
System.out.println("Lists of pos and neg training examples created");
287293

294+
// System.out.println("TRAINING BINS ON POSITIVE COMPLEXES:");
288295
posBayesGraph.trainBins(posExamples);
289-
// Min/Max update
290-
System.out.println("TRAINED BINS ON POSITIVE COMPLEXES:");
291-
for (FeatureSet feature : features) {
292-
List<String> statNames = feature.getDescriptions();
293-
Map<String, Statistic> statMap = feature.getStatisticMap();
294-
for (String statName : statNames) {
295-
Statistic stat = statMap.get(statName);
296-
Double min = stat.getRange().getMin();
297-
Double max = stat.getRange().getMax();
298-
System.out.println(statName + "\n\tMin: " + min + "\n\tMax: " + max);
299-
}
300-
}
296+
// for (FeatureSet feature : features) {
297+
// List<String> statNames = feature.getDescriptions();
298+
// Map<String, Statistic> statMap = feature.getStatisticMap();
299+
// for (String statName : statNames) {
300+
// Statistic stat = statMap.get(statName);
301+
// Double min = stat.getRange().getMin();
302+
// Double max = stat.getRange().getMax();
303+
// System.out.println(statName + "\n\tMin: " + min + "\n\tMax: " + max);
304+
// }
305+
// }
301306

307+
// System.out.println("TRAINING BINS ON NEGATIVE COMPLEXES:");
302308
negBayesGraph.trainBins(negExamples);
303-
System.out.println("TRAINED BINS ON NEGATIVE COMPLEXES:");
304-
for (FeatureSet feature : features) {
305-
List<String> statNames = feature.getDescriptions();
306-
Map<String, Statistic> statMap = feature.getStatisticMap();
307-
for (String statName : statNames) {
308-
Statistic stat = statMap.get(statName);
309-
Double min = stat.getRange().getMin();
310-
Double max = stat.getRange().getMax();
311-
System.out.println(statName + "\n\tMin: " + min + "\n\tMax: " + max);
312-
}
313-
}
314-
// Min/max update
309+
// for (FeatureSet feature : features) {
310+
// List<String> statNames = feature.getDescriptions();
311+
// Map<String, Statistic> statMap = feature.getStatisticMap();
312+
// for (String statName : statNames) {
313+
// Statistic stat = statMap.get(statName);
314+
// Double min = stat.getRange().getMin();
315+
// Double max = stat.getRange().getMax();
316+
// System.out.println(statName + "\n\tMin: " + min + "\n\tMax: " + max);
317+
// }
318+
// }
319+
320+
// System.out.println("TRAINING PROBABILITY - POSITIVE:");
315321
posBayesGraph.trainOn(posExamples);
316322
// Min/max stable
317-
System.out.println("Model has finished training on " + positiveExamples.size() + " positive Examples.");
318-
for(CySubNetwork neg: negativeExamples) {negExamples.add(new Cluster(features, neg));}
323+
// for (FeatureSet feature : features) {
324+
// List<String> statNames = feature.getDescriptions();
325+
// Map<String, Statistic> statMap = feature.getStatisticMap();
326+
// for (String statName : statNames) {
327+
// Statistic stat = statMap.get(statName);
328+
// Double min = stat.getRange().getMin();
329+
// Double max = stat.getRange().getMax();
330+
// System.out.println(statName + "\n\tMin: " + min + "\n\tMax: " + max);
331+
// }
332+
// }
319333

334+
// System.out.println("TRAINING PROBABILITY - NEGATIVE:");
320335
negBayesGraph.trainOn(negExamples);
321336
// Min/max stable
337+
// for (FeatureSet feature : features) {
338+
// List<String> statNames = feature.getDescriptions();
339+
// Map<String, Statistic> statMap = feature.getStatisticMap();
340+
// for (String statName : statNames) {
341+
// Statistic stat = statMap.get(statName);
342+
// Double min = stat.getRange().getMin();
343+
// Double max = stat.getRange().getMax();
344+
// System.out.println(statName + "\n\tMin: " + min + "\n\tMax: " + max);
345+
// }
346+
// }
322347
System.out.println("Model has finished training on " + negativeExamples.size() + " negative Examples.");
323348
}
324349

@@ -363,8 +388,8 @@ else if (! complexList.canRead()) {
363388
clusterNetwork.addNode(rootNetwork.getNode(proteinId));
364389
else if (! userInput.ignoreMissing)
365390
throw new Exception("Protein not found in network: " + proteins[i]);
366-
else
367-
System.out.println("Protein not found in network" + proteins[i]);
391+
// else
392+
// System.out.println("Protein not found in network" + proteins[i]);
368393
}
369394

370395
//test for edges and add to subnetwork
@@ -418,7 +443,7 @@ private double getSizeDistributionExponent(int[] positiveExampleSizes) {
418443
for (int i = 0; i < n; i++) {
419444
exponent = exponent + Math.log(positiveExampleSizes[i]/min);
420445
}
421-
System.out.println("exponent: " + exponent);
446+
// System.out.println("exponent: " + exponent);
422447
exponent = 1 + (n / exponent);
423448
} else {
424449
// Avoid dividing by zero

0 commit comments

Comments
 (0)