[Mist-support] MIST Test Code Error

Jacob Barhak jacob.barhak at gmail.com
Fri Apr 1 18:30:05 PDT 2016


Hi Everett,

You are correct in your thinking. Tables are designed to do exactly what
you are trying to do. However, you are also right that humans have
difficulty with constructing those tables - it is not easy above 2D.

There is a simple workaround if you want to use only 3D tables. Use 2D
tables that you were able to construct with Iif statements that are easier
to comprehend for humans. I myself use this sometimes for clarity, yet this
is not the efficient way to go, especially if you have more dimensions.

The real solution is writing a table with more dimensions. I decided to
write an example for a 3D table that returns the column that calls it. Here
is the example:

Table([ [Year, [NaN,2013,2014]], [Male, [NaN,0,1]], [Age,[0,30,60,120]] ],
[ [[111,112,113],[121,122,123]] , [[211,212,213],[221,222,223]] ])

Note the following elements:
1. The first parameter passed to table is the list of dimensions - think of
it as the row/column titles of a table you write on paper
1a. Each dimension has a range attached to it
1b. If you use NaN in the first range parameter this means the range is
categorical otherwise it is continuous. In any case range numbers should be
presented in increasing order
1c. Note that this example is a bit more complicated than yours, since Age
is continuous = float while year and Male are categorical parameters =
integers.
2.  The second parameter of the Table function contains the data
2a. The inner-most dimension is the one defined last in the list of
dimensions while the outermost is the first defined.
2b. In this example the data corresponds to the row/column within the
dimension that called it - this is a simple way of making sure your table
structure is ok before populating real data.
3. Since this is confusing, I sometimes write test code as a python script
to test that I used tables properly. You can find some below corresponding
to this example.

Hopefully this is sufficient information for you to proceed and write your
own tables.

             Jacob


##### Test Script to use with table #####

import DataDef as DB
NaN = DB.NaN

# Table([ [Year, [NaN,2013,2014]], [Male, [NaN,0,1]], [Age,[0,30,60,120]]
], [ [[111,112,113],[121,122,123]] , [[211,212,213],[221,222,223]] ])
# Should bring back element 111
Result = DB.TableRunTime([ [2013, [NaN,2013,2014]], [0, [NaN,0,1]],
[30,[0,30,60,120]] ], [ [[111,112,113],[121,122,123]] ,
[[211,212,213],[221,222,223]] ])
assert(Result == 111)

# Should bring back element 112, note that Age 31 is in the category of
30<Age<=60
Result = DB.TableRunTime([ [2013, [NaN,2013,2014]], [0, [NaN,0,1]],
[31,[0,30,60,120]] ], [ [[111,112,113],[121,122,123]] ,
[[211,212,213],[221,222,223]] ])
assert(Result == 112)
# Should bring back element 112
Result = DB.TableRunTime([ [2013, [NaN,2013,2014]], [0, [NaN,0,1]],
[60,[0,30,60,120]] ], [ [[111,112,113],[121,122,123]] ,
[[211,212,213],[221,222,223]] ])
assert(Result == 112)
# Should bring back element 211
Result = DB.TableRunTime([ [2014, [NaN,2013,2014]], [0, [NaN,0,1]],
[1,[0,30,60,120]] ], [ [[111,112,113],[121,122,123]] ,
[[211,212,213],[221,222,223]] ])
assert(Result == 211)
# Should bring back element 223,  note that Age 1 is in the category of
0<Age<=30
Result = DB.TableRunTime([ [2014, [NaN,2013,2014]], [1, [NaN,0,1]],
[120,[0,30,60,120]] ], [ [[111,112,113],[121,122,123]] ,
[[211,212,213],[221,222,223]] ])
assert(Result == 223)
print 'All Tests Passed OK'










On Fri, Apr 1, 2016 at 11:50 AM, Everett Mumford <emumford at uw.edu> wrote:

