Skip to content
Permalink
Browse files

Simulated annealing now outputs two files. One logs the path through …

…parameter- and score-space as a tab-delim table. The second holds the found best performing parameter set in the same format including the average maximum evaluation score, that is the maximum eval score AHRD could have achieved.
  • Loading branch information...
Asis Hallab
Asis Hallab committed Mar 15, 2012
1 parent 4f6de73 commit 74f90a83585c3d9a45863237548829354da58251
@@ -12,6 +12,7 @@ dist/ahrd.jar

# Ignore AHRD-Output generated by Test-Suite:
test/ahrd_output.csv
test/sim_anneal_path_log.csv

# Ignore subversion related files
.svn
@@ -79,6 +79,8 @@
<fileset dir="${classes}" includes="**/*Test.class" />
</batchtest>
</junit>
<delete file="test/ahrd_output.csv" />
<delete file="test/sim_anneal_path_log.csv" />
</target>

<target name="test.run" depends="compile.test">
@@ -49,6 +49,7 @@ public static void setSettings(Settings s) {
public static final String INTERPRO_RESULT_KEY = "interpro_result";
public static final String GENE_ONTOLOGY_RESULT_KEY = "gene_ontology_result";
public static final String OUTPUT_KEY = "output";
public static final String SIMULATED_ANNEALING_PATH_LOG_KEY = "path_log";
public static final String WRITE_SCORES_TO_OUTPUT = "write_scores_to_output";
public static final String WRITE_BEST_BLAST_HITS_TO_OUTPUT = "write_best_blast_hits_to_output";
public static final String WRITE_TOKEN_SET_TO_OUTPUT = "write_token_set_to_output";
@@ -79,6 +80,10 @@ public static void setSettings(Settings s) {
private String pathToInterproResults;
private String pathToGeneOntologyResults;
private String pathToOutput;
/**
* Trainer logs path through parameter- and score-space into this file:
*/
private String pathToSimulatedAnnealingPathLog;
/**
* Parameters representing weights and factors in the various formulas used
* in AHRD. They are subject to optimization and can be set by the user.
@@ -169,6 +174,10 @@ public void initialize(String pathToYml) throws IOException {
setPathToGeneOntologyResults((String) input
.get(GENE_ONTOLOGY_RESULT_KEY));
setPathToOutput((String) input.get(OUTPUT_KEY));
// Trainer logs path through parameter-space here:
if (input.get(SIMULATED_ANNEALING_PATH_LOG_KEY) != null)
setPathToSimulatedAnnealingPathLog((String) input
.get(SIMULATED_ANNEALING_PATH_LOG_KEY));
setTokenScoreBitScoreWeight(Double.parseDouble((String) input
.get(TOKEN_SCORE_BIT_SCORE_WEIGHT)));
setTokenScoreDatabaseScoreWeight(Double.parseDouble((String) input
@@ -608,4 +617,13 @@ public void setOptimizationAcceptanceProbabilityScalingFactor(
this.optimizationAcceptanceProbabilityScalingFactor = optimizationAcceptanceProbabilityScalingFactor;
}

public String getPathToSimulatedAnnealingPathLog() {
return pathToSimulatedAnnealingPathLog;
}

public void setPathToSimulatedAnnealingPathLog(
String pathToSimulatedAnnealingPathLog) {
this.pathToSimulatedAnnealingPathLog = pathToSimulatedAnnealingPathLog;
}

}
@@ -18,6 +18,12 @@
private Parameters bestParameters;
private TrainerOutputWriter outWriter;
private Set<Parameters> testedParameters;
/**
* The average of AHRD's maximum evaluation score for each Protein. This is
* the maximum of the evaluation scores calculated for all Descriptions of
* each Protein. These maximums are then averaged.
*/
private Double avgMaxEvaluationScore = 0.0;

/**
* @param args
@@ -36,11 +42,15 @@ public static void main(String[] args) {

// Try to find optimal parameters heuristically:
trainer.train();
// Calculate the average maximum evaluation score AHRD could have
// possible achieved:
trainer.calcAvgMaxEvaluationScore();

// Write final output
Settings bestSettings = getSettings().clone();
bestSettings.setParameters(trainer.getBestParameters());
trainer.outWriter.writeFinalOutput(bestSettings);
trainer.outWriter.writeFinalOutput(bestSettings,
trainer.getAvgMaxEvaluationScore());
System.out.println("Written output into:\n"
+ getSettings().getPathToOutput());
} catch (Exception e) {
@@ -258,6 +268,22 @@ public Parameters getAlreadyTestedParameters(Parameters current) {
return alreadyTested;
}

/**
* This calculates the average maximum evaluation score AHRD could possibly
* achieve.
*/
public void calcAvgMaxEvaluationScore() {
for (Protein prot : getProteins().values()) {
prot.getEvaluationScoreCalculator()
.findHighestPossibleEvaluationScore();
setAvgMaxEvaluationScore(getAvgMaxEvaluationScore()
+ prot.getEvaluationScoreCalculator()
.getHighestPossibleEvaluationScore());
}
setAvgMaxEvaluationScore(getAvgMaxEvaluationScore()
/ getProteins().size());
}

public Parameters getAcceptedParameters() {
return acceptedParameters;
}
@@ -277,4 +303,13 @@ public void setBestParameters(Parameters bestParameters) {
public Set<Parameters> getTestedParameters() {
return testedParameters;
}

public Double getAvgMaxEvaluationScore() {
return avgMaxEvaluationScore;
}

public void setAvgMaxEvaluationScore(Double avgMaxEvaluationScore) {
this.avgMaxEvaluationScore = avgMaxEvaluationScore;
}

}
@@ -155,16 +155,18 @@ private Parameters generateDistinctRandomParameters() {
batchYml.put(Settings.GENE_ONTOLOGY_RESULT_KEY,
getInput().get(Settings.GENE_ONTOLOGY_RESULT_KEY));

// Output-File:
String outputFile = getInput().get(OUTPUT_DIR_KEY).toString();

if (!outputFile.endsWith("/"))
outputFile += "/";

outputFile += batchName.replaceAll("\\.\\S+$", "")
+ "_ahrd_trainer_out.csv";

// Output-File and Log of simulated annealing's path through parameter-
// and score-space:
String outputDir = getInput().get(OUTPUT_DIR_KEY).toString();
if (!outputDir.endsWith("/"))
outputDir += "/";
String batchFileName = batchName.replaceAll("\\.\\S+$", "");
String outputFile = outputDir + batchFileName + "_ahrd_trainer_out.csv";
batchYml.put(Settings.OUTPUT_KEY, outputFile);
String simAnnealPathLog = outputDir + batchFileName
+ "_sim_anneal_path_log.csv";
batchYml.put(Settings.SIMULATED_ANNEALING_PATH_LOG_KEY,
simAnnealPathLog);

// Append best BlastHits to output?:
String appendBestBlastHitsToOutput = (String) getInput().get(
@@ -21,7 +21,8 @@
public static final DecimalFormat FRMT = new DecimalFormat(
"#,######0.######");

private BufferedWriter bufWrtr;
private BufferedWriter pathBufWrtr;
private BufferedWriter outBufWrtr;
private List<String> sortedBlastDatabases;

public TrainerOutputWriter() throws IOException {
@@ -31,40 +32,48 @@ public TrainerOutputWriter() throws IOException {
.getBlastDatabases());
Collections.sort(this.sortedBlastDatabases);
// Prepare buffered output-writer:
this.bufWrtr = new BufferedWriter(new FileWriter(getSettings()
.getPathToOutput()));
// And write the header:
writeHeader();
this.pathBufWrtr = new BufferedWriter(new FileWriter(getSettings()
.getPathToSimulatedAnnealingPathLog()));
// And write the header into the path-log:
this.pathBufWrtr.write(generateHeader(false));
}

public void writeHeader() throws IOException {
this.bufWrtr
.write("Temperature\tAverage Evaluation-Score\tAccepted\tAverage True-Positive-Rate\tAverage False-Positive-Rate\tDescription-Score-Pattern-Factor-Weight\tToken-Score-Bit-Score-Weight\tToken-Score-Database-Score-Weight\tToken-Score-Overlap-Score-Weight");
public String generateHeader(boolean addAvgMaxEvaluationScoreCol) {
String hdr = "Temperature\t";
if (addAvgMaxEvaluationScoreCol)
hdr += "Average Maximum-Evaluation-Score\t";
hdr += "Average Evaluation-Score\tAccepted\tAverage True-Positive-Rate\tAverage False-Positive-Rate\tDescription-Score-Pattern-Factor-Weight\tToken-Score-Bit-Score-Weight\tToken-Score-Database-Score-Weight\tToken-Score-Overlap-Score-Weight";
for (String blastDb : this.sortedBlastDatabases) {
this.bufWrtr.write("\t" + blastDb + "-Weight");
this.bufWrtr.write("\t" + blastDb
+ "-Description-Score-Bit-Score-Weight");
hdr += "\t" + blastDb + "-Weight";
hdr += "\t" + blastDb + "-Description-Score-Bit-Score-Weight";
}
this.bufWrtr.write("\n");
hdr += "\n";
return hdr;
}

public void writeIterationOutput(Settings currentSettings, int accepted)
throws IOException {
this.bufWrtr.write(settingsRow(currentSettings, accepted, false));
this.pathBufWrtr.write(settingsRow(currentSettings, accepted, null));
}

public void writeFinalOutput(Settings acceptedSettings) throws IOException {
this.bufWrtr.write(settingsRow(acceptedSettings, 1, true));
this.bufWrtr.close();
public void writeFinalOutput(Settings acceptedSettings,
Double avgMaxEvaluationScore) throws IOException {
this.outBufWrtr = new BufferedWriter(new FileWriter(getSettings()
.getPathToOutput()));
// this.outBufWrtr.write("Found best scoring Parameters:\n");
this.outBufWrtr.write(generateHeader(true));
this.outBufWrtr.write(settingsRow(acceptedSettings, 1,
avgMaxEvaluationScore));
this.outBufWrtr.close();
}

public String settingsRow(Settings s, int accepted, boolean bestSettings) {
String col = bestSettings ? "best-settings" : s.getTemperature()
.toString();
col += "\t" + s.getAvgEvaluationScore() + "\t"
+ FRMT.format(s.getAvgTruePositivesRate()) + "\t"
+ accepted + "\t"
+ FRMT.format(s.getAvgFalsePositivesRate()) + "\t"
public String settingsRow(Settings s, int accepted, Double avgMaxEvalScore) {
String col = s.getTemperature().toString() + "\t";
if (avgMaxEvalScore != null)
col += avgMaxEvalScore + "\t";
col += s.getAvgEvaluationScore() + "\t"
+ FRMT.format(s.getAvgTruePositivesRate()) + "\t" + accepted
+ "\t" + FRMT.format(s.getAvgFalsePositivesRate()) + "\t"
+ FRMT.format(s.getDescriptionScorePatternFactorWeight())
+ "\t" + FRMT.format(s.getTokenScoreBitScoreWeight()) + "\t"
+ FRMT.format(s.getTokenScoreDatabaseScoreWeight()) + "\t"
@@ -34,4 +34,5 @@ token_score_database_score_weight: 0.3
token_score_overlap_score_weight: 0.2
description_score_relative_description_frequency_weight: 0.6
output: ./test/ahrd_output.csv
path_log: ./test/sim_anneal_path_log.csv
remember_simulated_annealing_path: true

0 comments on commit 74f90a8

Please sign in to comment.
You can’t perform that action at this time.