Post Reply 
python libraries
04-22-2021, 06:58 PM
Post: #12
RE: python libraries
(04-22-2021 04:24 PM)robmio Wrote:  Although the "HP PRIME" G2 calculator is very fast, when it calculates the integral to obtain the "Studentize q Rance distribution CDF" function, it takes about 33 seconds. Is there a way, with Python, to reduce the computation time of this function?
...
This is one of the reasons why I asked if HP PRIME can "import" the Scipy library, Numpy or scipy.integrate (see https://www.youtube.com/watch?v=lzp48-AzUO0).

Best regards, Roberto
I don't think that any Python scientific library is faster than my own adaptive numeric integration algorithm with the same accuracy (for multiple integrals Monte-Carlo like methods will be much faster but much less accurate). You can try to optimize your call. For example if your bounds are infinity (something that is impossible with a non-CAS language like Python), the CAS will do a change of variable to have finite boundaries, and this might slow down the computation compared to taking reasonable finite boundaries, e.g. z=-10.0 to 10.0 in the inner integral. You could try:
Code:

f(q,s):=1/sqrt(2*π)* integrate(exp((-z^2)/2)*
(normald_cdf(0,1,z+q*s)-normald_cdf(0,1,z))^(k-1),z,-10.0,10.0);
p(k,ν,q):=(√(2*π)*k*ν^(ν/2))/(Gamma(ν/2)*2^(ν/2-1))/(√(2*π))*
integrate(s^(ν-1)*e^(-ν*s^2/2)*f(q,s),s,1e-6,5.0);
where you replace 1e-6 and 5.0 by something appropriate (I have no idea of this function and what arguments are expected).
Of course this will be much slower than a good implementation of a special function using for example series expansion for some range of arguments, and asymptotic expansion for other ranges, or Tchebyscheff polynomial approximations, etc.

And MicroPython is not Python, porting any (large) library to MicroPython to the Prime would require work. It's much easier to port a C library with the same functionnalities, for example blas+lapack instead of numpy.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
python libraries - robmio - 04-20-2021, 11:49 AM
RE: python libraries - jonmoore - 04-20-2021, 05:21 PM
RE: python libraries - parisse - 04-21-2021, 02:20 PM
RE: python libraries - jonmoore - 04-22-2021, 12:44 PM
RE: python libraries - toml_12953 - 04-22-2021, 01:28 PM
RE: python libraries - John Keith - 04-22-2021, 04:11 PM
RE: python libraries - roadrunner - 04-22-2021, 01:07 PM
RE: python libraries - parisse - 04-22-2021, 03:07 PM
RE: python libraries - jonmoore - 04-22-2021, 04:38 PM
RE: python libraries - robmio - 04-22-2021, 04:24 PM
RE: python libraries - parisse - 04-22-2021 06:58 PM
RE: python libraries - jonmoore - 04-23-2021, 05:13 AM
RE: python libraries - parisse - 04-23-2021, 05:51 AM
RE: python libraries - jonmoore - 04-23-2021, 09:23 AM
RE: python libraries - parisse - 04-23-2021, 10:54 AM
RE: python libraries - jonmoore - 04-23-2021, 11:08 AM



User(s) browsing this thread: 1 Guest(s)