Commit d844f7fc authored by Svetlana Pavlitskaya's avatar Svetlana Pavlitskaya
Browse files

Version 0.2.3-SNAPSHOT: moved to monticore 5.0.0, corresponding changes in grammar and symbol table

parent 733b7f32
Pipeline #67013 passed with stages
in 5 minutes and 46 seconds
......@@ -30,18 +30,18 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>cnn-train</artifactId>
<version>0.2.2-SNAPSHOT</version>
<version>0.2.3-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
<properties>
<!-- .. SE-Libraries .................................................. -->
<monticore.version>4.5.5</monticore.version>
<se-commons.version>1.7.7</se-commons.version>
<mc.grammars.assembly.version>0.0.6</mc.grammars.assembly.version>
<SIUnit.version>0.0.10-SNAPSHOT</SIUnit.version>
<Common-MontiCar.version>0.0.12</Common-MontiCar.version>
<monticore.version>5.0.0</monticore.version>
<se-commons.version>1.7.8</se-commons.version>
<mc.grammars.assembly.version>0.0.6-SNAPSHOT</mc.grammars.assembly.version>
<SIUnit.version>0.0.11</SIUnit.version>
<Common-MontiCar.version>0.0.14-SNAPSHOT</Common-MontiCar.version>
<!-- .. Libraries .................................................. -->
<guava.version>18.0</guava.version>
......@@ -50,7 +50,7 @@
<jscience.version>4.3.1</jscience.version>
<!-- .. Plugins ....................................................... -->
<monticore.plugin>4.5.3.1</monticore.plugin>
<monticore.plugin>5.0.0</monticore.plugin>
<assembly.plugin>2.5.4</assembly.plugin>
<compiler.plugin>3.3</compiler.plugin>
<source.plugin>2.4</source.plugin>
......
package de.monticore.lang.monticar;
grammar CNNTrain extends de.monticore.lang.monticar.Common2, de.monticore.lang.NumberUnit{
grammar CNNTrain extends de.monticore.lang.monticar.Common2, de.monticore.NumberUnit{
symbol scope CNNTrainCompilationUnit = "configuration"
name:Name&
......@@ -42,13 +42,11 @@ grammar CNNTrain extends de.monticore.lang.monticar.Common2, de.monticore.lang.N
DataVariable implements VariableReference = Name&;
IntegerValue implements ConfigValue = Number;
NumberValue implements ConfigValue = Number;
IntegerValue implements ConfigValue = NumberWithUnit;
NumberValue implements ConfigValue = NumberWithUnit;
BooleanValue implements ConfigValue = (TRUE:"true" | FALSE:"false");
interface OptimizerValue extends ConfigValue;
//ast OptimizerValue = method java.util.List<? extends ASTEntry> getParams(){}
// method String getName(){};
interface SGDEntry extends Entry;
SGDOptimizer implements OptimizerValue = name:"sgd" ("{" params:SGDEntry* "}")?;
......@@ -62,8 +60,6 @@ grammar CNNTrain extends de.monticore.lang.monticar.Common2, de.monticore.lang.N
interface AdaGradEntry extends Entry;
AdaGradOptimizer implements OptimizerValue = name:"adagrad" ("{" params:AdaGradEntry* "}")?;
//DCASGD, SGLD, Ftrl, Adamax
NesterovOptimizer implements OptimizerValue = name:"nag" ("{" params:SGDEntry* "}")?;
interface AdaDeltaEntry extends Entry;
......
......@@ -26,5 +26,5 @@ public interface ASTOptimizerValue extends ASTOptimizerValueTOP {
String getName();
List<? extends ASTEntry> getParams();
List<? extends ASTEntry> getParamsList();
}
......@@ -22,26 +22,16 @@ package de.monticore.lang.monticar.cnntrain._cocos;
import de.monticore.lang.monticar.cnntrain._ast.ASTIntegerValue;
import de.monticore.lang.monticar.cnntrain.helper.ErrorCodes;
import de.monticore.lang.numberunit._ast.ASTUnitNumber;
import de.se_rwth.commons.logging.Log;
import org.jscience.mathematics.number.Rational;
import java.util.Optional;
public class CheckInteger implements CNNTrainASTIntegerValueCoCo {
@Override
public void check(ASTIntegerValue node) {
Optional<ASTUnitNumber> unitNumber = node.getNumber().getUnitNumber();
if (unitNumber.isPresent()){
Rational number = unitNumber.get().getNumber().get();
if (number.getDivisor().intValue() != 1){
Log.error("0" + ErrorCodes.NOT_INTEGER_CODE +" Value has to be an integer."
, node.get_SourcePositionStart());
}
}
else {
throw new IllegalStateException("integer check");
Double unitNumber = node.getNumberWithUnit().getNumber().get();
if ((unitNumber % 1)!= 0) {
Log.error("0" + ErrorCodes.NOT_INTEGER_CODE +" Value has to be an integer."
, node.get_SourcePositionStart());
}
}
......
......@@ -92,7 +92,7 @@ public class CNNTrainSymbolTableCreator extends CNNTrainSymbolTableCreatorTOP {
@Override
public void endVisit(ASTOptimizerEntry node) {
for (ASTEntry nodeParam : node.getValue().getParams()) {
for (ASTEntry nodeParam : node.getValue().getParamsList()) {
OptimizerParamSymbol param = new OptimizerParamSymbol();
OptimizerParamValueSymbol valueSymbol = (OptimizerParamValueSymbol) nodeParam.getValue().getSymbol().get();
param.setValue(valueSymbol);
......@@ -105,7 +105,7 @@ public class CNNTrainSymbolTableCreator extends CNNTrainSymbolTableCreatorTOP {
public void endVisit(ASTNumEpochEntry node) {
EntrySymbol entry = new EntrySymbol(node.getName());
ValueSymbol value = new ValueSymbol();
Integer value_as_int = node.getValue().getNumber().getUnitNumber().get().getNumber().get().getDividend().intValue();
Integer value_as_int = getIntegerFromNumber(node.getValue());
value.setValue(value_as_int);
entry.setValue(value);
addToScopeAndLinkWithNode(entry, node);
......@@ -116,7 +116,7 @@ public class CNNTrainSymbolTableCreator extends CNNTrainSymbolTableCreatorTOP {
public void endVisit(ASTBatchSizeEntry node) {
EntrySymbol entry = new EntrySymbol(node.getName());
ValueSymbol value = new ValueSymbol();
Integer value_as_int = node.getValue().getNumber().getUnitNumber().get().getNumber().get().getDividend().intValue();
Integer value_as_int = getIntegerFromNumber(node.getValue());
value.setValue(value_as_int);
entry.setValue(value);
addToScopeAndLinkWithNode(entry, node);
......@@ -127,12 +127,7 @@ public class CNNTrainSymbolTableCreator extends CNNTrainSymbolTableCreatorTOP {
public void endVisit(ASTLoadCheckpointEntry node) {
EntrySymbol entry = new EntrySymbol(node.getName());
ValueSymbol value = new ValueSymbol();
if (node.getValue().getTRUE().isPresent()){
value.setValue(true);
}
else if (node.getValue().getFALSE().isPresent()){
value.setValue(false);
}
value.setValue(getBooleanForValue(node.getValue()));
entry.setValue(value);
addToScopeAndLinkWithNode(entry, node);
configuration.getEntryMap().put(node.getName(), entry);
......@@ -142,12 +137,7 @@ public class CNNTrainSymbolTableCreator extends CNNTrainSymbolTableCreatorTOP {
public void endVisit(ASTNormalizeEntry node) {
EntrySymbol entry = new EntrySymbol(node.getName());
ValueSymbol value = new ValueSymbol();
if (node.getValue().getTRUE().isPresent()){
value.setValue(true);
}
else if (node.getValue().getFALSE().isPresent()){
value.setValue(false);
}
value.setValue(getBooleanForValue(node.getValue()));
entry.setValue(value);
addToScopeAndLinkWithNode(entry, node);
configuration.getEntryMap().put(node.getName(), entry);
......@@ -157,7 +147,7 @@ public class CNNTrainSymbolTableCreator extends CNNTrainSymbolTableCreatorTOP {
public void visit(ASTTrainContextEntry node) {
EntrySymbol entry = new EntrySymbol(node.getName());
ValueSymbol value = new ValueSymbol();
if (node.getValue().cpuIsPresent()){
if (node.getValue().isPresentCpu()){
value.setValue(Context.CPU);
}
else {
......@@ -172,25 +162,25 @@ public class CNNTrainSymbolTableCreator extends CNNTrainSymbolTableCreatorTOP {
public void visit(ASTEvalMetricEntry node) {
EntrySymbol entry = new EntrySymbol(node.getName());
ValueSymbol value = new ValueSymbol();
if (node.getValue().getAccuracy().isPresent()){
if (node.getValue().isPresentAccuracy()){
value.setValue(EvalMetric.ACCURACY);
}
else if (node.getValue().getCrossEntropy().isPresent()){
else if (node.getValue().isPresentCrossEntropy()){
value.setValue(EvalMetric.CROSS_ENTROPY);
}
else if (node.getValue().getF1().isPresent()){
else if (node.getValue().isPresentF1()){
value.setValue(EvalMetric.F1);
}
else if (node.getValue().getMae().isPresent()){
else if (node.getValue().isPresentMae()){
value.setValue(EvalMetric.MAE);
}
else if (node.getValue().getMse().isPresent()){
else if (node.getValue().isPresentMse()){
value.setValue(EvalMetric.MSE);
}
else if (node.getValue().getRmse().isPresent()){
else if (node.getValue().isPresentRmse()){
value.setValue(EvalMetric.RMSE);
}
else if (node.getValue().getTopKAccuracy().isPresent()){
else if (node.getValue().isPresentTopKAccuracy()){
value.setValue(EvalMetric.TOP_K_ACCURACY);
}
entry.setValue(value);
......@@ -201,22 +191,22 @@ public class CNNTrainSymbolTableCreator extends CNNTrainSymbolTableCreatorTOP {
@Override
public void endVisit(ASTLRPolicyValue node) {
OptimizerParamValueSymbol value = new OptimizerParamValueSymbol();
if (node.getFixed().isPresent()){
if (node.isPresentFixed()){
value.setValue(LRPolicy.FIXED);
}
else if (node.getExp().isPresent()){
else if (node.isPresentExp()){
value.setValue(LRPolicy.EXP);
}
else if (node.getInv().isPresent()){
else if (node.isPresentInv()){
value.setValue(LRPolicy.INV);
}
else if (node.getStep().isPresent()){
else if (node.isPresentStep()){
value.setValue(LRPolicy.STEP);
}
else if (node.getSigmoid().isPresent()){
else if (node.isPresentSigmoid()){
value.setValue(LRPolicy.SIGMOID);
}
else if (node.getPoly().isPresent()){
else if (node.isPresentPoly()){
value.setValue(LRPolicy.POLY);
}
addToScopeAndLinkWithNode(value, node);
......@@ -225,7 +215,7 @@ public class CNNTrainSymbolTableCreator extends CNNTrainSymbolTableCreatorTOP {
@Override
public void endVisit(ASTNumberValue node) {
OptimizerParamValueSymbol value = new OptimizerParamValueSymbol();
Double number = node.getNumber().getUnitNumber().get().getNumber().get().doubleValue();
Double number = node.getNumberWithUnit().getNumber().get();
value.setValue(number);
addToScopeAndLinkWithNode(value, node);
}
......@@ -233,7 +223,7 @@ public class CNNTrainSymbolTableCreator extends CNNTrainSymbolTableCreatorTOP {
@Override
public void endVisit(ASTIntegerValue node) {
OptimizerParamValueSymbol value = new OptimizerParamValueSymbol();
Integer number = node.getNumber().getUnitNumber().get().getNumber().get().getDividend().intValue();
Integer number = getIntegerFromNumber(node);
value.setValue(number);
addToScopeAndLinkWithNode(value, node);
}
......@@ -241,13 +231,24 @@ public class CNNTrainSymbolTableCreator extends CNNTrainSymbolTableCreatorTOP {
@Override
public void endVisit(ASTBooleanValue node) {
OptimizerParamValueSymbol value = new OptimizerParamValueSymbol();
if (node.getTRUE().isPresent()){
if (node.isPresentTRUE()){
value.setValue(true);
}
else if (node.getFALSE().isPresent()){
else if (node.isPresentFALSE()){
value.setValue(false);
}
addToScopeAndLinkWithNode(value, node);
}
private int getIntegerFromNumber(ASTIntegerValue value) {
return value.getNumberWithUnit().getNumber().get().intValue();
}
private boolean getBooleanForValue(ASTBooleanValue value2) {
if (value2.isPresentTRUE()) {
return true;
}
return false;
}
}
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