Generating Random Numbers from Custom Probability Distributions

May 29th, 2014 No comments

STELLA® and iThink® provide many useful probability distribution functions (listed here).  However, sometimes you need to draw random numbers from a different probability distribution, perhaps one you have developed yourself.  In these cases, it is possible to invert the cumulative probability distribution and use a uniformly distributed random number between zero and one (using the RANDOM built-in) to draw a number from the intended distribution.  With a lot of math, this can be done analytically (briefly described here).  With no math at all, it can be closely approximated using the graphical function.

Find the Cumulative Distribution Function

Every probability distribution has a probability density function (PDF) that relates a value with its probability of occurring.  The most famous continuous PDF is the bell curve for the normal distribution:

image

From the PDF, we can see that the probability of randomly drawing 100 is just under 0.09 while the probability of randomly drawing 88 or 112 is close to zero.  Note that applying the techniques described in this article to a continuous probability distribution will only approximate that distribution.  The accuracy of the approximation will be determined by the number of data points included in the graphical function.

For discrete probability functions, the PDF resembles a histogram:

image

From this PDF, we can see that the probability of randomly drawing 1 is 0.4, while the probability of drawing 3 is 0.15.  As discrete probability distributions can be represented exactly within graphical functions, the remainder of this article will focus on them.

Read more…

Generating Custom Reports Using XMILE

September 4th, 2013 No comments

XMILE is an open standard for describing system dynamics models in XML.  Version 10 of iThink and STELLA output their models in the XMILE format.  One of the advantages of XML is that it is a text-based format that can be easily queried and manipulated.  This post will show you how to use XMLStarlet, a free XML command line management tool available for Windows, Macintosh, and Linux, to easily extract information from a XMILE model.  It will also demonstrate how to modify the XML style sheet (XSLT) generated by XMLStarlet to create custom HTML reports.

Our goal is to create a report that lists the stocks, flows, and converters in the susceptible-infected-recovered (SIR) model of infection shown below (available by clicking here).  Each model variable will be listed with its own equation and sorted by name.

SIR

XMLStarlet uses the select command (sel) for making queries to an XML file and formatting the results.  We will use all of the following select command options:

-t (template): define a set of rules (below) to be applied to the XML file
-m “XPath query” (match): find and select a set of nodes in the XML file
-s <options> “XPath expression” (sort): sort selected nodes by XPath expression
-v “XPath expression” (value): output value of XPath expression
-o “text” (output): output the quoted text
-n (newline): start a new line in the output

Reporting Stock Names

Let’s start by outputting the names of the stocks in the model.  In a XMILE file, stocks are identified by the <stock> tag, which is nested inside the <xmile> and <model> tags:

<xmile …>
   <model>
      <stock name="Infected">
         <eqn>1</eqn>
      </stock>
   </model>
</xmile>

There is one <stock> tag for every stock in the model and each stock has, at a minimum, both a name (in the “name” attribute) and an initialization equation (in the <eqn> tag).  To get the names of all stocks in the model, we can build a template using these XMLStarlet command options:

sel –t -m “_:xmile/_:model/_:stock” -v “@name” -n

The “sel” chooses the select command and the –t begins the template (the set of rules used to extract and format information from the XML file).  The –n at the end puts each stock name on its own line.

The –m option defines the XML path to any stock from the root.  In this case, the –m option is selecting all the XML nodes named stock (i.e., <stock> tags) that are under any <model> tags in the <xmile> tag.  From the XMILE file, one might expect the XML path to be “xmile/model/stock,” but the tags in the XMILE file are in the XMILE namespace and XPath, which is being used for this query, requires namespaces to be explicitly specified.  Luckily, XMLStarlet, starting in version 1.5.0, allows us to use “_” for the name of the namespace used by the XML file, in this case the XMILE namespace.  Thus, every XMILE name in a query must be preceded by “_:”.

Finally, the –v option allows us to output the name of each node selected with -m (stocks, in this case).  The “@” tells XPath that “name” is an attribute, not a tag, i.e., it is of the form name=”…” rather than <name>…</name>.

