CNNTrain.mc4 13.8 KB
Newer Older
Bernhard Rumpe's avatar
BR-sy    
Bernhard Rumpe committed
1
/* (c) https://github.com/MontiCore/monticore */
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
2
package de.monticore.lang.monticar;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
3

4
grammar CNNTrain extends de.monticore.lang.monticar.Common2, de.monticore.NumberUnit{
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

Nicola Gatto's avatar
Nicola Gatto committed
19
20
21
22
23
24
25
26
27
    // General Values
    DataVariable implements VariableReference = Name&;
    IntegerValue implements ConfigValue = NumberWithUnit;
    NumberValue implements ConfigValue = NumberWithUnit;
    StringValue implements ConfigValue = StringLiteral;
    BooleanValue implements ConfigValue = (TRUE:"true" | FALSE:"false");
    ComponentNameValue implements ConfigValue = Name ("."Name)*;
    DoubleVectorValue implements ConfigValue = "(" number:NumberWithUnit ("," number:NumberWithUnit)* ")";

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
28
29
    NumEpochEntry implements ConfigEntry = name:"num_epoch" ":" value:IntegerValue;
    BatchSizeEntry implements ConfigEntry = name:"batch_size" ":" value:IntegerValue;
30
    LoadCheckpointEntry implements ConfigEntry = name:"load_checkpoint" ":" value:BooleanValue;
31
    NormalizeEntry implements ConfigEntry = name:"normalize" ":" value:BooleanValue;
Nicola Gatto's avatar
Nicola Gatto committed
32
    OptimizerEntry implements ConfigEntry = (name:"optimizer" | name:"actor_optimizer") ":" value:OptimizerValue;
33
    TrainContextEntry implements ConfigEntry = name:"context" ":" value:TrainContextValue;
34
    EvalMetricEntry implements ConfigEntry = name:"eval_metric" ":" value:EvalMetricValue;
35
    LossEntry implements ConfigEntry = name:"loss" ":" value:LossValue;
36
37
    LossWeightsEntry implements ConfigEntry = name:"loss_weights" ":" value:DoubleVectorValue;
    
38
    EvalMetricValue implements ConfigValue =(accuracy:"accuracy"
Sebastian N.'s avatar
Sebastian N. committed
39
                                               | bleu:"bleu"
40
41
42
43
                                               | crossEntropy:"cross_entropy"
                                               | f1:"f1"
                                               | mae:"mae"
                                               | mse:"mse"
Sebastian N.'s avatar
Sebastian N. committed
44
                                               | perplexity:"perplexity"
45
46
                                               | rmse:"rmse"
                                               | topKAccuracy:"top_k_accuracy");
47

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
48
49
50
51
52
53
    LRPolicyValue implements ConfigValue =(fixed:"fixed"
                                         | step:"step"
                                         | exp:"exp"
                                         | inv:"inv"
                                         | poly:"poly"
                                         | sigmoid:"sigmoid");
54
    TrainContextValue implements ConfigValue = (cpu:"cpu" | gpu:"gpu");
55

Nicola Gatto's avatar
Nicola Gatto committed
56
    interface OptimizerParamEntry extends Entry;
57
58
59
60
61
62
63

    interface LossValue extends ConfigValue;

    L1Loss implements LossValue = name:"l1" ("{" params:Entry* "}")?;

    L2Loss implements LossValue = name:"l2" ("{" params:Entry* "}")?;

64
65
    EPELoss implements LossValue = name:"epe" ("{" params:Entry* "}")?;

Eyüp Harputlu's avatar
Eyüp Harputlu committed
66
67
    LogCoshLoss implements LossValue = name:"log_cosh" ("{" params:Entry* "}")?;

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
    interface HuberEntry extends Entry;
    HuberLoss implements LossValue = name:"huber" ("{" params:HuberEntry* "}")?;

    interface CrossEntropyEntry extends Entry;
    CrossEntropyLoss implements LossValue = name:"cross_entropy" ("{" params:CrossEntropyEntry* "}")?;

    interface SoftmaxCrossEntropyEntry extends Entry;
    SoftmaxCrossEntropyLoss implements LossValue = name:"softmax_cross_entropy" ("{" params:SoftmaxCrossEntropyEntry* "}")?;

    SigmoidBinaryCrossEntropyLoss implements LossValue = name:"sigmoid_binary_cross_entropy" ("{" params:Entry* "}")?;

    interface HingeEntry extends Entry;
    HingeLoss implements LossValue = name:"hinge" ("{" params:HingeEntry* "}")?;

    interface SquaredHingeEntry extends Entry;
    SquaredHingeLoss implements LossValue = name:"squared_hinge" ("{" params:SquaredHingeEntry* "}")?;

    interface LogisticEntry extends Entry;
    LogisticLoss implements LossValue = name:"logistic" ("{" params:LogisticEntry* "}")?;

    interface KullbackLeiblerEntry extends Entry;
    KullbackLeiblerLoss implements LossValue = name:"kullback_leibler" ("{" params:KullbackLeiblerEntry* "}")?;

    SparseLabelEntry implements CrossEntropyEntry, SoftmaxCrossEntropyEntry = name:"sparse_label" ":" value:BooleanValue;
    FromLogitsEntry implements SoftmaxCrossEntropyEntry, KullbackLeiblerEntry = name:"from_logits" ":" value:BooleanValue;
    MarginEntry implements HingeEntry, SquaredHingeEntry = name:"margin" ":" value:NumberValue;
    LabelFormatEntry implements LogisticEntry = name:"label_format" ":" value:StringValue;

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
96
    interface OptimizerValue extends ConfigValue;
Nicola Gatto's avatar
Nicola Gatto committed
97
    interface SGDEntry extends OptimizerParamEntry;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
98
99
    SGDOptimizer implements OptimizerValue = name:"sgd" ("{" params:SGDEntry* "}")?;

Nicola Gatto's avatar
Nicola Gatto committed
100
    interface AdamEntry extends OptimizerParamEntry;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
101
102
    AdamOptimizer implements OptimizerValue = name:"adam" ("{" params:AdamEntry* "}")?;

Nicola Gatto's avatar
Nicola Gatto committed
103
    interface RmsPropEntry extends OptimizerParamEntry;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
104
105
    RmsPropOptimizer implements OptimizerValue = name:"rmsprop" ("{" params:RmsPropEntry* "}")?;

Nicola Gatto's avatar
Nicola Gatto committed
106
    interface AdaGradEntry extends OptimizerParamEntry;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
107
108
109
110
    AdaGradOptimizer implements OptimizerValue = name:"adagrad" ("{" params:AdaGradEntry* "}")?;

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

Nicola Gatto's avatar
Nicola Gatto committed
111
    interface AdaDeltaEntry extends OptimizerParamEntry;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
112
113
114
115
    AdaDeltaOptimizer implements OptimizerValue = name:"adadelta" ("{" params:AdaDeltaEntry* "}")?;

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

116
    MinimumLearningRateEntry implements GeneralOptimizerEntry = name:"learning_rate_minimum" ":" value:NumberValue;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
    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;
134
    RhoEntry implements AdaDeltaEntry,RmsPropEntry,HuberEntry = name:"rho" ":" value:NumberValue;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
135

Nicola Gatto's avatar
Nicola Gatto committed
136
137
138
139
    // Reinforcement Extensions
    interface MultiParamValue extends ConfigValue;

    LearningMethodEntry implements ConfigEntry = name:"learning_method" ":" value:LearningMethodValue;
Nicola Gatto's avatar
Nicola Gatto committed
140
    RLAlgorithmEntry implements ConfigEntry = name:"rl_algorithm" ":" value:RLAlgorithmValue;
Nicola Gatto's avatar
Nicola Gatto committed
141
142
143
144
145
146
147
148
    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;
    SnapshotIntervalEntry implements ConfigEntry = name:"snapshot_interval" ":" value:IntegerValue;
    AgentNameEntry implements ConfigEntry = name:"agent_name" ":" value:StringValue;
    RewardFunctionEntry implements ConfigEntry = name:"reward_function" ":" value:ComponentNameValue;
Nicola Gatto's avatar
Nicola Gatto committed
149
150
    StartTrainingAtEntry implements ConfigEntry = name:"start_training_at" ":" value:IntegerValue;
    EvaluationSamplesEntry implements ConfigEntry = name:"evaluation_samples" ":" value:IntegerValue;
Nicola Gatto's avatar
Nicola Gatto committed
151
152
153

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

154
    RLAlgorithmValue implements ConfigValue = (dqn:"dqn-algorithm" | ddpg:"ddpg-algorithm" | tdThree:"td3-algorithm");
Nicola Gatto's avatar
Nicola Gatto committed
155

Nicola Gatto's avatar
Nicola Gatto committed
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
    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;

Nicola Gatto's avatar
Nicola Gatto committed
175
176
177
178
179
180
181
182
183
    // Strategy
    StrategyEntry implements MultiParamConfigEntry = name:"strategy" ":" value:StrategyValue;
    interface StrategyValue extends MultiParamValue;

    interface StrategyEpsGreedyEntry extends Entry;
    StrategyEpsGreedyValue implements StrategyValue = name:"epsgreedy" ("{" params:StrategyEpsGreedyEntry* "}")?;

    interface StrategyOrnsteinUhlenbeckEntry extends Entry;
    StrategyOrnsteinUhlenbeckValue implements StrategyValue = name:"ornstein_uhlenbeck" ("{" params:StrategyOrnsteinUhlenbeckEntry* "}")?;
Nicola Gatto's avatar
Nicola Gatto committed
184

185
186
187
188
189
    interface StrategyGaussianEntry extends Entry;
    StrategyGaussianValue implements StrategyValue = name:"gaussian" ("{" params:StrategyGaussianEntry* "}")?;

    StrategyGaussianNoiseVarianceEntry implements StrategyGaussianEntry = name: "noise_variance" ":" value:NumberValue;

Nicola Gatto's avatar
Nicola Gatto committed
190
191
192
    StrategyOUMu implements StrategyOrnsteinUhlenbeckEntry = name: "mu" ":" value:DoubleVectorValue;
    StrategyOUTheta implements StrategyOrnsteinUhlenbeckEntry = name: "theta" ":" value:DoubleVectorValue;
    StrategyOUSigma implements StrategyOrnsteinUhlenbeckEntry = name: "sigma" ":" value:DoubleVectorValue;
Nicola Gatto's avatar
Nicola Gatto committed
193

194
    interface GeneralStrategyEntry extends StrategyEpsGreedyEntry, StrategyOrnsteinUhlenbeckEntry, StrategyGaussianEntry;
Nicola Gatto's avatar
Nicola Gatto committed
195
196
197
198
199

    GreedyEpsilonEntry implements GeneralStrategyEntry = name:"epsilon" ":" value:NumberValue;
    MinEpsilonEntry implements GeneralStrategyEntry = name:"min_epsilon" ":" value:NumberValue;
    EpsilonDecayStartEntry implements GeneralStrategyEntry = name:"epsilon_decay_start" ":" value:IntegerValue;
    EpsilonDecayMethodEntry implements GeneralStrategyEntry = name:"epsilon_decay_method" ":" value:EpsilonDecayMethodValue;
Nicola Gatto's avatar
Nicola Gatto committed
200
    EpsilonDecayMethodValue implements ConfigValue = (linear:"linear" | no:"no");
201
    EpsilonDecayPerStepEntry implements GeneralStrategyEntry = name:"epsilon_decay_per_step" ":" value:BooleanValue;
Nicola Gatto's avatar
Nicola Gatto committed
202
    EpsilonDecayEntry implements GeneralStrategyEntry = name:"epsilon_decay" ":" value:NumberValue;
Nicola Gatto's avatar
Nicola Gatto committed
203
204
205
206
207
208
209
210
211
212

    // 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;
Nicola Gatto's avatar
Nicola Gatto committed
213
    RosEnvironmentValue implements EnvironmentValue = name:"ros_interface" ("{" params:RosEnvironmentEntry* "}")?;
Nicola Gatto's avatar
Nicola Gatto committed
214
215
216
217
    RosEnvironmentStateTopicEntry implements RosEnvironmentEntry = name:"state_topic" ":" value:StringValue;
    RosEnvironmentActionTopicEntry implements RosEnvironmentEntry = name:"action_topic" ":" value:StringValue;
    RosEnvironmentResetTopicEntry implements RosEnvironmentEntry = name:"reset_topic" ":" value:StringValue;
    RosEnvironmentTerminalStateTopicEntry implements RosEnvironmentEntry = name:"terminal_state_topic" ":" value:StringValue;
Nicola Gatto's avatar
Nicola Gatto committed
218
219
220
221
222
223
224
225
    RosEnvironmentRewardTopicEntry implements RosEnvironmentEntry = name:"reward_topic" ":" value:StringValue;

    // DQN exclusive parameters
    UseFixTargetNetworkEntry implements ConfigEntry = name:"use_fix_target_network" ":" value:BooleanValue;
    TargetNetworkUpdateIntervalEntry implements ConfigEntry = name:"target_network_update_interval" ":" value:IntegerValue;
    UseDoubleDQNEntry implements ConfigEntry = name:"use_double_dqn" ":" value:BooleanValue;


226
    // DDPG and TD3 exclusive parameters
Nicola Gatto's avatar
Nicola Gatto committed
227
228
229
    CriticNetworkEntry implements ConfigEntry = name:"critic" ":" value:ComponentNameValue;
    SoftTargetUpdateRateEntry implements ConfigEntry = name:"soft_target_update_rate" ":" value:NumberValue;
    CriticOptimizerEntry implements ConfigEntry = name:"critic_optimizer" ":" value:OptimizerValue;
230
231
232
233
234

    // TD3 exclusive parameters
    PolicyNoiseEntry implements ConfigEntry = name:"policy_noise" ":" value:NumberValue;
    NoiseClipEntry implements ConfigEntry = name:"noise_clip" ":" value:NumberValue;
    PolicyDelayEntry implements ConfigEntry = name:"policy_delay" ":" value:IntegerValue;
Nicola Gatto's avatar
Nicola Gatto committed
235
}