Aufgrund einer Wartung wird GitLab am 26.10. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 26.10. between 8:00 and 9:00 am.

Commit 85a88022 authored by Nicola Gatto's avatar Nicola Gatto
Browse files

Add learning method check

parent 68530093
......@@ -13,6 +13,8 @@ import static de.monticore.lang.monticar.cnntrain.helper.ConfigEntryNameConstant
import java.util.Optional;
class ASTConfigurationUtils {
final static ParameterAlgorithmMapping parameterChecker = new ParameterAlgorithmMapping();
static boolean isReinforcementLearning(final ASTConfiguration configuration) {
return configuration.getEntriesList().stream().anyMatch(e ->
(e instanceof ASTLearningMethodEntry)
......@@ -94,4 +96,16 @@ class ASTConfigurationUtils {
public static boolean isContinuousAlgorithm(final ASTConfiguration node) {
return isDdpgAlgorithm(node) || isTd3Algorithm(node);
}
public static boolean hasRLEntry(ASTConfiguration node) {
//return node.getEntriesList().stream()
// .anyMatch(e -> parameterChecker.isReinforcementLearningParameterOnly(e.getClass()));
for (ASTConfigEntry e : node.getEntriesList()) {
boolean b = parameterChecker.isReinforcementLearningParameterOnly(e.getClass());
if (b) {
return true;
}
}
return false;
}
}
......@@ -18,6 +18,7 @@ public class CNNTrainCocos {
return new CNNTrainCoCoChecker()
.addCoCo(new CheckEntryRepetition())
.addCoCo(new CheckInteger())
.addCoCo(new CheckRLParameterOnlyWithLearningMethodSet())
.addCoCo(new CheckFixTargetNetworkRequiresInterval())
.addCoCo(new CheckReinforcementRequiresEnvironment())
.addCoCo(new CheckLearningParameterCombination())
......
package de.monticore.lang.monticar.cnntrain._cocos;
import de.monticore.lang.monticar.cnntrain._ast.ASTConfiguration;
import de.monticore.lang.monticar.cnntrain.helper.ErrorCodes;
import de.se_rwth.commons.logging.Log;
public class CheckRLParameterOnlyWithLearningMethodSet implements CNNTrainASTConfigurationCoCo {
@Override
public void check(ASTConfiguration node) {
if (!ASTConfigurationUtils.isReinforcementLearning(node) && ASTConfigurationUtils.hasRLEntry(node)) {
Log.error(ErrorCodes.REQUIRED_PARAMETER_MISSING + " Reinforcement parameter used although learning " +
"method not set", node.get_SourcePositionStart());
}
}
}
......@@ -122,6 +122,15 @@ class ParameterAlgorithmMapping {
|| EXCLUSIVE_TD3_PARAMETERS.contains(entryClazz);
}
boolean isReinforcementLearningParameterOnly(Class<? extends ASTEntry> entryClazz) {
return (GENERAL_REINFORCEMENT_PARAMETERS.contains(entryClazz)
|| EXCLUSIVE_DQN_PARAMETERS.contains(entryClazz)
|| EXCLUSIVE_DDPG_PARAMETERS.contains(entryClazz)
|| EXCLUSIVE_TD3_PARAMETERS.contains(entryClazz))
&& !GENERAL_PARAMETERS.contains(entryClazz)
&& !EXCLUSIVE_SUPERVISED_PARAMETERS.contains(entryClazz);
}
boolean isSupervisedLearningParameter(Class<? extends ASTEntry> entryClazz) {
return GENERAL_PARAMETERS.contains(entryClazz)
|| EXCLUSIVE_SUPERVISED_PARAMETERS.contains(entryClazz);
......
......@@ -188,4 +188,11 @@ public class AllCoCoTest extends AbstractCoCoTest{
"invalid_cocos_tests", "CheckRosEnvironmentHasOnlyOneRewardSpecification",
new ExpectedErrorInfo(1, ErrorCodes.CONTRADICTING_PARAMETERS));
}
@Test
public void testInvalidCheckReinforcementLearningEntryIsSet () {
checkInvalid(new CNNTrainCoCoChecker().addCoCo(new CheckRLParameterOnlyWithLearningMethodSet()),
"invalid_cocos_tests", "CheckRLParameterOnlyWithLearningMethodSet",
new ExpectedErrorInfo(1, ErrorCodes.REQUIRED_PARAMETER_MISSING));
}
}
/* (c) https://github.com/MontiCore/monticore */
configuration CheckRLParameterOnlyWithLearningMethodSet {
agent_name : "reinforcement-agent"
environment : gym { name:"CartPole-v1" }
context : cpu
num_episodes : 300
num_max_steps : 9999
discount_factor : 0.998
target_score : 1000
training_interval : 10
loss : huber
use_fix_target_network : true
target_network_update_interval : 100
use_double_dqn : true
replay_memory : buffer{
memory_size : 1000000
sample_size : 64
}
strategy : epsgreedy{
epsilon : 1.0
min_epsilon : 0.01
epsilon_decay_method: linear
epsilon_decay : 0.0001
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment