Random draw in python function

Hi,

This may be a silly question because I'm a python novice. I'm working on a microsimulation and have defined a few python functions to update trackers and the like. In some cases, I need a random draw from a uniform(0, 1) distribution within those functions. To accomplish that, I've defined a uniform distribution and then I draw from the distribution in the python functions as follows:

rand = treeage.eval("DistForce(4)"),

where 4 is the index of the uniform distribution I defined. 

Is there a more computationally efficient way to draw from a uniform distribution in a python function within Treeage?

Thanks, 

Bill 

 

 

 

 

 

0

Comments

2 comments
  • Hi Bill,

    That's exactly what I do. I have looked up how to draw from distributions within regular Python (what else? Googled it) and there are methods. I just haven't gotten around to trying them out. Another option is to install native Python on your computer and then install numpy and scipy, i.e. numerical and scientific Python, on top of native Python. I believe these have built in distribution sampling. Then use the option to have TreeAge use your Python install rather than the built in one. You can get this stuff at python.org

    1
    Comment actions Permalink
  • Thanks David! I may look into other ways. I remember reading that treeage.eval calls are fairly slow, but maybe faster than using native Python. 

    0
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post