KANIPRATHI / bayesian-inference

Automatically exported from code.google.com/p/bayesian-inference
0 stars 0 forks source link

Parameter names and values as a dictionnary in gillespie method #5

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
This is just an idea: couldn't the gillespie function use a dictionnary instead 
of a list of values?

This would allow the transition functions to be more readable (and avoid wrong 
results from switching two indexes by accident):

'''
rates = [.001,.1]
prop=[lambda r, ini:r[0]*ini[0]*ini[1],lambda r,ini:r[0]*ini[1]]
'''
(as a side matter, I think one of those r[] should be one, so that people 
recover - see line 117 of gillespie.py)

Would become

'''
rates = {'inf':.001, 'rec':.1}
#prop=[lambda r, ini:r['inf']*ini[0]*ini[1],lambda r,ini:r['rec']*ini[1]]
'''

Original issue reported on code.google.com by rany...@gmail.com on 22 Nov 2010 at 6:21

GoogleCodeExporter commented 8 years ago
Unless this affects performance a lot...

Original comment by rany...@gmail.com on 22 Nov 2010 at 6:22

GoogleCodeExporter commented 8 years ago
One reason against doing this is the increased verbosity in the specification 
of the propensity functions, Although it may make it more readable, 
particularly in large models.

with regards to performance, I'd have to see.

Also, I think that rates being a list makes the code much simpler cause we can 
use the positional information. Dictionaries do not maintain the original order

Original comment by fccoelho on 22 Nov 2010 at 6:32

GoogleCodeExporter commented 8 years ago
You can always use the sorted keys to get the same order, but when do you use 
this information in the code?

Original comment by rany...@gmail.com on 22 Nov 2010 at 6:38

GoogleCodeExporter commented 8 years ago
In the GSSA method in the Model Class.

if you want to try and modify it, go ahead.

Original comment by fccoelho on 22 Nov 2010 at 7:15

GoogleCodeExporter commented 8 years ago
I just modified it and it works, I haven't checked the effect on runtime yet.

Original comment by rany...@gmail.com on 22 Nov 2010 at 7:32

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks,

I'll test them side by side and see which one is faster. I guess it'll be a 
matter of which is faster: an array or a dictionary lookup.

Original comment by fccoelho on 23 Nov 2010 at 9:35

GoogleCodeExporter commented 8 years ago

Original comment by fccoelho on 23 Nov 2010 at 9:36

GoogleCodeExporter commented 8 years ago
I tested it once yesterday.
The tuple took 27 seconds to run,
a dictionnary with numerical keys took 35 seconds,
a dictionnary with string keys took 47 seconds.

These numbers are just from one time each, but it's almost double the time...

Oh well = )

Original comment by rany...@gmail.com on 23 Nov 2010 at 10:13