Gillee

157 Reputation

8 Badges

4 years, 111 days

MaplePrimes Activity


These are questions asked by Gillee

Hi,

I was able to get Procedure 2 to work using a for - do loop. I was wondering if it is possible to speed up the calculation by using map to find the number of roots? I do not fully understand map and passing data.


tgf := proc(a, b, c, d, t, m, n)

          local X;

          X := [solve(abs(a*x + b) + abs(c*x + d) - t*x^2 + m*x - n = 0)]; 

          return nops(X);

end proc;

res := CodeTools:-Usage(map(tgf, L));
Error, (in CodeTools:-Usage) invalid input: tgf uses a 2nd argument, b, which is missing

The L Array is tripping me up, here is a partial display of the array:

Array(1..262, 1..7, [[5,2,3,9,1,1,1],[5,2,3,9,2,1,1],[5,4,3,7,1,1,1],[5,4,3,7,2,1,1],[5,5,3,6,1,1,1],[5,5,3,6,2,1,1],[5,5,4,8,1,1,2],[5,5,4,8,2,1,2], ... ,[10,10,5,10,2,2,2]], datatype = integer[4]).

I made L Array into a list of list, R. Somewhat works.

Here is the script:

Roots_with_map.mw 

Thanks for any help.

I was using the DirectSearch:-GlobalSearch function on a LaguerrelL for values of 4 and 5. At a value of 4 I get a solution, but at 5 I get an error message that the Kernel connection is lost. I ran this script on two different PCs using Maple 2019 and 2020 with WIN 10 and get the same results. Why does this happen?

 

Here is my worksheet. Thanks for looking.


mysearch2.mw


 

Hello,

I have noticed a small decrease in real time running 4 cpus versus 1 cpu. I am not sure if implemented the multi-threads  feature correctly or efficiently. Could you please show me some alternative coding methods with even more improvements? Thanks in advance.  

 

# Generative Model

n_trials := 16:
n_sample := 1:

subscribers := Vector[row](n_draw):
gen_model := proc(ib,ie)
        global n_trials, n_sample, prior_rate;
        local i, Y;
        for i from ib to ie do
          Y := RandomVariable(Binomial(n_trials, prior_rate(i)));
          subscribers(i) := apply(Sample(Y, n_sample), 1):
        end do:
        return subscribers:
end proc:

# Multi-threads, use 4 cpus
gm1 := Create(gen_model(1, n_draw/4), out1):
gm2 := Create(gen_model(n_draw/4 + 1, n_draw/2), out2):
gm3 := Create(gen_model(n_draw/2 + 1, 3*n_draw/4), out3):
gm4 := Create(gen_model(3*n_draw/4 + 1, n_draw), out4):


Usage(Wait(gm1, gm2, gm3, gm4));
memory used=1.97GiB, alloc change=0.52GiB, cpu time=83.56s, real time=45.52s, gc time=6.20s

 

ApproxBayesComp_Threads_2.mw

ApproxBayesComp_for_loop.mw

The observed data were 6 out 16 people signed up. Priors were defined by a uniform distribution. A Generative Model utilized a binomial distribution. A distribution of subscribers were generated, see plot below. By filtering the subscribers distribution for the value is equal 6, the posterior distribution was obtained. Why is the frequency the highest for subscribers = 16? Where did I go wrong in coding this problem?

Hello,

I have a procedure, SoS that returns the value for sos. After compiling the procedure, I get float(undefined) for the return value. How can this be fixed?

 

Thanks so much for your time.

 


 

restart; kernelopts(version); interface(version)

`Standard Worksheet Interface, Maple 2019.2, Windows 10, November 26 2019 Build ID 1435526`

(1)

NULL``

Erealm := Array([1235.773, 1383.61, 1457.262, 1500.264, 1550.184, 1612.161, 512.7612, 656.6554, 743.6461, 793.375, 855.7937, 939.1199, 79.9523, 128.1375, 167.1459, 193.592, 230.5401, 287.8348, 22.389, 29.41424, 35.91883, 40.86366, 48.79128, 63.4475, 15.34275, 17.10101, 18.63288, 19.77424, 21.5671, 24.84739, 13.8321, 14.52843, 15.07626, 15.47014, 16.07713, 17.16574, 13.13383, 13.63704, 13.95888, 14.16849, 14.46123, 14.93971, 12.76736, 13.2203, 13.50072, 13.673, 13.89852, 14.23242], datatype = float[8]); LFm := Array([.156795, .1248161, .1108722, .1032334, 0.9474591e-1, 0.8496174e-1, .361361, .3020133, .2706018, .2546556, .2356126, .2121333, .6883826, .6532309, .6155578, .5906291, .5578895, .5123917, .394458, .5326358, .6095816, .6489291, .6894866, .7232845, .1456468, .2226473, .2826954, .3228541, .3789496, .4632182, 0.6758032e-1, 0.9437384e-1, .1198126, .1387971, .1680719, .2181531, 0.5173809e-1, 0.586771e-1, 0.6591736e-1, 0.7206892e-1, 0.8243504e-1, .1024519, 0.457877e-1, 0.493836e-1, 0.5191291e-1, 0.539114e-1, 0.5708074e-1, 0.6330242e-1], datatype = float[8]); maxx := ArrayNumElems(LFm); E0 := 13.; E00 := 4200.; alpha := .5; beta := 0.7e-1
NULL

``

SoS := proc (E0::float, E00::float, alpha::float, beta::float, maxx::integer, Erealm::(Array(datatype = float[8])), LFm::(Array(datatype = float[8])))::float; local k, omegatau, Ecomplex, Erealc, Eimagc, LFc, sos; sos := 0.; for k to maxx do Ecomplex := Complex(Erealm[k], Erealm[k]*LFm[k]); omegatau := abs(-I*(((E0-E00)/(Ecomplex-E00))^(1/beta)-1)^(1/alpha)); Erealc := Re(E00+(E0-E00)/(1+(I*omegatau)^alpha)^beta); Eimagc := Im(E00+(E0-E00)/(1+(I*omegatau)^alpha)^beta); LFc := Eimagc/Erealc; sos := sos+(log10(Erealm[k])-log10(Erealc))^2+(LFm[k]-LFc)^2 end do; return sos end proc

``

``

SoS(E0, E00, alpha, beta, maxx, Erealm, LFm)

HFloat(0.015392438292813794)

(2)

cSoS := Compiler:-Compile(SoS); cSoS(E0, E00, alpha, beta, maxx, Erealm, LFm)

Float(undefined)

(3)

``

``


 

Download Compile_proc.mw

 

1 2 3 Page 2 of 3