Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DerivativeSettings.cpp
Go to the documentation of this file.
2
9
12
13namespace storm {
14namespace settings {
15namespace modules {
16
17const std::string DerivativeSettings::moduleName = "derivative";
18const std::string DerivativeSettings::feasibleInstantiationSearch = "gradient-descent";
19const std::string DerivativeSettings::derivativeAtInstantiation = "compute-derivative";
20const std::string DerivativeSettings::learningRate = "learning-rate";
21const std::string DerivativeSettings::miniBatchSize = "batch-size";
22const std::string DerivativeSettings::adamParams = "adam-params";
23const std::string DerivativeSettings::averageDecay = "average-decay";
24const std::string DerivativeSettings::squaredAverageDecay = "squared-average-decay";
25const std::string DerivativeSettings::terminationEpsilon = "termination-epsilon";
26const std::string DerivativeSettings::printJson = "print-json";
27const std::string DerivativeSettings::gradientDescentMethod = "descent-method";
28const std::string DerivativeSettings::omitInconsequentialParams = "omit-inconsequential-params";
29const std::string DerivativeSettings::constraintMethod = "constraint-method";
30
32 this->addOption(storm::settings::OptionBuilder(moduleName, feasibleInstantiationSearch, false,
33 "Search for a feasible instantiation (restart with new instantiation while not feasible)")
34 .build());
35 this->addOption(storm::settings::OptionBuilder(moduleName, derivativeAtInstantiation, false, "Compute the derivative at an input instantiation")
36 .addArgument(storm::settings::ArgumentBuilder::createStringArgument(derivativeAtInstantiation,
37 "Instantiation at which the derivative should be computed")
38 .build())
39 .build());
40 this->addOption(storm::settings::OptionBuilder(moduleName, learningRate, false, "Sets the learning rate of gradient descent")
41 .addArgument(storm::settings::ArgumentBuilder::createDoubleArgument(learningRate, "The learning rate of the gradient descent")
43 .build())
44 .build());
45 this->addOption(
46 storm::settings::OptionBuilder(moduleName, miniBatchSize, false, "Sets the size of the minibatch")
47 .setIsAdvanced()
48 .addArgument(storm::settings::ArgumentBuilder::createIntegerArgument(miniBatchSize, "The size of the minibatch").setDefaultValueInteger(32).build())
49 .build());
50 this->addOption(storm::settings::OptionBuilder(moduleName, gradientDescentMethod, false, "Sets the gradient descent method")
51 .setIsAdvanced()
53 gradientDescentMethod,
54 "Gradient Descent method (adam, radam, rmsprop, plain, plain-sign, momentum, momentum-sign, nesterov, nesterov-sign)")
56 .build())
57 .build());
58 this->addOption(
60 moduleName, adamParams, false,
61 "Sets hyperparameters of the Gradient Descent algorithms, especially (R)ADAM's. If you're using RMSProp, averageDecay is RMSProp's decay.")
62 .setIsAdvanced()
63 .addArgument(
64 storm::settings::ArgumentBuilder::createDoubleArgument(averageDecay, "Decay of decaying step average").setDefaultValueDouble(0.9).build())
65 .addArgument(storm::settings::ArgumentBuilder::createDoubleArgument(squaredAverageDecay, "Decay of squared decaying step average")
67 .build())
68 .build());
69 this->addOption(storm::settings::OptionBuilder(moduleName, printJson, false, "Print the run as json after finishing (slow!)").setIsAdvanced().build());
70 this->addOption(
71 storm::settings::OptionBuilder(moduleName, terminationEpsilon, false,
72 "The change in value that constitutes as a \"tiny change\", after a few of which the gradient descent will terminate")
73 .addArgument(storm::settings::ArgumentBuilder::createDoubleArgument(terminationEpsilon, "The epsilon").setDefaultValueDouble(1e-6).build())
74 .build());
75 this->addOption(
76 storm::settings::OptionBuilder(moduleName, omitInconsequentialParams, false,
77 "Parameters that are removed in minimization because they have no effect on the rational function are normally set to "
78 "0.5 in the final instantiation. If this flag is set, they will be omitted from the final instantiation entirely.")
79 .setIsAdvanced()
80 .build());
81 this->addOption(storm::settings::OptionBuilder(moduleName, constraintMethod, false, "Constraint Method")
82 .setIsAdvanced()
83 .addArgument(storm::settings::ArgumentBuilder::createStringArgument(constraintMethod, "Method for dealing with constraints")
84 .setDefaultValueString("project-gradient")
85 .build())
86 .build());
87}
88
90 return this->getOption(feasibleInstantiationSearch).getHasOptionBeenSet();
91}
92
93boost::optional<std::string> DerivativeSettings::getDerivativeAtInstantiation() const {
94 if (this->getOption(derivativeAtInstantiation).getHasOptionBeenSet()) {
95 return this->getOption(derivativeAtInstantiation).getArgumentByName(derivativeAtInstantiation).getValueAsString();
96 } else {
97 return boost::none;
98 }
99}
100
102 return this->getOption(learningRate).getArgumentByName(learningRate).getValueAsDouble();
103}
105 return this->getOption(miniBatchSize).getArgumentByName(miniBatchSize).getValueAsInteger();
106}
108 return this->getOption(adamParams).getArgumentByName(averageDecay).getValueAsDouble();
109}
111 return this->getOption(adamParams).getArgumentByName(squaredAverageDecay).getValueAsDouble();
112}
113
115 return this->getOption(printJson).getHasOptionBeenSet();
116}
117
119 return this->getOption(terminationEpsilon).getArgumentByName(terminationEpsilon).getValueAsDouble();
120}
121
122boost::optional<derivative::GradientDescentMethod> DerivativeSettings::getGradientDescentMethod() const {
123 return methodFromString(this->getOption(gradientDescentMethod).getArgumentByName(gradientDescentMethod).getValueAsString());
124}
125
127 return this->getOption(gradientDescentMethod).getArgumentByName(gradientDescentMethod).getValueAsString();
128}
129
131 return this->getOption(omitInconsequentialParams).getHasOptionBeenSet();
132}
133
134boost::optional<derivative::GradientDescentConstraintMethod> DerivativeSettings::getConstraintMethod() const {
135 return constraintMethodFromString(this->getOption(constraintMethod).getArgumentByName(constraintMethod).getValueAsString());
136}
137
139 return this->getOption(constraintMethod).getArgumentByName(constraintMethod).getValueAsString();
140}
141
142boost::optional<derivative::GradientDescentMethod> DerivativeSettings::methodFromString(const std::string &str) const {
144 if (str == "adam") {
146 } else if (str == "radam") {
148 } else if (str == "rmsprop") {
150 } else if (str == "plain") {
152 } else if (str == "plain-sign") {
154 } else if (str == "momentum") {
156 } else if (str == "momentum-sign") {
158 } else if (str == "nesterov") {
160 } else if (str == "nesterov-sign") {
162 } else {
163 return boost::none;
164 }
165 return method;
166}
167
168boost::optional<derivative::GradientDescentConstraintMethod> DerivativeSettings::constraintMethodFromString(const std::string &str) const {
170 if (str == "project-gradient") {
172 } else if (str == "project") {
174 } else if (str == "penalty-quadratic") {
176 } else if (str == "barrier-logarithmic") {
178 } else if (str == "barrier-infinity") {
180 } else if (str == "logistic-sigmoid") {
182 } else {
183 return boost::none;
184 }
185 return method;
186}
187
188} // namespace modules
189} // namespace settings
190} // namespace storm
virtual std::string getValueAsString() const =0
Retrieves the value of this argument as a string.
virtual int_fast64_t getValueAsInteger() const =0
Retrieves the value of this argument as an integer.
virtual double getValueAsDouble() const =0
Retrieves the value of this argument as a double.
static ArgumentBuilder createDoubleArgument(std::string const &name, std::string const &description)
Creates a double argument with the given parameters.
static ArgumentBuilder createIntegerArgument(std::string const &name, std::string const &description)
Creates an integer argument with the given parameters.
static ArgumentBuilder createStringArgument(std::string const &name, std::string const &description)
Creates a string argument with the given parameters.
This class provides the interface to create an option...
ArgumentBase const & getArgumentByName(std::string const &argumentName) const
Returns a reference to the argument with the specified long name.
Definition Option.cpp:79
bool getHasOptionBeenSet() const
Retrieves whether the option has been set.
Definition Option.cpp:125
boost::optional< std::string > getDerivativeAtInstantiation() const
Retrieves whether an extremum should be found by Gradient Descent.
double getSquaredAverageDecay() const
Retrieves the decay of the squared decaying step average of the ADAM algorithm.
std::string getGradientDescentMethodAsString() const
Retrieves the gradient descent method as a string.
uint_fast64_t getMiniBatchSize() const
Retrieves the mini batch size of the gradient descent.
boost::optional< derivative::GradientDescentMethod > getGradientDescentMethod() const
Retrieves the gradient descent method.
DerivativeSettings()
Creates a new set of monotonicity checking settings.
double getAverageDecay() const
Retrieves the decay of the decaying step average of the ADAM algorithm.
bool areInconsequentialParametersOmitted() const
Are inconsequential parameters omitted?
boost::optional< derivative::GradientDescentConstraintMethod > getConstraintMethod() const
Retrieves the gradient descent method constraint method.
bool isFeasibleInstantiationSearchSet() const
Retrieves whether a feasible instance should be found by Gradient Descent.
double getTerminationEpsilon() const
Retrieves the termination epsilon.
double getLearningRate() const
Retrieves the learning rate for the gradient descent.
bool isPrintJsonSet() const
Retrieves whether the GradientDescentInstantiationSearcher should print the run as json after finishi...
std::string getConstraintMethodAsString() const
Retrieves the gradient descent method constraint method as a string.
This is the base class of the settings for a particular module.
void addOption(std::shared_ptr< Option > const &option)
Adds and registers the given option.
Option & getOption(std::string const &longName)
Retrieves the option with the given long name.
GradientDescentMethod
GradientDescentMethod is the method of Gradient Descent the GradientDescentInstantiationSearcher shal...
GradientDescentConstraintMethod
GradientDescentConstraintMethod is the method for mitigating constraints that the GradientDescentInst...
SettingsType const & getModule()
Get module.
LabParser.cpp.
Definition cli.cpp:18