Skip to content

Commit 86ceebf

Browse files
authored
Merge pull request #43 from yaricom/trial-dir-creation
Extracted common method to create output directory for experiment trial.
2 parents f0e8996 + bb2badf commit 86ceebf

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

examples/pole/cartpole.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewCartPoleGenerationEvaluator(outDir string, randomStart bool, winBalanceS
3232
}
3333
}
3434

35-
// GenerationEvaluate This method evaluates one epoch for given population and prints results into output directory if any.
35+
// GenerationEvaluate evaluates one epoch for given population and prints results into output directory if any.
3636
func (e *cartPoleGenerationEvaluator) GenerationEvaluate(pop *genetics.Population, epoch *experiment.Generation, context *neat.Options) (err error) {
3737
// Evaluate each organism on a test
3838
for _, org := range pop.Organisms {
@@ -96,7 +96,7 @@ func (e *cartPoleGenerationEvaluator) GenerationEvaluate(pop *genetics.Populatio
9696
return err
9797
}
9898

99-
// This methods evaluates provided organism for cart pole balancing task
99+
// orgEvaluate evaluates provided organism for cart pole balancing task
100100
func (e *cartPoleGenerationEvaluator) orgEvaluate(organism *genetics.Organism) (bool, error) {
101101
// Try to balance a pole now
102102
if fitness, err := e.runCart(organism.Phenotype); err != nil {
@@ -131,7 +131,7 @@ func (e *cartPoleGenerationEvaluator) orgEvaluate(organism *genetics.Organism) (
131131
return organism.IsWinner, nil
132132
}
133133

134-
// run cart emulation and return number of emulation steps pole was balanced
134+
// runCart runs the cart emulation and return number of emulation steps pole was balanced
135135
func (e *cartPoleGenerationEvaluator) runCart(net *network.Network) (steps int, err error) {
136136
var x float64 /* cart position, meters */
137137
var xDot float64 /* cart velocity */
@@ -188,10 +188,10 @@ func (e *cartPoleGenerationEvaluator) runCart(net *network.Network) (steps int,
188188
return steps, nil
189189
}
190190

191-
// cart_and_pole() was take directly from the pole simulator written by Richard Sutton and Charles Anderson.
191+
// doAction was taken directly from the pole simulator written by Richard Sutton and Charles Anderson.
192192
// This simulator uses normalized, continuous inputs instead of discretizing the input space.
193193
/*----------------------------------------------------------------------
194-
cart_pole: Takes an action (0 or 1) and the current values of the
194+
Takes an action (0 or 1) and the current values of the
195195
four state variables and updates their values by estimating the state
196196
TAU seconds later.
197197
----------------------------------------------------------------------*/

experiment/utils/utils.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
// WriteGenomePlain is to write genome of the organism to the genomeFile in the outDir directory using plain encoding.
1414
// The method return path to the file if successful or error if failed.
1515
func WriteGenomePlain(genomeFile, outDir string, org *genetics.Organism, epoch *experiment.Generation) (string, error) {
16-
orgPath := fmt.Sprintf("%s/%s_%d-%d", createOutDirForTrial(outDir, epoch.TrialId),
16+
orgPath := fmt.Sprintf("%s/%s_%d-%d", CreateOutDirForTrial(outDir, epoch.TrialId),
1717
genomeFile, org.Phenotype.NodeCount(), org.Phenotype.LinkCount())
1818
if file, err := os.Create(orgPath); err != nil {
1919
return "", err
@@ -26,7 +26,7 @@ func WriteGenomePlain(genomeFile, outDir string, org *genetics.Organism, epoch *
2626
// WriteGenomeDOT is to write genome of the organism to the genomeFile in the outDir directory using DOT encoding.
2727
// The method return path to the file if successful or error if failed.
2828
func WriteGenomeDOT(genomeFile, outDir string, org *genetics.Organism, epoch *experiment.Generation) (string, error) {
29-
orgPath := fmt.Sprintf("%s/%s_%d-%d.dot", createOutDirForTrial(outDir, epoch.TrialId),
29+
orgPath := fmt.Sprintf("%s/%s_%d-%d.dot", CreateOutDirForTrial(outDir, epoch.TrialId),
3030
genomeFile, org.Phenotype.NodeCount(), org.Phenotype.LinkCount())
3131
if file, err := os.Create(orgPath); err != nil {
3232
return "", err
@@ -39,7 +39,7 @@ func WriteGenomeDOT(genomeFile, outDir string, org *genetics.Organism, epoch *ex
3939
// WriteGenomeCytoscapeJSON is to write genome of the organism to the genomeFile in the outDir directory using Cytoscape JSON encoding.
4040
// The method return path to the file if successful or error if failed.
4141
func WriteGenomeCytoscapeJSON(genomeFile, outDir string, org *genetics.Organism, epoch *experiment.Generation) (string, error) {
42-
orgPath := fmt.Sprintf("%s/%s_%d-%d.cyjs", createOutDirForTrial(outDir, epoch.TrialId),
42+
orgPath := fmt.Sprintf("%s/%s_%d-%d.cyjs", CreateOutDirForTrial(outDir, epoch.TrialId),
4343
genomeFile, org.Phenotype.NodeCount(), org.Phenotype.LinkCount())
4444
if file, err := os.Create(orgPath); err != nil {
4545
return "", err
@@ -52,7 +52,7 @@ func WriteGenomeCytoscapeJSON(genomeFile, outDir string, org *genetics.Organism,
5252
// WritePopulationPlain is to write genomes of the entire population using plain encoding in the outDir directory.
5353
// The methods return path to the file if successful or error if failed.
5454
func WritePopulationPlain(outDir string, pop *genetics.Population, epoch *experiment.Generation) (string, error) {
55-
popPath := fmt.Sprintf("%s/gen_%d", createOutDirForTrial(outDir, epoch.TrialId), epoch.Id)
55+
popPath := fmt.Sprintf("%s/gen_%d", CreateOutDirForTrial(outDir, epoch.TrialId), epoch.Id)
5656
if file, err := os.Create(popPath); err != nil {
5757
return "", err
5858
} else if err = pop.WriteBySpecies(file); err != nil {
@@ -61,8 +61,8 @@ func WritePopulationPlain(outDir string, pop *genetics.Population, epoch *experi
6161
return popPath, nil
6262
}
6363

64-
// createOutDirForTrial allows creating the output directory for specific trial using standard name.
65-
func createOutDirForTrial(outDir string, trialID int) string {
64+
// CreateOutDirForTrial allows creating the output directory for specific trial of the experiment using standard name.
65+
func CreateOutDirForTrial(outDir string, trialID int) string {
6666
dir := fmt.Sprintf("%s/%d", outDir, trialID)
6767
if _, err := os.Stat(dir); err != nil {
6868
// create output dir

0 commit comments

Comments
 (0)