CNNTrain.mc4 9.88 KB
Newer Older
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
1
package de.monticore.lang.monticar;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
2

3
grammar CNNTrain extends de.monticore.lang.monticar.Common2, de.monticore.NumberUnit{
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
4

5
    symbol scope CNNTrainCompilationUnit = "configuration"
6
                                 name:Name&
7 8 9
                                 Configuration;

    Configuration =  "{"entries:ConfigEntry* "}";
10

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
11 12 13 14 15
    interface Entry;
    ast Entry = method String getName(){}
                method ASTConfigValue getValue(){};
    interface ConfigValue;
    interface ConfigEntry extends Entry;
16 17
    interface VariableReference;
    ast VariableReference = method String getName(){};
18

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
19 20
    NumEpochEntry implements ConfigEntry = name:"num_epoch" ":" value:IntegerValue;
    BatchSizeEntry implements ConfigEntry = name:"batch_size" ":" value:IntegerValue;
21
    LoadCheckpointEntry implements ConfigEntry = name:"load_checkpoint" ":" value:BooleanValue;
22
    NormalizeEntry implements ConfigEntry = name:"normalize" ":" value:BooleanValue;
23
    OptimizerEntry implements ConfigEntry = name:"optimizer" ":" value:OptimizerValue;
24
    TrainContextEntry implements ConfigEntry = name:"context" ":" value:TrainContextValue;
25
    EvalMetricEntry implements ConfigEntry = name:"eval_metric" ":" value:EvalMetricValue;
26
    LossEntry implements ConfigEntry = name:"loss" ":" value:LossValue;
27 28 29 30 31 32 33 34

    EvalMetricValue implements ConfigValue =(accuracy:"accuracy"
                                               | crossEntropy:"cross_entropy"
                                               | f1:"f1"
                                               | mae:"mae"
                                               | mse:"mse"
                                               | rmse:"rmse"
                                               | topKAccuracy:"top_k_accuracy");
35

Nicola Gatto's avatar
Nicola Gatto committed
36 37 38 39
    LossValue implements ConfigValue =(euclidean:"euclidean"
                                           | l1: "l1"
                                           | crossEntropy:"cross_entropy"
                                           | huberLoss: "huber_loss");
40

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
41 42 43 44 45 46
    LRPolicyValue implements ConfigValue =(fixed:"fixed"
                                         | step:"step"
                                         | exp:"exp"
                                         | inv:"inv"
                                         | poly:"poly"
                                         | sigmoid:"sigmoid");
47
    TrainContextValue implements ConfigValue = (cpu:"cpu" | gpu:"gpu");
48 49


50
    DataVariable implements VariableReference = Name&;
51 52
    IntegerValue implements ConfigValue = NumberWithUnit;
    NumberValue implements ConfigValue = NumberWithUnit;
Nicola Gatto's avatar
Nicola Gatto committed
53
    StringValue implements ConfigValue = StringLiteral;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    BooleanValue implements ConfigValue = (TRUE:"true" | FALSE:"false");

    interface OptimizerValue extends ConfigValue;

    interface SGDEntry extends Entry;
    SGDOptimizer implements OptimizerValue = name:"sgd" ("{" params:SGDEntry* "}")?;

    interface AdamEntry extends Entry;
    AdamOptimizer implements OptimizerValue = name:"adam" ("{" params:AdamEntry* "}")?;

    interface RmsPropEntry extends Entry;
    RmsPropOptimizer implements OptimizerValue = name:"rmsprop" ("{" params:RmsPropEntry* "}")?;

    interface AdaGradEntry extends Entry;
    AdaGradOptimizer implements OptimizerValue = name:"adagrad" ("{" params:AdaGradEntry* "}")?;

    NesterovOptimizer implements OptimizerValue = name:"nag" ("{" params:SGDEntry* "}")?;

    interface AdaDeltaEntry extends Entry;
    AdaDeltaOptimizer implements OptimizerValue = name:"adadelta" ("{" params:AdaDeltaEntry* "}")?;

    interface GeneralOptimizerEntry extends SGDEntry,AdamEntry,RmsPropEntry,AdaGradEntry,AdaDeltaEntry;

77
    MinimumLearningRateEntry implements GeneralOptimizerEntry = name:"learning_rate_minimum" ":" value:NumberValue;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
    LearningRateEntry implements GeneralOptimizerEntry = name:"learning_rate" ":" value:NumberValue;
    WeightDecayEntry implements GeneralOptimizerEntry = name:"weight_decay" ":" value:NumberValue;
    LRDecayEntry implements GeneralOptimizerEntry = name:"learning_rate_decay" ":" value:NumberValue;
    LRPolicyEntry implements GeneralOptimizerEntry = name:"learning_rate_policy" ":" value:LRPolicyValue;
    RescaleGradEntry implements GeneralOptimizerEntry = name:"rescale_grad" ":" value:NumberValue;
    ClipGradEntry implements GeneralOptimizerEntry = name:"clip_gradient" ":" value:NumberValue;
    StepSizeEntry implements GeneralOptimizerEntry = name:"step_size" ":" value:IntegerValue;


    MomentumEntry implements SGDEntry = name:"momentum" ":" value:NumberValue;
    Beta1Entry implements AdamEntry = name:"beta1" ":" value:NumberValue;
    Beta2Entry implements AdamEntry = name:"beta2" ":" value:NumberValue;
    EpsilonEntry implements AdamEntry,AdaGradEntry,RmsPropEntry,AdaDeltaEntry = name:"epsilon" ":" value:NumberValue;
    Gamma1Entry implements RmsPropEntry = name:"gamma1" ":" value:NumberValue;
    Gamma2Entry implements RmsPropEntry = name:"gamma2" ":" value:NumberValue;
    CenteredEntry implements RmsPropEntry = name:"centered" ":" value:BooleanValue;
    ClipWeightsEntry implements RmsPropEntry = name:"clip_weights" ":" value:NumberValue;
    RhoEntry implements AdaDeltaEntry = name:"rho" ":" value:NumberValue;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
96

Nicola Gatto's avatar
Nicola Gatto committed
97 98 99 100
    // Reinforcement Extensions
    interface MultiParamValue extends ConfigValue;

    LearningMethodEntry implements ConfigEntry = name:"learning_method" ":" value:LearningMethodValue;
Nicola Gatto's avatar
Nicola Gatto committed
101
    RLAlgorithmEntry implements ConfigEntry = name:"rl_algorithm" ":" value:RLAlgorithmValue;
Nicola Gatto's avatar
Nicola Gatto committed
102 103 104 105 106 107 108 109 110 111 112
    NumEpisodesEntry implements ConfigEntry = name:"num_episodes" ":" value:IntegerValue;
    DiscountFactorEntry implements ConfigEntry = name:"discount_factor" ":" value:NumberValue;
    NumMaxStepsEntry implements ConfigEntry = name:"num_max_steps" ":" value:IntegerValue;
    TargetScoreEntry implements ConfigEntry = name:"target_score" ":" value:NumberValue;
    TrainingIntervalEntry implements ConfigEntry = name:"training_interval" ":" value:IntegerValue;
    UseFixTargetNetworkEntry implements ConfigEntry = name:"use_fix_target_network" ":" value:BooleanValue;
    TargetNetworkUpdateIntervalEntry implements ConfigEntry = name:"target_network_update_interval" ":" value:IntegerValue;
    SnapshotIntervalEntry implements ConfigEntry = name:"snapshot_interval" ":" value:IntegerValue;
    AgentNameEntry implements ConfigEntry = name:"agent_name" ":" value:StringValue;
    UseDoubleDQNEntry implements ConfigEntry = name:"use_double_dqn" ":" value:BooleanValue;
    RewardFunctionEntry implements ConfigEntry = name:"reward_function" ":" value:ComponentNameValue;
Nicola Gatto's avatar
Nicola Gatto committed
113
    CriticNetworkEntry implements ConfigEntry = name:"critic" ":" value:ComponentNameValue;
Nicola Gatto's avatar
Nicola Gatto committed
114 115 116 117 118

    ComponentNameValue implements ConfigValue = Name ("."Name)*;

    LearningMethodValue implements ConfigValue = (supervisedLearning:"supervised" | reinforcement:"reinforcement");

Nicola Gatto's avatar
Nicola Gatto committed
119 120
    RLAlgorithmValue implements ConfigValue = (dqn:"dqn-algorithm" | ddpg:"ddpg-algorithm");

Nicola Gatto's avatar
Nicola Gatto committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
    interface MultiParamConfigEntry extends ConfigEntry;

    // Replay Memory
    ReplayMemoryEntry implements MultiParamConfigEntry = name:"replay_memory" ":" value:ReplayMemoryValue;
    interface ReplayMemoryValue extends MultiParamValue;

    interface ReplayMemoryBufferEntry extends Entry;
    ReplayMemoryBufferValue implements ReplayMemoryValue = name:"buffer" ("{" params:ReplayMemoryBufferEntry* "}")?;

    ReplayMemoryOnlineValue implements ReplayMemoryValue = name:"online";

    interface ReplayMemoryCombinedEntry extends Entry;
    ReplayMemoryCombinedValue implements ReplayMemoryValue = name:"combined" ("{" params:ReplayMemoryCombinedEntry* "}")?;

    interface GeneralReplayMemoryEntry extends ReplayMemoryBufferEntry, ReplayMemoryCombinedEntry;

    MemorySizeEntry implements GeneralReplayMemoryEntry = name:"memory_size" ":" value:IntegerValue;
    SampleSizeEntry implements GeneralReplayMemoryEntry = name:"sample_size" ":" value:IntegerValue;

    // Action Selection
    ActionSelectionEntry implements MultiParamConfigEntry = name:"action_selection" ":" value:ActionSelectionValue;
    interface ActionSelectionValue extends MultiParamValue;

    interface ActionSelectionEpsGreedyEntry extends Entry;
    ActionSelectionEpsGreedyValue implements ActionSelectionValue = name:"epsgreedy" ("{" params:ActionSelectionEpsGreedyEntry* "}")?;

    GreedyEpsilonEntry implements ActionSelectionEpsGreedyEntry = name:"epsilon" ":" value:NumberValue;
    MinEpsilonEntry implements ActionSelectionEpsGreedyEntry = name:"min_epsilon" ":" value:NumberValue;
    EpsilonDecayMethodEntry implements ActionSelectionEpsGreedyEntry = name:"epsilon_decay_method" ":" value:EpsilonDecayMethodValue;
    EpsilonDecayMethodValue implements ConfigValue = (linear:"linear" | no:"no");
    EpsilonDecayEntry implements ActionSelectionEpsGreedyEntry = name:"epsilon_decay" ":" value:NumberValue;

    // Environment
    EnvironmentEntry implements MultiParamConfigEntry = name:"environment" ":" value:EnvironmentValue;
    interface EnvironmentValue extends MultiParamValue;

    interface GymEnvironmentEntry extends Entry;
    GymEnvironmentValue implements EnvironmentValue = name:"gym" ("{" params:GymEnvironmentEntry* "}");
    GymEnvironmentNameEntry implements GymEnvironmentEntry = name:"name" ":" value:StringValue;

    interface RosEnvironmentEntry extends Entry;
    RosEnvironmentValue implements EnvironmentValue = | name:"ros_interface" ("{" params:RosEnvironmentEntry* "}")?;
    RosEnvironmentStateTopicEntry implements RosEnvironmentEntry = name:"state_topic" ":" value:StringValue;
    RosEnvironmentActionTopicEntry implements RosEnvironmentEntry = name:"action_topic" ":" value:StringValue;
    RosEnvironmentResetTopicEntry implements RosEnvironmentEntry = name:"reset_topic" ":" value:StringValue;
    RosEnvironmentGreetingTopicEntry implements RosEnvironmentEntry = name:"greeting_topic" ":" value:StringValue;
    RosEnvironmentMetaTopicEntry implements RosEnvironmentEntry = name:"meta_topic" ":" value:StringValue;
    RosEnvironmentTerminalStateTopicEntry implements RosEnvironmentEntry = name:"terminal_state_topic" ":" value:StringValue;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
169
}