You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

174 lines
4.8 KiB

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Parametric Models"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Instantiating parametric models\n",
"\n",
"[01-parametric-models.py](https://github.com/moves-rwth/stormpy/blob/master/examples//parametric_models/01-parametric-models.py)\n",
"\n",
"Input formats such as prism allow to specify programs with open constants. We refer to these open constants as parameters.\n",
"If the constants only influence the probabilities or rates, but not the topology of the underlying model, we can build these models as parametric models:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
">>> import stormpy\n",
">>> import stormpy.examples\n",
">>> import stormpy.examples.files\n",
">>> path = stormpy.examples.files.prism_dtmc_die\n",
">>> prism_program = stormpy.parse_prism_program(path)\n",
">>> formula_str = \"P=? [F s=7 & d=2]\"\n",
">>> properties = stormpy.parse_properties(formula_str, prism_program)\n",
">>> model = stormpy.build_parametric_model(prism_program, properties)\n",
">>> parameters = model.collect_probability_parameters()\n",
">>> for x in parameters:\n",
"... print(x)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In order to obtain a standard DTMC, MDP or other Markov model, we need to instantiate these models by means of a model instantiator:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
">>> import stormpy.pars\n",
">>> instantiator = stormpy.pars.PDtmcInstantiator(model)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before we obtain an instantiated model, we need to map parameters to values: We build such a dictionary as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
">>> point = dict()\n",
">>> for x in parameters:\n",
"... print(x.name)\n",
"... point[x] = 0.4\n",
">>> instantiated_model = instantiator.instantiate(point)\n",
">>> result = stormpy.model_checking(instantiated_model, properties[0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Initial states and labels are set as for the parameter-free case."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Checking parametric models\n",
"\n",
"[02-parametric-models.py](https://github.com/moves-rwth/stormpy/blob/master/examples//parametric_models/02-parametric-models.py)\n",
"\n",
"It is also possible to check the parametric model directly, similar as before in [Checking properties](../getting_started.ipynb#checking-properties):"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
">>> result = stormpy.model_checking(model, properties[0])\n",
">>> initial_state = model.initial_states[0]\n",
">>> func = result.at(initial_state)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We collect the constraints ensuring that underlying model is well-formed and the graph structure does not change:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide-output": false
},
"outputs": [],
"source": [
">>> collector = stormpy.ConstraintCollector(model)\n",
">>> for formula in collector.wellformed_constraints:\n",
"... print(formula)\n",
">>> for formula in collector.graph_preserving_constraints:\n",
"... print(formula)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Collecting information about the parametric models\n",
"\n",
"[03-parametric-models.py](https://github.com/moves-rwth/stormpy/blob/master/examples//parametric_models/03-parametric-models.py)\n",
"\n",
"This example shows three implementations to obtain the number of transitions with probability one in a parametric model."
]
}
],
"metadata": {
"date": 1598178167.2485256,
"filename": "parametric_models.rst",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.2"
},
"title": "Parametric Models"
},
"nbformat": 4,
"nbformat_minor": 4
}