To build a full command, we need to add the path to XML Starlet to the beginning and the name of the XML file being queried to the end:

XMLStarlet_path/xml <options above> SIR.stmx

The entire command without the path to XMLStarlet is:

xml sel -t -m “_:xmile/_:model/_:stock” -v “@name” -n SIR.stmx

This command produces the following output:

Infected
Susceptible
Recovered

Read more…

XMILE – An open standard for system dynamics models

July 19th, 2013 No comments

In June, isee systems and IBM sponsored a new technical committee in OASIS, a large standards organization. This committee is developing a new system dynamics modeling standard called XMILE. This blog post will answer some important questions about XMILE.

1. What is XMILE?

XMILE is an open XML protocol for the sharing, interoperability, and reuse of system dynamics models and simulations.

2. What’s the difference between XMILE and SMILE?

XMILE is the XML representation of a system dynamics model. SMILE is the underlying system dynamics language that is represented in XML using XMILE. In this way, it is very similar to the DYNAMO language originally used to create system dynamics models. SMILE could eventually be encoded using something other than XML.

3. How does XMILE benefit iThink and STELLA users?

There are several immediate benefits to iThink and STELLA users:

  • XML files can be reformatted and styled with XSLT files. There are programs available that generate reports directly from XML files.
  • Model files can be examined and edited in a text editor, facilitating searches and simple replaces.
  • Because XMILE is a text file format, proper versioning of model files, showing meaningful differences between revisions, can be done with version control software such as SVN and Git.
  • Because XMILE is textual, platform-neutral, and descriptive, rather than a binary representation of the implementation, it is more resilient to possible file corruption.
  • As the standard becomes more widely adopted additional benefits will include a broader market for models and the ability to share models with colleagues working in different modeling software packages.

4. How will the adoption of the XMILE standard benefit the field of system dynamics?

The benefits of this standard are:

  • System dynamics models can be re-used to show how different policies produce different outcomes in complex environments.
  • Models can be stored in cloud-based libraries, shared within and between organizations, and used to communicate different outcomes with common vocabulary.
  • Model components can be re-used and plugged into other simulations.
  • It will allow the creation of online repositories modeling many common business decisions.
  • It will increase acceptance and use of system dynamics as a discipline.
  • It will help ISVs make new tools that help businesses to develop and understand models and simulations.
  • It will enable vendors to develop standards-based applications for new markets such as mobile and social media.

5. What is the connection to Big Data?

XMILE opens up system dynamics models to a broader audience and for new uses, including embedding models within larger processes. System dynamics models provide a new way to analyze Big Data, especially when pulling live data streams into a running model to determine the impacts of our decisions in real time against future outcomes, to hopefully avoid unintended consequences of our actions. Note, however, that the presumption of Big Data, or the addition of Big Data, does not automatically lead to large, complicated models. You do not have to create giant models just because you have a lot of data. We’re aggregating the data and looking at it in a more homogenous way, so the models can still stay relatively understandable.

6. Can I adapt existing iThink and STELLA models to XMILE?

All of the isee systems products (version 10 and later) already use the XMILE standard in its draft form. As the standard evolves, isee systems products will be updated to meet the changing standard and your models will be translated forward so they remain XMILE-compatible

7. Do you plan to extend XMILE to include discrete event or agent-based simulations?

XMILE focuses on the language of classic system dynamics, rooted in DYNAMO. While we anticipate the language to expand to include both discrete simulation and agent-based modeling, version one of the XMILE specification is restricted to system dynamics modeling.

8. Could you show an example of how XMILE is used in a model?

XMILE is used to describe the model and is the format used for saving it. A model snippet is shown below with the XMILE that completely describes both its simulation and its drawing properties (in the display tag).

image

xmile

9. A big part of system dynamics is graphical, will XMILE include this part of models?

Yes, all graphical information is stored within the display tag, as shown in the earlier example.

10. Why would you want to store visual layout in Xmile? Why not separate structure from layout?

