-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logging of random search results #16
- Loading branch information
B96
committed
Jul 8, 2019
1 parent
0ccd2f1
commit e0923dc
Showing
7 changed files
with
178 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
AutoTuning/src/main/java/RandomSearch/RandomSearchLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package RandomSearch; | ||
|
||
import java.io.*; | ||
import java.util.Date; | ||
|
||
public class RandomSearchLogger { | ||
|
||
private final FileWriter fileWriterCSV; | ||
private String directory = "./rs-output/"; | ||
|
||
public RandomSearchLogger(String scenario, HyperparameterSpace hyperparameterSpace) { | ||
|
||
try { | ||
// create directory for random search output if not yet created | ||
new File(directory + scenario).mkdirs(); | ||
File f = new File("rundata_" + new Date().getTime()); | ||
fileWriterCSV = new FileWriter(directory + scenario + File.separator + f.getName() + ".csv"); | ||
StringBuilder header = new StringBuilder(); | ||
for (Parameter p : hyperparameterSpace.getHyperParameters()) { | ||
header.append(p.getName() + ","); | ||
} | ||
fileWriterCSV.write(header.toString() + "runtime,coverage,performance" + "\n"); | ||
|
||
} catch (IOException e) { | ||
throw new IllegalStateException("Error occurred creating file", e); | ||
} | ||
|
||
} | ||
|
||
public void addValuesToLogging(HyperparameterSpace hyperparameterSpace) { | ||
|
||
try { | ||
StringBuilder values = new StringBuilder(); | ||
for (Parameter p : hyperparameterSpace.getHyperParameters()) { | ||
values.append(p.getCurrentValue() + ","); | ||
} | ||
values.append(hyperparameterSpace.getRuntime() + ","); | ||
values.append(hyperparameterSpace.getCoverage() + ","); | ||
values.append(hyperparameterSpace.getPerformance()); | ||
|
||
fileWriterCSV.write(values.toString() + "\n"); | ||
} catch (IOException e) { | ||
throw new IllegalStateException("Error occurred writing in the file", e); | ||
} | ||
|
||
} | ||
|
||
public void endLogging() { | ||
try { | ||
fileWriterCSV.close(); | ||
} catch (IOException e) { | ||
throw new IllegalStateException("Error occurred closing the file", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
AutoTuning/src/test/java/RandomSearch/RandomSearchLoggerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package RandomSearch; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
|
||
public class RandomSearchLoggerTest { | ||
|
||
@Test | ||
public void testFileCreation(){ | ||
//Given | ||
HyperparameterSpace hyperparameterSpace = new HyperparameterSpace(); | ||
RandomSearchLogger logger = new RandomSearchLogger("Titanic", hyperparameterSpace); | ||
|
||
logger.endLogging(); | ||
} | ||
|
||
} |