Page 1 of 2

Hypergeometric function

Posted: Tue Nov 14, 2017 7:08 am
by lorenzo.cioni
Hi
is there any way of implementing an hypergeometric function 1F1 with 3 parameters a, b and c in Vensim PLE Plus obviously through some other functions?
Al the best and many thanks for any suggestion.
Lorenzo

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 7:54 am
by Administrator
Can you give an example of what you want to implement?

And if you upload what you've tried, that would help as well.

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 8:27 am
by lorenzo.cioni
Administrator wrote:Can you give an example of what you want to implement?

And if you upload what you've tried, that would help as well.
Hi
thank you a lot. I'm trying to use Vensim to model a probability of infection with a relation I found in Teunis et alii 2016 "A generalized dose-response relationship for adenovirus infection and illness by exposuere pathway" where you can read that (relation (2))
Pinf(dose|a,b)=1-1F1(a,a+b, -dose)
At the present I've no model to upload, sorry.
All the best.
Lorenzo

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 10:00 am
by Administrator
Have you tried to replicate the 1F1 function in Vensim? The source code (in C (GNU Scientific Library)) is available on the internet.

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 10:19 am
by lorenzo.cioni
Administrator wrote:Have you tried to replicate the 1F1 function in Vensim? The source code (in C (GNU Scientific Library)) is available on the internet.
Hi
I just looked for some definitions and I found out some here
http://functions.wolfram.com/Hypergeome ... ric1F1/02/
but none, imho, directly replicable in Vensim.... any suggestion? I'm using Vensim PLE.
Lorenzo

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 10:49 am
by lorenzo.cioni
I found this site
http://keisan.casio.com/exec/system/1349143651
that looks nice. Unfortunately my z parameter is a dose parameter that increases over time depending on a certain number of other parameters and from the running time of my simulations too so I cannot use that tool...
any idea?
Lorenzo

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 10:55 am
by Administrator
Unfortunately, it looks like the easiest option might be to build an external function to do this (using the GNU Scientific Library).

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 11:13 am
by lorenzo.cioni
Administrator wrote:Unfortunately, it looks like the easiest option might be to build an external function to do this (using the GNU Scientific Library).
Thank you... unfortunately for me I'm a newbie of programming and have no idea of GNU Scientific Library so it would be very nice of you if you could give me some details, examples and references on how to proceed in Vensim PLE.
All the best.
Lorenzo

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 11:55 am
by Administrator
External functions cannot be implemented in PLE.

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 12:00 pm
by lorenzo.cioni
Administrator wrote:External functions cannot be implemented in PLE.
Gosh... any shortcut for solving my problem?
Lorenzo

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 12:04 pm
by Administrator
I've already suggested trying to replicate the function using the GSL source files, this is all you can do in PLE.

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 12:16 pm
by lorenzo.cioni
Administrator wrote:I've already suggested trying to replicate the function using the GSL source files, this is all you can do in PLE.
I remember but you too should remember that I asked you some more details on how to proceed and I'm still waiting... 8)
Lorenzo

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 1:00 pm
by Administrator
lorenzo.cioni wrote:
Administrator wrote:how to proceed and I'm still waiting
Search Google fpr GSL 1F1, this will give you the source code. Try and replicate this in Vensim.

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 4:18 pm
by tomfid
The difference between the hypergeometric distribution and the binomial distribution is drawing without vs. with replacement.

So, as long as the populations N and K are large with respect to the number drawn n, or n = 0 or 1, you can get a close approximation with RANDOM BINOMIAL.

This will generally be true as long as TIME STEP is small with respect to the time scale of the infection process.

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 5:13 pm
by lorenzo.cioni
tomfid wrote:The difference between the hypergeometric distribution and the binomial distribution is drawing without vs. with replacement.

So, as long as the populations N and K are large with respect to the number drawn n, or n = 0 or 1, you can get a close approximation with RANDOM BINOMIAL.