The structure is actually separate from the layout in the XML file. All visual information is embedded within display tags and can be ignored. XMILE defines three separate levels of compliance, with the lowest level being simulation information only (i.e., structure). A model does not need to include display information and any application is free to ignore it.

11. Will XMILE include data from running the model?

XMILE only represents the model structure, so no data is included.

12. Where can I get more information?

The OASIS technical committee for XMILE maintains a public record at https://www.oasis-open.org/committees/xmile/. This page is regularly updated with new information.

The draft standard can be found in these two documents:

http://www.iseesystems.com/community/support/SMILEv4.pdf http://www.iseesystems.com/community/support/XMILEv4.pdf

In addition, isee systems maintains a web page, http://www.iseesystems.com/community/support/XMILE.aspx, that will be updated periodically with new information about XMILE.

Categories: News & Announcements Tags:

Working with Array Equations in Version 10

December 17th, 2012 3 comments

STELLA/iThink version 10 introduces several new array features, including simplified and more powerful Apply-To-All equations that are designed to reduce the need to specify equations for every individual element.

Dimension names are optional

When an equation is written using other array names, the dimension names are not normally needed.  For example, given arrays A, B, and C, each with the dimensions Dim1 and Dim2, A can be set to the sum of B and C with this equation:

B + C

Dimension names are still needed when the dimensions do not match.  For example, to also add in the first 2-dimensional slice of the 3-dimensional array D[Dim1, Dim2, Dim3], the equation becomes:

B + C + D[Dim1, Dim2, 1]

The wildcard * is optional

When an array builtin is used, the * is normally not needed.  For example, to find the sum of the elements of a 2-dimensional array A[Dim1, Dim2] requires this equation:

SUM(A)

If, however, the sum of only the first column of A is desired, the * is still needed:

SUM(A[*, 1])

Simplified array builtins

There are five array builtins:  SIZE, SUM, MEAN, STDDEV, and RANK.  In addition, the MIN and MAX functions have been extended to take either one or two array arguments.  All but RANK can also be applied to queues and conveyors.

SUM, MEAN, and STDDEV all work in a similar way (see examples of SUM above).

Using the MAX function, it is possible to find the maximum value in array A,

MAX(A)

the maximum value in array A, or zero if everything is negative,

MAX(A, 0)

or the maximum across two arrays A and B,

MAX(A, B)

MIN works the same way, but finds the minimum.

The SIZE function requires an array parameter, but within an array, the special name SELF can be used to refer to the array whose equation is being set.  In addition, wildcards can be used to determine the size of any array slice.  In the equation for array A[Dim1, Dim2],

SIZE(SELF)

gives the total number of elements in array A while

SIZE(SELF[*, 1])

gives the size of the first dimension of A, i.e., the number of elements – or rows – in the first column.  Likewise,

SIZE(SELF[1, *])

gives the size of the second dimension of A, i.e., the number of elements – or columns – in the first row.

Read more…

2011 Barry Richmond Scholarship Award

August 10th, 2011 2 comments
Sarah accepts award

Sarah Boyar accepts Scholarship Award from Joanne Egner

The Barry Richmond Scholarship Award was established in 2007 by isee systems to honor and continue the legacy of its founder, Barry Richmond.  Barry was devoted to helping others become better systems citizens.  Systems citizens are members of a global community that strive to understand the complexities of today’s world and have the informed capacity to make a positive difference.  It was Barry’s mission to make systems thinking and system dynamics accessible to people of all ages, and in all fields.  The award is presented annually at the System Dynamics Society Conference to an individual whose work demonstrates a desire to expand the field of systems thinking or to apply it to current social issues.

Through most of his career, Barry focused on education as the key to spreading systems thinking.  As a teacher and a mentor he dedicated much of his time to developing tools and methodologies for teaching systems thinking.  With this in mind, it was a great pleasure to present this year’s award to Sarah Boyar, a recent graduate of the Masters Program in System Dynamics at Worcester Polytechnic Institute (WPI).