> Hi Jacob,
>
>
>
> Thank you again for all of your help using MIST! I am hoping to run a
> simulation that allows for transition probabilities to change as time
> progresses for an individual simulant. I want to transition simulants from
> an ‘Alive’ state to a ‘Dead’ state. I have mortality rates (transition
> probabilities) that differ by age, sex, and year. As a simulant ages, I am
> hoping to make his/her mortality change. For instance, the mortality rate
> for a given disease is different for a 50 year old male in 2013 than it is
> for that same male when he is an 51 years old in 2014. The mortality rate
> for a 50 year old male in 2013 is also different than the mortality rate
> for a 50 year old male in 2014.
>
>
>
> I think the best way to accomplish my goal is to create a 3 dimensional
> object in the ‘transitions between states in a model page’. I have been
> able to create a 2 dimensional table with dummy data using the expression
> below.
>
>
>
> Table([[sex,[NaN,1,2]],[age,[NaN,1,2]]],[[.25,.6],[.3,.55]])
>
>
>
> I believe the expression above creates a table that looks like this:
>
>
>
> age=1
>
> age=2
>
> sex=1
>
> 0.25
>
> 0.6
>
> sex=2
>
> 0.3
>
> 0.55
>
>
>
> I am hoping that I can make a table like this (thought with far more ages)
> for each year so that I can apply the correct mortality rate for each
> age/sex/year cohort in MIST. I believe that this is possible after reading
> through the online help page, but am having trouble writing the correct
> syntax. Is it possible to create a 3-dimensional object like I am
> describing? Or is there a better way that I can accomplish my goal of
> assigning different transition probabilities by age/sex/year?
>
>
>
> Best regards,
>
> Everett
>
>
>
> *From:* Everett Mumford
> *Sent:* Thursday, March 24, 2016 10:05 AM
> *To:* 'Jacob Barhak' <jacob.barhak at gmail.com>
> *Cc:* mist-support at simtk.org
> *Subject:* RE: [Mist-support] MIST Test Code Error
>
>
>
> Hi Jacob,
>
>
>
> Downgrading Matplotlib seems to have fixed the issue. Thank you for all of
> your help with this. I have really enjoyed using the MIST thus far and
> think that it will be very useful for my research.
>
>
>
> Best regards,
>
> Everett
>
>
>
> *From:* Jacob Barhak [mailto:jacob.barhak at gmail.com
> <jacob.barhak at gmail.com>]
> *Sent:* Thursday, March 24, 2016 12:30 AM
> *To:* Everett Mumford <emumford at uw.edu>
> *Cc:* mist-support at simtk.org
>
> *Subject:* Re: [Mist-support] MIST Test Code Error
>
>
>
> Hi Everett,
>
>
>
> It seems that the new version of Anaconda uses by default a new version of
> Matplotlib that breaks previous MIST code.
>
>
>
> If you wish to use MIST 0_92_0_0 with the plot capability, you should
> downgrade Matplotlib. Within anaconda, you can do this by using the command:
>
>
>
> conda install matplotlib=1.3.1
>
>
>
> This worked on my windows machine. And is a suitable ad hoc solution if
> you have no code that depends on a newer matplotlib version.
>
>
>
> Note that the plot capability is related to the MIST script
> CreatePlotsFromCSV.py. This script is rarely used for basic modeling and
> simulation, and you can use other MIST capabilities without changing the
> matplotlib version, as long as you ignore the plot capabilities in the
> CreatePlotsFromCSV.py script.
>
>
>
> If TestCode.py does not report any other error, you should be good to
> proceed. Yet it is better to test this at least once by using the
> matplotlib downgrade command.
>
>
>
> I will check downstream to see what was upgraded in Matplotlib to avoid
> this issue in the future and may provide other solutions. I also opened an
> issue in Github to address this.
>
>
>
> Let me know if you encounter any other issues.
>
>
>
> Yet hopefully, this solution will allow you to proceed for now.
>
>
>
>           Jacob
>
>
>
>
>
> On Wed, Mar 23, 2016 at 7:10 PM, Everett Mumford <emumford at uw.edu> wrote:
>
> Hi Jacob,
>
>
>
> Thank you for your prompt response. I am using Windows 8.1. I am using
> Anaconda (64-BIT) for Python 2.7. My matplotlib version is 1.5.1.
>
>
>
> Best regards,
>
> Everett Mumford
>
>
>
> *From:* Jacob Barhak [mailto:jacob.barhak at gmail.com]
> *Sent:* Wednesday, March 23, 2016 4:52 PM
> *To:* Everett Mumford <emumford at uw.edu>
> *Cc:* mist-support at simtk.org
> *Subject:* Re: [Mist-support] MIST Test Code Error
>
>
>
> Hi Everett,
>
> What OS are you using? What kind of python distribution you are using and
> what is your matplotlib version?
> If you are using anaconda, can you specify what version?
>
> This will help isolate the issue and treat it.
>
> The goods news are that if only the plots do not pass the test script,
> then you can still use the system for modeling and simulation and export
> data to create plots outside the system.
>
>         Jacob
>
> On Mar 23, 2016 6:40 PM, "Everett Mumford" <emumford at uw.edu> wrote:
>
> Hi MIST support,
>
>
>
> I am having issues running TestCode.py. The code gets an error when it
> reaches the PlotGeneration scripts. The code does not always error out on
> the same script (e.g. I have run into errors when the code tries to run
> PlotGeneration5_rmjj.py, PlotGenerationoit6qb.py, etc.). I have tried
> uninstalling and then reinstalling the package several times.
>
>
>
> Have you seen a similar error? And can you please provide assistance?
>
>
>
> Thanks!
>
>
>
> Best regards,
>
> Everett Mumford
>
>
> _______________________________________________
> MIST-support mailing list
> MIST-support at simtk.org
> https://simtk.org/mailman/listinfo/mist-support
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://simtk.org/pipermail/mist-support/attachments/20160401/448e98c1/attachment-0001.html>


More information about the MIST-support mailing list