This will generally be true as long as TIME STEP is small with respect to the time scale of the infection process.
Hi tomfid
maybe there is a misunderstanding... I'm talking about an hypergeometric function and not distribution: are you sure they are the same thing? :roll:
Anyway thank you a lot.
Lorenzo

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 5:15 pm
by lorenzo.cioni
Administrator wrote:
lorenzo.cioni wrote:
Administrator wrote:how to proceed and I'm still waiting
Search Google fpr GSL 1F1, this will give you the source code. Try and replicate this in Vensim.
I have searched and I've found that the funciotn is implemented through a routine called gsl_sf_hyperg_1F1 but I was able to find only references in pdf files but no source code, could you please be more precise?
Thank you a lot.
Lorenzo

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 5:51 pm
by lorenzo.cioni
lorenzo.cioni wrote:
Administrator wrote:
lorenzo.cioni wrote:
Search Google fpr GSL 1F1, this will give you the source code. Try and replicate this in Vensim.
I have searched and I've found that the funciotn is implemented through a routine called gsl_sf_hyperg_1F1 but I was able to find only references in pdf files but no source code, could you please be more precise?
Thank you a lot.
Lorenzo
A curiosity: any relation with gamma functions/distributions?
L.

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 6:03 pm
by Administrator
lorenzo.cioni wrote:could you please be more precise?
No (I had never heard of the function before you posted today).

I found the GNU Scientific Library when searching for 1F1. All I can suggest is downloading the source code and searching it.

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 6:08 pm
by lorenzo.cioni
Administrator wrote:
lorenzo.cioni wrote:could you please be more precise?
No (I had never heard of the function before you posted today).

I found the GNU Scientific Library when searching for 1F1. All I can suggest is downloading the source code and searching it.
Ok, thank you a lot.. at the ned I found the code but I'm 99% sure it cannot be used within Vensim without defining an external function and this definitely excludes the PLE version of the program.... :( :(
Lorenzo

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 7:01 pm
by tomfid
Ah ... I think the function is just a generalization of the series that appears in the pdf of the distribution. Seems like you should be able to implement the integral representation here,
http://mathworld.wolfram.com/ConfluentH ... tKind.html
because Vensim has the log Gamma function. (Maybe not in PLE though.)

What the heck are they using this for?

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 7:09 pm
by lorenzo.cioni
tomfid wrote:Ah ... I think the function is just a generalization of the series that appears in the pdf of the distribution. Seems like you should be able to implement the integral representation here,
http://mathworld.wolfram.com/ConfluentH ... tKind.html
because Vensim has the log Gamma function. (Maybe not in PLE though.)

What the heck are they using this for?
Hi tomfit
if I understand you well you are referring to relation (3). Are you sure it can be implemented in a Vensim model? :? :?
Lorenzo

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 7:11 pm
by lorenzo.cioni
lorenzo.cioni wrote:
tomfid wrote:Ah ... I think the function is just a generalization of the series that appears in the pdf of the distribution. Seems like you should be able to implement the integral representation here,
http://mathworld.wolfram.com/ConfluentH ... tKind.html
because Vensim has the log Gamma function. (Maybe not in PLE though.)

What the heck are they using this for?
Hi tomfit
if I understand you well you are referring to relation (3). Are you sure it can be implemented in a Vensim model? :? :?
Lorenzo
Tomfid, sorry

Re: Hypergeometric function

Posted: Tue Nov 14, 2017 7:26 pm
by tomfid
Tomfid, sorry
No problem.

I'm not 100% certain, but the integral breaks up to terms with e^x, xe^x, and x^2e^x, so it should be solvable. The gamma function may be a problem in PLE though.

Re: Hypergeometric function

Posted: Wed Nov 15, 2017 8:19 am
by lorenzo.cioni
tomfid wrote:
Tomfid, sorry
No problem.

I'm not 100% certain, but the integral breaks up to terms with e^x, xe^x, and x^2e^x, so it should be solvable. The gamma function may be a problem in PLE though.
Hi Tomfid
I was able to find this nice calculator
http://keisan.casio.com/exec/system/1349143651
so I will get a set of points of my dependent variable P having fixed the values of a and b and having only z vary over a certain set of values so to be able to implemet my function with a lookup in Vensim with z (the dose) as the only independent variable.
Thank you a lot (and to Adminisrtator too, of course) for having devoted part of your time and efforts to help me.
Lorenzo
PS I'll let you know....

Re: Hypergeometric function

Posted: Sat Nov 18, 2017 4:39 pm
by lorenzo.cioni
Hi
could you please check the attached model and explain the seemingly absurd behavior of the 1F1 variable through which I'm trying to implement the infinite series expression of such the 1F1 Hypergeometric function?
How many terms should I consider? Is there any better and more clever way (in Vensim, of course)?
All the best.
Lorenzo