Sarah Boyar and Karim Chichakly enjoy the conference banquet

Sarah Boyar and Karim Chichakly enjoy the conference banquet

Sarah presented a portfolio of her work to the scholarship committee.  In particular, an essay about her teaching philosophy resonated with us.  Sarah wrote this piece while taking a seminar in college teaching in order to fulfill her Real World Dynamics course requirement at WPI.  Since she already had plenty of experience as a consultant applying system dynamics to real world situations, Sarah managed to convince the WPI powers-that-be that an essential real world manifestation of system dynamics is the way that it is taught.  This is something Barry would have encouraged and been excited about.

Her essay titled Beliefs About Teaching and Learning begins as follows:

I teach System Dynamics. While I want my students to have some knowledge of system dynamics, most of all I want them to be excited and stimulated by it. I also want them to find it beautiful: I want to teach in such a way that my students find some aspect of beauty in the work, whether it’s through the visual arcs in the model interface, or the precision of algebra in the way we write statements, or the way that system dynamics can ameliorate a social ill that concerns them. I want my students to somehow feel a sense of peace and beauty derived from some aspect of the knowledge I am teaching.

Among Sarah’s aspirations is the desire to teach system dynamics to professionals in other fields, namely lawyers (potential judges) and medical doctors.  Incorporating a systems perspective within both the judicial system and in healthcare could certainly make a positive difference for us all.  Good luck and congratulations Sarah!

Connecting iThink and STELLA to a Database

April 28th, 2011 5 comments

A question we periodically get from our customers is: Can iThink or STELLA connect to a database? Saving and pulling information to/from databases presents a lot of advantages for storing, organizing and sharing model data. Thanks to iThink and STELLA’s ability to import and export data via commonly used spreadsheet file formats, it is possible to use comma separated value (CSV) files as a means to create a connection to database applications.

Essentially, data can be moved between a database and iThink/STELLA by using a CSV file as a bridge. CSV files are a widely supported file standard for storing table data, and both iThink/STELLA and many database programs are able to read and write to them.

Process overview

The process of connecting to a database using CSV files as an intermediary

The process can be automated when you use iThink/STELLA’s ability to run models automatically from the command line (Windows only). Most database applications also have command line interfaces, allowing you to create a single macro script that moves data between your model and a database in a single process.

In this post I will use a simple example to demonstrate how to import data from a Microsoft SQL Server database into an iThink model on Windows. The model and all files associated with the import process are available by clicking here. If you don’t have access to Microsoft SQL Server, you can download a free developer’s version called SQL Server Express from the Microsoft web site.

The Model

The model used in this example is a variation of the Beer Game model. The structure shown below represents the ordering process for a simple retailer supply chain.

Retail Supply Chain Model

The model has been set up to import the initial values for On Order with Wholesaler and Unfilled Orders stocks, target inventory and actual customer orders (a graphical function with 21 weeks of data). The source of the imported data is the file named import.csv in the example files.

To set up this example, I manually created the CSV file using the initial model parameters. (Later in this post, you’ll see that this file will be automatically created by the database.) The model has been initialized in a steady state with actual customer orders at a constant level of 4 cases per week over the 21 week period.

Read more…

What is the difference between STELLA and iThink?

March 9th, 2011 3 comments

The question we get asked most frequently by just about anyone who wants to know more about our modeling software is “What is the difference between STELLA and iThink?”  From a functional perspective, there are no differences between the STELLA and iThink software — they are two different brands of the same product.

The STELLA brand is targeted toward individuals in educational and research settings.  Supporting materials such as An Introduction to Systems Thinking with STELLA and sample models cover the natural and social sciences.

iThink, on the other hand, is targeted toward an audience of users in business settings.  An Introduction to Systems Thinking with iThink is written with the business user in mind and model examples apply the software to areas such as operations research, resource planning, and financial analysis.

Aside from the different program icons and other graphic design elements that go along with branding, there are just a few minor differences in the default settings for STELLA and iThink.  These differences are intended to pre-configure the software for the model author.  They do not limit you in any way from configuring the default setup to match your own individual preferences.

