60template<
typename ValueType>
70 std::vector<std::map<typename storm::utility::parametric::VariableType<ValueType>::type,
71 std::vector<typename storm::utility::parametric::CoefficientType<ValueType>::type>>>
77template<
template<
typename,
typename>
class ModelCheckerType,
typename ModelType,
typename ValueType,
typename SolveValueType =
double>
81 ModelCheckerType<ValueType, SolveValueType> derivativeModelchecker(model);
84 for (
auto const& property : input.
properties) {
88 derivativeModelchecker.specifyFormula(env, checkTask);
93 std::vector<typename storm::utility::parametric::VariableType<ValueType>::type> parameters;
94 std::vector<typename std::vector<typename storm::utility::parametric::CoefficientType<ValueType>::type>::const_iterator> iterators;
95 std::vector<typename std::vector<typename storm::utility::parametric::CoefficientType<ValueType>::type>::const_iterator> iteratorEnds;
101 iteratorEnds.clear();
103 for (
auto const& entry : product) {
104 parameters.push_back(entry.first);
105 iterators.push_back(entry.second.cbegin());
106 iteratorEnds.push_back(entry.second.cend());
112 for (uint64_t i = 0; i < parameters.size(); ++i) {
113 valuation[parameters[i]] = *iterators[i];
117 std::unique_ptr<storm::modelchecker::CheckResult> originalResult = originalModelchecker.
check(env, valuation);
118 valuationWatch.
stop();
120 boost::optional<std::vector<SolveValueType>> valueVector = boost::none;
121 if (originalResult) {
122 valueVector = originalResult->template asExplicitQuantitativeCheckResult<SolveValueType>().getFiniteValueVector();
128 for (
auto const& parameter : parameters) {
130 std::unique_ptr<storm::modelchecker::CheckResult> result = derivativeModelchecker.check(env, valuation, parameter, valueVector);
131 valuationWatch.
stop();
140 for (uint64_t i = 0; i < parameters.size(); ++i) {
142 if (iterators[i] == iteratorEnds[i]) {
144 iterators[i] = product.at(parameters[i]).cbegin();
147 if (i == parameters.size() - 1) {
163template<
template<
typename,
typename>
class ModelCheckerType,
typename ModelType,
typename ValueType,
typename SolveValueType = double,
bool Derivative =
false>
167 ModelCheckerType<ModelType, SolveValueType>
modelchecker(env, model);
169 for (
auto const& property : input.
properties) {
177 std::vector<typename storm::utility::parametric::VariableType<ValueType>::type> parameters;
178 std::vector<typename std::vector<typename storm::utility::parametric::CoefficientType<ValueType>::type>::const_iterator> iterators;
179 std::vector<typename std::vector<typename storm::utility::parametric::CoefficientType<ValueType>::type>::const_iterator> iteratorEnds;
185 iteratorEnds.clear();
187 for (
auto const& entry : product) {
188 parameters.push_back(entry.first);
189 iterators.push_back(entry.second.cbegin());
190 iteratorEnds.push_back(entry.second.cend());
196 for (uint64_t i = 0; i < parameters.size(); ++i) {
197 valuation[parameters[i]] = *iterators[i];
201 std::unique_ptr<storm::modelchecker::CheckResult> result =
modelchecker.check(env, valuation);
202 valuationWatch.
stop();
209 for (uint64_t i = 0; i < parameters.size(); ++i) {
211 if (iterators[i] == iteratorEnds[i]) {
213 iterators[i] = product.at(parameters[i]).cbegin();
216 if (i == parameters.size() - 1) {
232template<
typename ValueType,
typename SolveValueType =
double>
238 ValueType, SolveValueType>(env, *model->template as<storm::models::sparse::Dtmc<ValueType>>(), input, samples);
240 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Sampling the derivative is currently only supported for DTMCs.");
244template<
typename ValueType,
typename SolveValueType =
double>
249 SolveValueType>(env, *model->template as<storm::models::sparse::Dtmc<ValueType>>(), input, samples);
252 SolveValueType>(env, *model->template as<storm::models::sparse::Ctmc<ValueType>>(), input, samples);
255 SolveValueType>(env, *model->template as<storm::models::sparse::Mdp<ValueType>>(), input, samples);
257 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Sampling is currently only supported for DTMCs, CTMCs and MDPs.");
261template<
typename ValueType>
263 STORM_LOG_THROW(!model || model->isSparseModel(), storm::exceptions::NotSupportedException,
"Sampling is only supported for sparse models.");
266 if (sampleString.empty()) {
271 std::set<typename storm::utility::parametric::VariableType<ValueType>::type> modelParameters;
275 modelParameters.insert(rewParameters.begin(), rewParameters.end());
277 std::vector<std::string> cartesianProducts;
278 boost::split(cartesianProducts, sampleString, boost::is_any_of(
";"));
279 for (
auto& product : cartesianProducts) {
280 boost::trim(product);
283 std::vector<std::string> valuesForVariables;
284 boost::split(valuesForVariables, product, boost::is_any_of(
","));
285 for (
auto& values : valuesForVariables) {
289 std::set<typename storm::utility::parametric::VariableType<ValueType>::type> encounteredParameters;
292 for (
auto const& varValues : valuesForVariables) {
293 auto equalsPosition = varValues.find(
"=");
294 STORM_LOG_THROW(equalsPosition != varValues.npos, storm::exceptions::WrongFormatException,
"Incorrect format of samples.");
295 std::string variableName = varValues.substr(0, equalsPosition);
296 boost::trim(variableName);
297 std::string values = varValues.substr(equalsPosition + 1);
300 bool foundParameter =
false;
302 for (
auto const& parameter : modelParameters) {
303 std::stringstream parameterStream;
304 parameterStream << parameter;
305 if (parameterStream.str() == variableName) {
306 foundParameter =
true;
307 theParameter = parameter;
308 encounteredParameters.insert(parameter);
311 STORM_LOG_THROW(foundParameter, storm::exceptions::WrongFormatException,
"Unknown parameter '" << variableName <<
"'.");
313 std::vector<std::string> splitValues;
314 boost::split(splitValues, values, boost::is_any_of(
":"));
315 STORM_LOG_THROW(!splitValues.empty(), storm::exceptions::WrongFormatException,
"Expecting at least one value per parameter.");
317 auto& list = newCartesianProduct[theParameter];
319 for (
auto& value : splitValues) {
325 STORM_LOG_THROW(encounteredParameters == modelParameters, storm::exceptions::WrongFormatException,
326 "Variables for all parameters are required when providing samples.");
332template<
typename ValueType>
334 std::string
const& instantiationString) {
336 "Gradient descent is currently only supported for DTMCs.");
337 std::shared_ptr<storm::models::sparse::Dtmc<ValueType>> dtmc = model->template as<storm::models::sparse::Dtmc<ValueType>>();
340 auto formula = formulas[0];
342 STORM_LOG_THROW(formula->isProbabilityOperatorFormula() || formula->isRewardOperatorFormula(), storm::exceptions::NotSupportedException,
343 "Input formula needs to be either a probability operator formula or a reward operator formula.");
347 boost::optional<std::string> rewardModel = boost::none;
348 if (formula->isRewardOperatorFormula()) {
349 if (formula->asRewardOperatorFormula().hasRewardModelName()) {
350 rewardModel = std::string(formula->asRewardOperatorFormula().getRewardModelName());
352 rewardModel = std::string(
"");
355 vars.insert(rewardParameter);
363 for (
auto const& pair : keyValue) {
365 STORM_LOG_THROW(variable != storm::RationalFunctionVariable::NO_VARIABLE, storm::exceptions::WrongFormatException,
366 "Parameter '" << pair.first <<
"' does not exist in the model.");
368 instantiation.emplace(variable, value);
374 std::shared_ptr<storm::logic::Formula> formulaWithoutBound;
376 formulaWithoutBound = std::make_shared<storm::logic::ProbabilityOperatorFormula>(
380 formulaWithoutBound = std::make_shared<storm::logic::RewardOperatorFormula>(formulas[0]->asRewardOperatorFormula().getSubformula().asSharedPointer());
386 for (
auto const& parameter : vars) {
387 std::cout <<
"Derivative w.r.t. " << parameter <<
": ";
389 auto result = modelChecker.
check(env, instantiation, parameter);
390 std::cout << *result <<
'\n';
std::unique_ptr< modelchecker::ExplicitQuantitativeCheckResult< ConstantType > > check(Environment const &env, storm::utility::parametric::Valuation< FunctionType > const &valuation, typename utility::parametric::VariableType< FunctionType >::type const ¶meter, boost::optional< std::vector< ConstantType > > const &valueVector=boost::none)
check calculates the deriative of the model w.r.t.
void specifyFormula(Environment const &env, modelchecker::CheckTask< logic::Formula, FunctionType > const &checkTask)
specifyFormula specifies a CheckTask.
bool isRewardModelSet() const
Retrieves whether a reward model was set.
A qualitative check result over the states of a sparse model.
Class to efficiently check a formula on a parametric model with different parameter instantiations.
virtual std::unique_ptr< CheckResult > check(Environment const &env, storm::utility::parametric::Valuation< typename SparseModelType::ValueType > const &valuation) override
void specifyFormula(CheckTask< storm::logic::Formula, typename SparseModelType::ValueType > const &checkTask)
Base class for all sparse models.
A class that provides convenience operations to display run times.
void restart()
Reset the stopwatch and immediately start it.
void stop()
Stop stopwatch and add measured time to total time.
#define STORM_LOG_THROW(cond, exception, message)
storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > createTask(std::shared_ptr< const storm::logic::Formula > const &formula, bool onlyInitialStatesRelevant=false)
std::vector< std::shared_ptr< storm::logic::Formula const > > extractFormulasFromProperties(std::vector< storm::jani::Property > const &properties)
void printModelCheckingProperty(storm::jani::Property const &property)
std::set< storm::RationalFunctionVariable > getRewardParameters(Model< storm::RationalFunction > const &model)
Get all parameters occurring in rewards.
std::set< storm::RationalFunctionVariable > getProbabilityParameters(Model< storm::RationalFunction > const &model)
Get all probability parameters occurring on transitions.
void verifyPropertiesAtSamplePoints(storm::Environment const &env, ModelType const &model, cli::SymbolicInput const &input, SampleInformation< ValueType > const &samples)
void sampleDerivatives(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Model< ValueType > > model, cli::SymbolicInput const &input, std::string const &instantiationString)
void verifyPropertiesAtSamplePointsWithSparseEngineDerivatives(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, cli::SymbolicInput const &input, SampleInformation< ValueType > const &samples)
SampleInformation< ValueType > parseSamples(std::shared_ptr< storm::models::ModelBase > const &model, std::string const &sampleString, bool graphPreserving)
void verifyPropertiesAtSamplePointsDerivative(storm::Environment const &env, ModelType const &model, cli::SymbolicInput const &input, SampleInformation< ValueType > const &samples)
void printInitialStatesResult(std::unique_ptr< storm::modelchecker::CheckResult > const &result, storm::utility::Stopwatch *watch, const storm::utility::parametric::Valuation< ValueType > *valuation)
void verifyPropertiesAtSamplePointsWithSparseEngine(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, cli::SymbolicInput const &input, SampleInformation< ValueType > const &samples)
std::unordered_map< std::string, std::string > parseKeyValueString(std::string const &keyValueString)
std::map< typename VariableType< FunctionType >::type, typename CoefficientType< FunctionType >::type > Valuation
TargetType convertNumber(SourceType const &number)
RationalFunctionVariable findRFVariable(std::string const &name)
Retrieves the (already existing) rational-function variable with the given name.
#define STORM_PRINT_AND_LOG(message)