Skip to content

Commit

Permalink
fix bug MG_two_storages due to v0.4.2 and v0.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
VinF committed Jan 13, 2021
1 parent 5783c09 commit eb18de7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions deer/experiment/base_controllers.py
Expand Up @@ -551,11 +551,11 @@ def onEpochEnd(self, agent):
def onEnd(self, agent):
if (self._active == False):
return

bestIndex = np.argmax(self._validationScores)
print("Best neural net obtained after {} epochs, with validation score {}".format(bestIndex+1, self._validationScores[bestIndex]))
if self._testID != None:
print("Test score of this neural net: {}".format(self._testScores[bestIndex]))
if agent.mode() == -1:
print("Best neural net obtained after {} epochs, with validation score {}".format(bestIndex+1, self._validationScores[bestIndex]))
if self._testID != None:
print("Test score of this neural net: {}".format(self._testScores[bestIndex]))

try:
os.mkdir("scores")
Expand Down
8 changes: 4 additions & 4 deletions examples/MG_two_storages/MG_two_storages_env.py
Expand Up @@ -20,15 +20,15 @@
#from plot_MG_operation import plot_op

class MyEnv(Environment):
VALIDATION_MODE = 0
TEST_MODE = 1

def __init__(self, rng, reduce_qty_data=None, length_history=None, start_history=None):
""" Initialize environment
Arguments:
rng - the numpy random number generator
"""
self.VALIDATION_MODE = 0
self.TEST_MODE = 1

reduce_qty_data=int(reduce_qty_data) if reduce_qty_data is not None else int(1)
length_history=int(length_history) if length_history is not None else int(12)
start_history=int(start_history) if start_history is not None else int(0)
Expand Down Expand Up @@ -148,7 +148,7 @@ def reset(self, mode):
self.production=self.production_train
self.consumption_norm=self.consumption_train_norm
self.consumption=self.consumption_train
elif mode == MyEnv.VALIDATION_MODE:
elif mode == self.VALIDATION_MODE:
self.production_norm=self.production_valid_norm
self.production=self.production_valid
self.consumption_norm=self.consumption_valid_norm
Expand Down
10 changes: 5 additions & 5 deletions examples/MG_two_storages/run_MG_two_storages.py
Expand Up @@ -7,7 +7,7 @@
import numpy as np
from joblib import hash, dump, load
import os
#import matplotlib.pyplot as plt
import matplotlib.pyplot as plt

import sys
from os import path
Expand Down Expand Up @@ -158,16 +158,16 @@ class Defaults:
# used to plot the evolution of the validation and test scores (see below) or simply recover the resulting neural
# network for your application.
agent.attach(bc.FindBestController(
validationID=MG_two_storages_env.VALIDATION_MODE,
testID=MG_two_storages_env.TEST_MODE,
validationID=env.VALIDATION_MODE,
testID=env.TEST_MODE,
unique_fname=fname))

# All previous controllers control the agent during the epochs it goes through. However, we want to interleave a
# "validation epoch" between each training epoch (hence the periodicity=1). For each validation epoch, we want also
# to display the sum of all rewards obtained, hence the showScore=True. Finally, we never want this controller to
# call the summarizePerformance method of MG_two_storage_env.
agent.attach(bc.InterleavedTestEpochController(
id=MG_two_storages_env.VALIDATION_MODE,
id=env.VALIDATION_MODE,
epoch_length=parameters.steps_per_epoch,
periodicity=1,
show_score=True,
Expand All @@ -178,7 +178,7 @@ class Defaults:
# want to display the sum of all rewards obtained, hence the showScore=True. Finally, we want to call the
# summarizePerformance method of MG_two_storage_env every [parameters.period_btw_summary_perfs] *test* epochs.
agent.attach(bc.InterleavedTestEpochController(
id=MG_two_storages_env.TEST_MODE,
id=env.TEST_MODE,
epoch_length=parameters.steps_per_test,
periodicity=1,
show_score=True,
Expand Down

0 comments on commit eb18de7

Please sign in to comment.