Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "STEM Model Creator/Tutorials"

(Add New Model Parameter)
(Enter Rate Equations)
Line 113: Line 113:
 
For our SEIR model, the next step is to enter the equations for the five transitions we created in the previous step.
 
For our SEIR model, the next step is to enter the equations for the five transitions we created in the previous step.
  
{| cellspacing="0" cellpadding="5" border="1"
+
# In the Visual Editor, select the '''Chooser tool''' in the toolbar
 +
#: [ Chooser Tool Icon ]
 +
# Select '''connector edge''' between the ''' s ''' and ''' e ''' compartment boxes
 +
# In the ''' Expression Editor ''', enter the equation expression
 +
#: '''Note:'''  The final statement starts with the word '''delta''' and end with a semicolon '''( ; )'''
 +
#* For S → E, enter:
 +
#*: <code>delta transmissionRate*S*effective(i);</code>
 +
#: '' ''' Tip ''' You can use auto-completing expression assistance as you enter your expression.  Just type ''' Control - S ''' as you type for the assistance dialog! ''
 +
#* For S → E, select the box next to ''' incidence ''' under ''' For Incidence '''
 +
#*: '' This tells the STEM simulation to count this transition as part of the disease incidence
 +
#: [ Expression Editor picture ]
 +
# Repeat these steps for the other transitions in the model, entering these expressions for the transition:
 +
:{| cellspacing="0" cellpadding="5" border="1"
 
|-
 
|-
 
| '''Transition'''
 
| '''Transition'''
 
| '''Expression'''
 
| '''Expression'''
 +
| ''' Incidences to select '''
 
|-
 
|-
 
| S → E
 
| S → E
 
| <code>delta transmissionRate*S*effective(i);</code>
 
| <code>delta transmissionRate*S*effective(i);</code>
 +
| '''incidence'''
 
|-
 
|-
 
| E → I
 
| E → I
 
| <code>delta incubationRate*E;</code>
 
| <code>delta incubationRate*E;</code>
 +
| '' none ''
 
|-
 
|-
 
| I → R
 
| I → R
 
| <code>delta recoveryRate*I;</code>
 
| <code>delta recoveryRate*I;</code>
 +
| '' none ''
 
|-
 
|-
 
| I → diseaseDeaths
 
| I → diseaseDeaths
 
| <code>delta infectiousMortalityRate*I;</code>
 
| <code>delta infectiousMortalityRate*I;</code>
 +
| '' none ''
 
|-
 
|-
 
| R → S
 
| R → S
 
| <code>delta immunityLossRate*R;</code>
 
| <code>delta immunityLossRate*R;</code>
 +
| '' none ''
 
|}
 
|}
  

Revision as of 15:17, 21 June 2013

Tutorials

Create a SEIR model by extending SIR

This tutorial shows how to create a new SEIR Disease Model by extending the existing SIR Disease Model. STEM already has a built-in SEIR model, so this tutorial is more a simple how-to.

Create Model Project and Initial Disease Model

  1. Launch the STEM application
  2. Open the Designer perspective
  3. From the New menu, select Model Generator Project
    STEM ModelCreator NewModelGeneratorProject.png
  4. Choose Create and configure a new STEM Model Package
  5. Click Next
  6. On the Model Package page, enter the following values:
    • Package Name: Demo
    • Package Prefix: com.example.diseasemodels
  7. Click Add Model to add the disease model
  8. On the Model Properties page, enter these values:
    • Model Name: MySEIR
    • Model Type: Disease Model
    • Parent Model: Select SIR from the list
    [ Model Properties image]
  9. Click Finish
  10. At this point, your package properties should look like this:
    package properties image
  11. Click Finish to run the Model Generator and create your model project
    This step may take 1-2 minutes to complete
  12. After the Model Generator finishes, the Visual Editor should automatically open
    Initial layout picture

Add New Compartment

Now that your model project is created, it's time to add new parameters and compartments. First, lets create a new compartment.

We're creating an S-E-I-R model, which is made up of compartments S, E, I, and R. Since we extended the built-in S-I-R model, we need to add a new E compartment.

  1. In the Visual Editor, click the Add Compartment button.
    Add Compartment Button
  2. In the Add Compartment dialog, enter the following values
    • Name: e (make sure this is lower case)
    • Compartment Type: Standard
    • Data Type: double
  3. Click Finish
  4. A new e box now appears in the diagram.
  5. You may want to rearrange the shapes so that the S, E, I, and R boxes are in order (easier when connecting the compartments)
    To rearrange, select a compartment and drag it to a new location.
    [ layout picture ]

