<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Making Connections &#187; Modeling Tips</title>
	<atom:link href="http://blog.iseesystems.com/wp-404-handler.php?404;http://blog.iseesystems.com:80/category/modeling-tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.iseesystems.com</link>
	<description>isee systems blog</description>
	<lastBuildDate>Wed, 30 Nov 2011 22:01:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using PEST to Calibrate Models</title>
		<link>http://blog.iseesystems.com/modeling-tips/calibrate-models-pest/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/calibrate-models-pest/#comments</comments>
		<pubDate>Fri, 14 Jan 2011 23:00:18 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[calibration]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[h1n1]]></category>
		<category><![CDATA[iThink/STELLA]]></category>
		<category><![CDATA[Version 9.1.2]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=3529</guid>
		<description><![CDATA[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, [...]]]></description>
			<content:encoded><![CDATA[<p>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 <a href="http://www.pesthomepage.org/">www.pesthomepage.org</a>. 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 <a href="http://blog.iseesystems.com/modeling-tips/running-models-automatically-from-the-command-line/">command line interface</a> 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.</p>
<p>The model and all files associated with its calibration are available by clicking <a title="here" href="blog.iseesystems.com"></a><a href="http://blog.iseesystems.com/wp-content/uploads/2011/01/calibrate.zip">here</a>.</p>
<p><strong>The Model</strong></p>
<p>The model being used is the simple SIR model first presented in my blog post <a href="http://blog.iseesystems.com/stella-ithink/limits-to-growth/">Limits to Growth</a>. The model is shown again below. There are two parameters: <em>infection rate</em> and <em>recovery rate</em>. Technically, the initial value for the <em>Susceptible</em> 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.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border: 0px;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2011/01/image2.png" border="0" alt="image" width="299" height="125" /></p>
<p><strong>The Data Set</strong></p>
<p>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).</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border-width: 0px;" title="clip_image004" src="http://blog.iseesystems.com/wp-content/uploads/2011/01/clip_image004.gif" border="0" alt="clip_image004" width="330" height="266" /></p>
<p>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).</p>
<p>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.</p>
<p><strong> </strong></p>
<p><span id="more-3529"></span></p>
<p><strong>Preparing the Model</strong></p>
<p>The original model ran from 0 to 40 days. This needs to be changed to match the data, i.e., to 1 to 13 weeks. Changing this will force us to change the parameter values also, as described below.</p>
<p>The initial values of <em>Susceptible</em> and <em>Infected</em> must be changed to match the data set. The total number of people in the model should match the total population in the data. Summing the Hong Kong flu data set gives a population of 1035 people. The initial value for <em>Infected</em> is just the first reported value, 14. That leaves 1021 people that are <em>Susceptible</em>.</p>
<p>If you run the model using the original parameter values, you will find the infection is spreading far too quickly. To improve the chances of the calibration succeeding, it is necessary to adjust the parameters so that the results are in the ballpark of the historical data. To do this, it is useful to paste the historical data into a graphical function (called <em>data</em> in this model) and graph it alongside the model output. I first reduced the <em>infection rate</em> from 0.005 to 0.0015 and then adjusted <em>recovery rate</em> from 0.25 to 0.5 to get a closer fit to the data.</p>
<p>The model must also be modified to persistently import its parameters and export the time series we wish to fit to the historical data. The import sheet is most easily set up by creating an empty CSV file, exporting “all model variables” and “One set of values” to this file, and then removing the variables that are not needed from this file. The file can also be built manually. The final file, input.csv, looks like this:</p>
<pre style="padding-left: 30px;">infection rate,recovery rate
0.0015,0.5</pre>
<p>You will also need to create an empty file called output.csv for the exported data.</p>
<p>Set up the import by choosing Edit-&gt;Import Data… and entering the settings shown below:</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border-width: 0px;" title="clip_image006" src="http://blog.iseesystems.com/wp-content/uploads/2011/01/clip_image006.jpg" border="0" alt="clip_image006" width="502" height="464" /></p>
<p>Add a table, called Table 1, to the model and add the stock <em>Infected</em> to the table. Set up the export by choosing Edit-&gt;Export Data… and entering the settings shown below. Note the “Use table settings” option is not used. This option cannot be used for calibration as it will restrict to precision of the output to match the table.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border-width: 0px;" title="clip_image008" src="http://blog.iseesystems.com/wp-content/uploads/2011/01/clip_image008.jpg" border="0" alt="clip_image008" width="494" height="620" /></p>
<p>Save the model. It is ready to be calibrated.</p>
<p><strong>Setting up PEST</strong></p>
<p>PEST is a very powerful program. This post will only touch on the simplest capabilities that it provides. For more details and for more complex uses, consult the PEST manual.</p>
<p>PEST requires three text input files:</p>
<ul>
<li>The template file (.tpl), which tells it how to write the parameters to the model input file (input.csv in our case). </li>
<li>The instruction file (.ins), which tells it how to read the data from the model output file (output.csv in our case). </li>
<li>The control file (.pst), which tells PEST what to do. </li>
</ul>
<p><strong>Creating the Template File</strong></p>
<p>This is the simplest file to create, as it only requires replacing data values in the model input file with markers so PEST can insert the parameter values it chooses.</p>
<p>Open the model input file, input.csv, in a text editor. Add the following line to the top of the file:</p>
<pre style="padding-left: 30px;">ptf #</pre>
<p>This tells PEST this is a template file and that parameter fields, including the parameter name, will be surrounded by pound signs (#).</p>
<p>Replace each parameter value in the file with a short alphanumeric name for that parameter, surrounded by #s. Add any additional spaces that are necessary to make each field 13 characters long, <em>including</em> the pound signs. Using 13-character field widths, which is the maximum precision in single-precision floating point, is absolutely necessary to make certain the calibration succeeds (see end note about precision).</p>
<p>Save this file as input.tpl. The final file should look like this:</p>
<pre style="padding-left: 30px;">ptf #
infection rate,recovery rate
#infectrate #,#recoverrate#</pre>
<p><strong>Creating the Instruction File</strong></p>
<p>The instruction file contains a set of instructions that PEST can follow to extract the model-generated data that corresponds to the historical data from the model output file. The model output file is a CSV file that has a header line followed by 13 lines, one for each week in the model run. Each of the 13 lines contains two numbers separated by a comma. The first value on each line is the week number and the second is the number of people who have been infected.</p>
<p>The contents of the instruction file, output.ins, appear below:</p>
<pre style="padding-left: 30px;">pif @
l2 @,@ !infected1!
l1 @,@ !infected2!
l1 @,@ !infected3!
l1 @,@ !infected4!
l1 @,@ !infected5!
l1 @,@ !infected6!
l1 @,@ !infected7!
l1 @,@ !infected8!
l1 @,@ !infected9!
l1 @,@ !infected10!
l1 @,@ !infected11!
l1 @,@ !infected12!
l1 @,@ !infected13!</pre>
<p>The first line tells PEST that this is an instruction file and that the at-sign (@) will be used to delimit search keys. Each succeeding line tells PEST how to read the model output file, output.csv.</p>
<p>Each instruction line starts with a lowercase L, the PEST command to skip to the beginning of the Nth following line. The number one (1) is used to move to the start of the next line (interpreted as the start of the first line when at the beginning of the file), while larger numbers skip over an additional N &#8211; 1 lines. Thus, the “l2” in the first command, moves to the start of the second line in the file, skipping over the header. Each additional command uses “l1” to move to the start of the next line.</p>
<p>On every single line, it is necessary to skip to the second field (<em>Infected</em>), as we do not care about the week number. Surrounding the comma in at-signs (@,@) tells PEST to move to the next comma it finds (which will be the first comma on the line in all cases shown here). The exclamation points (!) delimit the name of the observation (historical data point) that corresponds to the data after the comma (called <em>observation names</em> in PEST). Note that each value of a time-series requires a unique observation name and that each observation name cannot be longer than 20 characters. In this case, there are 13 values, one for each week, in our historical data and our model-generated data, so the variables are named <em>infected1</em> thru <em>infected13</em>.</p>
<p>In many cases, there will be far more data values that need to be assigned names. The instructions in this file, including the ever-incrementing names, can be quickly created in some text editors and also in Excel. The following formula can be pasted into cell A1 of Excel and filled down as far as necessary to create the proper instructions:</p>
<p style="padding-left: 30px;">=CONCATENATE(&#8220;l1 @,@ !infected&#8221;, ROW(A1), &#8220;!&#8221;)</p>
<p>The above instruction names uses the name <em>infected</em> as the root of all observation names. Make sure to change this name in the above formula to match the variable name in your model. After you copy the text generated by Excel into your instruction file, make sure to change the <em>first</em> command so that it begins with “l2” rather than “l1”. If you fail to do this, PEST will not skip over the header in output.csv and will abort when it tries to read numeric values from the text that appears there.</p>
<p>There will also be cases where it is desirable to calibrate to multiple pieces of data. In this case, the commands in the instruction file will have to be modified to include the additional data. For example, if there is a second historical time series <em>Treated</em> and <em>Treated</em> appears after <em>Infected</em> in the model output file, each command would change to (using the fifth value as an example):</p>
<pre style="padding-left: 30px;">l1 @,@ !infected5! @,@ !treated5!</pre>
<p><strong>Creating the Control File</strong></p>
<p>The control file contains a number of PEST parameters, the historical data, the command to run the model, and the names of the other files needed by PEST. It is a difficult file to create on your own. Luckily, PEST provides some command line tools to help. In particular, PESTGEN will generate the control file (with default settings) from two simpler text files:</p>
<ul>
<li>The parameter file (.par), which lists the input parameters to the model </li>
<li>The observations file (.obf), which lists the historical time series; INSCHEK can generate this from the model output file and the instruction file Both files are fixed-format, which means the field widths and alignment must be properly respected. It is easiest to create the parameter file by editing an existing parameter file (PEST outputs a parameter file containing the final parameter values at the end of a calibration; the file used for this calibration is also included with the model). </li>
</ul>
<p>The parameter file for this model, hkflu.par, appears below.</p>
<pre>  single point
    infectrate    1.5000000E-03     1.000000         0.000000
   recoverrate    0.5000000         1.000000         0.000000    </pre>
<p>The first line tells PEST to use single-precision floating point and to always include the decimal point when writing parameters to the model input file. The file then contains one line for each input parameter.</p>
<p>Each line starts with the name of the input parameter, as it appears in the template file, right-justified. This is followed by the initial value of that parameter, a scale factor (normally one) and an offset (normally zero). To add additional parameters, copy and paste the lines and make sure the columns line up with the existing lines.</p>
<p>The observations file contains all of the observation names with the historical data values for each. The command line tool INSCHEK, which comes with PEST, will generate this file by merging the observation names in the instruction file with data in a file formatted the same as the model output file. The instruction file has already been created. To complete this process, copy and paste the historical data into the second column (<em>Infected</em>) of the model output file, output.csv, and save it. Open the Windows command prompt window by choosing “Command Prompt” under All Programs-&gt;Accessories. Make sure to change the current directory to the directory containing your model and your PEST files. This is easily done by type “cd ” (the ending space is necessary) and then <em>dragging</em> the folder icon in the address field of the Windows Explorer window for that folder onto the command window. Reselect the command window and press Enter. The directory is now set. Now type:</p>
<p style="padding-left: 30px;">inschek output.ins</p>
<p>Note that inschek will need to be preceded by the path to the PEST directory if you have not added the PEST directory to your PATH environment variable. This command will verify there are no syntax errors in your instruction file. If you get any errors, correct them and check again. Continue until there are no errors reported. Then type:</p>
<p style="padding-left: 30px;">inschek output.ins output.csv</p>
<p>This will create the observations file, output.obf, from the data you pasted into output.csv.</p>
<p>It is now possible to create the control file, hkflu.pst. Type:</p>
<p style="padding-left: 30px;">pestgen hkflu hkflu.par output.obf</p>
<p>If there are errors reported in the parameter file, fix them and try again. This command generates a default control file for case <em>hkflu</em> (short for Hong Kong flu – you can name it anything you want) with your parameter values and historical data. This file will require some editing before PEST can be run.</p>
<p><strong>Editing the Control File</strong></p>
<p>The generated file looks like this (to view, right-click on hkflu.pst, choose “Open With…”, and select WordPad):</p>
<pre>pcf
* control data
restart  estimation
    2    13     2     0     1
    1     1 single point   1   0   0
  5.0   2.0   0.3  0.03    10
  3.0   3.0 0.001
  0.1
   30  0.01     3     3  0.01     3
    1     1     1
* parameter groups
infectrate   relative 0.01  0.0  switch  2.0 parabolic
recoverrate  relative 0.01  0.0  switch  2.0 parabolic
* parameter data
infectrate   none relative   1.500000E-03  -1.000000E+10   1.000000E+10
<img src="http://blog.iseesystems.com/wp-content/uploads/2011/01/indent_char.gif" alt="" width="11" height="13" /> infectrate     1.0000        0.0000      1
recoverrate  none relative   0.500000      -1.000000E+10   1.000000E+10
<img src="http://blog.iseesystems.com/wp-content/uploads/2011/01/indent_char.gif" alt="" width="11" height="13" /> recoverrate     1.0000        0.0000      1
* observation groups
obsgroup
* observation data
infected1      14.0000      1.0  obsgroup
infected2      28.0000      1.0  obsgroup
infected3      50.0000      1.0  obsgroup
infected4      66.0000      1.0  obsgroup
infected5      156.000      1.0  obsgroup
infected6      190.000      1.0  obsgroup
infected7      156.000      1.0  obsgroup
infected8      108.000      1.0  obsgroup
infected9      68.0000      1.0  obsgroup
infected10     77.0000      1.0  obsgroup
infected11     33.0000      1.0  obsgroup
infected12     65.0000      1.0  obsgroup
infected13     24.0000      1.0  obsgroup
* model command line
model
* model input/output
model.tpl  model.inp
model.ins  model.out
* prior information</pre>
<p>This is also a fixed-format file, so you need to be careful when editing it. Luckily, only a few things need to be edited.</p>
<p>The “pcf” at the top of the file tells PEST this is a control file. The control data section sets a number of parameters that can stay the way they are unless the calibration does not work (in which case, you will need to dig deeply into the PEST manual to figure out what to change and how to change it). The parameter groups section, the observation groups section, and the observation data sections will not require any changes. However, the parameter data section needs to be adjusted and both the model command line and model input/output need to be specified.</p>
<p>For each parameter under parameter data, you must decide whether the changes made by PEST to the parameter will be <em>relative</em> (i.e., additive – the default), or <em>factor</em> (i.e., multiplicative). There are advantages and disadvantages to each, however, for a STELLA model, this simple guideline should help: change all time constants, rates, and multipliers to <em>factor</em>. In the SIR model, both variables are rates, so the word “relative” must be replaced with “factor ”. Note the two extra spaces after “factor”; the new text must <em>completely</em> fill the space formerly occupied by “relative”.</p>
<p>The default domain for each parameter is set to -1.0e10 to 1.0e10. You are likely to have better information (especially if it is a multiplier) and should enter it here in place of those numbers. I restricted the domain of <em>infectrate</em> to between 0.0001 and 0.01 and that of <em>recoverrate</em> to between 0.01 and 1.0. This was based on both my knowledge of these variables and some simple experiments I ran. The domains for these parameters could be much wider, as long as they stay above zero in both cases. This leads to the following changed lines (truncated after limits):</p>
<pre style="padding-left: 30px;">infectrate   none factor     1.500000E-03   1.000000E-04   1.000000E-02 …
recoverrate  none factor     0.250000       1.000000E-02   1.000000E+00 …</pre>
<p>The model command line is changed to:</p>
<pre style="padding-left: 30px;">run.bat</pre>
<p>The batch file run.bat contains commands to create the model output file and to run the STELLA SIR.stm model:</p>
<p style="padding-left: 30px;">@echo off<br />
 echo &gt; output.csv<br />
 start /min /wait &#8220;&#8221; &#8220;C:\Program Files\isee systems\STELLA 9.1.4\STELLA&#8221; -r SIR.stm</p>
<p>If STELLA was not installed to the default directory shown in the above command, run.bat will need to be edited to contain the correct path to STELLA.  The model output file needs to be recreated in the batch file (using echo) because PEST deletes the model output file before running the model.</p>
<p>Finally, the model input/output section was changed to name the template, model input, instruction, and model output files. Note these are not fixed-width fields.</p>
<pre style="padding-left: 30px;">input.tpl  input.csv
output.ins output.csv</pre>
<p><strong>Running PEST</strong></p>
<p>Before running PEST, it is a good idea to verify that all of the input files are valid. This is accomplished with PESTCHEK:</p>
<p style="padding-left: 30px;">pestchek hkflu</p>
<p>Fix any errors that are reported and repeat until all errors are gone. Note that PESTCHEK does not require the case name (<em>hkflu</em>) to be specified. Without the name, it will find all case names in the current directory (by searching for PEST control files) and check them all.</p>
<p>Finally, start the calibration process with:</p>
<p style="padding-left: 30px;">pest hkflu</p>
<p>PEST will run until it detects no further changes or cannot proceed. Each iteration, it will report a value named <em>phi</em>. This is the sum of the squared residuals and should be decreasing each iteration. If PEST succeeds, the model input file will contain the best parameter values found and the model output file will contain the results obtained with those parameter values.</p>
<p>PEST outputs a number of files as well. As already discussed, the parameter file (.par) will be updated (or created) to contain the final successful parameter values. The run details file (.rec) will contain a log of the search, including parameter values tried and their relative success, as well as the final results compared to the historical data, with residuals. The 95% confidence interval for the parameters is also given. A number of other files are generated by PEST. See the PEST manual for further details.</p>
<p>The results of running PEST with this model and these initial parameters are shown in the graph below. The final parameter settings discovered by PEST were <em>infection rate</em> = 0.0015766646 and <em>recovery rate</em> = 0.82166505, with a final error (phi) of 4785.7 (compared to 773,059 with the original parameters).</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border-width: 0px;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2011/01/image.png" border="0" alt="image" width="455" height="252" /></p>
<p><strong>Changing the Data Set</strong></p>
<p>Shown below is the number of weekly deaths per thousand people in the UK due to the Spanish flu (H1N1) in the winter of 1918-1919.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border-width: 0px;" title="clip_image012" src="http://blog.iseesystems.com/wp-content/uploads/2011/01/clip_image012.gif" border="0" alt="clip_image012" width="343" height="267" /></p>
<p>To calibrate to this data set, it is necessary to change the initial values of the <em>Susceptible</em> and <em>Infected</em> stocks in the model. The historical data values in the PEST control file must also be changed.</p>
<p>The initial value of <em>Infected</em> is, again, the first data value (1 in this case). The initial value of <em>Susceptible</em> is, again, the remaining population (148). The model SIR2.stm contains these changed settings, as well as the new historical data set.</p>
<p>While it is relatively easy to regenerate and edit the PEST control file, it is just as easy to edit the few historical values. Control file spflu.pst contains the new dataset. It also uses run2.bat to run SIR2.stm instead of SIR.stm.  Type:</p>
<p style="padding-left: 30px;">pest spflu</p>
<p>Although it takes some time, the calibration almost succeeds using the same starting parameters as those for the Hong Kong flu. It fails in the end because the domain of <em>infection rate</em> is too narrow; <em>infection rate</em> gets stuck at 0.01. It is important to note that PEST reported success in this case. Looking at the graph in STELLA, however, made it clear that it only came close, while looking at the chosen parameters showed the boundary was reached. Changing the maximum value to 0.1 in spflu.pst fixed that problem. The final results are shown below.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border-width: 0px;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2011/01/image1.png" border="0" alt="image" width="455" height="252" /></p>
<p>This was generated with <em>infection rate</em> = 0.012101631 and <em>recovery rate</em> = 0.89054160. The error decreased from 2233.8 at the start to 110.6 with these parameters.</p>
<p><strong>Troubleshooting PEST</strong></p>
<p>Chapter five of the PEST User Manual includes a detailed troubleshooting section titled “If PEST Won’t Optimize.” If PEST is not changing parameters or not succeeding, this section will help you discover why.</p>
<p><strong>Troubleshooting Data</strong></p>
<p>In the examples used in this post, the model-generated data was one-to-one with the historical data. In many cases, data is not collected at a set frequency, does not coincide in time with model-generated data, and there are missing data points. While this was not covered in this example, PEST is capable of dealing with these cases. Missing data points can be handled by using !dum! as a placeholder in the instruction file (or additional lines can be skipped between points). PEST can also interpolate the model-generated data to match it in time to the historical data. Refer to the PEST manual for instructions to handle these cases.</p>
<p><strong>End Note (about precision): </strong>While STELLA and iThink use double-precision for its calculations and PEST supports double-precision output, it is not possible to directly interface to PEST in double-precision mode as PEST outputs exponentials using “D” instead of “E” when in double-precision mode (as FORTRAN does). Such non-standard numeric formats cannot be read by STELLA. Double-precision can be used if necessary by adding a preprocessor to convert those “D”s in the model input file to “E”s before running STELLA and by adding a post-processor after running STELLA to change the “E”s output by STELLA to “D”s. Each parameter should also be given a field that is 23 characters wide, instead of 13, in the template file. Most applications will not need to use double-precision.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/calibrate-models-pest/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>What is Delta Time (DT)?</title>
		<link>http://blog.iseesystems.com/modeling-tips/why-dt-matters/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/why-dt-matters/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 17:13:15 +0000</pubDate>
		<dc:creator>Nat Pierson</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[DT]]></category>
		<category><![CDATA[iThink/STELLA]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=3004</guid>
		<description><![CDATA[After reading Karim Chichakly’s recent post on Integration Methods and DT, I was reminded that delta time (DT) has always been a tricky modeling concept for me to grasp.   Beginning modelers don&#8217;t usually need to think about changing DT since STELLA and iThink set it to a useful default value of 0.25.   But once you [...]]]></description>
			<content:encoded><![CDATA[<p>After reading Karim Chichakly’s recent <a href="http://blog.iseesystems.com/modeling-tips/integration-methods-and-dt/" target="_blank">post on Integration Methods and DT</a>, I was reminded that delta time (DT) has always been a tricky modeling concept for me to grasp.   Beginning modelers don&#8217;t usually need to think about changing DT since STELLA and <em>iThink</em> set it to a useful default value of 0.25.   But once you progress with your modeling skills, you might consider the advantages and risks of playing with DT.</p>
<div id="attachment_3162" class="wp-caption alignright" style="width: 300px"><img class="size-full wp-image-3162 " title="RunSpecs" src="http://blog.iseesystems.com/wp-content/uploads/2010/07/RunSpecs1.png" alt="" width="290" height="218" /><p class="wp-caption-text">The DT setting is found in the Run Specs menu.</p></div>
<p>By definition, system dynamics models run over time and DT controls how frequently calculations are applied each unit of time.  Think of it this way, if your model was a movie, then DT would indicate the time interval between still frames in the strip of movie film.  For a simulation over a period of 12 hours, a DT of 1/4 (0.25) would give you a single frame every 15 minutes.  Lowering the DT to 1/60 would give a frame every minute.   The smaller the DT is, the higher the calculation frequency (1/DT).</p>
<p><strong>Beware of the Extremes</strong></p>
<p>A common tendency for modelers is to set the calculation frequency too high.  Without really thinking too hard about it, more data seems to imply a higher quality model &#8211; just like more frames in movie film make for smoother motion.  If your model calculates more data for every time unit, its behavior will begin to resemble the behavior of a smoothly continuous system.  But a higher frequency of calculations can greatly slow down your model’s run performance and more data does not directly translate to a better simulation.</p>
<p><strong>Beware of Discrete Event Models</strong></p>
<p>Another situation where DT can often lead to unexpected behavior is with models that depend on discrete events.   My eyes were opened to this when I attended one of isee’s <a href="http://www.iseesystems.com/store/Training/InterDynamicModelingIthink.aspx" target="_blank">workshops </a>taught by Corey Peck and Steve Peterson of Lexidyne LLC.</p>
<p>One of the workshop exercises involved a simple model where the DT is set to the default 0.25, the inflow is set to a constant 10, and the outflow is set to flush out the stock’s contents as soon as it reaches 50.   This is how the model&#8217;s structure and equations looked:</p>
<p style="text-align: center;"><img class="size-full wp-image-3007 aligncenter" style="margin-top: -10px; margin-bottom: -30px;" title="Discrete Model" src="http://blog.iseesystems.com/wp-content/uploads/2010/07/discrete_model1.png" alt="Discrete Model" width="369" height="102" /></p>
<p style="text-align: center;"><span style="font-size: 9pt; font-family: Courier, monospace;">Stock = 0</span></p>
<p style="text-align: center;"><span style="font-size: 9pt; font-family: Courier, monospace;">inflow = 10</span></p>
<p style="text-align: center;"><span style="font-size: 9pt; font-family: Courier, monospace;">outflow = IF Stock &gt;= 50 THEN 50 ELSE 0</span></p>
<p>I would have expected the value of the stock to plunge to zero after it reached or exceeded 50, but this graph shows the resulting odd saw-tooth pattern.</p>
<p style="text-align: center;"><img class="size-full wp-image-3006 aligncenter" title="Sawtooth Model Behavior" src="http://blog.iseesystems.com/wp-content/uploads/2010/07/discrete_graph.png" alt="Sawtooth Model Behavior" width="422" height="244" /></p>
<p>The model ends up behaving like a skipping scratched record, in a perpetual state of never progressing far enough to reach the goal of zero.  (<a href="http://blog.iseesystems.com/wp-content/uploads/2010/08/DeltaTime.itm">Click here</a> to download the model.)</p>
<p><p><img class="size-full wp-image-3081    alignleft" style="margin-top: 10px; margin-bottom: 10px;" title="Table Output" src="http://blog.iseesystems.com/wp-content/uploads/2010/07/dt_discrete_table.png" alt="" width="210" height="236" /></p>
</p>
<p>What is happening in the model?  In the first DT after the stock’s value reaches exactly 50, the outflow sets itself to 50 in order to remove the contents from the stock. So far so good, but now the DT gotcha begins to occur.   Since the outflow works over time, its value is always per time.  To get the quantity of material that actually flowed, you must multiply the outflow value (or rate) by how long the material was flowing.  When DT is set to 0.25,  the material flows 0.25 time units each DT.  Hence, the quantity of material removed from the stock is 50*0.25 = 12.50.</p>
<p>Suddenly we are in a situation where only 12.50 has been removed from the stock but the stock’s value is now less than 50.  Since the stock is no longer greater than or equal to 50, the outflow sets itself back to 0 and never actually flushes out the full contents of the stock. </p>
<p>So what do we do?  One solution to this problem would be to use the PULSE built-in to remove the full value from the stock.   Here&#8217;s what the equation for the outflow would look like:</p>
<p style="text-align: center;"><span style="font-size: 9pt; font-family: Courier, monospace;">outflow = IF Stock &gt;= 50 THEN PULSE(Stock) ELSE 0</span></p>
<p><em>(Note: This option will only work using Euler&#8217;s integration method.)</em></p>
<p style="text-align: left;"><strong>Further Reading</strong></p>
<p>STELLA and <em>iThink</em> have great help documentation on DT.  The general <a href="http://www.iseesystems.com/Helpv9/Content/DT/How_does_DT_work_.htm" target="_blank">introduction</a> provides a good explanation of how DT works. The more advanced <a href="http://www.iseesystems.com/Helpv9/Content/DT/DT_Special_Care.htm" target="_blank">DT Situations Requiring Special Care</a> section focuses more on artifactual delays and the discrete model issues mentioned in this post.  Delta time and resulting model behaviors are reminders that system dynamics models run over time, but they achieve this by applying numerous discrete calculations in order to simulate the smooth behavior of actual systems.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/why-dt-matters/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Integration Methods and DT</title>
		<link>http://blog.iseesystems.com/modeling-tips/integration-methods-and-dt/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/integration-methods-and-dt/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 20:51:56 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[DT]]></category>
		<category><![CDATA[Euler]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[RK4]]></category>
		<category><![CDATA[Runge-Kutta]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=2982</guid>
		<description><![CDATA[The simulation engine underlying STELLA® and iThink® uses numerical integration.  Numerical integration differs from the integration you may have learned in Calculus in that it uses algorithms that approximate the solution to the integration.  The two approximations currently available are known as Euler’s method and the Runge-Kutta method.  All algorithms require a finite value for [...]]]></description>
			<content:encoded><![CDATA[<p>The simulation engine underlying STELLA® and <em>iThink</em>® uses numerical integration.  Numerical integration differs from the integration you may have learned in Calculus in that it uses algorithms that approximate the solution to the integration.  The two approximations currently available are known as Euler’s method and the Runge-Kutta method.  All algorithms require a finite value for DT, the integration step-size, rather than the infinitesimally small value used in Calculus.  On the surface, it may seem that the smaller DT is, the more accurate the results, but this turns out not to be true.</p>
<p><strong>Compound Interest:  Euler’s Method over Runge-Kutta</strong></p>
<p>To introduce Euler’s method, let’s take a look at the simple problem of compound interest.  If we have $100 that we invest at 10% (or 0.1) compounded annually, we can calculate the interest after <em>N</em> years by adding in the interest each year and recalculating:</p>
<p style="padding-left: 30px;">1st year:  <em>interest</em> = $1000 × 0.1 = $100; <em>Balance</em> = 1000 + 100 = $1100 <br />
 2nd year: <em>interest</em> = $1100 × 0.1 = $110; <em>Balance</em> = 1100 + 110 = $1210 <br />
 3rd year:  <em>interest</em> = $1210 × 0.1 = $121; <em>Balance</em> = 1210 + 121 = $1331</p>
<p>And so on up to year <em>N</em>.  We have just seen the essence of how Euler’s method works.  It calculates the new change in the stock for this DT (in this case, <em>interest</em>) and then adds that to the previous value of the stock (<em>Balance</em>) to get the new value of the stock.  In this example, DT = 1 year.</p>
<p>By noticing we always add the existing balance in, we can instead just multiply the previous year’s balance by 1 + <em>rate</em> = 1 + 0.1 = 1.1:</p>
<p style="padding-left: 30px;">1st year:  <em>Balance</em> = $1000 × 1.1 = $1100 <br />
 2nd year: <em>Balance</em> = $1100 × 1.1 = $1210 <br />
 3rd year:  <em>Balance</em> = $1210 × 1.1 = $1331</p>
<p>And so on up to year <em>N. </em>We can further generalize by noticing we are multiplying by 1.1 <em>N</em> times and thus arrive at the compound interest formula:</p>
<p style="padding-left: 30px;"><em>Balance</em> = <em>Initial_Balance</em>*(1 + <em>rate</em>)^<em>N</em></p>
<p>Checking this, we find our <em>Balance</em> at the end of year 3 is 1000*1.1^3 = $1331.  In the general case of the formula, <em>rate</em> is the fractional interest rate per compounding period and <em>N</em> is the number of compounding periods (an integer).  In our example, the compounding period is one year, so <em>rate</em> is the annual fractional interest rate and <em>N</em> is the number of years.  However, if interest is compounded quarterly (four times a year), the interest rate has to be adjusted to a per quarter rate by dividing by 4 (so <em>rate</em> = 0.1/4 = 0.025) and <em>N</em> must be expressed as the number of quarters (<em>N</em> = number of years*4 = 3*4 = 12 for the end of year 3).  We can use this formula in our model to test the accuracy of Euler’s method.  Note that for quarterly compounding, we would set DT = 1/4 = 0.25 years.</p>
<p>To explore the differences between Euler’s and Runge-Kutta, the following structure will be used for all of the examples in this post.  This structure models the compound interest problem outlined above.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border-width: 0px;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2010/07/image8.png" border="0" alt="image" width="186" height="180" /></p>
<p>The equations change for each example and can be seen in the individual model files (accessed by clicking <a href="http://blog.iseesystems.com/wp-content/uploads/2010/07/Integration-Methods.zip"></a><a href="http://blog.iseesystems.com/wp-content/uploads/2010/07/Integration-Methods1.zip">here</a>).  For this example, the actual value is calculated using the compound interest formula, <em>Initial_Balance</em>*(1 + <em>rate</em>)^<em>TIME</em>.  The approximated value is calculated by integrating <em>rate</em>*<em>Approx_Balance</em> (into <em>Approx_Balance</em>).</p>
<p>In addition to the actual and approximate values, three errors are also calculated across the model run:  the maximum absolute error, the maximum relative error, and the root-mean-squared error (RMSE).  The absolute error is:</p>
<p style="padding-left: 30px;">ABS(<em>Actual_Balance</em> – <em>Approx_Balance</em>)</p>
<p>The relative error is:</p>
<p style="padding-left: 30px;"><em>absolute_error</em>/ABS(<em>Actual_Balance</em>)</p>
<p>and is usually expressed as a percentage.  The RMSE is found by averaging the values of the absolute error squared, and then taking the square root of that average.</p>
<p><span id="more-2982"></span>Running this model under Euler’s method leads to the behavior shown in the following graph.  As expected, Euler’s method tracks this function perfectly.  All three errors are essentially zero.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border: 0px;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2010/07/image9.png" border="0" alt="image" width="454" height="251" /></p>
<p>However, changing the integration method to Runge-Kutta 4 (known as RK4) does not give a good approximation (see graph below).  The relative error is 1.6%, the absolute error is $56 and the RMSE is $26, all rather large for RK4.  DT must be reduced a factor of 32, to 1/128, in order to bring the errors below 0.1% (0.001).</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border: 0px;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2010/07/image10.png" border="0" alt="image" width="454" height="251" /></p>
<p><strong>Continuous Compounding:  Runge-Kutta over Euler’s Method</strong></p>
<p>Our friend Euler was a busy mathematician.  He is also famous for discovering the formula for continuously compounding interest.  If you increase the frequency of compounding from once a year to once a month to once a day (what most banks do now and called “daily compounding”) to once a second and so on until you are compounding every infinitesimally small instant (which should remind you of the dt from Calculus), the compound interest formula becomes:</p>
<p style="padding-left: 30px;"><em>Balance</em> = <em>Initial_Balance</em>*<em>e</em>^(<em>rate</em>*<em>time</em>)</p>
<p>where <em>e</em> ≈ 2.718281828 is Euler’s number, <em>rate</em> is the annual fractional interest rate, and <em>time</em> is the number of years that have passed (a real number).  Using continuous compounding, our <em>Balance</em> at the end of year 3 is 1000*<em>e</em>^(0.1*3) ≈ $1350, $8 more than with annual compounding.</p>
<p>This function is known as <em>continuous</em> function, which, in layman’s terms, means its value smoothly changes with time, rather than experiencing jumps or gaps.  [Note the compound interest formula given in the first section is <em>not</em> continuous; since <em>N</em> must be an integer, this function only exists at integer values.]  While Euler’s method does not depend on a function being continuous, it does introduce an error proportional to DT when trying to integrate these equations (called <em>truncation error</em>).  Thus, the only way to reduce these errors is to reduce DT, requiring more computations.  Unfortunately, this only works up to a point.  Below that point, errors increase again due to <em>round-off error</em> in the computer’s finite representation of floating point values.</p>
<p>The graph below shows the effect of using Euler’s method to calculate continuously compounding interest.  Note it does not follow the actual curve, calculated with the EXP function, very well.  The relative error is 1.6%, the maximum error is $56, and the RMSE is $25.  If we cut DT in half, to 1/8, the errors also cut in half as we expect, to 0.8%, $29, and $13, respectively.  This will continue until DT reaches the limit of the machine’s representation, which is approximately 1/2048 for single-precision floating point numbers and 1/67,108,864 (1/2^26) for double-precision floating point numbers (note STELLA and <em>iThink</em> always use double-precision).  After this point, errors will increase again.  Note these values are theoretical; your mileage will vary.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border: 0px;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2010/07/image11.png" border="0" alt="image" width="454" height="251" /></p>
<p>There is a better solution than reducing DT.  The Runge-Kutta integration method assumes a continuous function and takes steps to follow such a function very closely.  Because it uses a weighted average of values across each DT-interval, it does not perform well with <em>discontinuous</em> functions, i.e., functions that have gaps or sharp changes, such as that produced with the STEP and PULSE functions (however, STELLA and <em>iThink</em> compensate for this so that these functions still perform correctly under Runge-Kutta).  Leaving DT at 0.25 and changing the integration method to RK4 produces the following graph, with the largest relative error being 0.0077%, the largest absolute error being $0.27 and the RMSE being $0.14.  To achieve this level of accuracy with Euler’s method, it is necessary to reduce DT to 1/1024.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border: 0px;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2010/07/image12.png" border="0" alt="image" width="454" height="251" /></p>
<p>The number after the RK is the order of the integration method.  Typically, but not always, higher-order methods will give smaller errors.  Euler’s method is a first-order method and RK4 is a fourth-order method.  Note, however, that Euler’s outperformed RK4 in the first example.  STELLA and <em>iThink</em> also provide a second-order method, Runge-Kutta 2 (RK2), which is a compromise between Euler’s and RK4; with the speed of today’s computers, it is no longer necessary to use and remains only for backward-compatibility.</p>
<p><strong>Oscillations:  The Case for Runge-Kutta</strong></p>
<p>Oscillations represent one area where RK4 really shines.  The following graph shows the results of using Euler’s method to integrate the sine function with DT = 0.25.  Notice it misses horribly.  The resulting function is clearly outside the range of the sine function [-1, 1].  The maximum absolute error is 0.25 and the RMSE is 0.15.  However, the maximum relative error is 340%!</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border-width: 0px;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2010/07/image5.png" border="0" alt="image" width="454" height="251" /></p>
<p>Reducing DT by a factor of 128 to 1/512 helps somewhat (below).  The maximum absolute error reduces to 0.0020 and the RMSE to 0.0012, but the maximum relative error only decreases to 200%.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border-width: 0px;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2010/07/image6.png" border="0" alt="image" width="454" height="251" /></p>
<p>On the other hand, if we leave DT = 0.25 and change the integration method to RK4, it calculates the sine function quite well, with a maximum absolute error of only 0.0078 and an RMSE of 0.0045.  The maximum relative error is also acceptable at 2.2%.  Cutting DT in half to 1/8 reduces the maximum relative error an order of magnitude, to 0.34%.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto; border-width: 0px;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2010/07/image7.png" border="0" alt="image" width="454" height="251" /></p>
<p><strong>Guidelines for DT</strong></p>
<p>DT should initially be set to one-half of the smallest time constant in your model.  This minimal value, according to Nyquist’s Sampling Theorem, avoids undersampling your values.  [Undersampling means looking at your signal so infrequently that you distort the signal, or, more to the point, do not have enough information to reconstruct it.  For example, in the sine wave above, evaluating it every π will make you think you have a straight line at the origin, since all you will see are the zeroes.]</p>
<p>Finding the smallest time constant can be tricky.  They often appear in compounding or in draining processes.  For example, in the first two examples, the interest rate is the reciprocal of the time constant (it always appears in the divisor).  Thus, the time constant for this compounding formula is 10.  This suggests DT could start at 5, but there are other constraints.  In fact, we wish to compound every quarter, so DT must be set to 1/4.</p>
<p>Run the model with your chosen DT.  Then cut DT in half and try again.  If the results change, cut DT in half and try again.  If they do not change, the previously chosen DT is likely fine.</p>
<p>Whenever possible, choose a value of DT that is a power of 2 (1, 1/2, 1/4, 1/8, 1/16, … or 1, 0.5, 0.25, 0.125, 0.0625, …).  This is because most other fractions, for example 1/10, are repeating decimals in base-2 and so cannot be accurately represented on the computer.  Obviously if your problem requires you to use a DT of 1/7, in weekly simulations for example, do so, but understand that adding 1/7 seven times will not equal one.  There are also other cases where you might need to use a DT that is not a power of 2.  If your smallest time constant is 1/52, for example, choosing the closest power of 2 to (1/52)/2 = 1/104, which is 1/128, would be disastrous.  Your time constant would then be 1/64 sometimes and 1/32 other times, not at all close to what you need.  Make sure you can represent your smallest time constants as a multiple of whatever DT you choose.</p>
<p><strong>Guidelines for Integration Method</strong></p>
<p>Changing DT is often not sufficient.  Your system may exhibit instabilities or wild oscillations caused by the errors in Euler’s method.  It is therefore also wise to always run the model in Euler’s and then in RK4.  If there is a difference, stick with RK4 and proceed to test DT.</p>
<p>Euler’s method is noticeably faster than RK4 and works fine in many situations.  A system that has linear relationships and uses exponential functions that are <em>not</em> based on Euler’s number will work fine using Euler’s method.  For qualitative results, Euler’s will work well in a broad variety of situations.  Euler’s is also the preferred method when you are using discontinuous or discrete functions (but note the discrete functions in STELLA and <em>iThink</em> are Runge-Kutta-aware and should work reasonably well under RK4).</p>
<p>Any continuous system that is based on exponential functions using Euler’s number as a base, and this includes trigonometric functions, oscillations, and logistic functions, will be better served by RK4.  In these cases, you should generally use this method from the start.</p>
<p>There is one additional type of system you may run into that neither of these methods will solve very well:  stiff systems.  In simple terms, a stiff system is one that has time constants of wildly different magnitudes, for example, 0.005 and 10,000.  The smaller time constant suggests a DT of 0.0025 which is far too small for the part of the system with a time constant of 10,000.  It is best to reframe your problem to avoid these situations when possible.  For example, when simulating such a system, the part of the system with a time constant of 10,000 can often be considered constant over a shorter period of interest.  Over long periods of interest, it is often possible to aggregate the behavior of the part of the system with the shorter time constant, using averages instead of exact values.</p>
<p><em>Note:  The integration method and DT are both set in the Run Specs, accessible from the Run menu.  Additional information can be found in the chapter on DT in the </em><a href="http://www.iseesystems.com/Helpv9/Content/DT/How_does_DT_work_.htm"><em>Technical Documentation</em></a><em>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/integration-methods-and-dt/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Steady-State Initialization of Conveyors</title>
		<link>http://blog.iseesystems.com/modeling-tips/steady-state-init-of-conveyors/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/steady-state-init-of-conveyors/#comments</comments>
		<pubDate>Tue, 25 May 2010 20:55:22 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[conveyor]]></category>
		<category><![CDATA[leakage]]></category>
		<category><![CDATA[steady-state]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=2827</guid>
		<description><![CDATA[Conveyors are useful model elements for representing pipelines or processes that take a certain amount of time to complete.  However, adding a leakage flow to a conveyor can make it difficult to initialize a model in steady-state.  The following discussion will explain how to initialize conveyors with leakage in steady-state.  Please refer to the model [...]]]></description>
			<content:encoded><![CDATA[<p>Conveyors are useful model elements for representing pipelines or processes that take a certain amount of time to complete.  However, adding a leakage flow to a conveyor can make it difficult to initialize a model in steady-state.  The following discussion will explain how to initialize conveyors with leakage in steady-state.  Please refer to the model structure below while reading this discussion.</p>
<p><img style="border-width: 0px; display: block; margin-left: auto; margin-right: auto;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2010/05/image.png" border="0" alt="image" width="347" height="153" /></p>
<p>These additional variables will be also used:</p>
<p style="padding-left: 30px;"><em>transit_time</em> = TRANSTIME(<em>conveyor</em>) <br />
<em>conveyor_length</em> = <em>transit_time</em>/DT <br />
<em>leakage_fraction</em> = the user-specified leakage fraction</p>
<p><strong>Linear Leakage</strong></p>
<p>The default leakage is linear in behavior.  The total amount that leaks across the length of the conveyor is directly proportional to the inflowing amount.  The leakage fraction is the constant of proportionality.  Thus, the <em>fraction</em> of inflowing material that makes it to the conveyor&#8217;s outflow is exactly</p>
<p style="padding-left: 30px;">1 – <em>leakage_fraction</em></p>
<p>Given the sample model structure above, to achieve equilibrium, <em>conveyor_outflow</em> must equal <em>outflow</em>.  For this to happen, we need to set the <em>inflow</em> as follows:</p>
<p style="padding-left: 30px;"><em>inflow</em> = <em>outflow</em>/(1 – <em>leakage_fraction</em>)</p>
<p>The conveyor’s steady-state value is then:</p>
<p style="padding-left: 30px;"><em>conveyor</em> = <em>transit_time</em>*<em>inflow</em> – (<em>conveyor_length</em> – 1)*<em>leakage</em>*DT/2</p>
<p>where the initial value of <em>leakage</em> is:</p>
<p style="padding-left: 30px;"><em>leakage</em> = <em>leakage_fraction</em>*<em>inflow</em></p>
<p>This must be calculated outside the program and entered as a constant into the conveyor as conveyors cannot be given equations (they can, however, be set to a the value of a single converter, but you must be careful how you calculate this to avoid circularity).</p>
<p><strong>Exponential Leakage</strong></p>
<p>Optionally, leakage can be made exponential.  The amount that leaks each DT is proportional to the amount remaining in the conveyor.  In this case, the leakage fraction is the fraction that leaks each unit of time so, for long conveyors, a lot of material can leak away.  Given the transit time, the <em>fraction</em> of inflowing material that makes it to the conveyor&#8217;s outflow is approximately</p>
<p style="padding-left: 30px;">1 &#8211; (1 &#8211; <em>leakage_fraction</em>)^<em>transit_time</em></p>
<p>Given the sample model structure above, to achieve equilibrium, <em>conveyor_outflow</em> must equal <em>outflow</em>.  For this to happen, we need to set the <em>inflow</em> as follows:</p>
<p style="padding-left: 30px;"><em>per_dt_no_leak</em> = 1 – <em>leakage_fraction</em>*DT <br />
<em>inflow</em> = <em>outflow</em>/(<em>per_dt_no_leak</em>^<em>conveyor_length</em>)</p>
<p>For steady-state, the conveyor itself must then be set as follows:</p>
<p style="padding-left: 30px;"><em>conveyor</em> = (<em>inflow</em>*DT)*(1 – <em>per_dt_no_leak</em>^<em>conveyor_length</em>)/(1 – <em>per_dt_no_leak</em>)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/steady-state-init-of-conveyors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Converting a Sector-based Model to Modules</title>
		<link>http://blog.iseesystems.com/modeling-tips/converting-sectors-to-modules/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/converting-sectors-to-modules/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 08:17:36 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[iThink/STELLA]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[sectors]]></category>
		<category><![CDATA[Version 9.1.2]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=2736</guid>
		<description><![CDATA[I generally do not use modules to build very small models (only a couple of stocks and flows), which may then lead me to use sectors as the model grows because they are very convenient.  By the time I have three sectors, though, it starts to become clear that I should have used modules.  I [...]]]></description>
			<content:encoded><![CDATA[<p>I generally do not use modules to build very small models (only a couple of stocks and flows), which may then lead me to use sectors as the model grows because they are very convenient.  By the time I have three sectors, though, it starts to become clear that I should have used modules.  I will then need to convert my sector-based model into a module-based model.  Historically, I also have a number of sector-based models that are crying to be module-based.</p>
<p>Converting from sectors to modules is not very difficult:</p>
<ol>
<li>Make sure there are no connections or flows between sectors.  Replace any of these with ghosts in the target sector.</li>
<li>In a new model, create one module for every sector.</li>
<li>Copy and paste the structure from each sector into its corresponding module.</li>
<li>Connect the modules:  At this point, the model structure has been rearranged into modules, but none of the modules are connected.  The ghosts that were in the sectors became real entities when they were pasted into the modules.  Go back to identify all of these connections and reconnect them in the module-based model.</li>
</ol>
<p><strong>Stepping Through a Sample Model</strong></p>
<p>Let’s walk through an example.  A small sector-based model is shown below (and is available by clicking <a href="http://blog.iseesystems.com/wp-content/uploads/2010/03/Population1.itm">here</a>).</p>
<p><img style="border: 0pt none; display: block; margin-left: auto; margin-right: auto;" title="Sectors" src="http://blog.iseesystems.com/wp-content/uploads/2010/03/image.png" border="0" alt="image" width="403" height="393" /></p>
<p>This model violates what I would call good sector etiquette:  there are connectors that run between the sectors.  This is often useful in a small model such as this because it makes the feedback loops visible.  However, in a larger model, this can lead to problems such as crossed connections and difficulty in maintaining the model because sectors cannot be easily moved.</p>
<p><strong> </strong><span id="more-2736"></span><strong>Eliminating Cross-Sector Connections</strong></p>
<p>To convert this sector-based model to modules, it is first necessary to remove these cross-sector connections.  This is done with the ghost tool.  The stock <em>Population</em> needs to be ghosted and placed in the <em>Resources Sector</em> and the stock <em>Natural Resources</em> needs to be ghosted and placed in the <em>Population Sector</em>.  The end result is shown below.</p>
<p><img style="border: 0pt none; display: block; margin-left: auto; margin-right: auto;" title="Sectors with Ghosts" src="http://blog.iseesystems.com/wp-content/uploads/2010/03/image1.png" border="0" alt="image" width="388" height="437" /></p>
<p><strong>Creating the Modules</strong></p>
<p>We are now ready to create, in a new model, one module for each sector, using the Module tool.  The result is shown below.  Although you could manually draw the connections between these modules, we will let the software create the connections for us.</p>
<p><img style="border: 0pt none; display: block; margin-left: auto; margin-right: auto;" title="Modules" src="http://blog.iseesystems.com/wp-content/uploads/2010/03/image2.png" border="0" alt="image" width="73" height="145" /></p>
<p>Each module needs to be associated with its own model file.  This is done by double-clicking on each module and choosing “Create Model&#8230;”.  Double-click <em>Population</em>, choose “Create Model…”, and name the model file “Population”.  Repeat for <em>Natural Resources</em>, but name the model file “Natural Resources”.</p>
<p><strong>Pasting Structure into the Modules</strong></p>
<p>It is now a simple matter to paste the structure from each sector into each module.  Using the selection tool in the sector frame, select all of the structure in the <em>Population Sector</em> and copy it by choosing Edit-&gt;Copy.  Open the <em>Population</em> module in the new model and paste in the structure by choosing Edit-&gt;Paste.  The module contents will appear as shown below.  Note that <em>Natural Resources</em> is no longer a ghost; there is no connection to the other module.</p>
<p><img style="border: 0pt none; display: block; margin-left: auto; margin-right: auto;" title="Population module" src="http://blog.iseesystems.com/wp-content/uploads/2010/03/image3.png" border="0" alt="image" width="337" height="196" /></p>
<p>Repeat this process with the <em>Resources Sector</em> and the <em>Natural Resources</em> module.  The module contents will appear as shown below.  Note that <em>Population</em> is no longer a ghost.</p>
<p><img style="border: 0pt none; display: block; margin-left: auto; margin-right: auto;" title="Natural Resources module" src="http://blog.iseesystems.com/wp-content/uploads/2010/03/image4.png" border="0" alt="image" width="305" height="191" /></p>
<p><strong>Connecting the Modules</strong></p>
<p>All that remains is to connect the modules.  Inside the <em>Population</em> module, the stock <em>Natural Resources</em> needs to be replaced with a ghost of the real stock.  Inside the <em>Natural Resources</em> stock, the <em>Population</em> stock must be replaced with a ghost.</p>
<p>There are two ways to do this:  manually or semi-automatically with the Ghost tool.  I tend to use the Ghost tool most of the time.  [The documentation chapter “Working with Module Inputs and Outputs” (available by clicking <a href="http://www.iseesystems.com/Helpv9/Content/Modules/Intro_to_Module_Inputs_and_Outputs.htm">here</a>) explains how to forge these connections manually.]</p>
<p>To connect the modules, first go into the <em>Natural Resources</em> module and select the <em>Natural Resources</em> stock with the Ghost tool.  Go up one level and then down into the <em>Population</em> module.  The cursor should still be a stock.  Click next to the existing <em>Natural Resources</em> stock to deposit the ghost.  Run a connector from the ghost to <em>resources\person</em> (as the stock does) and then delete the stock.  Drag the ghost over to approximately where the stock was.  Open <em>resources\person</em> and press “OK”.  An error will appear and “Natural_Resources” will be selected.  This happens because <em>Natural Resources</em> is no longer connected to <em>resources\person</em>.  Click on the ghost’s name (<em>Natural Resources.Natural Resources</em>) in the “Required Inputs” list and press “OK”.  The <em>Population</em> module is now properly connected to the <em>Natural Resources</em> module.</p>
<p>Repeat this process to connect a ghost of the real <em>Population</em> stock to the <em>Natural Resources</em> module.  After finishing, the <em>Population</em> module contents appears as shown below.  Note that <em>Population</em> has a double border to signify it is providing its value to another module.</p>
<p><img style="border: 0pt none; display: block; margin-left: auto; margin-right: auto;" title="Population module connected" src="http://blog.iseesystems.com/wp-content/uploads/2010/03/image5.png" border="0" alt="image" width="337" height="209" /></p>
<p>The contents of the <em>Natural Resources</em> module appears as shown below.  Note the double border around the <em>Natural Resources</em> stock, signifying that it is providing its value to another module.</p>
<p><img style="border: 0pt none; display: block; margin-left: auto; margin-right: auto;" title="Natural Resources module connected" src="http://blog.iseesystems.com/wp-content/uploads/2010/03/image6.png" border="0" alt="image" width="333" height="191" /></p>
<p>Finally, returning to the top-level, we see that the software automatically created the required connections between the modules.  Below, the connections have been embellished with their polarity to make the balancing loop obvious.  [The final model is available by clicking <a href="http://blog.iseesystems.com/wp-content/uploads/2010/03/Population3.zip">here</a>.]</p>
<p><img style="border: 0pt none; display: block; margin-left: auto; margin-right: auto;" title="Modules connected" src="http://blog.iseesystems.com/wp-content/uploads/2010/03/image7.png" border="0" alt="image" width="91" height="145" /></p>
<p><strong>A Cautionary Tale</strong></p>
<p>This mechanical process for converting a sector-based model to a module-based model is very appealing due to its simplicity.  It works very well with models that have a small number of sectors (up to about five), but will fall apart beyond that.</p>
<p>Last summer, I helped Khalid Saeed (<a href="http://www.wpi.edu/academics/Depts/SSPS/People/kqs.html" target="_blank">Worcestor Polytechnic Institute</a>) convert a sector-based model of Jay Forrester’s Urban Dynamics model to modules.  A direct translation using the above process led to the following top-level diagram:</p>
<p><img style="border: 0pt none; display: block; margin-left: auto; margin-right: auto;" title="Urban Dynamics - all on one level" src="http://blog.iseesystems.com/wp-content/uploads/2010/03/image8.png" border="0" alt="image" width="260" height="239" />It should be clear that everything is connected to almost everything else.  There is no way to rearrange this diagram to clear up this mess.  For a short time, I flirted with the idea of module ghosts as a solution, but it does not take too long to see that ghosts cannot solve this problem either (indeed, they make it worse).</p>
<p>Recently, I decided to follow my own advice on module hierarchy (see <a href="http://blog.iseesystems.com/stories-from-the-field/building-health-care-model-hierarchically/">this post</a>).  I also remembered the famous article “The Magical Number Seven, Plus or Minus Two: Some Limits on Our Capacity for Processing Information” by G.A. Miller (1956).  It explains that we cannot keep more than five to nine things simultaneously in our heads, depending on the person.  So I may be able to absorb the meaning of a diagram with seven modules, but someone else may only be able to understand one with five modules.  For this reason, we should strive to keep the number of modules in a diagram below seven (which also may help explain why the above method works well for a small number of sectors).</p>
<p>Rearranging the Urban Dynamics model into three levels, I was able to simplify the top-level of the diagram to the following, which shows all of the important high-level feedback loops:</p>
<p><img style="border: 0pt none; display: block; margin-left: auto; margin-right: auto;" title="Urban Dynamics - top-level of three levels" src="http://blog.iseesystems.com/wp-content/uploads/2010/03/image9.png" border="0" alt="image" width="259" height="275" /></p>
<p>There are also lower-level feedback loops within each of these modules.  The one within w<em>orkforce</em> is just as complicated:</p>
<p><img style="border: 0pt none; display: block; margin-left: auto; margin-right: auto;" title="workforce module (2nd level of Urban Dynamics)" src="http://blog.iseesystems.com/wp-content/uploads/2010/03/image10.png" border="0" alt="image" width="363" height="249" /></p>
<p>The model logic rests within these second-level modules.  For example, the module <em>underemployed mobility</em> contains the following logic:</p>
<p><img style="border: 0pt none; display: block; margin-left: auto; margin-right: auto;" title="underemployed mobility module (bottom-level of Urban Dynamics)" src="http://blog.iseesystems.com/wp-content/uploads/2010/03/image11.png" border="0" alt="image" width="481" height="342" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/converting-sectors-to-modules/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Modeling Customers Switching Between Brands – The General Case</title>
		<link>http://blog.iseesystems.com/modeling-tips/array-methods-4/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/array-methods-4/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 13:00:04 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[2D array]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[iThink/STELLA]]></category>
		<category><![CDATA[market dynamics]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=2248</guid>
		<description><![CDATA[This is the last installment of a four-part series.  The first three parts can be accessed by clicking on the links below.
Methods for Using Arrays Effectively
Modeling a Watershed with Arrays
Modeling Customers Switching Between Brands 
Generalizing the Model
When I showed Steve Peterson (at Lexidyne) my brand switching model, he told me there is a more general [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is the last installment of a four-part series.  The first three parts can be accessed by clicking on the links below.<br />
<a href="http://blog.iseesystems.com/modeling-tips/array-methods-1/">Methods for Using Arrays Effectively</a></em><em><br />
<a href="http://blog.iseesystems.com/modeling-tips/array-methods-2/">Modeling a Watershed with Arrays</a><a href="http://blog.iseesystems.com/modeling-tips/array-methods-3/"><br />
Modeling Customers Switching Between Brands </a></em></p>
<p><strong>Generalizing the Model</strong></p>
<p>When I showed Steve Peterson (at <a href="http://www.lexidyne.com/">Lexidyne</a>) my brand switching model, he told me there is a more general version that separates the customer loss fraction from the fraction won by another competitor.  This has been presented in <a title="Pharmaceutical Product Strategy" href="http://www.lexidyne.com/Publications/publications.htm"><span style="text-decoration: underline;">Pharmaceutical Product Strategy</span></a> by Mark Paich, Corey Peck, and Jason Valant.</p>
<p>In my original formulation, the <em>switching probability</em> matrix was the product of these two variables.  However, in many practical cases, the data available comes from two different places and reflects these two separate components.  The revised model structure is shown below.</p>
<p><img style="border: 0px currentColor; margin-right: auto; margin-left: auto; display: block;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2009/10/image_thumb.png" alt="image" width="306" height="237" border="0" /></p>
<p>Instead of one composite <em>switching probability</em>, this model uses a <em>switching out probability</em> that is distinct from the <em>switching in probability</em>.  The <em>switching out probability</em> is a one-dimensional array that, for each product, contains the fraction of customers lost to rivals every time unit (in our case, month).  A sample for the five brands <em>A</em>, <em>B</em>, <em>C</em>, <em>D</em>, and <em>E</em> appears below.</p>
<table style="width: 190px; margin-left: 30px;" border="1" frame="box" rules="rows" cellspacing="0" cellpadding="2">
<tbody>
<tr align="center">
<td valign="top" width="83">Brand</td>
<td valign="top" width="105">Fraction Lost</td>
</tr>
<tr align="center">
<td valign="top" width="83">A</td>
<td valign="top" width="105">0.091</td>
</tr>
<tr align="center">
<td valign="top" width="83">B</td>
<td valign="top" width="105">0.170</td>
</tr>
<tr align="center">
<td valign="top" width="83">C</td>
<td valign="top" width="105">0.046</td>
</tr>
<tr align="center">
<td valign="top" width="83">D</td>
<td valign="top" width="105">0.026</td>
</tr>
<tr align="center">
<td valign="top" width="83">E</td>
<td valign="top" width="106">0.071</td>
</tr>
</tbody>
</table>
<p style="padding-left: 60px;"><span style="font-size: x-small;"><strong>switching out probability</strong></span></p>
<p>We can see from this table that Brand <em>B</em> is losing 17% of its customers to rivals each and every month!  Whoever is managing that product had better do something quickly.</p>
<p>The other side of the story has to do with which brand the customers are switching to.  The <em>switching in probability</em> matrix contains, for each brand, the fraction of lost customers that migrate to a rival brand.  Thus, each row of this matrix <em>must</em> add up to one (100% of lost customers).  A sample appears below.</p>
<table style="width: 400px; margin-left: 30px;" border="1" frame="box" rules="rows" cellspacing="0" cellpadding="2">
<tbody>
<tr align="center">
<td valign="top" width="66">From\To</td>
<td valign="top" width="66">A</td>
<td valign="top" width="66">B</td>
<td valign="top" width="66">C</td>
<td valign="top" width="66">D</td>
<td valign="top" width="66">E</td>
</tr>
<tr align="center">
<td valign="top" width="66">A</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.11</td>
<td valign="top" width="66">0.33</td>
<td valign="top" width="66">0.55</td>
<td valign="top" width="66">0.01</td>
</tr>
<tr align="center">
<td valign="top" width="66">B</td>
<td valign="top" width="66">0.18</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.29</td>
<td valign="top" width="66">0.41</td>
<td valign="top" width="66">0.12</td>
</tr>
<tr align="center">
<td valign="top" width="66">C</td>
<td valign="top" width="66">0.22</td>
<td valign="top" width="66">0.02</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.44</td>
<td valign="top" width="66">0.32</td>
</tr>
<tr align="center">
<td valign="top" width="66">D</td>
<td valign="top" width="66">0.04</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.77</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.19</td>
</tr>
<tr align="center">
<td valign="top" width="66">E</td>
<td valign="top" width="66">0.02</td>
<td valign="top" width="66">0.07</td>
<td valign="top" width="66">0.28</td>
<td valign="top" width="66">0.63</td>
<td valign="top" width="66">0.00</td>
</tr>
</tbody>
</table>
<p style="padding-left: 150px;"><span style="font-size: x-small;"><strong>switching in probability</strong></span></p>
<p>Note the diagonal will always be zero.</p>
<p>We can determine a lot of things from this table.  For example, brand <em>B</em> offers no competition to brand <em>D</em>, brand <em>D</em> is the biggest rival of all the other brands, and brand <em>C</em> is brand <em>D’</em>s biggest rival.</p>
<p><span id="more-2248"></span>Given these probabilities, we can find the number of customers <em>switching out</em> with the equation:</p>
<p style="padding-left: 30px;">switching_out_probability[Products]*Customers[Products]</p>
<p>We can then use the exact same formulation as previously for <em>switching to</em>:</p>
<p style="padding-left: 30px;">switching_out[Products]*switching_in_probability[Products, Products]</p>
<p>and <em>switching in</em>:</p>
<p style="padding-left: 30px;">ARRAYSUM(switching_to[*, Products])</p>
<p>Note that all customers that switch between two brands also pass through a stock called <em>Customers Switching</em>.  This was Steve Peterson&#8217;s idea:  If the equations in the model are correct and all rows of <em>switching in probability</em> add up to one, as they ought to, this stock will always be zero.  If it is ever non-zero, you immediately know there is something wrong with the numbers in <em>switching in probability</em>.  [Note:  Due to truncation errors during the simulation, the stock will not identically equal zero, so it has been globally scaled from –1 to +1 using the Range Specs.]</p>
<p><strong>Expanding the Model</strong></p>
<p>The structure given above models rivalry for existing customers quite well.  However, it does not include flows for new customers entering the market or existing customers leaving the market.  The full structure for acquiring and retaining customers looks like this (and is available by clicking <a href="http://blog.iseesystems.com/wp-content/uploads/2009/10/switching2.itm">here</a>):</p>
<p><img style="border: 0px currentColor; margin-right: auto; margin-left: auto; display: block;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2009/10/image_thumb1.png" alt="image" width="378" height="272" border="0" /></p>
<p>New customers are gained by each brand based on their respective market shares.  Each brand also has a fraction of customers who are lost completely to this market, who perhaps move on to other technology or just stop using that type of product.</p>
<p>The simulation results are shown below for the case where all products start with 100 customers, no new customers are added, and the <em>loss rate</em> is zero.</p>
<p><img style="border: 0px currentColor; margin-right: auto; margin-left: auto; display: block;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2009/10/image_thumb4.png" alt="image" width="496" height="286" border="0" /></p>
<p><strong>Switching Based on Market Shares</strong></p>
<p>There is one further variant to customer brand switching that may be useful in some circumstances (it is available by clicking <a href="http://blog.iseesystems.com/wp-content/uploads/2009/10/switching3.itm">here</a>):</p>
<p><img style="border: 0px currentColor; margin-right: auto; margin-left: auto; display: block;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2009/10/image_thumb3.png" alt="image" width="338" height="217" border="0" /></p>
<p>In this version, rather than using a <em>switching in probability</em>, the number of customers gained each unit time is determined by a dynamic overall market share, the one-dimensional array <em>switching in market share</em>.  Whereas the previous model (above) includes a mechanism whereby brand <em>X</em> explicitly gains customers from brand <em>Y</em>, this model bases switching on market share dynamics; if a customer decides to stop using brand <em>X</em>, they might then go searching for a replacement and would be more likely pick the market leader.  Note the <em>switching in market share</em> can be the same as the brand’s overall <em>market share</em> or, as shown, it can reflect the different market shares between new customers (<em>market share</em>) and switching customers (<em>switching in market share</em>).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/array-methods-4/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Running Mean and Standard Deviation</title>
		<link>http://blog.iseesystems.com/modeling-tips/running-mean-and-stddev/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/running-mean-and-stddev/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 15:25:57 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[builtins]]></category>
		<category><![CDATA[iThink/STELLA]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[Version 9.1.2]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=2139</guid>
		<description><![CDATA[This is an update to post published on August 31, 2009.  The attached model was updated to find negative means and an alternate method was included at the end.
I am frequently asked which built-in function gives either the running mean or running standard deviation of a model variable.  Unfortunately, there is no such built-in at [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is an update to post published on August 31, 2009.  The attached model was updated to find negative means and an alternate method was included at the end.</em></p>
<p>I am frequently asked which built-in function gives either the running mean or running standard deviation of a model variable.  Unfortunately, there is no such built-in at this time (no, that is not what MEAN() does).</p>
<p>Luckily, however, we can replicate the behavior we desire from built-in functions by creating a reusable module.  I can create a module that calculates a running average and a running standard deviation from any model variable.</p>
<p>When building a reusable module component, it is important to carefully define what the input to the module will be (i.e., what are the parameters to the built-in function) and what the output of the module will be (i.e., what is the result or return value of the built-in function).  In this particular case, the input will be the variable whose running average or running standard deviation we wish to find.  There are two outputs:  the running average and the running standard deviation.  Note we do not have to use both outputs all the time.</p>
<p>Thus, our new module can be used as shown below:</p>
<p><img style="border-top-width: 0px; display: block; border-left-width: 0px; float: none; border-bottom-width: 0px; margin-left: auto; margin-right: auto; border-right-width: 0px" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2009/08/image_thumb.png" border="0" alt="image" width="372" height="189" /></p>
<p>Note the name of the module was chosen to give a meaningful context to the running mean and standard deviation variables, which have fixed names defined inside the reusable module.  As in this example, it is always a good idea to give the module outputs general names that make sense when qualified by a context (the module name).</p>
<p>The reusable module itself was built and tested in <em>iThink</em>, and can also be used in STELLA.  The input parameter was given an equation to allow the model to be completely tested and debugged before being reused.  The model appears below and can be downloaded by clicking <a href="http://blog.iseesystems.com/wp-content/uploads/2009/08/mean-and-stddev.itm"></a><a href="http://blog.iseesystems.com/wp-content/uploads/2009/08/mean-and-stddev.itm">here</a>.</p>
<p><img style="border-top-width: 0px; display: block; border-left-width: 0px; float: none; border-bottom-width: 0px; margin-left: auto; margin-right: auto; border-right-width: 0px" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2009/08/image_thumb1.png" border="0" alt="image" width="392" height="206" /></p>
<p>Note the input to the module is named <em>value</em>.  After importing the module, this will need to be assigned to the variable in question, <em>Cash</em> in the above example.  This can be done from outside the module by right-clicking on <em>Cash</em> and choosing “Module-&gt;Assign to”, or right-clicking on <em>value</em> and choosing “Module-&gt;Assign Input to”.  The outputs can be assigned in a similar way, or the Ghost tool can be used.</p>
<p>This method, while relatively easy to understand, does accurately compute the standard deviation when the mean of the <em>running sum of squares</em> is close in magnitude to the <em>running mean</em> squared.  An alternate method that does not suffer this problem was developed by Welford in 1962 and is implemented in the model that can be downloaded by clicking <a href="http://blog.iseesystems.com/wp-content/uploads/2009/08/mean-and-stddev2.itm">here</a>.</p>
<p>Finally, I am including a simple reusable module that finds the maximum value of a model variable across the entire run of a simulation.  It can be downloaded by clicking <a href="http://blog.iseesystems.com/wp-content/uploads/2009/08/maximum-value.itm">here</a>.  It uses a stock to hold the maximum value seen so far, and takes advantage of the fact that uniflows cannot be negative.  It is used the same way as the running mean and standard deviation module, but only has one output called <em>maximum</em>.</p>
<p>For more information about modules, consult the <em>iThink</em> and STELLA help files.  These on-line resources are also available:</p>
<p><a href="http://blog.iseesystems.com/training/features-introduced-in-stella-and-ithink-version-91/">Using Modules Webinar</a></p>
<p><a href="http://blog.iseesystems.com/modeling-tips/module-faqs/">Module FAQs</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/running-mean-and-stddev/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Modeling Customers Switching Between Brands</title>
		<link>http://blog.iseesystems.com/modeling-tips/array-methods-3/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/array-methods-3/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 09:15:57 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[2D array]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[iThink/STELLA]]></category>
		<category><![CDATA[market dynamics]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=2204</guid>
		<description><![CDATA[This is the third installment of a four-part series.  The other three parts can be accessed by clicking on the links below.
Methods for Using Arrays Effectively
Modeling a Watershed with Arrays
Modeling Customers Switching Between Brands &#8211; The General Case 
&#160;
In the second post of this series, I showed how to selectively pull information from an array [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is the third installment of a four-part series.  The other three parts can be accessed by clicking on the links below.<br />
<a href="../modeling-tips/array-methods-1/">Methods for Using Arrays Effectively</a></em><em><br />
<a href="../modeling-tips/array-methods-2/">Modeling a Watershed with Arrays</a><br />
<a href="../modeling-tips/array-methods-4/">Modeling Customers Switching Between Brands &#8211; The General Case </a></em></p>
<p>&nbsp;</p>
<p>In the second post of this series, I showed how to selectively pull information from an array in order to route water through a watershed.  In this post, I will use the exact same technique to move customers between different product brands.</p>
<p><strong>Switching Customers between Different Products</strong></p>
<p>Business models often need to model gaining customers from, and losing customers to, competing products in a relatively mature market (what Kim Warren, in his excellent book <span style="text-decoration: underline;">Strategy Management Dynamics</span>, calls “Type 2 Rivalry”).  These are often driven with statistical models developed through market research.  For this application, we need a matrix describing the probability of switching from product <em>A</em> to product <em>B</em> each time unit.  A sample appears in the table below.</p>
<table style="width: 400px; margin-left: 30px;" border="1" frame="box" rules="rows" cellspacing="0" cellpadding="2">
<tbody>
<tr align="center">
<td valign="top" width="66">From\To</td>
<td valign="top" width="66">A</td>
<td valign="top" width="66">B</td>
<td valign="top" width="66">C</td>
<td valign="top" width="66">D</td>
<td valign="top" width="66">E</td>
</tr>
<tr align="center">
<td valign="top" width="66">A</td>
<td valign="top" width="66">0.000</td>
<td valign="top" width="66">0.010</td>
<td valign="top" width="66">0.030</td>
<td valign="top" width="66">0.050</td>
<td valign="top" width="66">0.001</td>
</tr>
<tr align="center">
<td valign="top" width="66">B</td>
<td valign="top" width="66">0.030</td>
<td valign="top" width="66">0.000</td>
<td valign="top" width="66">0.050</td>
<td valign="top" width="66">0.070</td>
<td valign="top" width="66">0.020</td>
</tr>
<tr align="center">
<td valign="top" width="66">C</td>
<td valign="top" width="66">0.010</td>
<td valign="top" width="66">0.001</td>
<td valign="top" width="66">0.000</td>
<td valign="top" width="66">0.020</td>
<td valign="top" width="66">0.015</td>
</tr>
<tr align="center">
<td valign="top" width="66">D</td>
<td valign="top" width="66">0.001</td>
<td valign="top" width="66">0.000</td>
<td valign="top" width="66">0.020</td>
<td valign="top" width="66">0.000</td>
<td valign="top" width="66">0.005</td>
</tr>
<tr align="center">
<td valign="top" width="66">E</td>
<td valign="top" width="66">0.001</td>
<td valign="top" width="66">0.005</td>
<td valign="top" width="66">0.020</td>
<td valign="top" width="66">0.045</td>
<td valign="top" width="66">0.000</td>
</tr>
</tbody>
</table>
<p style="padding-left: 100px;"><strong style="font-size: x-small;">switching probability (units: dimensionless)<br />
</strong></p>
<p>To read this table, locate the product the customer is presently using in the left column (say, <em>B</em>).  Read across that row (the second row, in this case) until you find the product the customer is switching to (say, <em>C</em>).  The number in that cell (in this case, 0.05 or 5%) is the probability the customer will switch from the first product to the second (from <em>B</em> to <em>C</em>) in this time unit.  If the model is running in months, as ours is, this table indicates that 5% of customers using product <em>B</em> switch to product <em>C</em> <em>every</em> month.</p>
<p>Of course, the values in the table do not need to be constant.  Often each cell will contain a regression equation based on various product characteristics – including market share, marketing effort, product features, and product quality – that evolve over the course of the simulation.</p>
<p>Note the diagonal is zero.  This means customers do not switch from one product to the same product.</p>
<p>Note also that the sum in any row cannot exceed 1.0, which represents 100% of the customers using that product.  It is quite normal for it to be below 1.0 because we do not include people who are not switching.  Some modelers find it easier to always have each row add up to 1.0.  If you desire to do this, fill the diagonal with the difference between 1.0 and the sum of the other columns.  For example, to do this for product <em>A</em>, replace the top left cell with 1.0 &#8211; (0.01 + 0.03 + 0.05 + 0.001) = 0.909 [for you Beatles fans].</p>
<p>&nbsp;</p>
<p><span id="more-2204"></span><strong>Exploring the Model</strong></p>
<p>The model is slightly different from the watershed model in my previous post.  This model is driven by the probability of switching.  Thus, it is driven by the stock of customers for each product, while the watershed model was driven by the outflow from each reach.  This is shown below (and is available by clicking <a href="http://blog.iseesystems.com/wp-content/uploads/2009/09/switching.itm">here</a>).</p>
<p><img style="border: 0px currentColor; margin-right: auto; margin-left: auto; display: block;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2009/09/image_thumb6.png" alt="image" width="326" height="212" border="0" /></p>
<p>The two-dimensional array <em>switching</em> (called a “switching matrix”) is derived by multiplying customers by the switching probability:</p>
<p style="padding-left: 30px;">Customers[Products]*switching_probability[Products, Products]</p>
<p>This equation does not perform a traditional matrix multiplication, but multiplies each element of <em>Customers</em> (a one-dimensional column) by every element in the corresponding row of <em>switching probability</em> (two-dimensional).  [For more information about matrix arithmetic in <em>iThink</em> and STELLA, click <a href="../modeling-tips/matrix-arithmetic/">here</a>.]  As an example, given the <em>switching probability</em> above, if 100 customers use each of products <em>A</em>, <em>B</em>, <em>C</em>, <em>D</em>, and <em>E</em>, the values of <em>switching</em> with its row and column totals would be:</p>
<table style="width: 470px; margin-left: 30px;" border="1" frame="box" rules="rows" cellspacing="0" cellpadding="2">
<tbody>
<tr align="center">
<td valign="top" width="66">From\To</td>
<td valign="top" width="66">A</td>
<td valign="top" width="66">B</td>
<td valign="top" width="66">C</td>
<td valign="top" width="66">D</td>
<td valign="top" width="66">E</td>
<td style="background-color: #f0f0f0;" valign="top" width="66">Total Out</td>
</tr>
<tr align="center">
<td valign="top" width="66">A</td>
<td valign="top" width="66">0.0</td>
<td valign="top" width="66">1.0</td>
<td valign="top" width="66">3.0</td>
<td valign="top" width="66">5.0</td>
<td valign="top" width="66">0.1</td>
<td style="background-color: #f0f0f0;" valign="top" width="66">9.1</td>
</tr>
<tr align="center">
<td valign="top" width="66">B</td>
<td valign="top" width="66">3.0</td>
<td valign="top" width="66">0.0</td>
<td valign="top" width="66">5.0</td>
<td valign="top" width="66">7.0</td>
<td valign="top" width="66">2.0</td>
<td style="background-color: #f0f0f0;" valign="top" width="66">17.0</td>
</tr>
<tr align="center">
<td valign="top" width="66">C</td>
<td valign="top" width="66">1.0</td>
<td valign="top" width="66">0.1</td>
<td valign="top" width="66">0.0</td>
<td valign="top" width="66">2.0</td>
<td valign="top" width="66">1.5</td>
<td style="background-color: #f0f0f0;" valign="top" width="66">4.6</td>
</tr>
<tr align="center">
<td valign="top" width="66">D</td>
<td valign="top" width="66">0.1</td>
<td valign="top" width="66">0.0</td>
<td valign="top" width="66">2.0</td>
<td valign="top" width="66">0.0</td>
<td valign="top" width="66">0.5</td>
<td style="background-color: #f0f0f0;" valign="top" width="66">2.6</td>
</tr>
<tr align="center">
<td valign="top" width="66">E</td>
<td valign="top" width="66">0.1</td>
<td valign="top" width="66">0.5</td>
<td valign="top" width="66">2.0</td>
<td valign="top" width="66">4.5</td>
<td valign="top" width="66">0.0</td>
<td style="background-color: #f0f0f0;" valign="top" width="66">7.1</td>
</tr>
<tr style="background-color: #f0f0f0;" align="center">
<td valign="top" width="66">Total In</td>
<td valign="top" width="66">4.2</td>
<td valign="top" width="66">1.6</td>
<td valign="top" width="66">12.0</td>
<td valign="top" width="66">18.5</td>
<td valign="top" width="66">4.1</td>
<td style="background-color: silver;" valign="top" width="66">40.4</td>
</tr>
</tbody>
</table>
<p style="padding-left: 180px;"><strong style="font-size: x-small;">switching (units: customers)<br />
</strong></p>
<p>These numbers are derived by multiplying the entire row for each product by 100, the number of customers using that product (again, this example uses 100 customers for each product).  The number of customers switching from a given brand each month is the sum of that product&#8217;s row.  The number of customers switching to a given brand each month is the sum of that product&#8217;s column.</p>
<p>Thus, 9.1 existing customers switch from (stop using) product <em>A</em> this month while 4.2 customers switch to (start using) product <em>A</em> this month.  Product <em>A</em> will therefore have a net loss of 9.1 &#8211; 4.2 = 4.9 customers for the month.</p>
<p>The switching matrix directly drives both the loss of customers and the gain of customers.  The former, <em>losing_customers</em>, sums rows:</p>
<p style="padding-left: 30px;">ARRAYSUM(switching[Products, *])</p>
<p>while the latter, <em>gaining_customers</em>, sums columns:</p>
<p style="padding-left: 30px;">ARRAYSUM(switching[*, Products]).</p>
<p><strong>Running the Model</strong></p>
<p>The simulation results are shown below for the case where all products start with 100 customers and no new customers are added.</p>
<p><img style="border: 0px currentColor; display: inline;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2009/09/image_thumb5.png" alt="image" width="496" height="286" border="0" /></p>
<p>Note the product with the largest net gain = Total In &#8211; Total Out, product <em>D</em>, gains the most market share over the course of the simulation, while that with the smallest net gain, product <em>B</em>, loses the most.</p>
<p>Next time, I will show a more general switching matrix formulation.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/array-methods-3/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Modeling a Watershed with Arrays</title>
		<link>http://blog.iseesystems.com/modeling-tips/array-methods-2/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/array-methods-2/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 14:29:22 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[2D array]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[iThink/STELLA]]></category>
		<category><![CDATA[spatial]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=2184</guid>
		<description><![CDATA[This is the second installment of a four-part series.  The other three parts can be accessed by clicking on the links below.
Methods for Using Arrays Effectively
Modeling Customers Switching Between Brands
Modeling Customers Switching Between Brands – The General Case 
&#160;
This is the second installment of a multipart series.  The first part can be found by clicking [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is the second installment of a four-part series.  The other three parts can be accessed by clicking on the links below.<br />
<a href="http://blog.iseesystems.com/modeling-tips/array-methods-1/">Methods for Using Arrays Effectively</a></em><em><br />
<a href="http://blog.iseesystems.com/modeling-tips/array-methods-3/">Modeling Customers Switching Between Brands</a><br />
<a href="http://blog.iseesystems.com/modeling-tips/array-methods-4/">Modeling Customers Switching Between Brands – The General Case </a></em></p>
<p>&nbsp;</p>
<p><em>This is the second installment of a multipart series.  The first part can be found by clicking <a href="http://blog.iseesystems.com/modeling-tips/array-methods-1/">here</a>. </em><em>Part 3 is available <a href="http://blog.iseesystems.com/modeling-tips/array-methods-3/">here</a>.</em></p>
<p>In the first post of this series, I showed how to conditionally pull information from an array.  In this post, I will extend this concept to show how to route information through an arrayed model.  This is especially useful in spatial modeling applications.</p>
<p><strong>Routing Water Through a Watershed</strong></p>
<p>A common ecology application is the modeling of a watershed.  Part of such a model will necessarily involve a network of stream or river segments – called <em>reaches</em> – which feed each other.  It is desirable to implement this in a way that makes it easy to modify the reach network.  Using an explicit stock-flow network makes this very difficult.  However, it is relatively straightforward to use arrays of stocks and flows to build an easily configurable network.</p>
<p>Imagine a small watershed broken down into reaches as shown below:</p>
<p><img style="border: 0px currentColor; margin-right: auto; margin-left: auto; display: block;" title="clip_image001[6]" src="http://blog.iseesystems.com/wp-content/uploads/2009/09/clip_image0016_thumb.gif" alt="clip_image001[6]" width="236" height="176" border="0" /></p>
<p>For our purposes, a new reach will need to be created at every junction point.  Therefore, in this example and from a topological point-of-view, it is not strictly necessary to treat reach 4 separately from reach 2 nor reach 5 separately from reach 3, but reaches 2 and 3 must be separate from reach 1.  There are, of course, other reasons to separate reach 4 from 2 and reach 5 from 3, for example, slope, channel width, length, etc.</p>
<p>Every reach flows into exactly one other reach at its head, but many reaches can flow into the head of the same reach.  This requires a many-to-one representation of the reach network.  This is accomplished quite easily with a routing map which, for each reach, contains the number of the reach that this reach flows into.  We also need someway to signify the outlet.  Since reach numbers start at one, we can use zero to signify the outlet.  Using these rules, the above network is completely represented in the following routing map:</p>
<table style="width: 180px; margin-left: 30px;" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="89"><span style="text-decoration: underline;">Reach</span></td>
<td valign="top" width="89"><span style="text-decoration: underline;">Flows into</span></td>
</tr>
<tr>
<td valign="top" width="89">1</td>
<td valign="top" width="89">0</td>
</tr>
<tr>
<td valign="top" width="89">2</td>
<td valign="top" width="89">1</td>
</tr>
<tr>
<td valign="top" width="89">3</td>
<td valign="top" width="89">1</td>
</tr>
<tr>
<td valign="top" width="89">4</td>
<td valign="top" width="89">2</td>
</tr>
<tr>
<td valign="top" width="89">5</td>
<td valign="top" width="89">3</td>
</tr>
</tbody>
</table>
<p>The nice thing about this representation is that it fits nicely into a one-dimensional array where the array index is the reach number and the reach it flows into is the value stored in that array element.</p>
<p>The model itself uses one stock to represent each reach.  <em> </em>That stock has one inflow for water entering the reach and one outflow for water leaving the reach: <em>(Download the zipped STELLA model <a href="http://blog.iseesystems.com/wp-content/uploads/2009/09/routing.zip">here</a>) </em></p>
<p><img style="border: 0px currentColor; margin-right: auto; margin-left: auto; display: block;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2009/09/image_thumb.png" alt="image" width="387" height="195" border="0" /></p>
<p><span id="more-2184"></span><strong>The Routing Magic</strong></p>
<p>The outflow of one reach is directed to the next through the two-dimensional array <em>route water</em>.  This array is arranged with one outflow per row and one inflow per column.  Thus, the outflows are placed one per row in the proper column for the reach it is headed for.  This means there can only be one non-zero value in each row.  For example, at one point in the simulation, the array <em>route water</em> contains these values:</p>
<div>
<table style="width: 400px; margin-left: 30px;" border="1" frame="box" rules="rows" cellspacing="0" cellpadding="2">
<tbody>
<tr align="center">
<td valign="top" width="66">From\To</td>
<td valign="top" width="66">1</td>
<td valign="top" width="66">2</td>
<td valign="top" width="66">3</td>
<td valign="top" width="66">4</td>
<td valign="top" width="66">5</td>
</tr>
<tr align="center">
<td valign="top" width="66">1</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.00</td>
</tr>
<tr align="center">
<td valign="top" width="66">2</td>
<td valign="top" width="66">1.04</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.00</td>
</tr>
<tr align="center">
<td valign="top" width="66">3</td>
<td valign="top" width="66">0.87</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.00</td>
</tr>
<tr align="center">
<td valign="top" width="66">4</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.33</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.00</td>
</tr>
<tr align="center">
<td valign="top" width="66">5</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.24</td>
<td valign="top" width="66">0.00</td>
<td valign="top" width="66">0.00</td>
</tr>
</tbody>
</table>
</div>
<p>As expected, there is at most one non-zero value for each row.  There is no non-zero value in the first row because that corresponds to the outlet, so no water is routed to another reach.  The value in the second row is the outflow from reach 2, the value in the third is the outflow from reach 3, and so on.  The columns sum to the amount of water being fed to the given reach.  So reach 1 will receive 1.04 + 0.87 = 1.91, reach 2 will receive 0.33, and reach 3 will receive 0.24.  Reaches 4 and 5 receive no inflow because they are at the top of the watershed (there are no reaches feeding into them).</p>
<p>The equation that does this magic is:</p>
<p style="padding-left: 30px;">IF (routing_map[Reaches] = ARRAYIDX(2))<br />
THEN outflow[Reaches]<br />
ELSE 0</p>
<p>This says that when the column number (ARRAYIDX(2)) equals the reach number of the downstream reach (routing_map[Reaches]), fill the cell with that reach’s outflow.  Note that we at most define one downstream reach for each reach, so this will only be non-zero in only one column.  In this way, we avoid violating conservation of water.</p>
<p>The inflow then needs to sum the columns to get the total flow directed into that reach:</p>
<p style="padding-left: 30px;">ARRAYSUM(route_water[*,Reaches])</p>
<p>The outflow at the stream outlet is captured in the converter <em>final outflow</em>, which has the equation:</p>
<p style="padding-left: 30px;">ARRAYVALUE(outflow[*], ARRAYMINIDX(routing_map[*]))</p>
<p>This picks up the outflow value of the reach that has the smallest entry in the routing map.  Since we defined the outlet to have the smallest value, zero, as long as we do not accidentally give two entries a zero value in the routing map, ARRAYMINIDX will find the array index (i.e., reach number) of the outlet.</p>
<p>With constant precipitation, the behavior of the model at the end of a storm event appears below:</p>
<p><img style="border: 0px currentColor; margin-right: auto; margin-left: auto; display: block;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2009/09/image_thumb1.png" alt="image" width="496" height="286" border="0" /></p>
<p><strong>Extending the Model<br />
</strong></p>
<p>This particular example has two simplifications that are easy to extend.  The average time it takes water to flow through a reach (<em>avg reach length in minutes</em>) is constant, but can be made an array with different values for each reach.  These values can also be calculated as the simulation progresses based on existing conditions in the reach.  There is also a constant precipitation to all reaches all the time to keep water flowing into the system.  This can be replaced by an array and a more intricate model of how precipitation flows into the stream over the landscape, or by a simple time series using a graphical function.</p>
<p>One final note about the model:  I chose a stock with an average residence time to represent each reach.  Under some circumstances, this may generate results that are confusing.  For example, because it is an <em>average</em> residence time that follows an exponential distribution, some water that appears at the top of a reach will immediately exit from the bottom of the reach and other water that enters the reach will exit long after the average time has expired.  In individual circumstances, for example a single short storm event, this representation may not match the real world very well.  However, on average, over a long enough period of time, it matches the real behavior quite closely.</p>
<p>One alternative that enforces an exact delay for water moving across each reach is a conveyor.  However, a conveyor is discrete in its behavior, so the model will not behave as true water flow does, i.e., continuously.  Three stocks, i.e., a third-order material delay, could also be used for each reach to reduce the amount of entering water that exits immediately.  Although this does cause the model to retain more water at the start of an event, it also leads to water being lost more quickly at the end.</p>
<p>Next time, I will use this same structure to model customers switching between different brands.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/array-methods-2/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Methods for Using Arrays Effectively, Part 1</title>
		<link>http://blog.iseesystems.com/modeling-tips/array-methods-1/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/array-methods-1/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 19:33:55 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[2D array]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[iThink/STELLA]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=2150</guid>
		<description><![CDATA[This is the first installment of a four-part series. The remaining three parts can be accessed by clicking on the links below.
Modeling a Watershed with Arrays
Modeling Customers Switching Between Brands
Modeling Customers Switching Between Brands &#8211; The General Case 
&#160;
Using arrays can be quite intimidating for most people. Many times, it is difficult to discover the [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is the first installment of a four-part series. The remaining three parts can be accessed by clicking on the links below.<br />
<a href="../modeling-tips/array-methods-2/">Modeling a Watershed with Arrays</a><br />
<a href="../modeling-tips/array-methods-3/">Modeling Customers Switching Between Brands</a><br />
<a href="../modeling-tips/array-methods-4/">Modeling Customers Switching Between Brands &#8211; The General Case </a></em></p>
<p>&nbsp;</p>
<p>Using arrays can be quite intimidating for most people. Many times, it is difficult to discover the correct way to formulate a problem in terms of arrays, especially when trying to do so in terms of single equations that can be applied to all elements of the array.</p>
<p>Consider the case where you might wish to count the number of occurrences of a value in an array. This can arise in many applications that need to track attributes, but is prevalent in spatially-explicit business applications. In such an application, you may associate a product code with a location and then want a count of the products of a given type. The following examples demonstrate a common way to extract conditional information from an array.</p>
<p><strong>Finding the Number of Stations with a Given Status</strong></p>
<p>Imagine you have a two-dimensional grid of fire stations in a city, called <em>Stations</em>, that stores one of four statuses:</p>
<p style="padding-left: 30px;">0: no station in this sector<br />
1: ready<br />
2: away on a call<br />
3: refitting</p>
<p>You consider the number of fire stations ready at any given moment to be an important metric. To calculate this, connect <em>Stations</em> to another two-dimensional array of the same size called <em>ready stations</em>. This will have a one in an array element if the station for that quadrant is ready and a zero otherwise. Its equation is:</p>
<p style="padding-left: 30px;">IF Stations[Y, X] = 1 THEN 1 ELSE 0 { station ready? }</p>
<p>Note this equations uses <em>dimension names</em> (<em>i.e., Stations</em>[<em>Y</em>, <em>X</em>]) rather than <em>element names</em> (e.g., <em>Stations</em>[1, 2]). This allows you to create just one equation for the entire array (with &#8220;Apply to All&#8221; turned on), rather than a separate equation for each individual array element (with &#8220;Apply to All&#8221; turned off). When &#8220;Apply to All&#8221; is turned on, the equation for each element of the array is automatically generated by substituting that element&#8217;s dimensions for the dimension name in the given equation. All of the examples in this post use dimension names.</p>
<p>The total number of ready stations is now just the sum of all of the elements in the array <em>ready stations</em>. This is easily calculated by connecting <em>ready stations</em> to a scalar converter named <em>total ready stations</em> that has the equation</p>
<p style="padding-left: 30px;">ARRAYSUM(ready_stations[*, *])</p>
<p>The model is shown below and can be downloaded by clicking <a href="http://blog.iseesystems.com/wp-content/uploads/2009/08/stations.itm">here</a>.</p>
<p><img style="border: 0px currentColor; margin-right: auto; margin-left: auto; display: block;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2009/08/image_thumb2.png" alt="image" width="313" height="127" border="0" /></p>
<p>This general method can be used anytime we need to count the number of elements in an array based on some condition. First, create an array that has its elements set to one if the array-based condition is met and zero otherwise (IF condition THEN 1 ELSE 0). Then create a converter to sum the elements of this new array (using ARRAYSUM). Remember to turn &#8220;Apply to All&#8221; on and use <em>dimension names</em> in the condition rather than <em>element names</em>.</p>
<p><span id="more-2150"></span></p>
<p><strong>Finding the Number of Stations with Each Status</strong></p>
<p>We can extend this method to map data from an array indexed by one attribute (or dimension), say location, to another array indexed by a different attribute, say status. Imagine now that instead of just counting how many stations are ready, you want to know how many stations have each status.</p>
<p>One way to do this is to extend the structure above to separately count the number of stations in each status, as shown below.</p>
<p><img style="border: 0px currentColor; margin-right: auto; margin-left: auto; display: block;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2009/08/image_thumb4.png" alt="image" width="321" height="226" border="0" /></p>
<p>In this case, <em>away stations</em> and <em>refitting stations</em> have the following formulas, respectively:</p>
<p style="padding-left: 30px;">IF Stations[Y, X] = 2 THEN 1 ELSE 0 { station away? }<br />
IF Stations[Y, X] = 3 THEN 1 ELSE 0 { station refitting? }</p>
<p><strong>Walking Through a Specific Example</strong></p>
<p>Let&#8217;s look at what happens in this model if array of fire stations is only one-dimensional, <em>Stations</em>[<em>Location</em>], and each location is named. This eliminates the &#8220;no station in this sector&#8221; status. Consider a five-location fire department with the following statuses in each location, held in the array <em>Stations</em>:</p>
<div>
<table style="width: 200px; margin-left: 30px;" border="1" frame="box" rules="rows" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="100"><strong>Location</strong></td>
<td valign="top" width="100"><strong>Status</strong></td>
</tr>
<tr>
<td valign="top" width="100">North</td>
<td valign="top" width="100">1 (ready)</td>
</tr>
<tr>
<td valign="top" width="100">South</td>
<td valign="top" width="100">3 (refitting)</td>
</tr>
<tr>
<td valign="top" width="100">Central</td>
<td valign="top" width="100">1 (ready)</td>
</tr>
<tr>
<td valign="top" width="100">East</td>
<td valign="top" width="100">2 (away)</td>
</tr>
<tr>
<td valign="top" width="100">West</td>
<td valign="top" width="100">1 (ready)</td>
</tr>
</tbody>
</table>
</div>
<p>The structure above would generate the following values in the three separate arrays <em>ready stations</em>, <em>away stations</em>, and <em>refitting stations</em>. Their respective sums, in the three corresponding &#8220;<em>total </em>status<em> stations&#8221;</em> converters, are shown at the bottom.</p>
<table style="width: 339px; margin-left: 30px;" border="1" frame="box" rules="rows" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="bottom" width="108"><strong>Location</strong></td>
<td align="center" valign="top" width="77"><strong><em>ready<br />
stations</em></strong></td>
<td align="center" valign="top" width="77"><strong><em>away<br />
stations</em></strong></td>
<td align="center" valign="top" width="75"><em><strong>refitting<br />
stations</strong></em></td>
</tr>
<tr>
<td align="left" valign="top" width="108">North</td>
<td align="center" valign="top" width="77">1</td>
<td align="center" valign="top" width="77">0</td>
<td align="center" valign="top" width="75">0</td>
</tr>
<tr>
<td align="left" valign="top" width="108">South</td>
<td align="center" valign="top" width="77">0</td>
<td align="center" valign="top" width="77">0</td>
<td align="center" valign="top" width="75">1</td>
</tr>
<tr>
<td align="left" valign="top" width="108">Central</td>
<td align="center" valign="top" width="77">1</td>
<td align="center" valign="top" width="77">0</td>
<td align="center" valign="top" width="75">0</td>
</tr>
<tr>
<td align="left" valign="top" width="108">East</td>
<td align="center" valign="top" width="77">0</td>
<td align="center" valign="top" width="77">1</td>
<td align="center" valign="top" width="75">0</td>
</tr>
<tr>
<td align="left" valign="top" width="108">West</td>
<td align="center" valign="top" width="77">1</td>
<td align="center" valign="top" width="77">0</td>
<td align="center" valign="top" width="75">0</td>
</tr>
<tr>
<td align="left" valign="top" width="108"><strong><em>total </em>status <em>stations</em></strong></td>
<td align="center" valign="top" width="77"><strong>3</strong></td>
<td align="center" valign="top" width="77"><strong>1</strong></td>
<td align="center" valign="top" width="75"><strong>1</strong></td>
</tr>
</tbody>
</table>
<p>While this method works, it does not have a very flexible structure. It requires structural changes whenever a new status is added (or removed) and also needs to be customized for every individual application. There are also applications (for example, tracking products) where it is necessary to move between arrays that are indexed by location, as <em>Stations</em> is, and arrays that are indexed by the data within the location, in this case by status.</p>
<p><strong>A More General Solution</strong></p>
<p>If we define another array dimension called <em>Status</em>, with element names <em>Ready</em>, <em>Away</em>, and <em>Refitting</em> that correspond to the numeric statuses 1, 2, and 3, we can represent this same solution in one two-dimensional array <em>station map</em>[<em>Location</em>, <em>Status</em>]:</p>
<div>
<table style="width: 299px; margin-left: 30px;" border="1" frame="box" rules="rows" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td align="left" valign="top" width="71"><strong>Location</strong></td>
<td align="center" valign="top" width="71"><strong>Ready</strong></td>
<td align="center" valign="top" width="71"><strong>Away</strong></td>
<td align="center" valign="top" width="84"><strong>Refitting</strong></td>
</tr>
<tr>
<td align="left" valign="top" width="71">North</td>
<td align="center" valign="top" width="71">1</td>
<td align="center" valign="top" width="71">0</td>
<td align="center" valign="top" width="84">0</td>
</tr>
<tr>
<td align="left" valign="top" width="71">South</td>
<td align="center" valign="top" width="71">0</td>
<td align="center" valign="top" width="71">0</td>
<td align="center" valign="top" width="84">1</td>
</tr>
<tr>
<td align="left" valign="top" width="71">Central</td>
<td align="center" valign="top" width="71">1</td>
<td align="center" valign="top" width="71">0</td>
<td align="center" valign="top" width="84">0</td>
</tr>
<tr>
<td align="left" valign="top" width="71">East</td>
<td align="center" valign="top" width="71">0</td>
<td align="center" valign="top" width="71">1</td>
<td align="center" valign="top" width="84">0</td>
</tr>
<tr>
<td align="left" valign="top" width="71">West</td>
<td align="center" valign="top" width="71">1</td>
<td align="center" valign="top" width="71">0</td>
<td align="center" valign="top" width="84">0</td>
</tr>
</tbody>
</table>
</div>
<p>The array <em>station map</em> allows us to map stations directly to their statuses. Each row of the map represents one station. By definition, there can only be one &#8220;1&#8243; in each row because a station can only have one status. The sum of each row is the number of statuses that are assigned to that station, which must always be one. Each column of the map represents one status. Multiple &#8220;1&#8243;s can appear in the columns because many stations can have the same status. The sum of each column is the number of stations assigned to that status, the value we are trying to determine.</p>
<p>Note the similarity between this two-dimensional array and the preceding table that shows the contents of the individual one-dimensional arrays <em>ready stations, away stations</em>, and <em>refitting stations</em>. Each column of <em>station map</em> corresponds to one of these one-dimensional arrays.</p>
<p>The model for this more general solution is shown below and can be downloaded by clicking <a href="http://blog.iseesystems.com/wp-content/uploads/2009/08/stations2.itm">here</a>.</p>
<p><img style="border: 0px currentColor; margin-right: auto; margin-left: auto; display: block;" title="image" src="http://blog.iseesystems.com/wp-content/uploads/2009/08/image_thumb3.png" alt="image" width="306" height="130" border="0" /></p>
<p>The equation for <em>station map</em>[<em>Location</em>, <em>Status</em>], which will map <em>Stations</em> as illustrated above, is</p>
<p style="padding-left: 30px;">IF Stations[Location] = ARRAYIDX(2) THEN 1 ELSE 0</p>
<p>Note the use of ARRAYIDX() to parameterize the status we are interested in for this array element. The parameter to ARRAYIDX, 2, gives the index of the second dimension for this array element, i.e., the index that corresponds to <em>Status</em>. Since Apply to All is on, this will become the desired status for each array element.</p>
<p>The number of stations with each status is calculated in the one-dimensional converter <em>station totals</em>[<em>Status</em>] using the equation</p>
<p style="padding-left: 30px;">ARRAYSUM(station_map[*, Status])</p>
<p>This equation sums the columns of <em>station map</em>. For the above example, <em>station totals</em> will be filled with the values 3 (<em>Ready</em>), 1 (<em>Away</em>), and 1 (<em>Refitting</em>). Note we have used an intermediate two-dimensional array, <em>station map</em>, to properly map our data from a one-dimensional array indexed by the attribute <em>Location</em> to another one-dimensional array indexed by the attribute <em>Status</em>.</p>
<p>Next time, I will expand this concept to create general routing structures.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/array-methods-1/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Download the isee NetSim Template Model</title>
		<link>http://blog.iseesystems.com/modeling-tips/download-the-netsim-model-template/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/download-the-netsim-model-template/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 17:12:11 +0000</pubDate>
		<dc:creator>Jeremy Merritt</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[netsim]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=2094</guid>
		<description><![CDATA[A few months ago, we designed an interface template for our isee NetSim sample models.  The template is an iThink/STELLA model in which the interface layer is designed to look like a website:

Navigation buttons are styled to look like hyperlinks instead of push buttons. 
Push buttons are used to perform actions, such as running the [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago, we designed an interface template for our isee NetSim sample models.  The template is an <em>iThink</em>/STELLA model in which the interface layer is designed to look like a website:</p>
<ul>
<li>Navigation buttons are styled to look like hyperlinks instead of push buttons. </li>
<li>Push buttons are used to perform actions, such as running the simulation.</li>
<li>Tabs along the top of each page let the viewer know which section they are in, as well as providing a way to quickly jump to any section. </li>
</ul>
<div class="wp-caption aligncenter" style="width: 472px"><a href="http://forio.com/service/netsims/netsim/success/index.html" target="_blank"><img class="  " style="border: 0pt none; display: block;" title="An example of the interface template applied to a model published online" src="http://blog.iseesystems.com/wp-content/uploads/2009/08/CropperCapture34_thumb.png" border="0" alt="CropperCapture[34]" width="462" height="309" /></a><p class="wp-caption-text">An example of the interface template applied to a model published online</p></div>
<p><br class="spacer_" /></p>
<p>You can download the template model and use it as a starting point for creating interfaces to models you want to publish online.</p>
<p><a href="http://bit.ly/10eqVo">Download the template for STELLA</a></p>
<p><a href="http://bit.ly/WtfKM">Download the template for iThink</a></p>
<p><strong>How to use the template</strong></p>
<p>The template model consists of four interface pages: <em>Home</em>, <em>Background</em>, <em>Explore Model</em> and <em>Simulate</em>.  Navigation buttons to and from each page are already setup within the interface.  You can customize each section by replacing the placeholder text.  The pages are a starting point that establishes a website-like look and feel.</p>
<p>The easiest way to apply the template model&#8217;s interface to your own model is to simply copy and paste the pages.</p>
<ol>
<li>Open your own model and switch to the Interface layer.  Choose &#8216;Interface Prefs&#8217; from the Interface menu and make sure the &#8216;Show Pages’ option is selected.  Set Page Size to 800&#215;600.  This will allow you to see the page boundaries as you apply the template.</li>
<li>Open the template model and from the Interface layer choose the Edit menu –&gt; Select All, then Edit menu –&gt; Copy to copy all of the pages to the clipboard. </li>
<li>Go back to the interface layer of your model and choose Edit menu –&gt; Paste.</li>
</ol>
<p>When you have pasted the pages into your model, they will probably not be lined up correctly within the page boundaries.  The dashed lines show the boundaries of each page.  Using these dashed lines as a guide, use the arrow keys on your keyboard to make the pasted pages line up properly.</p>
<p>Now you can customize the title and text in each page.  Add a picture to the home page and build a control panel.  If you want, you can use the hyperlink button on the ‘Background’ page to link to online information, (PDFs, other models, Wikipedia, etc.).  Consider building a storytelling sequence on the ‘Explore Model’ page to unfurl the model a chunk at a time.  These are just a few customizations you can make.  Take a look at some of our <a href="http://www.iseesystems.com/community/downloads/NetsimModels.aspx">sample models published online</a> with isee NetSim for ideas.</p>
<p>If you publish some models online that use the template, we’d love to see them!  Leave a link in the comments so we can check them out!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/download-the-netsim-model-template/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Matrix Arithmetic</title>
		<link>http://blog.iseesystems.com/modeling-tips/matrix-arithmetic/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/matrix-arithmetic/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 11:29:09 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[2D array]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[iThink/STELLA]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=1869</guid>
		<description><![CDATA[iThink and STELLA support a variety of matrix operations. In this post, I will explain the following common operations and how to perform them:

Addition and Subtraction
Transposition
Extracting the Diagonal of a Square Matrix
Multiplying and Dividing by a Scalar
Multiplying a Square Matrix by a Vector
Multiplying a Non-Square Matrix by a Vector
Multiplying Two Matrices

In the examples provided, I [...]]]></description>
			<content:encoded><![CDATA[<p><em>iThink</em> and STELLA support a variety of matrix operations. In this post, I will explain the following common operations and how to perform them:<img class="alignright size-full wp-image-1924" title="Matrix Cube" src="http://blog.iseesystems.com/wp-content/uploads/2009/07/cube-matrix.jpg" alt="Matrix Cube" width="230" height="218" /></p>
<ul>
<li><a href="http://blog.iseesystems.com/modeling-tips/matrix-arithmetic/#0">Addition and Subtraction</a></li>
<li><a href="http://blog.iseesystems.com/modeling-tips/matrix-arithmetic/#1">Transposition</a></li>
<li><a href="http://blog.iseesystems.com/modeling-tips/matrix-arithmetic/#2">Extracting the Diagonal of a Square Matrix</a></li>
<li><a href="http://blog.iseesystems.com/modeling-tips/matrix-arithmetic/#3">Multiplying and Dividing by a Scalar</a></li>
<li><a href="http://blog.iseesystems.com/modeling-tips/matrix-arithmetic/#4">Multiplying a Square Matrix by a Vector</a></li>
<li><a href="http://blog.iseesystems.com/modeling-tips/matrix-arithmetic/#5">Multiplying a Non-Square Matrix by a Vector</a></li>
<li><a href="http://blog.iseesystems.com/modeling-tips/matrix-arithmetic/#6">Multiplying Two Matrices</a></li>
</ul>
<p>In the examples provided, I use five different arrays of varying dimensions. They are all defined using the subscript name <em>Dim3</em>, which is size 3.</p>
<p class="code1" style="padding-left: 60px;"><em>a</em>: 3&#215;3 <br />
<em>b</em>: 3&#215;3 <br />
<em>c</em>: 3&#215;3 <br />
<em>d</em>: 3&#215;1 [one-dimensional] <br />
<em>e</em>: 3&#215;1 [one-dimensional]</p>
<p>I also use two arrays based on <em>Dim3</em>, as well as the subscript name <em>Dim2</em>, which is size 2.</p>
<p class="code1" style="padding-left: 60px;"><em>s</em>: 2&#215;3<br />
<em>t</em>: 3&#215;2</p>
<p><span id="more-1869"></span></p>
<p style="padding-left: 60px;">
<p><a class="anchor_header" name="0"><strong>Addition and Subtraction</strong></a></p>
<p>The easiest functions to perform are addition and subtraction. When two arrays have the same dimensions, they can be added and subtracted in the usual way, placing the result in a third array of the same dimensions.</p>
<p>For example, to place the difference of <em>b</em> and <em>c</em> into array <em>a</em>, set the equation of <em>a</em> to</p>
<p class="code1" style="padding-left: 60px;"><em>b</em>[<em>Dim3</em>, <em>Dim3</em>] – <em>c</em>[<em>Dim3</em>, <em>Dim3</em>]</p>
<p><a class="anchor_header" name="1"><strong>Transposition</strong></a></p>
<p>Transposition of a 2-dimensional array is also relatively easy, especially when the dimensions differ. Suppose we wish to transpose <em>s</em> and place the result in <em>t</em>. Simply set the equation for <em>t</em> to</p>
<p class="code1" style="padding-left: 60px;"><em>s</em>[<em>Dim2</em>, <em>Dim3</em>]</p>
<p>This will properly fill <em>t</em>, which has dimensions <em>Dim3</em>x<em>Dim2</em>, with:</p>
<p class="code1" style="padding-left: 60px;"><em>s</em><sub>11</sub>   <em>s</em><sub>21</sub><br />
<em>s</em><sub>12</sub>   <em>s</em><sub>22</sub><br />
<em>s</em><sub>13</sub>   <em>s</em><sub>23</sub></p>
<p>However, if the two dimensions of the array have the same name, the ARRAYVALUE built-in must be used. Suppose we wish to transpose <em>b</em>, placing its transposition in <em>a</em>. Set the equation of <em>a</em> to</p>
<p class="code1" style="padding-left: 60px;">ARRAYVALUE(<em>b</em>[*, *], ARRAYIDX(2), ARRAYIDX())</p>
<p>Note the index of <em>a</em>’s second dimension is used as the index for <em>b</em>’s first dimension and the index of <em>a</em>’s first dimension is used as the index for <em>b</em>’s second dimension.</p>
<p><a class="anchor_header" name="2"><strong>Extracting the Diagonal of a Square Matrix</strong></a></p>
<p>Extracting the diagonal from a 2-dimensional array is also very easy. To place the diagonal of <em>a</em> into <em>d</em>, set the equation of <em>d</em> to</p>
<p class="code1" style="padding-left: 60px;"><em>a</em>[<em>Dim3</em>, <em>Dim3</em>]</p>
<p><a class="anchor_header" name="3"><strong>Multiplying and Dividing by a Scalar</strong></a></p>
<p>Multiplying or dividing by a scalar works as expected. The contents of <em>b</em> can be multiplied by a scalar <em>x</em>, for example, by setting the equation of <em>a</em> to</p>
<p class="code1" style="padding-left: 60px;"><em>x</em>*<em>b</em>[<em>Dim3</em>, <em>Dim3</em>]</p>
<p><a class="anchor_header" name="4"><strong>Multiplying a Square Matrix by a Vector</strong></a></p>
<p>Matrix multiplication, as defined in linear algebra, is not directly supported at present. It is possible to multiply two arrays, but the results will not match matrix multiplication. When you multiply a 1-dimensional array by a 2-dimensional array, the size of the 1-dimensional array must match either the number of rows or the number of columns in the 2-dimensional array. In both cases, <em>iThink</em> and STELLA treats the 1-dimensional array as either a column or row of scalars that are multiplied across each corresponding row or column, respectively, of the 2-dimensional array.</p>
<p>Given the following equation in <em>a</em>,</p>
<p class="code1" style="padding-left: 60px;"><em>d</em>[<em>Dim3</em>]*<em>b</em>[<em>Dim3</em>, <em>Dim3</em>]</p>
<p><em>d</em> will be treated as a column of scalars (when the 2-dimensional array is square with the same dimension name in both directions, the 1-dimensional array is always treated as a column vector). Each scalar in <em>d</em> will be multiplied across each corresponding row of <em>b</em>. Note this equation does not represent a valid matrix multiplication, and also that switching the order to <em>b</em>[<em>Dim3</em>, <em>Dim3</em>]*<em>d</em>[<em>Dim3</em>], while now a valid matrix multiplication, will not change the result. I recommend leaving the order as above to emphasize that it is not a normal matrix multiplication.</p>
<p>More precisely, the array <em>a</em> will be populated with these values:</p>
<p class="code1" style="padding-left: 60px;"><em>d</em><sub>1</sub>*<em>b</em><sub>11</sub>   <em>d</em><sub>1</sub>*<em>b</em><sub>12</sub>   <em>d</em><sub>1</sub>*<em>b</em><sub>13</sub><br />
<em>d</em><sub>2</sub>*<em>b</em><sub>21</sub>   <em>d</em><sub>2</sub>*<em>b</em><sub>22</sub>   <em>d</em><sub>2</sub>*<em>b</em><sub>23</sub><br />
<em>d</em><sub>3</sub>*<em>b</em><sub>31</sub>   <em>d</em><sub>3</sub>*<em>b</em><sub>32</sub>   <em>d</em><sub>3</sub>*<em>b</em><sub>33</sub></p>
<p>Note that these are <em>not</em> the correct terms for matrix multiplication. If we multiply <em>b</em>[<em>Dim3</em>, <em>Dim3</em>]*<em>d</em>[<em>Dim3</em>], which is the only correct way to express it, the linear algebra result is a one-dimensional vector with these values:</p>
<p class="code1" style="padding-left: 60px;"><em>d</em><sub>1</sub>*<em>b</em><sub>11</sub> + <em>d</em><sub>2</sub>*<em>b</em><sub>12</sub> + <em>d</em><sub>3</sub>*<em>b</em><sub>13</sub><br />
<em>d</em><sub>1</sub>*<em>b</em><sub>21</sub> + <em>d</em><sub>2</sub>*<em>b</em><sub>22</sub> + <em>d</em><sub>3</sub>*<em>b</em><sub>23</sub><br />
<em>d</em><sub>1</sub>*<em>b</em><sub>31</sub> + <em>d</em><sub>2</sub>*<em>b</em><sub>32</sub> + <em>d</em><sub>3</sub>*<em>b</em><sub>33</sub></p>
<p>If we desire to generate these terms, we must first transpose <em>b</em> by placing the transposition equation given above in <em>c</em>:</p>
<p class="code1" style="padding-left: 60px;">ARRAYVALUE(<em>b</em>[*, *], ARRAYIDX(2), ARRAYIDX())</p>
<p>This puts the following values in <em>c</em>, i.e., <em>b</em> transposed:</p>
<p class="code1" style="padding-left: 60px;"><em>b</em><sub>11</sub>   <em>b</em><sub>21</sub>   <em>b</em><sub>31</sub><br />
<em>b</em><sub>12</sub>   <em>b</em><sub>22</sub>   <em>b</em><sub>32</sub><br />
<em>b</em><sub>13</sub>   <em>b</em><sub>23</sub>   <em>b</em><sub>33</sub></p>
<p>The equation for <em>a</em> can now be set to</p>
<p class="code1" style="padding-left: 60px;"><em>d</em>[<em>Dim3</em>]*<em>c</em>[<em>Dim3</em>, <em>Dim3</em>]</p>
<p>This equation will populate <em>a</em> with these values:</p>
<p class="code1" style="padding-left: 60px;"><em>d</em><sub>1</sub>*<em>b</em><sub>11</sub>   <em>d</em><sub>1</sub>*<em>b</em><sub>21</sub>   <em>d</em><sub>1</sub>*<em>b</em><sub>31</sub><br />
<em>d</em><sub>2</sub>*<em>b</em><sub>12</sub>   <em>d</em><sub>2</sub>*<em>b</em><sub>22</sub>   <em>d</em><sub>2</sub>*<em>b</em><sub>32</sub><br />
<em>d</em><sub>3</sub>*<em>b</em><sub>13</sub>   <em>d</em><sub>3</sub>*<em>b</em><sub>23</sub>    <em>d</em><sub>3</sub>*<em>b</em><sub>33</sub></p>
<p>Note that this gives the proper terms for the matrix multiplication, arranged vertically. The final answer is found by summing each column, using the following equation in vector <em>e</em>:</p>
<p class="code1" style="padding-left: 60px;">ARRAYSUM(<em>a</em>[*, <em>Dim3</em>])</p>
<p>Aside: The terms we get from the original equation for <em>a</em>, <em>d</em>[<em>Dim3</em>]*<em>b</em>[<em>Dim3</em>, <em>Dim3</em>], are the correct terms for <em>d</em><sup>T</sup><em>b</em>, i.e., <em>d</em>-transposed times <em>b</em>, again arranged vertically. If this was the desired result, we do not need to first transpose <em>b</em> and can just sum the columns into vector <em>e</em> as shown above.</p>
<p><a class="anchor_header" name="5"><strong>Multiplying a Non-Square Matrix by a Vector</strong></a></p>
<p>If the matrices do not use the same dimension name for both dimensions (square or not), you have much more control over the resultant terms and do not have to resort to transposition at all. The following discussion uses the following additional arrays:</p>
<p class="code1" style="padding-left: 60px;"><em>f</em>: 2&#215;3<br />
<em>g</em>: 2&#215;1 [one-dimensional]<br />
<em>s</em>: 2&#215;3<em>t</em>: 3&#215;2</p>
<p>If we multiply <em>f</em> times <em>d</em>, we will get a different result based on whether the resultant array is 2&#215;3 or 3&#215;2. Placing the equation <em>d</em>[<em>Dim3</em>]*<em>f </em>[<em>Dim2</em>, <em>Dim3</em>] into array <em>s</em> yields exactly the terms needed for a matrix multiplication, arranged horizontally:</p>
<p class="code1" style="padding-left: 60px;"><em>d</em><sub>1</sub>*<em>f</em><sub>11</sub>   <em>d</em><sub>2</sub>*<em>f</em><sub>12</sub>   <em>d</em><sub>3</sub>*<em>f</em><sub>13</sub><br />
<em>d</em><sub>1</sub>*<em>f</em><sub>21</sub>   <em>d</em><sub>2</sub>*<em>f</em><sub>22</sub>   <em>d</em><sub>3</sub>*<em>f</em><sub>23</sub></p>
<p>Setting the equation of <em>g</em> to</p>
<p class="code1" style="padding-left: 60px;">ARRAYSUM(<em>s</em>[<em>Dim2</em>, *])</p>
<p>will properly sum the rows into <em>g</em>, giving the result of the matrix multiplication <em>f</em> *<em>d</em>.</p>
<p>If, instead, we place the same equation <em>d</em>[<em>Dim3</em>]*<em>f </em>[<em>Dim2</em>, <em>Dim3</em>] into array <em>t</em>, we get these terms instead:</p>
<p class="code1" style="padding-left: 60px;"><em>d</em><sub>1</sub>*<em>f</em><sub>11</sub>   <em>d</em><sub>1</sub>*<em>f</em><sub>21</sub><br />
<em>d</em><sub>2</sub>*<em>f</em><sub>12</sub>   <em>d</em><sub>2</sub>*<em>f</em><sub>22</sub><br />
<em>d</em><sub>3</sub>*<em>f</em><sub>13</sub>   <em>d</em><sub>3</sub>*<em>f</em><sub>23</sub></p>
<p>The correct terms are still available, only now they are arranged vertically and the columns must be summed to arrive at the proper result:</p>
<p class="code1" style="padding-left: 60px;">ARRAYSUM(<em>t</em>[*, <em>Dim2</em>])</p>
<p>Multiplying by <em>g</em> instead, i.e., placing the equation <em>g</em>[<em>Dim2</em>]*<em>f </em>[<em>Dim2</em>, <em>Dim3</em>] into <em>s</em>, yields these terms:</p>
<p class="code1" style="padding-left: 60px;"><em>g</em><sub>1</sub>*<em>f</em><sub>11</sub>   <em>g</em><sub>1</sub>*<em>f</em><sub>12</sub>   <em>g</em><sub>1</sub>*<em>f</em><sub>13</sub><br />
<em>g</em><sub>2</sub>*<em>f</em><sub>21</sub>   <em>g</em><sub>2</sub>*<em>f</em><sub>22</sub>   <em>g</em><sub>2</sub>*<em>f</em><sub>23</sub></p>
<p>These are the terms for <em>g</em><sup>T</sup><em>f</em> , arranged vertically. Placing the equation into <em>t</em> gives the same terms horizontally. To calculate <em>f</em> <sup>T</sup><em>g</em>, it is necessary to first transpose <em>f</em> by setting <em>t</em> to the equation</p>
<p class="code1" style="padding-left: 60px;"><em>f</em> [<em>Dim2</em>, <em>Dim3</em>]</p>
<p>When this is multiplied by <em>g</em>, the correct terms for <em>f</em> <sup>T</sup><em>g</em> will be generated (horizontally in a 3&#215;2 array and vertically in a 2&#215;3 array).<strong> </strong></p>
<p><a class="anchor_header" name="6"><strong>Multiplying Two Matrices</strong></a></p>
<p>Unfortunately, there is no way to easily generate the terms for multiplying two matrices. The equations must be individually tailored for each case. As an example, let’s look at multiplying <em>t</em>*<em>s</em> and storing the result in <em>a</em>. Array <em>t</em> is 3&#215;2 and array <em>s</em> is 2&#215;3, so the result will fit in <em>a</em> (3&#215;3). The correct answer is:</p>
<p class="code1" style="padding-left: 60px;"><em>t</em><sub>11</sub>*<em>s</em><sub>11</sub> + <em>t</em><sub>12</sub>*<em>s</em><sub>21</sub>    <em>t</em><sub>11</sub>*<em>s</em><sub>12</sub> + <em>t</em><sub>12</sub>*<em>s</em><sub>22</sub>    <em>t</em><sub>11</sub>*<em>s</em><sub>13</sub> + <em>t</em><sub>12</sub>*<em>s</em><sub>23</sub><br />
<em>t</em><sub>21</sub>*<em>s</em><sub>11</sub> + <em>t</em><sub>22</sub>*<em>s</em><sub>21</sub>    <em>t</em><sub>21</sub>*<em>s</em><sub>12</sub> + <em>t</em><sub>22</sub>*<em>s</em><sub>22</sub>    <em>t</em><sub>21</sub>*<em>s</em><sub>13</sub> + <em>t</em><sub>22</sub>*<em>s</em><sub>23</sub><br />
<em>t</em><sub>31</sub>*<em>s</em><sub>11</sub> + <em>t</em><sub>32</sub>*<em>s</em><sub>21</sub>    <em>t</em><sub>31</sub>*<em>s</em><sub>12</sub> + <em>t</em><sub>32</sub>*<em>s</em><sub>22</sub>    <em>t</em><sub>31</sub>*<em>s</em><sub>13</sub> + <em>t</em><sub>32</sub>*<em>s</em><sub>23</sub></p>
<p>Examining these values for a pattern that could be used in an apply-to-all equation, we can see the proper equation for array <em>a</em> is</p>
<p class="code1" style="padding-left: 60px;"><em>t</em>[<em>Dim3</em>, 1]*<em>s</em>[1, <em>Dim3</em>] + <em>t</em>[<em>Dim3</em>, 2]*<em>s</em>[2, <em>Dim3</em>]</p>
<p>This pattern, incidentally, will hold in general for any two matrices. However, this equation does not work as an apply-to-all equation because the same name is used for both the first and second dimensions so it is not possible to tell which of the two varying <em>Dim3</em> values to use. In this case, <em>iThink</em> and STELLA currently always substitutes the value of the first dimension, which will not give the correct answer. This will always be a problem when the resulting array is square. One workaround is to define an additional dimension name that is the same size as <em>Dim3</em>. This works, but may lead to other array incompatibilities. The other solution is similar to how we transposed a square matrix – explicitly use ARRAYVALUE for any references to the second dimension:</p>
<p class="code1" style="padding-left: 60px;"><em>t</em>[<em>Dim3</em>, 1]*ARRAYVALUE(<em>s</em>[*, *], 1, ARRAYIDX(2))<br />
+ <em>t</em>[<em>Dim3</em>, 2]*ARRAYVALUE(<em>s</em>[*, *], 2, ARRAYIDX(2))</p>
<p>This is certainly not as clear, but it works and is only necessary when the result is square. One last example underscores this point and also shows how to expand the general pattern to a larger array. For this example, one more dimension name, <em>Dim4</em>, of size 4 and two more arrays are needed:</p>
<p class="code1" style="padding-left: 60px;"><em>u</em>: 3&#215;4<br />
<em>v</em>: 2&#215;4</p>
<p>To calculate the result of <em>s</em>*<em>u</em> in array <em>v</em>, where <em>s</em> is 2&#215;3, <em>u</em> is 3&#215;4, and <em>v</em> is (correctly) 2&#215;4, set the equation for <em>v</em> to:</p>
<p class="code1" style="padding-left: 60px;"><em>s</em>[<em>Dim2</em>, 1]*<em>u</em>[1, <em>Dim4</em>] + <em>s</em>[<em>Dim2</em>, 2]*<em>u</em>[2, <em>Dim4</em>] + <em>s</em>[<em>Dim2</em>, 3]*<em>u</em>[3, <em>Dim4</em>]</p>
<p>Note this same method can be used for multiplying a 2-dimensional array by a 1-dimensional array instead of the method presented above. It avoids both the intermediate transposition and product arrays, but results in more complex expressions that must be tailored to each combination of array sizes.</p></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/matrix-arithmetic/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Module FAQs</title>
		<link>http://blog.iseesystems.com/modeling-tips/module-faqs/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/module-faqs/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 14:17:18 +0000</pubDate>
		<dc:creator>Jeremy Merritt</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[Decision Process Diamonds]]></category>
		<category><![CDATA[iThink/STELLA]]></category>
		<category><![CDATA[modules]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=1851</guid>
		<description><![CDATA[The version 9.1 release of iThink &#38; STELLA introduced a new approach to modeling complex systems: hierarchical modules.  Modeling with modules can really simplify the way you think about, construct and communicate systems.
Since a lot of customers are now getting their feet wet with modules, we’ve been receiving a steady stream of questions.  We asked [...]]]></description>
			<content:encoded><![CDATA[<p>The version 9.1 release of <em>iThink</em> &amp; STELLA introduced a new approach to modeling complex systems: hierarchical modules.  Modeling with modules can really simplify the way you think about, construct and communicate systems.</p>
<p>Since a lot of customers are now getting their feet wet with modules, we’ve been receiving a steady stream of questions.  We asked our Director of Product Development <span><a title="Read other posts by Karim" href="../author/kchichakly/">Karim Chichakly</a> to compile a list of frequently asked questions that he thought would be useful for anyone using modules.  The questions and answers are listed below. </span>If you have any additional questions, post them in the comments and we’ll respond.</p>
<p><strong> What is a module?</strong></p>
<p><img style="border: 0pt none; display: inline; margin-left: 0px; margin-right: 0px;" title="The module icon" src="http://blog.iseesystems.com/wp-content/uploads/2009/07/CropperCapture12.png" border="0" alt="CropperCapture[12]" width="171" height="72" align="right" /> A module is a container for lower-level model structure.  It is designed to support a process of top-down model design and development.</p>
<p><strong>What is a module input?</strong></p>
<p><img style="border: 0pt none; display: inline; margin-left: 0px; margin-right: 0px;" title="A converter that is configured to accept input" src="http://blog.iseesystems.com/wp-content/uploads/2009/07/CropperCapture18.png" border="0" alt="CropperCapture[18]" width="175" height="101" align="right" />A module input is a variable that can become the ghost of another variable at a different level of the module hierarchy.   It becomes the ghost when you assign it to that other variable.  After it is assigned, it is referred to both as a cross-level ghost and an assigned module input.  All of this is managed transparently if you use the ghost tool.</p>
<p><strong>What is a module output?</strong></p>
<p><img style="border: 0pt none; display: inline; margin-left: 0px; margin-right: 0px;" title="The stock is designated as a module output" src="http://blog.iseesystems.com/wp-content/uploads/2009/07/CropperCapture19.png" border="0" alt="CropperCapture[19]" width="175" height="68" align="right" /> When a variable is designated as a module output, you are telling the software that this variable can be ghosted on a different level of the module hierarchy.  While any variable can be a module output, it is important to carefully manage which variables you intend to be shared across modules.</p>
<p><strong>How are modules different from Decision Process Diamonds (DPDs)?</strong></p>
<p><a href="http://www.iseesystems.com/Helpv9/Content/Building_Blocks/The_DPD.htm" target="_blank">DPDs</a> were designed to collapse one level of structure and hide non-essential details while modules were designed for top-down development of complex models.  Their goals are very different and so is their behavior.  While it is true that modules can be used to replace DPDs, the reverse is not true.</p>
<p><br class="spacer_" /></p>
<p><span id="more-1851"></span></p>
<p><strong>Why can&#8217;t I directly connect modules to variables as I can with DPDs?</strong></p>
<p><strong><a href="http://blog.iseesystems.com/wp-content/uploads/2009/06/CropperCapture17.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="DPD with nub" src="http://blog.iseesystems.com/wp-content/uploads/2009/06/CropperCapture17_thumb.png" border="0" alt="DPD with nub" width="254" height="252" align="right" /></a></strong>Although it may appear that they are, DPDs are never directly connected to anything.  When a DPD is connected to a variable, a &#8220;nub&#8221; (which is just a placeholder) is placed inside the DPD.  In order to get the model to work, you must open the DPD and connect that nub to a variable in the DPD.  When you do this, you have connected a variable that is hidden inside the DPD directly to a variable outside the DPD &#8211; and this connection is visible while the DPD is extant.</p>
<p>We chose a different metaphor for modules because modules do not appear side-by-side with the model they are in.  Thus, you cannot see the connections.  Although we could have created nubs like in the DPD, we would have had to give the nubs names which then persisted on connections going out to the diagram frame after the variable was connected.  Again, it is important to remember that DPDs are not connected to variables any more than modules are &#8211; variables are connected one-to-one with other variables.</p>
<p><strong>What is the metaphor for modules?</strong></p>
<p>For modules, we decided the proper metaphor was that of ghosts, which are already used to refer to a variable elsewhere in a model.  In fact, the most natural (and easiest) method to connect variables in different modules is with the ghost tool.</p>
<p>As a result, all variables used from another module are clearly visible within the module that uses them.  The use of those variables inside the module is also clearly visible.</p>
<p>A direct consequence of this metaphor is that no connections can be made across levels without first going through a cross-level ghost (also known as a module input).  This is different from the requirements of a DPD, which allowed you to see the variable inside the DPD at the same time as the variable outside the DPD.</p>
<p><strong>How are modules different from submodels?</strong></p>
<p>Like DPDs, submodels collapse one level of structure.  They were specifically designed to hide low-level details of processes from the top-level of the model.  A submodel is a proxy for a stock and, in this way, varies dramatically from a module which presently has no value at all.  Also, a submodel allows several outflows from a process to be rolled up (summed) into one outflow of the submodel, which modules do not allow (there are not flows into or out of modules).  However, modules do allow a main chain to cross their boundaries in much the same way a submodel does.</p>
<p><strong>How are modules different from sectors?</strong></p>
<p>Sectors and modules represent the same basic concept:  A fundamental unit of the model at a high-level with detail inside.  The difference is the sector does not hide that detail within it and cannot be nested.  The module hides the detail within it and can be nested as many levels as desired.  Sectors can still be useful for breaking up small models.</p>
<p><strong>Will all four methods of organizing model structure continue to exist in the future?</strong></p>
<p>While there remain clear and separate uses for sectors and modules, the functionality of the DPD almost completely overlaps that of the module.  The submodel, which is used infrequently nowadays, also mostly overlaps with the module.  At some point in the future, both the DPD and the submodel will be removed from the software.</p>
<p><strong>Why can&#8217;t I connect a module to a module output?</strong></p>
<p>Whatever variable a module gets connected to must be able to become a cross-level ghost.  This means it cannot have any connections into it and it cannot be a module output, as no variable can be both a module input and a module output.  To use a variable in a module, you must first ghost it in the current module.</p>
<p><strong>Why can&#8217;t a variable be both a module input and module output?</strong></p>
<p>Because a module input is the ghost of another variable.  A ghost just represents the variable &#8211; it is not the variable itself.  Connections should be made from the original variable whenever possible.  When this is not possible, an intermediate variable set identically equal to the original variable can be used.</p>
<p><strong>Why does the software complain that I cannot connect a module to a module output when I didn&#8217;t create a module output (and there is no indication on the variable concerned)?</strong></p>
<p>There are two types of module outputs:  explicit and implicit.  An explicit module output is created by right-clicking on the variable and choosing Module-&gt;Provide Output from the context menu.  After doing this, there will be a second border drawn inside the variable (that looks like a large O in converters and flows) and that variable will be accessible in the module directly above this one and in all modules (and their submodules) connected to this one.  Note the ghost tool also creates explicit module outputs.</p>
<p>An implicit module output is created any time a variable is connected to a module.  This variable is treated as a parameter to that module and that module alone, so can only be accessed inside that module.  The only visual indication that this is a module output is the connecter running from the variable to the module.  There is no mark on the variable and the context menu will not claim it is a module output.  This is because the context menu is for setting explicit module outputs which behave slightly differently.</p>
<p><strong>Can the file hierarchy for modules match the model hierarchy?</strong></p>
<p>At present, all modules must exist at the same level in the Modules folder.  This does mean that all filenames must be unique.</p>
<p><strong>Can the modules be saved in one file with the top-level model?</strong></p>
<p>At present, all modules must exist as separate files in the Modules folder.</p>
<p><strong>Can I control import and export independently at each level of the module hierarchy?</strong></p>
<p>At present, import and export sheets can be associated only with the top-level model and should be in the Data folder.  Multiple sheets are allowed, so they can be organized by module.  To import a module variable, make sure to precede the name in the import sheet with the name of the module and a period.  For example, to import variable &#8220;x&#8221; in module &#8220;mod&#8221;, the name in the import sheet must be &#8220;mod.x&#8221;.</p>
<p><strong>Can I put my import and export sheets in the same directory as my modules?</strong></p>
<p>Import and export sheets must appear either within the same directory as the model or in the Data folder, which is itself in the same directory as the model.</p>
<p><strong> </strong></p>
<p><strong>If two modules have the same logic, can I share the same module file?</strong></p>
<p>Yes.  However, you will be unable to edit the module while it is assigned to more than one module.  This is indicated by a disabled toolbar and a lock in the upper-left hand corner of the screen.  To edit the module, temporarily disconnect it from all modules but one, edit it, and then reconnect it.  Alternatively, you can open the ITT file directly, edit it, and then re-import it into your model.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/module-faqs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tips, Tricks and Shortcuts for using iThink and STELLA</title>
		<link>http://blog.iseesystems.com/modeling-tips/tips-tricks-shortcuts/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/tips-tricks-shortcuts/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 20:55:33 +0000</pubDate>
		<dc:creator>Sarah Davie</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[paintbrush]]></category>
		<category><![CDATA[shortcuts]]></category>
		<category><![CDATA[toolbar]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=1571</guid>
		<description><![CDATA[I recently saw an iThink/STELLA power user change the direction of a Flow with a simple keystroke. And I thought the only way to change a Flow direction was to delete and redraw it! This prompted me to search for other tricks about using the software that I might not be aware of. As it turns [...]]]></description>
			<content:encoded><![CDATA[<p>I recently saw an <em>iThink</em>/STELLA power user change the direction of a Flow with a simple keystroke. And I thought the only way to change a Flow direction was to delete and redraw it! This prompted me to search for other tricks about using the software that I might not be aware of. As it turns out there are quite a few! I took a stab at creating a list.</p>
<p>The list ranges from Paintbrush tips to keyboard shortcuts. If there are other tricks that you know about, please post a comment and share them with the rest of us!</p>
<div id="attachment_1653" class="wp-caption alignright" style="width: 298px"><img class="size-full wp-image-1653" title="On bended flow" src="http://blog.iseesystems.com/wp-content/uploads/2009/06/croppercapture99.png" alt="On bended flow" width="288" height="144" /><p class="wp-caption-text">Bending a flow</p></div>
<p><strong>Flows</strong></p>
<p><em>•  Bend a Flow </em>— Drop a Flow and start dragging it. When you want it to change direction at a 90 degree angle, hold the shift key while you move the cursor in the direction you want the Flow to go.</p>
<p><em>• Change the Flow direction</em> — Hold the Control key and click on the head of the arrow.</p>
<p><em>• Disconnect a Flow</em> — Click and hold on the end of the Flow (either the arrow end or the tail end) to drag it from a Stock.</p>
<p><span id="more-1571"></span></p>
<p><strong>Paintbrush</strong></p>
<div id="attachment_1647" class="wp-caption alignright" style="width: 214px"><a href="http://blog.iseesystems.com/wp-content/uploads/2009/06/floating-palette1.png"><img class="size-full wp-image-1647" title="floating-palette1" src="http://blog.iseesystems.com/wp-content/uploads/2009/06/floating-palette1.png" alt="floating-palette1" width="204" height="198" /></a><p class="wp-caption-text">Floating Paintbrush palette</p></div>
<p><em>• Move Color Palette</em> — Click on the Paintbrush tool and hold while moving cursor until it moves the whole palette. Drag it anywhere on the window.</p>
<p><em>• Eyedropper Tool</em> — If you want to duplicate the color of an object but you are not sure which shade you used, you can use the Eyedropper to &#8220;extract&#8221; the color and reuse it. To identify the color of an entity, select the Paintbrush; do a Control-shift (Windows) or Command-shift (Mac) , and the Eyedropper will appear. Click on the entity and the Paintbrush will take on the color of that entity. Now you can color your model as before.</p>
<p><strong>Toolbar</strong></p>
<div id="attachment_1644" class="wp-caption alignleft" style="width: 251px"><img class="size-full wp-image-1644" title="stock-drop-down4" src="http://blog.iseesystems.com/wp-content/uploads/2009/06/stock-drop-down4.png" alt="Tool Menu" width="241" height="185" /><p class="wp-caption-text">Tool Menu</p></div>
<p><em>• Tool drop down list</em> — Click on a tool and hold to get drop down menu of related choices.</p>
<p><em>• Activating the last tool </em>— If you have just added an object to your model such as a Stock, and you want to add another, press and hold the Alt key(Windows) or Option key (Macintosh) and click on the model layer to drop additional Stocks. You can use the Alt key to go to back to the last tool you used.</p>
<p><em>• Sticky tool</em> — Double-click on an object in the toolbar to make it &#8220;sticky&#8221;.  In this mode the software will not switch back to the arrow after you have dropped the object on the page.  You can keep adding more of the same objects until you hit the Esc key or click on another tool.</p>
<p><em>• Change default color of a tool </em>— Select a color from the Paintbrush palette, then hold the Alt key (Windows) or Option key (Macintosh) and click on the item in the toolbar.</p>
<p><strong>Graphs &amp; Tables</strong></p>
<div id="attachment_1590" class="wp-caption alignright" style="width: 335px"><a href="http://blog.iseesystems.com/wp-content/uploads/2009/06/grach-variable-precision.png"><img class="size-full wp-image-1590" title="variable precision" src="http://blog.iseesystems.com/wp-content/uploads/2009/06/grach-variable-precision.png" alt="variable precision" width="325" height="188" /></a><p class="wp-caption-text">Variable precision</p></div>
<p><em>• Change precision for a graphed variable</em> — Right-click, (Control-click on Macintosh) on the name of the variable in the graph or table.  Select Precision from the menu and choose from the available options.</p>
<p><em>• Delete pages</em> — Click on the Dynamite tool in the toolbar and drag it to the dog ear on the lower left corner of the graph or table. Click again to delete the current page.</p>
<p><em>• Clear data </em>— Click on the Dynamite icon on the graph or table itself to clear the data.</p>
<p><em>• Color variables </em>— Click on the Paintbrush and select a color. Click on the variable name in the graph or table to change the color.</p>
<p><strong>Keyboard Shortcuts</strong></p>
<p>Here is a table of menu shortcuts. It is organized by software layer. I also added some navigation and miscellaneous shortcuts.</p>
<p><a href="http://blog.iseesystems.com/wp-content/uploads/2009/06/table-of-keyboard-shortcuts3.pdf">Table of keyboard shortcuts (PDF file)</a> <img class="alignnone" title="PDF" src="http://www.iseesystems.com/images/icons/pdf.gif" alt="" width="12" height="11" /></p>
<p><strong>Miscellaneous</strong></p>
<p><em> </em></p>
<div id="attachment_1662" class="wp-caption alignright" style="width: 328px"><a href="http://blog.iseesystems.com/wp-content/uploads/2009/06/key-pad31.png"><img class="size-full wp-image-1662" title="key pad" src="http://blog.iseesystems.com/wp-content/uploads/2009/06/key-pad31.png" alt="Key pad w/ ALT or Option key pressed" width="318" height="142" /></a><p class="wp-caption-text">Calculator w/ Alt or Option key pressed</p></div>
<p><em>• Changing input keys on the Calculator</em> — To change the available input keys on the Calculator, press the Alt key (Windows) or Option key (Mac).</p>
<p><em>• Navigating out of a Module while building a story</em> — If the story you are building takes you into a Module, you can back out of the Module by holding the Control key (Windows) or Option key (Macintosh) and double-clicking on a blank part of the model layer.</p>
<p><em>• Quitting out of a Runtime model</em> — To exit out of Runtime model, click on Control key and Q (Windows) or Option key and Q (Macintosh).</p>
<p>So let us know if you have more tips, tricks or shortcuts to share by adding a comment to this post!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/tips-tricks-shortcuts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Storytelling Simulations</title>
		<link>http://blog.iseesystems.com/modeling-tips/storytelling-simulations/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/storytelling-simulations/#comments</comments>
		<pubDate>Thu, 21 May 2009 21:39:56 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[iThink/STELLA]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[storytelling]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=1441</guid>
		<description><![CDATA[Storytelling is a powerful feature that provides precise control over the presentation of a model to your audience.  It also allows kiosk-style presentations to be created that step through the model, explaining it piece-by-piece.  Many people use it only for this purpose, but storytelling offers so much more.
Because a basic premise of System [...]]]></description>
			<content:encoded><![CDATA[<p>Storytelling is a powerful feature that provides precise control over the presentation of a model to your audience.  It also allows kiosk-style presentations to be created that step through the model, explaining it piece-by-piece.  Many people use it only for this purpose, but storytelling offers so much more.</p>
<p>Because a basic premise of System Dynamics is that structure and behavior are linked, one of the key ideas behind storytelling is to allow the behavioral story to grow as the structural story unfurls.  To create this effect, we neutralize structure that is not showing.  This is extremely powerful because it allows you, for example, to selectively show the behavior of different loops within the system.</p>
<p>A simple example will solidify this concept.  Consider the following simple population model:</p>
<p style="text-align: center;" align="center"><img class="aligncenter size-full wp-image-1442" title="population-model" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/population-model.png" alt="population-model" width="347" height="125" /></p>
<p>The death rate multiplier is a simple resource constraint on the growth of population.  More complex constraints would also affect the birth rate.</p>
<p><span id="more-1441"></span></p>
<p>This model can be sequenced into a very meaningful structure/behavior story.  The storyboard with the corresponding graph of Population for each story panel is:</p>
<table style="width: 596px;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td align="right">
<p><img style="margin-bottom:10px;margin-top:10px;" title="population1" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/population1.png" alt="population1" width="458" height="125" /><br />
 <img style="margin-bottom:10px;" title="population2" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/population2.png" alt="population2" width="547" height="125" /></p>
<p><img style="margin-bottom:10px;" title="population3" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/population3.png" alt="population3" width="543" height="125" /></p>
<p><img style="margin-bottom:10px;" title="population4" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/population4.png" alt="population4" width="573" height="119" /></p>
<p><img style="margin-bottom:10px;margin-top:10px;" title="population5" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/population5.png" alt="population5" width="571" height="125" /></p>
</td>
</tr>
</tbody>
</table>
<p style="text-align: center;"><em>death rate multiplier</em> = <em>Population</em>/INIT(<em>Population</em>)</p>
<p>Note how the behavior of the model changes as more of the structure becomes extant, and especially as more loops are closed.  This is something that cannot be done with, for example, Run by Modules or Run by Sectors.</p>
<p><!--more--><br class="spacer_" /></p>
<p><strong>How Run by Modules/Sectors Operates</strong></p>
<p>These latter two run options work identically.  When you run a set of modules (or sectors), inputs from modules that are not running are held at their initial values.  Flows across the boundary act as if there is a cloud at whichever end is not in the running module.  If sectors are placed around the different pieces of structure in this story and Run by Sectors is used, the behavior is identical (the second to last graph) for all steps but the last.</p>
<p><br class="spacer_" /></p>
<p><strong>How Running Under Storytelling Operates</strong></p>
<p>In storytelling, entities that are not visible are essentially removed from the model.  The program neutralizes them by setting them to either zero or one based on how they are used in each visible entity&#8217;s equation.  If there is a either a &#8220;+&#8221; or a &#8220;-&#8221; in the visible entity&#8217;s equation, the invisible entity will evaluate to zero in that equation.  Otherwise, it will evaluate to one in that equation.  You can override this default behavior for each entity in the storytelling dialog.  In addition, flows that have none of their inputs shown can also be set to default values by hovering over them and typing in a value.  This is how <em>births</em> and <em>deaths</em> were set in the first two panels of the story.</p>
<p>Let&#8217;s look at a few simple examples to get the feel of it.  Let <strong><em>a</em> = 5</strong>, <strong><em>b</em> = 7</strong>, and <strong><em>c</em> = 2</strong>.</p>
<p>The story panels below show the values of <em>x</em> under these scenarios of visible and invisible entities.</p>
<p><br class="spacer_" /></p>
<p><strong><em>x</em></strong><strong> = <em>a</em> + <em>b</em>:</strong></p>
<p><em>The equation is additive, therefore entities not shown are set equal to 0</em></p>
<table class="SSTable" border="0">
<tbody>
<tr>
<td class="SSTD" style="width: 70px;"><em>Visible Entities</em></td>
<td class="SSTD" style="width: 144px;"><img title="a-and-b1" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b1.png" alt="a-and-b1" width="144" height="39" /></td>
<td class="SSTD" style="width: 112px;"><img title="a-and-b2" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b2.png" alt="a-and-b2" width="112" height="37" /></td>
<td class="SSTD" style="width: 114px;"><img title="a-and-b3" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b3.png" alt="a-and-b3" width="114" height="37" /></td>
<td class="SSTD" style="width: 138px;"><img title="a-and-b4" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b4.png" alt="a-and-b4" width="138" height="37" /></td>
</tr>
<tr>
<td class="SSTD" style="width: 70px;"><em>Values</em></td>
<td class="SSTD" style="width: 144px;"><em>a</em> = 0, <em>b</em> = 0</td>
<td class="SSTD" style="width: 112px;"><em>a</em> = 5, <em>b</em> = 0</td>
<td class="SSTD" style="width: 114px;"><em>a</em> = 0, <em>b</em> = 7</td>
<td class="SSTD" style="width: 138px;"><em>a</em> = 5, <em>b</em> = 7</td>
</tr>
<tr>
<td class="SSTD" style="width: 70px;"><em>x</em></td>
<td class="SSTD" style="width: 144px;">0 + 0 = 0</td>
<td class="SSTD" style="width: 112px;">5 + 0 = 5</td>
<td class="SSTD" style="width: 114px;">0 + 7 = 7</td>
<td class="SSTD" style="width: 138px;">5 + 7 = 12</td>
</tr>
</tbody>
</table>
<p><br class="spacer_" /></p>
<p><strong><em>x</em></strong><strong> = <em>a</em>*<em>b</em>:</strong></p>
<p><em>The equation is multiplicative, therefore entities not shown are set equal to 1</em></p>
<table class="SSTable" border="0">
<tbody>
<tr>
<td class="SSTD" style="width: 70px;"><em>Visible Entities</em></td>
<td class="SSTD" style="width: 144px;"><img class="aligncenter size-full wp-image-1463" title="a-times-b1" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-times-b1.png" alt="a-times-b1" width="144" height="36" /></td>
<td class="SSTD" style="width: 112px;"><img class="aligncenter size-full wp-image-1458" title="a-times-b2" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-times-b2.png" alt="a-times-b2" width="112" height="37" /></td>
<td class="SSTD" style="width: 114px;"><img class="aligncenter size-full wp-image-1459" title="a-times-b3" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-times-b3.png" alt="a-times-b3" width="114" height="37" /></td>
<td class="SSTD" style="width: 138px;"><img class="aligncenter size-full wp-image-1464" title="a-times-b4" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-times-b4.png" alt="a-times-b4" width="138" height="36" /></td>
</tr>
<tr>
<td class="SSTD" style="width: 70px;"><em>Values</em></td>
<td class="SSTD" style="width: 144px;"><em>a</em> = 1, <em>b</em> =   1</td>
<td class="SSTD" style="width: 112px;"><em>a</em> = 5, <em>b</em> =   1</td>
<td class="SSTD" style="width: 114px;"><em>a</em> = 1, <em>b</em> =   7</td>
<td class="SSTD" style="width: 138px;"><em>a</em> = 5, <em>b</em> =   7</td>
</tr>
<tr>
<td class="SSTD" style="width: 70px;"><em>x</em></td>
<td class="SSTD" style="width: 144px;">1*1 = 1</td>
<td class="SSTD" style="width: 112px;">5*1 = 5</td>
<td class="SSTD" style="width: 114px;">1*7 = 7</td>
<td class="SSTD" style="width: 138px;">5*7 = 35</td>
</tr>
</tbody>
</table>
<p><br class="spacer_" /></p>
<p><strong><em>x</em></strong><strong> = (<em>a</em> + <em>b</em>)*<em>c</em>:</strong></p>
<p><em>The equation is treated as additive because it has a + symbol, therefore entities not shown are set equal to 0</em></p>
<table class="SSTable" border="0">
<tbody>
<tr>
<td class="SSTD" style="width: 70px;"><em>Visible Entities</em></td>
<td class="SSTD" style="width: 144px;"><img class="aligncenter size-full wp-image-1465" title="a-and-b-times-c1" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c1.png" alt="a-and-b-times-c1" width="144" height="39" /></td>
<td class="SSTD" style="width: 112px;"><img class="aligncenter size-full wp-image-1473" title="a-and-b-times-c2" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c2.png" alt="a-and-b-times-c2" width="112" height="36" /></td>
<td class="SSTD" style="width: 114px;"><img class="aligncenter size-full wp-image-1469" title="a-and-b-times-c3" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c3.png" alt="a-and-b-times-c3" width="114" height="36" /></td>
<td class="SSTD" style="width: 138px;"><img class="aligncenter size-full wp-image-1474" title="a-and-b-times-c4" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c4.png" alt="a-and-b-times-c4" width="138" height="83" /></td>
</tr>
<tr>
<td class="SSTD" style="width: 70px;"><em>Values</em></td>
<td class="SSTD" style="width: 144px;"><em>a</em> = 0, <em>b</em> = 0,   <em>c</em> = 0</td>
<td class="SSTD" style="width: 112px;"><em>a</em> = 5, <em>b</em> = 0,   <em>c</em> = 0</td>
<td class="SSTD" style="width: 114px;"><em>a</em> = 0, <em>b</em> =   7, <em>c</em> = 0</td>
<td class="SSTD" style="width: 138px;"><em>a</em> = 0, <em>b</em> = 0,   <em>c</em> = 2</td>
</tr>
<tr>
<td class="SSTD" style="width: 70px;"><em>x</em></td>
<td class="SSTD" style="width: 144px;"><span style="font-size: x-small;">(0 + 0)*0 = 0 </span></td>
<td class="SSTD" style="width: 112px;"><span style="font-size: x-small;">(5 + 0)*0 = 0 </span></td>
<td class="SSTD" style="width: 114px;"><span style="font-size: x-small;">(0 + 7)*0 = 0 </span></td>
<td class="SSTD" style="width: 138px;"><span style="font-size: x-small;">(0 + 0)*2 = 0 </span></td>
</tr>
</tbody>
</table>
<table class="SSTable" border="0">
<tbody>
<tr>
<td class="SSTD" style="width: 70px;"><em>Visible Entities</em></td>
<td class="SSTD" style="width: 144px;"><img title="a-and-b-times-c5" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c5.png" alt="a-and-b-times-c5" width="144" height="36" /></td>
<td class="SSTD" style="width: 112px;"><img title="a-and-b-times-c6" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c6.png" alt="a-and-b-times-c6" width="112" height="85" /></td>
<td class="SSTD" style="width: 114px;"><img title="a-and-b-times-c7" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c7.png" alt="a-and-b-times-c7" width="114" height="86" /></td>
<td class="SSTD" style="width: 138px;"><img title="a-and-b-times-c8" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c8.png" alt="a-and-b-times-c8" width="138" height="85" /></td>
</tr>
<tr>
<td class="SSTD" style="width: 70px;"><em>Values</em></td>
<td class="SSTD" style="width: 144px;"><em>a</em> = 5, <em>b</em> =   7, <em>c</em> = 0</td>
<td class="SSTD" style="width: 112px;"><em>a</em> = 5, <em>b</em> = 0,   <em>c</em> = 2</td>
<td class="SSTD" style="width: 114px;"><em>a</em> = 0, <em>b</em> =   7, <em>c</em> = 2</td>
<td class="SSTD" style="width: 138px;"><em>a</em> = 5, <em>b</em> =   7, <em>c</em> = 2</td>
</tr>
<tr>
<td class="SSTD" style="width: 70px;"><em>x</em></td>
<td class="SSTD" style="width: 144px;">(5 + 7)*0 = 0</td>
<td class="SSTD" style="width: 112px;">(5 + 0)*2 = 10</td>
<td class="SSTD" style="width: 114px;">(0 + 7)*2 = 14</td>
<td class="SSTD" style="width: 138px;">(5 + 7)*2 = 24</td>
</tr>
</tbody>
</table>
<p>The value of the invisible variables is zero in the first and last cases, and one in the middle case.  The last case is treated as additive by default because there is a plus sign.  This may or may not give the result desired.</p>
<p>It is possible to override the default behavior in the storytelling dialog (by selecting the entity and using the &#8220;+ -&gt; *&#8221; button at the bottom), though this may not be desired depending on the application.  However, to ensure the desired result by default, separate such expressions into their additive and multiplicative components.  In this case, add a converter <em>d</em> = <em>a</em> + <em>b</em> and make <em>x</em> = <em>d</em>*<em>c</em>.  In this way, <em>x</em> will only be zero when both <em>a</em> and <em>b</em> are invisible.</p>
<p>The following story panels show the values of <em>x</em> under these scenarios of visible and invisible entities.</p>
<p><br class="spacer_" /></p>
<p><strong><em>x</em></strong><strong> = (<em>a</em> + <em>b</em>)*<em>c</em> overridden to be multiplicative:<br />
 </strong></p>
<p><em>The default additive behavior is overridden to be multiplicative in this case and therefore the entities not shown are set equal to 1</em></p>
<table class="SSTable" border="0">
<tbody>
<tr>
<td class="SSTD" style="width: 70px;"><em>Visible Entities</em></td>
<td class="SSTD" style="width: 144px;"><img class="aligncenter size-full wp-image-1466" title="a-and-b-times-c-over1" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c-over1.png" alt="a-and-b-times-c-over1" width="144" height="36" /></td>
<td class="SSTD" style="width: 114px;"><img class="aligncenter size-full wp-image-1481" title="a-and-b-times-c-over2" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c-over2.png" alt="a-and-b-times-c-over2" width="114" height="36" /></td>
<td class="SSTD" style="width: 114px;"><img class="aligncenter size-full wp-image-1483" title="a-and-b-times-c-over3" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c-over3.png" alt="a-and-b-times-c-over3" width="114" height="36" /></td>
<td class="SSTD" style="width: 144px;"><img class="aligncenter size-full wp-image-1484" title="a-and-b-times-c-over4" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c-over4.png" alt="a-and-b-times-c-over4" width="144" height="85" /></td>
</tr>
<tr>
<td class="SSTD" style="width: 70px;"><em>Values</em></td>
<td class="SSTD" style="width: 144px;"><em>a</em> = 1, <em>b</em> =   1, <em>c</em> = 1</td>
<td class="SSTD" style="width: 114px;"><em>a</em> = 5, <em>b</em> =   1, <em>c</em> = 1</td>
<td class="SSTD" style="width: 114px;"><em>a</em> = 1, <em>b</em> =   7, <em>c</em> = 1</td>
<td class="SSTD" style="width: 144px;"><em>a</em> = 1, <em>b</em> =   1, <em>c</em> = 2</td>
</tr>
<tr>
<td class="SSTD" style="width: 70px;"><em>x</em></td>
<td class="SSTD" style="width: 144px;">(1 + 1)*1 = 1</td>
<td class="SSTD" style="width: 114px;">(5 + 1)*1 = 6</td>
<td class="SSTD" style="width: 114px;">(1 + 7)*1 = 8</td>
<td class="SSTD" style="width: 144px;">(1 + 1)*2 = 4</td>
</tr>
</tbody>
</table>
<table class="SSTable" border="0">
<tbody>
<tr>
<td class="SSTD" style="width: 70px;"><em>Visible Entities</em></td>
<td class="SSTD" style="width: 144px;"><img class="aligncenter size-full wp-image-1460" title="a-and-b-times-c-over5" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c-over5.png" alt="a-and-b-times-c-over5" width="144" height="37" /></td>
<td class="SSTD" style="width: 114px;"><img class="aligncenter size-full wp-image-1485" title="a-and-b-times-c-over6" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c-over6.png" alt="a-and-b-times-c-over6" width="114" height="84" /></td>
<td class="SSTD" style="width: 114px;"><img class="aligncenter size-full wp-image-1486" title="a-and-b-times-c-over7" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c-over7.png" alt="a-and-b-times-c-over7" width="114" height="85" /></td>
<td class="SSTD" style="width: 144px;"><img class="aligncenter size-full wp-image-1480" title="a-and-b-times-c-over8" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/a-and-b-times-c-over8.png" alt="a-and-b-times-c-over8" width="144" height="85" /></td>
</tr>
<tr>
<td class="SSTD" style="width: 70px;"><em>Values</em></td>
<td class="SSTD" style="width: 144px;"><em>a</em> = 5, <em>b</em> =   7, <em>c</em> = 1</td>
<td class="SSTD" style="width: 114px;"><em>a</em> = 5, <em>b</em> =   1, <em>c</em> = 2</td>
<td class="SSTD" style="width: 114px;"><em>a</em> = 1, <em>b</em> =   7, <em>c</em> = 2</td>
<td class="SSTD" style="width: 144px;"><em>a</em> = 5, <em>b</em> =   7, <em>c</em> = 2</td>
</tr>
<tr>
<td class="SSTD" style="width: 70px;"><em>x</em></td>
<td class="SSTD" style="width: 144px;">(5 + 7)*1 = 12</td>
<td class="SSTD" style="width: 114px;">(5 + 1)*2 = 12</td>
<td class="SSTD" style="width: 114px;">(1 + 7)*2 = 16</td>
<td class="SSTD" style="width: 144px;">(5 + 7)*2 = 24</td>
</tr>
</tbody>
</table>
<p><br class="spacer_" /></p>
<p><strong><em>x</em></strong><strong> = <em>d</em>*<em>c</em>, where <em>d</em> = <em>a</em> + <em>b</em>:</strong></p>
<p><em>The equation behavior for <strong>x</strong> is multiplicative and for <strong>d</strong> it is additive.  Entities that are not shown and inputs to <strong>x</strong> will be set equal to <strong>1</strong>. Entities that are not shown and inputs to <strong>d</strong> will be set equal to <strong>0</strong>.</em></p>
<table class="SSTable" border="0">
<tbody>
<tr>
<td class="SSTD" style="width: 45px;"><em>Visible Entities</em></td>
<td class="SSTD" style="width: 70px;"><img class="aligncenter size-full wp-image-1467" title="d-times-c1" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/d-times-c1.png" alt="d-times-c1" width="70" height="36" /></td>
<td class="SSTD" style="width: 122px;"><img class="aligncenter size-full wp-image-1488" title="d-times-c2" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/d-times-c2.png" alt="d-times-c2" width="122" height="35" /></td>
<td class="SSTD" style="width: 114px;"><img class="aligncenter size-full wp-image-1489" title="d-times-c3" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/d-times-c3.png" alt="d-times-c3" width="114" height="86" /></td>
<td class="SSTD" style="width: 112px;"><img class="aligncenter size-full wp-image-1490" title="d-times-c4" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/d-times-c4.png" alt="d-times-c4" width="112" height="86" /></td>
<td class="SSTD" style="width: 130px;"><img class="aligncenter size-full wp-image-1491" title="d-times-c5" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/d-times-c5.png" alt="d-times-c5" width="130" height="81" /></td>
</tr>
<tr>
<td class="SSTD" style="width: 45px;"><em>Values</em></td>
<td class="SSTD" style="width: 70px;"><em>d</em> = 1, <em>c</em> =   1</td>
<td class="SSTD" style="width: 122px;"><em>d</em> = 1, <em>c</em> = 2</td>
<td class="SSTD" style="width: 114px;"><em>a</em> = 5, <em>b</em> =   0, <em>c</em> = 1</td>
<td class="SSTD" style="width: 112px;"><em>a</em> = 0, <em>b</em> =   7, <em>c</em> = 1</td>
<td class="SSTD" style="width: 130px;"><em>d</em> = 1, <em>c</em> = 2</td>
</tr>
<tr>
<td class="SSTD" style="width: 45px;"><em>x</em></td>
<td class="SSTD" style="width: 70px;">1*1 = 1</td>
<td class="SSTD" style="width: 122px;">1*2 = 2</td>
<td class="SSTD" style="width: 114px;">(5 + 0)*1 = 5</td>
<td class="SSTD" style="width: 112px;">(0 + 7)*1 = 7</td>
<td class="SSTD" style="width: 130px;">1*2 = 2</td>
</tr>
<tr>
<td class="SSTD" style="width: 45px;"><em>Note</em></td>
<td class="SSTD" style="width: 70px;"><em>a</em> and <em>b</em> are   not evaluated</td>
<td class="SSTD" style="width: 122px;"><em>a</em> and <em>b</em> are   not evaluated</td>
<td class="SSTD" style="width: 114px;"><em> </em></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
</td>
<td class="SSTD" style="width: 112px;"><em> </em></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
</td>
<td class="SSTD" style="width: 130px;"><em>a</em> and <em>b</em> are   not evaluated</td>
</tr>
</tbody>
</table>
<table class="SSTable" border="0">
<tbody>
<tr>
<td class="SSTD" style="width: 45px;"><em>Visible Entities</em></td>
<td class="SSTD" style="width: 70px;"><img class="aligncenter size-full wp-image-1492" title="d-times-c6" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/d-times-c6.png" alt="d-times-c6" width="70" height="86" /></td>
<td class="SSTD" style="width: 122px;"><img class="aligncenter size-full wp-image-1493" title="d-times-c7" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/d-times-c7.png" alt="d-times-c7" width="122" height="83" /></td>
<td class="SSTD" style="width: 114px;"><img class="aligncenter size-full wp-image-1494" title="d-times-c8" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/d-times-c8.png" alt="d-times-c8" width="114" height="86" /></td>
<td class="SSTD" style="width: 112px;"><img class="aligncenter size-full wp-image-1495" title="d-times-c9" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/d-times-c9.png" alt="d-times-c9" width="112" height="79" /></td>
<td class="SSTD" style="width: 130px;"><img class="aligncenter size-full wp-image-1496" title="d-times-c10" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/d-times-c10.png" alt="d-times-c10" width="130" height="85" /></td>
</tr>
<tr>
<td class="SSTD" style="width: 45px;"><em>Values</em></td>
<td class="SSTD" style="width: 70px;"><em>d</em> = 0, <em>c</em> = 1</td>
<td class="SSTD" style="width: 122px;"><em>a</em> = 5, <em>b</em> =   7, <em>c</em> = 1</td>
<td class="SSTD" style="width: 114px;"><em>a</em> = 5, <em>b</em> =   0, <em>c</em> = 2</td>
<td class="SSTD" style="width: 112px;"><em>a</em> = 0, <em>b</em> =   7, <em>c</em> = 2</td>
<td class="SSTD" style="width: 130px;"><em>a</em> = 5, <em>b</em> =   7, <em>c</em> = 2</td>
</tr>
<tr>
<td class="SSTD" style="width: 45px;"><em>x</em></td>
<td class="SSTD" style="width: 70px;">0*1 = 0</td>
<td class="SSTD" style="width: 122px;">(5 + 7)*1 = 12</td>
<td class="SSTD" style="width: 114px;">(5 + 0)*2 = 10</td>
<td class="SSTD" style="width: 112px;">(0 + 7)*2 = 14</td>
<td class="SSTD" style="width: 130px;">(5 + 7)*2 = 24</td>
</tr>
<tr>
<td class="SSTD" style="width: 45px;"><em>Note</em></td>
<td class="SSTD" style="width: 70px;"><em>a</em> and <em>b</em> are   not evaluated</td>
<td class="SSTD" style="width: 122px;"><img src="http://blog.iseesystems.com/wp-content/uploads/2009/05/90.gif" alt="" width="40" height="1" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
</td>
<td class="SSTD" style="width: 114px;"><img src="http://blog.iseesystems.com/wp-content/uploads/2009/05/90.gif" alt="" width="10" height="1" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
</td>
<td class="SSTD" style="width: 112px;"><img src="http://blog.iseesystems.com/wp-content/uploads/2009/05/90.gif" alt="" width="12" height="1" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
</td>
<td class="SSTD" style="width: 130px;"><img src="http://blog.iseesystems.com/wp-content/uploads/2009/05/90.gif" alt="" width="13" height="1" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
</td>
</tr>
</tbody>
</table>
<p><br class="spacer_" /></p>
<p><strong>Behavior of Ghosts Under Storytelling</strong></p>
<p>Finally, ghosts behave the same, irrespective of whether their parent is visible.  This means all the above rules apply, which can sometimes be confusing.  For example, if a stock called Population initialized to the constant 100, the story below does what is expected:  the ghost of Population will equal 100.</p>
<p align="center"><img class="aligncenter size-full wp-image-1448" title="ghost1" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/ghost1.png" alt="ghost1" width="192" height="143" /></p>
<p>However, in the story below, the behavior is not very likely to be what is expected.  If <em>death rate</em> is a constant, there will be no surprises.  However, if <em>death rate</em> depends on other variables, as in the example at the beginning of this post, you may be very surprised by the results.  In that case, <em>death rate</em> was determined by multiplying two other variables, so it will evaluate to <em>one</em> in this story.  To make it evaluate to a more meaningful value, you must also include some of its inputs in this story panel (as was done in that story).  This is true, by the way, whether <em>death rate</em> is a ghost or not.</p>
<p align="center"><img class="aligncenter size-full wp-image-1449" title="ghost2" src="http://blog.iseesystems.com/wp-content/uploads/2009/05/ghost2.png" alt="ghost2" width="159" height="99" /></p>
<p>The simulation rules for storytelling can sometimes lead to confusing results, especially in larger models.  Hopefully, this post clears up much of the confusion and allows you to build more effective behavioral stories.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/storytelling-simulations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spatial Modeling with isee Spatial Map</title>
		<link>http://blog.iseesystems.com/modeling-tips/spatial-modeling-map/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/spatial-modeling-map/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 16:16:50 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[2D array]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[diffusion]]></category>
		<category><![CDATA[iThink/STELLA]]></category>
		<category><![CDATA[spatial]]></category>
		<category><![CDATA[Version 9.1.2]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=1244</guid>
		<description><![CDATA[Editor&#8217;s Note:  This is part 3 of a 3-part series on spatial modeling in iThink and STELLA.  Part 1 is available here.  Part 2 is available here.


Last time, we explored a two dimensional diffusion problem by looking at a metal plate with constant heat applied to the center.  The model is [...]]]></description>
			<content:encoded><![CDATA[<p><em>Editor&#8217;s Note:  This is part 3 of a 3-part series on spatial modeling in iThink and STELLA.  Part 1 is available <a href="http://blog.iseesystems.com/modeling-tips/spatial-modeling/">here</a>.  Part 2 is available <a href="http://blog.iseesystems.com/modeling-tips/spatial-modeling-2d/">here</a>.</em></p>
<hr />
<p><br class="spacer_" /></p>
<p>Last time, we explored a two dimensional diffusion problem by looking at a metal plate with constant heat applied to the center.  The model is available here:  <a href="http://blog.iseesystems.com/wp-content/uploads/2009/04/2d-diffusion.zip">2d-diffusion</a>.  The results, using isee Spatial Map, of the start (left) and end (right) of a six-minute simulation are shown below.</p>
<p style="text-align: center;" align="center"><img class="aligncenter size-full wp-image-1208" title="2d-element-results" src="http://blog.iseesystems.com/wp-content/uploads/2009/04/2d-element-results.png" alt="2d-element-results" width="386" height="132" /></p>
<p>I am frequently asked how to set up Spatial Map.  isee Spatial Map is a simple program that can be used to display any dataset as a two dimensional grid with specific colors assigned to data ranges.  Since it is stand-alone, <em>iThink</em> and STELLA communicate with it through the Export Data functionality.  If you wish to plot simulation results in Spatial Map, you must first set up a persistent link to a CSV file.  This persistent link is always going to be from a table that contains just one element of the array you wish to view in Spatial Map.</p>
<p>In this example, a table named &#8220;Temp Export Table&#8221; was created to export the temperature data.  The first element, temperature[1, 1], was placed in the table.  There is a subtlety here that cannot be overlooked.  I wish to plot the values of the stock <em>T</em> as it varies over time.  Yet I export a different variable named &#8220;temperature&#8221;.  Why is this?</p>
<p>This is necessary because although stocks can be exported in the format Spatial Map expects, the export settings that are compatible with Spatial Map only export their initial values no matter where the simulation is.  If we export <em>T</em>, we will only ever see the initial conditions in Spatial Map.  Thus, when displaying a stock in Spatial Map, and we almost always do display stocks, it is necessary to create a converter that is set identically equal to the stock.  The converter will export its current values, and since it is equal to the stock, the stock&#8217;s current values will be exported.  The converter used for this purpose in this sample model is named &#8220;temperature&#8221;.</p>
<p>Next it is necessary to set up the persistent link.  Choose Export Data&#8230; from the Edit menu.  The Export Type should already be set to Persistent and Dynamic.  Under Export Data Source, select &#8220;Export variables in table&#8221; and choose the table with the array element in it from the pop-up menu.  In this case, that table is called &#8220;Temp Export Table&#8221;.  Also select &#8220;One set of values&#8221; under Interval.  This forces the data to be export in the format required by Spatial Map.  These settings are shown below.</p>
<p style="text-align: center;" align="center"><img class="aligncenter size-full wp-image-1247" title="spatial-export" src="http://blog.iseesystems.com/wp-content/uploads/2009/04/spatial-export.png" alt="spatial-export" width="458" height="342" /></p>
<p>To finish setting up the export, choose the CSV file to export to and press OK.  For this model, the file is named &#8220;2D Diffusion.csv&#8221;.  Note that all of this has already been set up in the attached sample, so you will not be able to set it up again.  You can examine the settings, though, by choosing Manage Persistent Links in the Edit menu and then pressing the Edit link at the end of the &#8220;Temp Export Data&#8221; line in the Export block.</p>
<p>The value of &#8220;temperature&#8221; will now be exported once at the start of each run and once at the end.  If you wish to see the simulation unfold in Spatial Map, it will be necessary to set a Pause interval, as dynamic links are also exported every time the simulation pauses.  Under Runs Specs&#8230; in the Run menu, you can see that I have set the Pause Interval to 20.  This forces the Spatial Map to update every 20 seconds during the simulation run.  This also forces the user to keep pressing Run to advance the simulation.</p>
<p><span id="more-1244"></span></p>
<p>Finally, it is necessary to set up Spatial Map.  Launch isee Spatial Map from the <em>iThink</em> or STELLA installation [in the Start menu on Windows, or in the <em>iThink</em>/STELLA folder in Application on the Macintosh].  Press the &#8220;Set CSV&#8221; button and choose the CSV file that is the target of the export.  For this example, the file is named &#8220;2D Diffusion.csv&#8221;.  An empty grid with the same dimensions as the exported array should appear.  In this case, the temperature array is 10 by 10.  Press the Settings button in the upper left corner.  Its icon is three intermeshed gears.  This dialog is where most of the magic of Spatial Map occurs.  Please refer to Part 3 of the Technical Documentation (<a href="http://www.iseesystems.com/Help">www.iseesystems.com/Help</a>) for a full description of how to use this dialog.</p>
<p>At this point, it is important to take a moment to plan what you hope to see.  The temperature values on this plate vary from 0 to 100 degrees.  It would be ideal if the temperature on the plate was displayed white at zero degrees, red at 100 degrees, and a graduated blend from white to red for values in-between.</p>
<p>Spatial Map allows colors to be assigned to ranges of variables.  Blends have been added on top of this interface, making the setting up of blends a little tricky.</p>
<p>The left side of the Settings dialog shows the colors assigned to the various ranges.  This will be blank when you first open the dialog.  To see an example, double-click the sample named &#8220;Test Configuration&#8221; on the right side.  At this point, three numbers will appear on the left side with colors directly across from each value:</p>
<p style="text-align: center;" align="center"><img class="aligncenter size-full wp-image-1248" title="spatial-test-config" src="http://blog.iseesystems.com/wp-content/uploads/2009/04/spatial-test-config.png" alt="spatial-test-config" width="327" height="143" /></p>
<p>Each value corresponds to the starting value in a range.  The previous range ends just below the value given as the start for the next range.  For the above setup, if 0 = <em>value</em> &lt; 10, the cell will be colored <span style="color: red;">red</span>.  If 10 = <em>value</em> &lt; 20, the cell will be colored <span style="color: blue;">blue</span>.  If <em>value</em> = 20, the cell will be colored <span style="color: green;">green</span>.  Spatial Map always colors values below the lowest value given in white, so if <em>value</em> &lt; 0, the cell will be colored white.</p>
<p>This is fairly straightforward, but does not map directly to blended colors.  If values between 0 and 10 are supposed to appear in some shade of red, which value should be <span style="color: red;">full red</span>?  0?  10?  5?  If values between 10 and 20 are supposed to appear in some shade of blue, which value should be the <span style="color: blue;">full blue</span> that appears here?  And what happens at the boundary between red and blue, i.e., at 10?  If this is a perfect blend between the two colors, it would seem that values at the boundary (10) should be a 50/50 <span style="color: purple;">blend</span> of the two colors red and blue.  Based on this fixed point, Spatial Map applies the full color at the middle of the range and blends out to middle of the neighboring ranges.  Thus, full red is at 5 and full blue is at 15 with the gradations shown below:</p>
<table style="padding-left: 60px;" border="0">
<tbody>
<tr>
<td align="right">5:</td>
<td style="color: red; background-color: red;">__________</td>
<td>red</td>
</tr>
<tr>
<td align="right">7.5:</td>
<td style="color: #cc0044; background-color: #cc0044;">__________</td>
<td>75% red and 25% blue</td>
</tr>
<tr>
<td align="right">10:</td>
<td style="color: purple; background-color: purple;">__________</td>
<td>half red and half blue</td>
</tr>
<tr>
<td align="right">12.5:</td>
<td style="color: #4400cc; background-color: #4400cc;">__________</td>
<td>25% red and 75% blue</td>
</tr>
<tr>
<td align="right">15:</td>
<td style="color: blue; background-color: blue;">__________</td>
<td>blue</td>
</tr>
</tbody>
</table>
<p>On the other side, the red region blends to an equal-sized white region.  Therefore, cell values containing zero will be half white and half red.</p>
<p>This definition of blends also requires that the top color have a fully-defined range so it can be blended with its neighbor and with white beyond that limit.  When you select &#8220;Blend Colors&#8221; at the bottom of the dialog, you are also asked to enter the ending value of the last range.  This is really the start of the hidden white range at the top.</p>
<p>For this example, we want to show 0 in white and 100 in red.  The simple setup below will not do this.</p>
<p style="text-align: center;" align="center"><img class="aligncenter size-full wp-image-1249" title="spatial-config-guess" src="http://blog.iseesystems.com/wp-content/uploads/2009/04/spatial-config-guess.png" alt="spatial-config-guess" width="329" height="114" /></p>
<p>With blend colors on and the end of the last range set to 150, this setup uses white for all values less than 50 (the middle of the first range), full red at 125 (the middle of the second range), a blend from white to red between 50 and 125 (with half white and half red at 100) and a blend from red to white from 125 to 175 (with half red and half white at 150).</p>
<p>The desired behavior, however, is white at 0, full red at 100, and a blend from white to red in-between.  We expect the color to be half white and half red at 50.  This gives us three points to use to set up the proper ranges for this blended behavior:</p>
<table style="padding-left: 60px;" border="0">
<tbody>
<tr>
<td align="right">0:</td>
<td style="color: white; background-color: white;">__________</td>
<td>white</td>
</tr>
<tr>
<td align="right">50:</td>
<td style="color: #ff8888; background-color: #ff8888;">__________</td>
<td>half white and half red</td>
</tr>
<tr>
<td align="right">100:</td>
<td style="color: red; background-color: red;">__________</td>
<td>red</td>
</tr>
</tbody>
</table>
<p>We learned above that the half-blend point is the value we need to use for the start of the range for the second color.  Thus, we will place red at 50.</p>
<p>We also learned that the full colors appear at the midpoint of the ranges.  Thus, to get white at 0 when the next range boundary is at 50, we must go 50 back from 0 to -50.  So we will place white at -50.  Finally, we need to define the end of the red range.  If 100 is the midpoint of a range that starts at 50, the range will end at 150.  This configuration is shown below:</p>
<p style="text-align: center;" align="center"><img class="aligncenter size-full wp-image-1250" title="spatial-config" src="http://blog.iseesystems.com/wp-content/uploads/2009/04/spatial-config.png" alt="spatial-config" width="328" height="178" /></p>
<p>The specific red used in this example is a slightly darkened version of pure red, chosen in order to look more realistic.  Click on the color on the right to open the color picker.  Start by selecting pure red from the list of basic colors (fourth down in the second column).  Tone down the Red (or the Val) component from 255 to 230 in the bottom right (see below) and press OK.</p>
<p style="text-align: center;" align="center"><img class="aligncenter size-full wp-image-1251" title="spatial-color" src="http://blog.iseesystems.com/wp-content/uploads/2009/04/spatial-color.png" alt="spatial-color" width="243" height="102" /></p>
<p>If you have set up Spatial Map correctly, when you run the model, you will see the temperature diffuse across the plate as the simulation progresses, with the spatial map updating each time the model pauses.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/spatial-modeling-map/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Spatial Modeling in Two Dimensions</title>
		<link>http://blog.iseesystems.com/modeling-tips/spatial-modeling-2d/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/spatial-modeling-2d/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 17:03:37 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[2D array]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[diffusion]]></category>
		<category><![CDATA[iThink/STELLA]]></category>
		<category><![CDATA[spatial]]></category>
		<category><![CDATA[Version 9.1.2]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=1203</guid>
		<description><![CDATA[Editor&#8217;s Note:  This is part 2 of a 3-part series on spatial modeling in iThink and STELLA.  Part 1 is available here.  Part 3 is available here.


Last time, we explored spatial modeling using the one-dimensional diffusion problem as an example.  Many spatial applications, however, require two dimensional formulations.  As an extension, we will now explore [...]]]></description>
			<content:encoded><![CDATA[<p><em>Editor&#8217;s Note:  This is part 2 of a 3-part series on spatial modeling in iThink and STELLA.  Part 1 is available <a href="http://blog.iseesystems.com/modeling-tips/spatial-modeling/">here</a>.  Part 3 is available <a href="http://blog.iseesystems.com/modeling-tips/spatial-modeling-map/">here</a>.</em></p>
<hr />
<p><br class="spacer_" /></p>
<p>Last time, we explored spatial modeling using the one-dimensional diffusion problem as an example.  Many spatial applications, however, require two dimensional formulations.  As an extension, we will now explore the two-dimensional diffusion problem.  Instead of a one-meter metal bar with constant heat applied at its ends, the two-dimensional diffusion problem looks at the response of a one-meter by one-meter metal plate with constant heat applied to its center.  We then watch the heat diffuse across the plate.</p>
<p>At first blush, one might think the two-dimensional case is much more difficult than the one-dimensional case.  In particular, if a grid is superimposed over the plate, each finite element on the plate has eight neighbors, as shown below.  It is tempting, therefore, to consider radiating heat in each of these eight directions.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-1206" title="2d-radiation" src="http://blog.iseesystems.com/wp-content/uploads/2009/04/2d-radiation.png" alt="2d-radiation" width="131" height="131" /></p>
<p>However, without looking at the two-dimensional diffusion equations, if we consider just the physical layout of this system, the four corners of the finite element only touch the four corner neighbors (1, 3, 5, and 7) at one point.  In contrast, the four sides of the finite element are shared with each of its four immediate neighbors (2, 4, 6, and 8).  This suggests that heat only radiates to (and from) these four neighbors, not all eight.  In fact, if we examine the two-dimensional diffusion equation, we find that there are only component contributions in the <em>x</em>- and the <em>y</em>-directions.  There are no contributions on the diagonal (which would appear in the equation as ∂<sup>2</sup><em>u</em>/∂<em>x</em>∂<em>y</em> and ∂<sup>2</sup><em>u</em>/∂<em>y</em>∂<em>x</em> terms).</p>
<p>Intuitively, then, we have a finite element that is very similar to the one-dimensional case.  We only need to add corresponding flows in the <em>y</em>-direction.  This leads to the following model with the individual finite elements arrayed.</p>
<p style="text-align: center;" align="center"><img class="aligncenter size-full wp-image-1207" title="2d-element-model" src="http://blog.iseesystems.com/wp-content/uploads/2009/04/2d-element-model.png" alt="2d-element-model" width="260" height="268" /></p>
<p>The array <em>T</em> is now two-dimensional, in <em>x</em> and in <em>y</em>.  In addition, <em>dx</em> can differ from <em>dy</em>, so the diffusion constant <em>C</em> must be broken down into its constituent parts <em>C<sub>x</sub></em> = <em>k</em>/<em>dx</em><sup>2</sup> and <em>C<sub>y</sub></em> = <em>k</em>/<em>dy</em><sup>2</sup>.  This leads to the following set of equations for the radiant flows through the plate:</p>
<p style="padding-left: 30px;"><em>in left</em> = <em>Cx</em>*<em>T</em>[<em>X</em> - 1, <em>Y</em>]                               <em>in top</em> = <em>Cy</em>*<em>T</em>[<em>X</em>, <em>Y</em> - 1]<em><br />
 out left</em> = <em>Cx</em>*<em>T</em>[<em>X</em>, <em>Y</em>]                                  <em>out top</em> = <em>Cy</em>*<em>T</em>[<em>X</em>, <em>Y</em>]<em><br />
 out right</em> = <em>Cx</em>*<em>T</em>[<em>X</em>, <em>Y</em>]                              <em>out bottom</em> = <em>Cy</em>*<em>T</em>[<em>X</em>, <em>Y</em>]<em><br />
 in right</em> = <em>Cx</em>*<em>T</em>[<em>X</em> + 1, <em>Y</em>]                          <em>in right</em> = <em>Cy</em>*<em>T</em>[<em>X</em>, <em>Y</em> + 1]</p>
<p><em>X</em> and <em>Y</em> are dimension names for the elements in the <em>x</em>- and ­<em>y</em>-directions, respectively.</p>
<p>Using isee Spatial Map, it is possible to view the results of this diffusion across two dimensions.  Spatial Map displays an array as a one-dimensional or two-dimensional grid (depending on the array).  Each cell in the grid is filled with a color corresponding to the value in the corresponding cell of the array.  Below are two spatial maps.  The one on the left shows the initial conditions of the metal plate.  Note that heat only appears in the center of the plate, where it is being externally applied.  The map on the right shows the distribution of heat across the plate at the end of a six-minute simulation.</p>
<p style="text-align: center;" align="center"><img class="aligncenter size-full wp-image-1208" title="2d-element-results" src="http://blog.iseesystems.com/wp-content/uploads/2009/04/2d-element-results.png" alt="2d-element-results" width="386" height="132" /></p>
<p>The model is available here:  <a href="http://blog.iseesystems.com/wp-content/uploads/2009/04/2d-diffusion.zip">2d-diffusion</a>.  It is already configured to use isee Spatial Map.  In <a href="http://blog.iseesystems.com/modeling-tips/spatial-modeling-map/">the final installment of this 3-part series</a>, I will describe how to set up isee Spatial Map.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/spatial-modeling-2d/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Spatial Modeling in iThink and STELLA</title>
		<link>http://blog.iseesystems.com/modeling-tips/spatial-modeling/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/spatial-modeling/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 16:19:19 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[diffusion]]></category>
		<category><![CDATA[iThink/STELLA]]></category>
		<category><![CDATA[spatial]]></category>
		<category><![CDATA[Version 9.1.2]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=976</guid>
		<description><![CDATA[STELLA and iThink provide capabilities to model spatial problems.  Version 9.1.2 expands these capabilities to allow more intuitive equation formulations.
Spatial modeling is concerned with modeling behavior over space as well as time.  Common applications include modeling flows in lakes and streams or modeling development in an urban landscape.  To demonstrate the new capabilities in version [...]]]></description>
			<content:encoded><![CDATA[<p>STELLA and iThink provide capabilities to model spatial problems.  Version 9.1.2 expands these capabilities to allow more intuitive equation formulations.</p>
<p>Spatial modeling is concerned with modeling behavior over space as well as time.  Common applications include modeling flows in lakes and streams or modeling development in an urban landscape.  To demonstrate the new capabilities in version 9.1.2, the one-dimensional diffusion problem will be modeled in STELLA.</p>
<p>Consider the diffusion of heat through a one meter metal bar when a constant temperature is applied to both ends.  This problem is typically introduced as the following partial differential equation for temperature function <em>u</em>(<em>x</em>, <em>t</em>) with the given boundary conditions:</p>
<p style="padding-left: 30px;">∂<em>u</em>/∂<em>t</em> &#8211; <em>k</em> ∂<sup>2</sup><em>u</em>/∂<em>x</em><sup>2</sup> = 0<br />
 <em> u</em>(<em>x</em>, 0) = 0, 0 &lt; <em>x</em> &lt; 1<br />
 <em> u</em>(0, <em>t</em>) = <em>u</em><sub>0</sub>, <em>t</em> ≥ 0<em><br />
 u</em>(1, <em>t</em>) = <em>u</em><sub>0</sub>, <em>t</em> ≥ 0</p>
<p>Here, <em>k</em> is the diffusion coefficient (based on thermal conductivity, density, and heat capacity) and <em>u</em><sub>0</sub> is the constant temperature applied to both ends of the bar.  The finite difference solution to this problem (with the above initial conditions) is:</p>
<p style="padding-left: 30px;"><em>u</em>(<em>x</em>, <em>t</em> + <em>dt</em>) = <em>u</em>(<em>x</em>, <em>t</em>) + ∂<em>u</em>/∂<em>t</em><br />
 ∂<em>u</em>/∂<em>t</em> = <em>k</em> (<em>u</em>(<em>x</em> + <em>dx</em>, <em>t</em>) &#8211; 2<em>u</em>(<em>x</em>, <em>t</em>) + <em>u</em>(<em>x</em> &#8211; <em>dx</em>, <em>t</em>))/<em>dx</em><sup>2</sup></p>
<p>It is also possible to derive a closed-form solution.  Unless you are an astrophysicist, this solution probably does little to help you understand what is happening.  It is far more intuitive to develop a physical model of the underlying mechanics than to wrestle with the mathematics.</p>
<p><span id="more-976"></span>If you consider the metal bar as a single object that is being acted on by its environment, it is possible to consider some of the changes to that bar over time.  If the environment is warmer than the bar, there will be an inflow of heat to the bar.  If the bar is warmer than its surrounding environment, there will be an outflow of heat from the bar.  We probably all know from experience that a hot bar will radiate heat outward in all directions, so in a three-dimensional problem, heat would flow outward in all directions.</p>
<p>If you divide the bar into a set of consecutive finite elements (a finite element is just a fancy word for a small fixed-size section of a larger object &#8211; finite because its size is bounded), it becomes possible to imagine a model of what happens to each of these elements individually.  Connecting them in tandem should then yield the behavior of the entire bar.  This is the essence of spatial modeling.</p>
<p>Using the ideas above, we must have some amount of heat entering each element and some amount leaving each element.  For this problem, however, which way does the heat radiate?  The problem is intentionally limited to one dimension, <em>x</em>, so the only choice for the direction of radiation (from an element&#8217;s point of view) is left or right.  Thus, we can have heat radiating into the element from either the left or right side, and heat radiating out of the element from either the left or right side.  This is shown in the diagram below and is our model for a finite element of the metal bar.  Note that for clarity <em>u</em> has been renamed <em>T</em> for temperature.</p>
<p style="text-align: center;" align="center"><a rel="attachment wp-att-983" href="http://blog.iseesystems.com/?attachment_id=983"></a><img class="aligncenter size-full wp-image-990" title="element" src="http://blog.iseesystems.com/wp-content/uploads/2009/03/element.png" alt="element" width="262" height="88" /></p>
<p>If we chain a number of these elements together horizontally, we will have a model of the entire metal bar.  Using three elements leads to the following model of the metal bar.</p>
<p style="text-align: center;" align="center"><a rel="attachment wp-att-980" href="http://blog.iseesystems.com/?attachment_id=980"></a><img class="aligncenter size-full wp-image-991" title="elements-in-tandem" src="http://blog.iseesystems.com/wp-content/uploads/2009/03/elements-in-tandem.png" alt="elements-in-tandem" width="473" height="88" /></p>
<p>This model is obviously greatly simplified.  Note that <em>heat applied left</em> is the heat arriving from the left side of <em>T1</em>.  The heat leaving from the left side is zero, so is not even shown.  An analogous simplification has been made to <em>T3</em>.  This simplified model allows us to consider the nature of each of the four flows in our modeled element, as all of them relate to the neighbors of that element.  In this example, <em>T2</em> has one neighbor to the left, <em>T1</em>, and one neighbor to the right, <em>T3</em>.  Thus, any heat gained from the left must come from <em>T1</em> and any heat gained from right must come from <em>T3</em>.  In addition, any excess heat <em>T2</em> has will radiate out to <em>T1</em> on the left and <em>T3</em> on the right.  This simple structure allows us to arrive at the equations for the four flows in our finite element model, shown in terms of both this example and the general finite element model:</p>
<p style="padding-left: 30px;"><em>in left</em> = <em>C</em>·<em>T1</em> = <em>C</em>·<em>T</em>(<em>x</em> &#8211; <em>dx</em>, <em>t</em>)<em><br />
 out left</em> = <em>C</em>·<em>T2</em> = <em>C</em>·<em>T</em>(<em>x</em>, <em>t</em>)<em><br />
 out right</em> = <em>C</em>·<em>T2</em> = <em>C</em>·<em>T</em>(<em>x</em>, <em>t</em>)<em><br />
 in right</em> = <em>C</em>·<em>T3</em> = <em>C</em>·<em>T</em>(<em>x</em> + <em>dx</em>, <em>t</em>)</p>
<p><em>C</em> is a diffusion constant describing the rate of temperature loss from a warm body, i.e., the fraction radiated by a finite element.  In the one-dimensional case, <em>C</em> = <em>k</em>/<em>dx</em><sup>2</sup>.  Note that summing these four flows together properly (i.e., adding the inflows and subtracting the outflows) yields the exact same ∂<em>u</em>/∂<em>t</em> equation derived mathematically and shown above.</p>
<p>But are three elements, two of which are held at the applied temperature, sufficient to properly model a one meter metal bar?  Not really.  The number of elements used defines <em>dx</em>.  Specifically, <em>dx</em> = bar length/number of elements, in this case 1 m/3 = 1/3 m.  Like <em>dt</em>, <em>dx</em> must be small enough to properly catch the dynamics of the system.  We need far more elements to properly model this problem.  Since we have broken the metal bar down into identical finite elements, it becomes natural to build the metal bar up using an array of finite elements rather than showing each individual element.  This model looks like this:</p>
<p style="text-align: center;" align="center"><a rel="attachment wp-att-986" href="http://blog.iseesystems.com/?attachment_id=986"></a><img class="aligncenter size-full wp-image-992" title="element-model" src="http://blog.iseesystems.com/wp-content/uploads/2009/03/element-model.png" alt="element-model" width="262" height="90" /></p>
<p>Version 9.1.2 allows the equations above to be naturally expressed as Apply to All equations as follows:</p>
<p style="padding-left: 30px;"><em>in left</em> = <em>C</em>*<em>T</em>[<em>X</em> - 1]<em><br />
 out left</em> = <em>C</em>*<em>T</em>[<em>X</em>]<em><br />
 out right</em> = <em>C</em>*<em>T</em>[<em>X</em>]<em><br />
 in right</em> = <em>C</em>*<em>T</em>[<em>X</em> + 1]</p>
<p>where <em>X</em> is name of the array dimension.  Note the value one is used instead of <em>dx</em>.  This is because each array element represents a finite element of width <em>dx</em>.  The subscript for the array counts elements rather than distance.  To get the position of the element along the bar it is necessary to multiply the index of the element by <em>dx</em>.  Also note that <em>t</em> is not represented by a subscript in the array.  This is because all models already simulate across time.  Therefore, all entities in a model are functions of time.  Running this model gives the expected behavior:</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-987" title="element-results" src="http://blog.iseesystems.com/wp-content/uploads/2009/03/element-results.png" alt="element-results" width="625" height="175" /></p>
<p>A final note:  Version 9.1.2 allows any constant, not just one, to be added to, or subtracted from, a dimension name in an equation.  The software evaluates <em>T</em>[<em>X</em> + <em>c</em>] to <em>zero</em> when <em>X</em> + <em>c</em> results in a subscript beyond the bounds of the array.  Thus, when <em>X</em> = 1, the first element, <em>T</em>[<em>X</em> - 1] will be forced to zero.  Likewise, when <em>X</em> = DIMSIZE(), the last element, <em>T</em>[<em>X</em> + 1] will be forced to zero.  As you will discover when you explore it, this particular model (<a href="http://blog.iseesystems.com/wp-content/uploads/2009/03/1d-diffusion.zip">1d-diffusion</a><a rel="attachment wp-att-1004" href="http://blog.iseesystems.com/?attachment_id=1004"></a>) forces these end conditions to the constant temperature being applied (100 in this case).</p>
<p><em>Editor’s Note:  This is part 1 of a 3-part series on spatial modeling in iThink and STELLA.  Part 2 is available <a href="http://blog.iseesystems.com/modeling-tips/spatial-modeling-2d/">here</a>.  Part 3 will be posted the week of April 12th, 2009.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/spatial-modeling/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Running Models from the Command Line</title>
		<link>http://blog.iseesystems.com/modeling-tips/running-models-automatically-from-the-command-line/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/running-models-automatically-from-the-command-line/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 14:55:50 +0000</pubDate>
		<dc:creator>Nat Pierson</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[Version 9.1.2]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=812</guid>
		<description><![CDATA[Version 9.1.2 introduces the oft-requested ability to run models from the command line outside of iThink or STELLA (Windows only).  This feature opens up a number of possibilities for users who need to automate their modeling tasks.  For example, you could use the command line to automatically run a model multiple times, start a model from [...]]]></description>
			<content:encoded><![CDATA[<p>Version 9.1.2 introduces the oft-requested ability to run models from the command line outside of <em>iThink</em> or STELLA (Windows only).  This feature opens up a number of possibilities for users who need to automate their modeling tasks.  For example, you could use the command line to automatically run a model multiple times, start a model from a script, or create a shortcut that opens and runs a model when you double-click on the icon.</p>
<p>I have set up a simple example that illustrates how you could run an <em>iThink</em> model multiple times to skirt the 32,767 time step limit that advanced users sometimes run up against.  The model itself does nothing extraordinary, it simply increments the value of a Stock by one at each time step. What makes it worth noticing is that it runs 32,000 iterations three times to mimic a 96,000 step run.</p>
<p><a href="http://blog.iseesystems.com/wp-content/uploads/2009/03/Command_Line_Feature_Sample.zip">&gt;&gt; Download the Sample Files</a></p>
<p>This example will open and run the model file named <em>multiple_run.itm</em>, import data at the beginning of each run, and export data at the end of each run.  You can double-click on the &#8220;Start batch runs&#8221; shortcut to kick things off or you can use the batch file that is provided. Note that you may have to edit these start files to make them work on your computer</p>
<p><strong>Command Line Syntax</strong><br class="spacer_" /></p>
<pre style="padding-left: 30px;">"c:\program files\isee systems\iThink 9.1.2\iThink.exe" -rn 3 multiple_run.itm</pre>
<p><img class="size-full wp-image-835 alignright" title="shortcut" src="http://blog.iseesystems.com/wp-content/uploads/2009/03/shortcut.png" alt="Shortcut Properties" width="330" height="458" /></p>
<p>The command line above was entered into the &#8220;Target&#8221; field of the &#8220;Start batch runs&#8221; Properties dialog.  Note the &#8220;Start in&#8221; field is intentionally left blank so that the shortcut will run the model from the current directory.  If you move the shortcut file to a different directory,  you&#8217;ll need to enter that directory into this field.</p>
<p>The identical command line syntax is used in the supplied batch file named &#8220;go.bat&#8221; and can be edited using Notepad.</p>
<p><strong>Sample Model and Spreadsheet</strong></p>
<p>The sample model uses a table to report the value of the Stock at the end of each run so that it can be exported to the &#8220;multiple_run_data.xls&#8221; Excel file. In Excel, I linked the exported value of the Stock to an &#8220;Import&#8221; worksheet.   This way, one run hands off the final data to start the subsequent run like runners in a relay race passing a baton.  <em>Note the initial Stock value will need to be reset in Excel before starting a new batch of runs.</em></p>
<p>Running the sample command line puts <em>iThink </em>into a macro mode.  It opens just as if you double-clicked its icon and manually started the runs yourself.   Sit back and watch the model open, and let the model run three times on its own.  Try to leave the process alone while it executes, I did find that if the runs were interrupted the Excel file could sometimes lose its formatting.</p>
<p>For an experiment you could add &#8220;-nq&#8221; to the command so that the model stays open after running.  After adding the new parameter your command would look like this:</p>
<pre style="padding-left: 30px;">"c:\program files\isee systems\iThink 9.1.2\iThink.exe" -rn 3 -nq multiple_run.itm</pre>
<p><br class="spacer_" /></p>
<p>There are many more command options available.  <a href="http://www.iseesystems.com/Helpv9/Content/Command_Line_Options/Command_Line_Options.htm" target="iseeHelp">View the full list here and experiment with other parameters.<br />
</a></p>
<p><strong>UPDATE:</strong></p>
<p>Another advantage to running from the command line is that you can start and run a model from inside Excel. Not only can you run the model this way, but you can take advantage of all the parameters.</p>
<p>Create a shortcut as described in the post and save it. In Excel, pick a cell and select Insert hyperlink. Browse to and select the shortcut and then click OK. It’s that easy!!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/running-models-automatically-from-the-command-line/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>LOOKUP Built-in Allows Reuse of Graphical Function Curves</title>
		<link>http://blog.iseesystems.com/modeling-tips/lookup-built-in-allows-reuse-of-graphical-function-curves/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/lookup-built-in-allows-reuse-of-graphical-function-curves/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 14:00:37 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[builtins]]></category>
		<category><![CDATA[graphical function]]></category>
		<category><![CDATA[iThink/STELLA]]></category>
		<category><![CDATA[lookup]]></category>
		<category><![CDATA[Version 9.1.2]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=615</guid>
		<description><![CDATA[Sometimes it is necessary to access a data set from multiple places within a model.  For example, a manufacturer may have a non-linear curve that maps capacity required for a given product to raw material required to manufacture it.  Such a curve is shown below:

If one production line needs to know this information, a graphical [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes it is necessary to access a data set from multiple places within a model.  For example, a manufacturer may have a non-linear curve that maps capacity required for a given product to raw material required to manufacture it.  Such a curve is shown below:</p>
<p><img class="size-full wp-image-614 alignright" style="margin-left: 18px; margin-right: 18px;" title="Lookup Graphical Function Curve" src="http://blog.iseesystems.com/wp-content/uploads/2009/03/lookupgraphicalfunctioncurve.jpg" alt="lookupgraphicalfunctioncurve" width="303" height="243" /></p>
<p>If one production line needs to know this information, a graphical function works fine.  However, if there are two production lines in the model, the second line also needs this information.  If the two lines are identical in structure, the model could be arrayed to share the curve for both lines.  If they are not, it was necessary in versions prior to 9.1 to make a copy of this curve for the second production line.  Then if, at a later time, one copy of the curve needed to be changed, the other one also needed to be changed in the same way.</p>
<p>Version 9.1 introduced the LOOKUP built-in.  This allows any graphical function curve to be re-used as many times as desired within the same model.  Note that a graphical function, by definition, ties a specific equation to the given curve.  Using LOOKUP, it is now possible to evaluate that same curve using several different equations in the same time step.</p>
<p>In this case, let’s assume the second production line has similar variables with “2” appended to their names.  Thus, there is a <em>capacity2</em> and a <em>material needed 2</em>.  Prior to version 9.1, it was necessary for <em>material needed 2</em> to be an identical copy of <em>material needed</em>.<br />
 Since version 9.1 allows the curve to be re-evaluated for any arbitrary<br />
 expression, <em>material needed 2</em> no longer needs to be a graphical function.<br />
 Instead, it contains the equation:</p>
<dl style="margin:18px;">
<dd><em>material_needed_2</em> = LOOKUP(<em>material_needed</em>, <em>capacity_2</em>)</dd>
</dl>
<p>This equation simply evaluates the graphical function stored in <em>material needed</em> using <em>capacity 2</em> as the <em>x</em>-coordinat</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/lookup-built-in-allows-reuse-of-graphical-function-curves/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Imported file not found?</title>
		<link>http://blog.iseesystems.com/modeling-tips/imported-file-not-found/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/imported-file-not-found/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 20:03:17 +0000</pubDate>
		<dc:creator>Sarah Davie</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[imported files]]></category>
		<category><![CDATA[links]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=731</guid>
		<description><![CDATA[We often get calls from customers who have copied a model to another computer and then get the dreaded &#8220;&#8230;file was not found&#8221; message when they open the model.  It may be a missing picture, Excel spreadsheet or some other imported file. When copying a model from one computer to another, you may need to [...]]]></description>
			<content:encoded><![CDATA[<p>We often get calls from customers who have copied a model to another computer and then get the dreaded &#8220;&#8230;file was not found&#8221; message when they open the model.  It may be a missing picture, Excel spreadsheet or some other imported file. When copying a model from one computer to another, you may need to copy more than just the model file.  <img class="alignright size-full wp-image-749" style="margin: 10px;" title="files2" src="http://blog.iseesystems.com/wp-content/uploads/2009/03/files2.jpg" alt="files2" width="207" height="358" />If your model uses other files such as graphics, sounds or spreadsheets you&#8217;ll need to package all of them with the model file.</p>
<p>If you have to e-mail your model to isee support, it&#8217;s good to know how to package all the necessary files so that we can recreate your setup.</p>
<p>Here&#8217;s a list of the files your model may need:</p>
<ul>
<li>Modules (.itt files)</li>
<li>Links (Files that a local file hyperlink button points to)</li>
<li>Data (Excel and .csv files for import/export)</li>
<li>Graphics </li>
<li>Sounds </li>
<li>Movies </li>
</ul>
<p>Locate all the associated files in the same place as your model file.</p>
<p>If you have a lot of associated files you can organize them into sub-folders as pictured below:</p>
<p><br class="spacer_" /></p>
<p><img class="alignleft size-full wp-image-804" title="folders" src="http://blog.iseesystems.com/wp-content/uploads/2009/03/folders1_crop.jpg" alt="folders" width="243" height="265" />The one thing to watch out for is the situation of having one file that is accessed in more than one way.  For instance, an Excel file that is used for importing data but is also accessed via a hyperlink button.  In this case, the Excel file should not be in a sub-folder.  Instead, keep it in the same folder as the model file.</p>
<p>Now you can copy the folder to another computer or flash drive, or burn it to a CD.</p>
<p>If you are going to e-mail the folder, you might want to zip it up so you only have one file to send.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/imported-file-not-found/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LOOKUPXY Built-in Increases Dataset Flexibility</title>
		<link>http://blog.iseesystems.com/modeling-tips/lookupxy-built-in-increases-dataset-flexibility/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/lookupxy-built-in-increases-dataset-flexibility/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 18:40:08 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[builtins]]></category>
		<category><![CDATA[graphical function]]></category>
		<category><![CDATA[iThink/STELLA]]></category>
		<category><![CDATA[lookupxy]]></category>
		<category><![CDATA[Version 9.1.2]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=641</guid>
		<description><![CDATA[Version 9.1.2 adds the ability to incorporate non-regularly sampled data easily into your models.  Many people use the graphical function for historical records of data.  The graphical function, however, assumes a fixed interval along the x-axis.  This can make it difficult to use data like the following:



 Day
 Flow


1
12.1


3
7.6


4
15.2


6
13.5


9
23.8


12
17.3



While it is easy to determine the [...]]]></description>
			<content:encoded><![CDATA[<p>Version 9.1.2 adds the ability to incorporate non-regularly sampled data easily into your models.  Many people use the graphical function for historical records of data.  The graphical function, however, assumes a fixed interval along the <em>x</em>-axis.  This can make it difficult to use data like the following:</p>
<table style="margin-left:60px;" border="0">
<tbody>
<tr>
<th> Day</th>
<th> Flow</th>
</tr>
<tr align="right">
<td>1</td>
<td>12.1</td>
</tr>
<tr align="right">
<td>3</td>
<td>7.6</td>
</tr>
<tr align="right">
<td>4</td>
<td>15.2</td>
</tr>
<tr align="right">
<td>6</td>
<td>13.5</td>
</tr>
<tr align="right">
<td>9</td>
<td>23.8</td>
</tr>
<tr align="right">
<td>12</td>
<td>17.3</td>
</tr>
</tbody>
</table>
<p>While it is easy to determine the fixed interval to use to capture all of these points (1 day), it is more difficult to determine what data points to use for the missing intermediate 1-day values.  There are also many cases where it is very difficult to find a fixed interval that works for a given dataset.</p>
<div class="wp-caption alignright" style="width: 300px"><a href="http://blog.iseesystems.com/wp-content/uploads/2009/03/GraphicalFunctionDay.jpg"><img title="Graphical Function Day Data" src="http://blog.iseesystems.com/wp-content/uploads/2009/03/GraphicalFunctionDay_sm.jpg" alt="Graphical Function Day" width="290" height="156" /></a><p class="wp-caption-text">Graphical Function Day (click for full size)</p></div>
<p>The LOOKUPXY built-in was specifically added to address this issue.  It is unique in that it requires two separate graphical functions:  one for the <em>x</em>-coordinates of each pair and one for the <em>y</em>-coordinates of each pair.  The number of points in each graphical function should match; if they do not, extraneous points are ignored.  The data values (<em>x</em>-coordinates and <em>y</em>-coordinates) are both entered by the user as the <em>y</em>-values in each graphical function.  The <em>x</em>-values in each graphical function are ignored; only the number of points matter.  It is a good idea, though, to run the <em>x</em>-axis of both from one to the number of points.  That way, it is easy to verify that the values in each graphical function properly align with one another.  In addition, the <em>x</em>-coordinates should be in increasing order.  If they are not, however, the program will automatically readjust them when the model is first run.</p>
<p><span id="more-641"></span></p>
<div class="wp-caption alignright" style="width: 300px"><a href="http://blog.iseesystems.com/wp-content/uploads/2009/03/GraphicalFunctionFlow.jpg"><img title="Graphical Function Flow" src="http://blog.iseesystems.com/wp-content/uploads/2009/03/GraphicalFunctionFlow_sm.jpg" alt="Graphical Function Flow Data" width="290" height="157" /></a><p class="wp-caption-text">Graphical Function Flow (click for full size)</p></div>
<p style="margin-bottom:80px;">The data above are entered into two graphical functions <em>day</em> and <em>flow</em> as shown at the right.  Note the equation for each graphical function is also unimportant.  It is always safe to use TIME (the default when you press “Become Graphical Function”).</p>
<p>The model is very simple:</p>
<p><img style="margin-left:40px;" src="http://blog.iseesystems.com/wp-content/uploads/2009/03/ModelStructure.gif" alt="Model Structure" width="90" height="96" /></p>
<p>The following equation for <em>daily flow</em> retrieves this data over the course of the simulation (topping out at 17.3 after time 12):</p>
<dl style="margin:18px;">
<dd><em>daily_flow</em> = LOOKUPXY(<em>day</em>, <em>flow</em>, TIME)</dd>
</dl>
<p>Note the graphical function for the <em>x</em>-coordinates is given before the graphical function for the <em>y</em>-coordinates.  In addition, the graph of <em>daily flow</em> is necessarily different from what appears in the graphical function <em>flow</em>, which has the data points drawn at a fixed interval.</p>
<p align="center"><img title="Chart: Daily Flow" src="http://blog.iseesystems.com/wp-content/uploads/2009/03/ChartDailyFlow.gif" alt="" width="452" height="249" /></p>
<p>As with the graphical function, linear interpolation is used between the given points and out-of-range <em>x</em>-values evaluate to either the first or last <em>y</em>-coordinate, depending whether the value is below the minimum <em>x</em>-coordinate or above the maximum <em>x</em>-coordinate, respectively.  The discrete option is also available.  Make sure to set it in the variable containing the <em>y</em>-coordinates.  [Note that setting it in the variable containing the <em>x</em>-coordinates merely serves to drop the last point.]</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/lookupxy-built-in-increases-dataset-flexibility/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting Number of Points in a Graphical Function</title>
		<link>http://blog.iseesystems.com/modeling-tips/setting-number-of-points-in-a-graphical-function/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/setting-number-of-points-in-a-graphical-function/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 19:39:33 +0000</pubDate>
		<dc:creator>Karim Chichakly</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[graphical function]]></category>
		<category><![CDATA[iThink/STELLA]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=535</guid>
		<description><![CDATA[One of the questions I am sometimes asked is, &#8220;If I need a specific x-value to appear in my graphical function, how do I determine the number of points required to include that exact point?&#8221;  This arises because in a graphical function, the x­-axis is divided into fixed intervals; the user is only allowed to [...]]]></description>
			<content:encoded><![CDATA[<p>One of the questions I am sometimes asked is, &#8220;If I need a specific x-value to appear in my graphical function, how do I determine the number of points required to include that exact point?&#8221;  This arises because in a graphical function, the <em>x­</em>-axis is divided into fixed intervals; the user is only allowed to specify <em>x</em>-min, <em>x</em>-max, and the number of data points.  [If you really need a graphical function with arbitrary (<em>x</em>, <em>y</em>) points, use the LOOKUPXY() built-in function available in version 9.1.2.]</p>
<p>For the following discussion, the range on the <em>x</em>-axis will be needed:</p>
<p style="padding-left: 30px;">range = <em>x</em>_max &#8211; <em>x</em>_min</p>
<p>In all of the examples below, <em>x</em>_min = 3.000 and <em>x</em>_max = 7.000, so the range = 7 &#8211; 3 = 4.</p>
<p>For integer values, here is a simple formula that always works:</p>
<div style="background-color:#dedede">
<p style="padding-left: 30px;"># of data points = range + 1                                                                                  (1)</p>
</div>
<p>For example (using the range above), if the number 6 (an integer) must appear as a point on the <em>x</em>-axis, 4 + 1 = 5 points will be needed.  This divides the ­<em>x</em>-axis into the points 3.0, 4.0, 5.0, 6.0, and 7.0.</p>
<p>Fractional values, however, are more difficult.  In general, if you can isolate the fractional part (and this evenly divides the range), the <em>maximum</em> number of points needed is given by this formula:</p>
<p><br class="spacer_" /></p>
<p><span id="more-535"></span></p>
<p><br class="spacer_" /></p>
<div style="background-color:#dedede">
<p style="padding-left: 30px;"># of data points = range/fraction + 1                                                                      (2)</p>
</div>
<p>Note for integers, which have a fraction of one, this just simplifies to formula (1).  For example, suppose that the number 4.333 must appear on the <em>x</em>-axis.  The fractional part of this value is 0.333, or 1/3, so 4/(1/3) + 1 = 4*3 + 1 = 13 points will be needed.  This divides the <em>x</em>-axis into 3.0, 3.333, 3.667, 4.0, 4.333, 4.667, etc.</p>
<p>Note, however, that this is not the smallest number of data points needed.  In fact, four points are sufficient:  3.0, 4.333, 5.667, 7.0.  The problem with fractional values is that the equivalent of the least common divisor (LCD) must somehow be found (I leave this derivation to the reader).  The following formula, when it evaluates to an integer, gives this:</p>
<div style="background-color:#dedede">
<p style="padding-left: 30px;"># of data points = range/(desired_point &#8211; <em>x</em>_min) + 1                                            (3)</p>
</div>
<p>For the above example,</p>
<p style="padding-left: 30px;">range/(desired_point &#8211; <em>x</em>_min) + 1 = 4/(4.3333 &#8211; 3.0) + 1 = 4/1.3333 + 1 = 3.000 + 1 = 4</p>
<p>The number 4/1.3333 = 3 is important.  The desired value 4.333 will appear in the set of <em>x</em>-axis points whenever the number of data points is set to any of 3<em>k</em> + 1, where <em>k</em> = 1, 2, 3, &#8230;  This series contains the values 4, 7, 10, 13, 15, &#8230;  Any of these values can be used for the number of data points and 4.333 will appear somewhere on the <em>x</em>-axis.</p>
<p>There are more difficult cases.  If 4.3 is desired on the <em>x</em>-axis and 4.333 is just not close enough, the first formula yields 4/0.1 + 1 = 41 data points.  Note 0.3 could not be used as the fractional part because it does not go evenly into 4.  The largest factor of 0.3 that does go into 4 is 0.1, hence 0.1 is used in the formula.</p>
<p>Is there a smaller number of data points that might work?  Formula (3) can help here:</p>
<p style="padding-left: 30px;">range/(desired_point &#8211; <em>x</em>_min) + 1 = 4/(4.3 &#8211; 3) + 1 = 4/1.3 + 1 = 3.077 + 1 = 4.077</p>
<p>This does not look promising as it is not an integer.  In fact, there is no value for the number of data points less than 41 that will work in this case.  Note that all values 40<em>k</em> + 1 will work (for <em>k</em> = 1, 2, 3, &#8230;).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/setting-number-of-points-in-a-graphical-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tip: Setting up imports for 2D Graphical Functions</title>
		<link>http://blog.iseesystems.com/modeling-tips/setting-up-imports-for-2d-graphical-functions/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/setting-up-imports-for-2d-graphical-functions/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 17:09:45 +0000</pubDate>
		<dc:creator>Sarah Davie</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[2D array]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[graphical function]]></category>
		<category><![CDATA[import]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=255</guid>
		<description><![CDATA[iThink and STELLA version 9.0 introduced a powerful new feature: data import and export with Excel.  Here at isee, we were excited to hear from our customers about how much they appreciated the feature and how easy it was to use.  In fact, many customers told us that it was the major reason they upgraded [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.iseesystems.com" target="_blank"><em>iThink </em>and STELLA </a>version 9.0 introduced a powerful new feature: data import and export with Excel.  Here at isee, we were excited to hear from our customers about how much they appreciated the feature and how easy it was to use.  In fact, many customers told us that it was the major reason they upgraded to version 9.0<br />
<img class="size-full wp-image-337 alignright" style="margin-bottom: 1px;" title="simple import 1" src="http://blog.iseesystems.com/wp-content/uploads/2009/02/croppercapture42sm.png" alt="simple import 1" width="153" height="78" /></p>
<p>Setting up a data import from Excel is pretty straight forward:  type the name of the model variable in one cell, type the value you want to import in the cell below it, (or <em>beside it</em> if you are using horizontal orientation):</p>
<p>If you are importing a time series or graphical function, you just keep listing the data points in the cells below the variable name:</p>
<p><img class="size-full wp-image-338 alignleft" title="simple import 2" src="http://blog.iseesystems.com/wp-content/uploads/2009/02/croppercapture44sm.png" alt="simple import 2" width="86" height="110" /></p>
<p>This kind of data formatting works well since an Excel sheet is made up of columns and rows.  But how do you format data that is harder to visualize?  Things get a little tricky when you start dealing with arrayed variables.  The most complex import is a 2 dimensional array of graphical functions.  <em>It&#8217;s actually 3 dimensions!</em></p>
<p>I&#8217;ve put together a simple example to illustrate how to do this.</p>
<p><span id="more-255"></span></p>
<p>Let&#8217;s say you have a model set up to look at 3 teams&#8217; performance on 3 different projects.  The model has an array of Projects and Teams. The Project dimension has 3 elements: Project 1, Project 2 and Project 3.  The Team dimension has 3 elements: Team 1,Team 2 and Team 3.</p>
<p>In this model we&#8217;ll put down a converter called &#8220;Performance rates&#8221; which we&#8217;ll later define as a 2D array of graphical functions over time.  The converter will contain historical data on the various teams performance rates for the various projects.</p>
<p>You can see how this sort of setup is pretty close to what someone would want to do &#8211; track performance over time per project per team.</p>
<p>The format of the Excel spreasheet would look like this:</p>
<table style="width: 381pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0" width="508">
<colgroup span="1">
<col style="width: 66pt;" span="1" width="88"></col>
<col style="width: 40pt;" span="1" width="53"></col>
<col style="width: 41pt;" span="1" width="55"></col>
<col style="width: 39pt;" span="1" width="52"></col>
<col style="width: 40pt;" span="1" width="53"></col>
<col style="width: 41pt;" span="1" width="55"></col>
<col style="width: 38pt;" span="1" width="51"></col>
<col style="width: 40pt;" span="1" width="53"></col>
<col style="width: 36pt;" span="1" width="48"></col>
</colgroup>
<tbody>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="width: 66pt; height: 12.75pt; background-color: #ffff99; border: #f0f0f0;" width="88" height="17"><span style="font-size: x-small; font-family: Arial;"><strong><em></em></strong></span></td>
<td class="xl26" style="width: 81pt; background-color: #ffff99; border: #f0f0f0;" colspan="2" width="108"><strong><em><span style="font-size: x-small; font-family: Arial;">Project 1</span></em></strong></td>
<td class="xl24" style="width: 39pt; background-color: silver; border: #f0f0f0;" width="52"> </td>
<td class="xl25" style="width: 81pt; background-color: silver; border: #f0f0f0;" colspan="2" width="108"><strong><em><span style="font-size: x-small; font-family: Arial;">Project 2</span></em></strong></td>
<td class="xl28" style="width: 38pt; background-color: #ccffff; border: #f0f0f0;" width="51"> </td>
<td class="xl29" style="width: 76pt; background-color: #ccffff; border: #f0f0f0;" colspan="2" width="101"><strong><em><span style="font-size: x-small; font-family: Arial;">Project 3</span></em></strong></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl33" style="height: 12.75pt; background-color: #ffff99; border: #f0f0f0;" height="17"><span style="font-size: x-small; font-family: Arial;">Team 1</span></td>
<td class="xl30" style="background-color: #ffff99; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">Team 2</span></td>
<td class="xl27" style="background-color: #ffff99; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">Team 3</span></td>
<td class="xl24" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">Team 1</span></td>
<td class="xl32" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">Team 2</span></td>
<td class="xl24" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">Team 3</span></td>
<td class="xl28" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">Team 1</span></td>
<td class="xl31" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">Team 2</span></td>
<td class="xl28" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">Team 3</span></td>
</tr>
<tr style="height: 13.5pt;" height="18">
<td class="xl27" style="height: 13.5pt; background-color: #ffff99; border: #f0f0f0;" height="18"> </td>
<td class="xl27" style="background-color: #ffff99; border: #f0f0f0;"> </td>
<td class="xl27" style="background-color: #ffff99; border: #f0f0f0;"> </td>
<td class="xl24" style="background-color: silver; border: #f0f0f0;"> </td>
<td class="xl24" style="background-color: silver; border: #f0f0f0;"> </td>
<td class="xl24" style="background-color: silver; border: #f0f0f0;"> </td>
<td class="xl28" style="background-color: #ccffff; border: #f0f0f0;"> </td>
<td class="xl28" style="background-color: #ccffff; border: #f0f0f0;"> </td>
<td class="xl28" style="background-color: #ccffff; border: #f0f0f0;"> </td>
</tr>
<tr style="height: 23.25pt;" height="31">
<td class="xl40" style="width: 66pt; height: 23.25pt; background-color: #ffff99; border: #f0f0f0;" width="88" height="31"><strong><span style="font-size: x-small; font-family: Arial;">Performance rates</span></strong></td>
<td class="xl37" style="background-color: #ffff99; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">…</span></td>
<td class="xl37" style="background-color: #ffff99; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">…</span></td>
<td class="xl38" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">***</span></td>
<td class="xl38" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">…</span></td>
<td class="xl38" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">…</span></td>
<td class="xl39" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">***</span></td>
<td class="xl39" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">…</span></td>
<td class="xl39" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">…</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl34" style="height: 12.75pt; background-color: #ffff99; border: #f0f0f0;" height="17"><span style="font-size: x-small; font-family: Arial;">100</span></td>
<td class="xl34" style="background-color: #ffff99; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">34</span></td>
<td class="xl34" style="background-color: #ffff99; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">63</span></td>
<td class="xl35" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">98</span></td>
<td class="xl35" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">87</span></td>
<td class="xl35" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">18</span></td>
<td class="xl36" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">20</span></td>
<td class="xl36" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">14</span></td>
<td class="xl36" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">3</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl34" style="height: 12.75pt; background-color: #ffff99; border: #f0f0f0;" height="17"><span style="font-size: x-small; font-family: Arial;">45</span></td>
<td class="xl34" style="background-color: #ffff99; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">25</span></td>
<td class="xl34" style="background-color: #ffff99; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">78</span></td>
<td class="xl35" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">69</span></td>
<td class="xl35" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">35</span></td>
<td class="xl35" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">99</span></td>
<td class="xl36" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">25</span></td>
<td class="xl36" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">13</span></td>
<td class="xl36" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">25</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl34" style="height: 12.75pt; background-color: #ffff99; border: #f0f0f0;" height="17"><span style="font-size: x-small; font-family: Arial;">67</span></td>
<td class="xl34" style="background-color: #ffff99; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">53</span></td>
<td class="xl34" style="background-color: #ffff99; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">23</span></td>
<td class="xl35" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">100</span></td>
<td class="xl35" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">43</span></td>
<td class="xl35" style="background-color: silver; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">78</span></td>
<td class="xl36" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">98</span></td>
<td class="xl36" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">55</span></td>
<td class="xl36" style="background-color: #ccffff; border: #f0f0f0;"><span style="font-size: x-small; font-family: Arial;">76</span></td>
</tr>
</tbody>
</table>
<p>Notice that the Team 2 and Team 3 columns have an ellipsis (&#8230;) in the header that indicates the column is still part of the Project 1 array element.  Start the next array element, Project 2 with 3 asterisks  (***) at the top of the column.</p>
<p><em>This is important:</em> The converter name is listed first, then then an ellipsis for each element of the team dimension, (since Team is our first dimension).  The Project dimensions are delimited by the *** and of course the time data goes down.</p>
<p>After setting up your spreadsheet, you  need to set the converter correctly.</p>
<p><em>Converter Dialog:</em></p>
<p><a href="http://blog.iseesystems.com/wp-content/uploads/2009/01/converter.png"><img class="alignnone size-full wp-image-400" title="Converter" src="http://blog.iseesystems.com/wp-content/uploads/2009/01/converter_cropped.png" alt="Converter" width="619" height="207" /><br />
</a></p>
<p>In the converter dialog, first check Array, change it from 1D to 2D, (Teams and Projects) and <em>leave Apply to All checked</em>.</p>
<p>Click on the &#8220;Become Graphical Function&#8221; button on the lower left.  This will switch to the Graphical Function dialog.</p>
<p><em>Graphical Function Dialog:</em></p>
<p><em><a href="http://blog.iseesystems.com/wp-content/uploads/2009/01/graphical_function.png"><img class="alignnone size-full wp-image-401" title="Graphical Function Dialogue" src="http://blog.iseesystems.com/wp-content/uploads/2009/01/graphical_function.png" alt="graphical_function" width="440" height="335" /></a><br />
</em></p>
<p>Uncheck Apply to All and be sure you have 3 data points set up for each Row/Column combination.  This corresponds to the three time data points we set up going down in the Excel sheet.</p>
<p><img class="size-full wp-image-420 alignnone" style="margin-top: 20px; margin-bottom: 20px;" title="Import dialog" src="http://blog.iseesystems.com/wp-content/uploads/2009/01/croppercapture45.png" alt="Import dialog" width="495" height="460" /></p>
<div id="attachment_423" class="wp-caption alignright" style="width: 246px"><img class="size-full wp-image-423" title="Data imported!" src="http://blog.iseesystems.com/wp-content/uploads/2009/01/hover.png" alt="Data imported!" width="236" height="166" /><p class="wp-caption-text">The data has been imported into the conveter</p></div>
<p>Open the Import Data dialog under the Edit Menu. Set up the link so that you are pointing to the spreadsheet you just created.</p>
<p>Select the Import Type you want and browse for the Excel file and worksheet you created.  The data orientation you pick should match the orientation of the spreadsheet.</p>
<p>Once you click OK, a message will let you know if data was successfully imported or not.</p>
<p>Now check to see that the data was imported by hovering over the arrayed variable.</p>
<p>It worked!! You’re good to go.</p>
<p> <a class="downloadLink" href="http://blog.iseesystems.com/wp-content/uploads/2009/01/2d_array_gf_example.zip">&gt;&gt; Download the Sample Files</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/setting-up-imports-for-2d-graphical-functions/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Save Time Setting up Data Imports</title>
		<link>http://blog.iseesystems.com/modeling-tips/save-time-setting-up-data-imports/</link>
		<comments>http://blog.iseesystems.com/modeling-tips/save-time-setting-up-data-imports/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 17:30:54 +0000</pubDate>
		<dc:creator>Joanne Egner</dc:creator>
				<category><![CDATA[Modeling Tips]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[import]]></category>

		<guid isPermaLink="false">http://blog.iseesystems.com/?p=204</guid>
		<description><![CDATA[Setting up an Excel spreadsheet to import data into your model is easy when you&#8217;ve got just a few variables but it can get cumbersome when you&#8217;ve got lots of variables, especially if some of them are arrayed.
If you want to avoid lots of copying, pasting, and switching back and forth between your model and Excel, we suggest using the [...]]]></description>
			<content:encoded><![CDATA[<p>Setting up an Excel spreadsheet to import data into your model is easy when you&#8217;ve got just a few variables but it can get cumbersome when you&#8217;ve got lots of variables, especially if some of them are arrayed.</p>
<p>If you want to avoid lots of copying, pasting, and switching back and forth between your model and Excel, we suggest using the <em>export</em> data feature to set up your data <em>import </em>spreadsheet.</p>
<p>Below are a few simple steps that can save you a bunch of time and headache:</p>
<div id="attachment_300" class="wp-caption alignright" style="width: 290px;"><a rel="lightbox[204]" href="http://blog.iseesystems.com/wp-content/uploads/2009/02/exportdata_new.png"><img class="size-full wp-image-300" title="Export data" src="http://blog.iseesystems.com/wp-content/uploads/2009/02/exportdata_sm.jpg" alt="Click to expand" width="280" height="281" /></a></div>
<p class="wp-caption-text">Click to expand</p>
<ol>
<li>
<div class="mceTemp">
<div class="mceTemp">In your model, create a Table with all of the variables that you want to import data to.</div>
</div>
</li>
<li>From the Edit menu, choose <strong>Export Data</strong>. The Export Data dialog will appear.</li>
<li>Under &#8220;Export Type&#8221;, select <strong>One Time.</strong></li>
<li>Under &#8220;Export Data Source&#8221;, select <strong>Export variables in table </strong>and select the table that you created in Step 1.</li>
<li>Under &#8220;Interval&#8221;, select <strong>One set of values</strong>.</li>
<li>Under &#8220;Export Destination&#8221;, <strong>Browse </strong>to an empty Excel file and Worksheet Name that you have created for your data import.</li>
<li>Select the &#8220;Data Orientation&#8221; that you prefer.</li>
<li>Click OK.</li>
</ol>
<p>Voila! Your import sheet should be all set to enter data values for each of the variable names AND it will be in the correct format.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.iseesystems.com/modeling-tips/save-time-setting-up-data-imports/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>