Below is a list of all the differences between the default settings for STELLA and iThink.

Opening Models

When opening a model with STELLA on Windows, by default, the software looks for files with a .STM extension.  Similarly, iThink looks for files with an .ITM extension.  If you want to open an iThink model using STELLA or vice-versa, you need to change the file type in the Open File dialog as shown below.

STELLA file open dialog

On Macs, the open dialog will show both iThink and STELLA models as valid files to open.

If you open a model with a file type associated with the different product than the one you are using, you’ll get a message similar to the one below warning you that the model will be opened as “Untitled”.  Simply click OK to continue.

STELLA file conversion dialog

Saving Models

When saving a model in STELLA, by default, the software saves the model with a .STM file extension.  Similarly, iThink saves model s with an .ITM extension.  If you’re using STELLA and want to save your model as an iThink file or vice-versa, use the Save As… menu option and select the appropriate type as shown below.

STELLA save as dialog

STELLA on Windows save dialog

 

STELLA on Mac save dialog

STELLA on Mac save dialog

Run Specs

Since iThink is targeted toward business users who tend to measure performance monthly, the default Unit of time for iThink is set to Months.  It’s also easier to think about simulations starting in month 1 (rather than month zero) so we set the default simulation length in iThink to run from 1 to 13.  STELLA on the other hand, reports the Unit of time as “Time” and, by default, runs simulations from 0 to 12.

Run Spec comparison

Run Spec Default Settings Comparison

Table Reporting

In a business context, financial results are generally reported at the end of a time period and the values are summed over the report interval.  For example, in a report showing 2010 revenues we would assume the values reflect total revenues at the end of the year.  In line with this assumption, the default Table settings in iThink include reporting Ending balances, Summed flow values, and a report interval of one time step.

In a research setting, scientists tend to prefer reporting precise values at a particular time.   For this reason, the default Table settings in STELLA are configured to report Beginning balances, Instantaneous flow values, and a report interval of Every DT.

table default settings comparison

Table Default Settings Comparison

STELLA or iThink

When choosing between STELLA or iThink, try to think about the kinds of models you intend to build and the problems you are looking to solve.  If your objective is to drive business improvement, chances are iThink will be a better fit.  If your purpose is to understand the dynamics of a natural environment or social system, STELLA will likely be your brand of choice.  Whatever you decide, both products will provide you with the exact same functionality and can easily be configured to suit your own preferences.

Using PEST to Calibrate Models

January 14th, 2011 21 comments

There are times when it is helpful to calibrate, or fit, your model to historical data. This capability is not built into the iThink/STELLA program, but it is possible to interface to external programs to accomplish this task. One generally available program to calibrate models is PEST, available freely from www.pesthomepage.org. In this blog post, I will demonstrate how to calibrate a simple STELLA model using PEST on Windows. Note that this method relies on the Windows command line interface added in version 9.1.2 and will not work on the Macintosh. The export to comma-separated value (CSV) file feature, added in version 9.1.2, is also used.

The model and all files associated with its calibration are available by clicking here.

The Model

The model being used is the simple SIR model first presented in my blog post Limits to Growth. The model is shown again below. There are two parameters: infection rate and recovery rate. Technically, the initial value for the Susceptible stock is also a parameter. However, since this is a conserved system, we can make an excellent guess as to its value and do not need to calibrate it.

image

The Data Set

We will calibrate this model to two data sets. The first is the number of weekly deaths caused by the Hong Kong flu in New York City over the winter of 1968-1969 (below).

clip_image004

The second is the number of weekly deaths per thousand people in the UK due to the Spanish flu (H1N1) in the winter of 1918-1919 (shown later).

In both cases, I am using the number of deaths as a proxy for the number of people infected, which we do not know. This is reasonable because the number of deaths is directly proportional to the number of infected individuals. If we knew the constant of proportionality, we could multiply the deaths by this constant to get the number of people infected.

Read more…