That's it. You've added a new compartment to your model. This is now a S-E-I-R model.

Add New Model Parameter

In addition to inheriting compartments from the parent SIR model, the new model also inherits the model (or rate) parameters from SIR. Inherited parameters include Transmission Rate (transmissionRate), Recovery Rate (recoveryRate), Immunity Loss Rate, etc.

We already added the new Exposed state to the disease model. In the textbook SEIR example, the movement from the E to I compartments is called the Incubation Rate. The next step is to add the incubationRate model parameter to the MySEIR model.

  1. In the Visual Editor, click the Edit Model button.
    [ Edit Model Button ]
  2. In the Edit Model dialog, click the Add Parameter button
  3. In the Edit Parameter dialog, enter the following values:
    • Name: incubationRate
    • Display Name: Incubation Rate
    • Data Type: double (default)
    • Default Value: 0.0 (default)
    • Optionally, add a minValue constraint of 0.0
  4. Click OK to add the parameter
  5. Click OK again to apply the changes

Regenerate the Model Project

Changing a model's parameters or compartments requires a Model Regeneration. This operations rebuilds several of the key Java files that make up the structure of your model project. For more information, see the section on Model Regeneration.

To run the Model Generator:

  1. In the Visual Editor , save the metamodel file
  2. Click the Model Generator button in the Visual Editor Toolbar
    [ Model Generator button ]
  3. If prompted, save the metamodel file
  4. In the Model Generator wizard, immediately click Finish
  5. Wait while the model is regenerated
    This may take up to a minute to complete

After the Model Generator wizard closes, you're ready to implement the model's transitions and expressions.

Create Transitions and Expressions

You're now ready to move on to the fun part - creating the transitions that describe the movement of a population between various states in the disease model.

Transitions have three key pieces;

  • The Source Compartment
  • The Target Compartment
  • The equation that describes the flow rate out of the source compartment and into the target compartment per time step

With the STEM Visual Editor, you can easily draw the transitions as graph edges between a source and target compartment then use the STEM Expression Editor to enter the rate equation.

Draw Transitions

For this SEIR Model, we will create transitions between these compartments

  • S → E
  • E → I
  • I → R
  • I → diseaseDeaths
  • R → S

To draw transitions:

  1. In the Visual Editor, select the Draw Transition Tool button.
    [ Draw Transition toolbar image ]
  2. To create the S → E transition:
    • Select the S compartment as the source. Click once on the s compartment box
    • Select the E compartment as the target. Move the mouse to and click once on the e compartment box
  3. You should now see a directed connector between the s and e compartment boxes
    [ First Image ]
  4. Repeat for the other transitions listed above
  5. After you create all five transitions, your diagram should look like this:
    [ Final image ]
Enter Rate Equations

Using the Expression Editor , you can easily enter the equations that represent the state changes in your model as STEM Expressions. For more information, please read about the STEM Expression Language and the Expression Editor.

For our SEIR model, the next step is to enter the equations for the five transitions we created in the previous step.

  1. In the Visual Editor, select the Chooser tool in the toolbar
    [ Chooser Tool Icon ]
  2. Select connector edge between the s and e compartment boxes
  3. In the Expression Editor , enter the equation expression
    Note: The final statement starts with the word delta and end with a semicolon ( ; )
    • For S → E, enter:
      delta transmissionRate*S*effective(i);
    Tip You can use auto-completing expression assistance as you enter your expression. Just type Control - S as you type for the assistance dialog!
    • For S → E, select the box next to incidence under For Incidence
      This tells the STEM simulation to count this transition as part of the disease incidence
    [ Expression Editor picture ]
  4. Repeat these steps for the other transitions in the model, entering these expressions for the transition:
Transition Expression Incidences to select
S → E delta transmissionRate*S*effective(i); incidence
E → I delta incubationRate*E; none
I → R delta recoveryRate*I; none
I → diseaseDeaths delta infectiousMortalityRate*I; none
R → S delta immunityLossRate*R; none

Create Disease and Add to Scenario

Run in STEM

Add seasonal modulation to the SEIR model

Copyright © Eclipse Foundation, Inc. All Rights Reserved.