Petra Heijnen

115 Reputation

2 Badges

13 years, 179 days

MaplePrimes Activity


These are answers submitted by Petra Heijnen

Thank you very much for the work.

It worked very well. I've more files like this. So this is very very useful.

 

I solved my problem by making a list of probabilities once and then search in this list. Not a very elegant solution, but good enough for my purpose.
If someone knows a more elegant way, I'm always interested.

Make probability list
> ProbList:=proc(lambda,kmin)
local P,i,p,k:
P:=[seq(0,k=0..kmin-1)]: p:=0:
for k from kmin to 1000 do
 p:=p+k^(-lambda)/Zeta(0,lambda,kmin):
 P:=[op(P),p]:
od:
return P:
end proc:
Search probability list
> SearchList:=proc(P,s)
local i:
i:=2:
while s>P[i] do i:=i+1: od:
return i-1:
end proc:
Generate random sample of size N from power law distribution (k>=kmin) with parameter g
> GenSample:=proc(lambda,kmin,N)
local P,U,S,k,f:
P:=ProbList(lambda,kmin):
f:=x->SearchList(P,x):
U:=RandomVariable(Uniform(0,1)):
S:=Sample(U,N):
convert(map(f,S),list):
end proc:

 

How does Maple draw a sample from an Exponential distribution.
It has more or less the same structure as a power-law distribtution, although the power-law is (in my case) discrete.
But sampling from an exponential distribution is so very fast.
Is there a possibility to use the same procedure as Maple does for my power-law distribution?

 

Thanks for this procedure.
Problem is that I really need large (n>1000) and many samples to find the critical values for a Kolmogorov Smirnov statistic.
Using fsolve for all elements in the sample, makes the procedure quite slow.
Is there a way to avoid this?

At least, I realize now that I can use the built-in Zeta fuction. That is already one improvement.

ZetaII:=proc(g,a)
local i:
sum(1/(i+a)^g,i=0..infinity):
end proc:

But I don't think that the ZetaII function is causing the problem. I get the same problem if I make the piecewise function simpler.
See, the example below. The total sum of probabilities equals 1, since f(1)=f(2)=f(3)=1/3.

> f:=piecewise(k>0 and k<4 and k::integer,1/3,0):
ND:=Distribution(PDF=unapply(f,k)):
X:=RandomVariable(ND):
Sample(X,5);
Error, (in simplify) too many levels of recursion

Even if I make it a continuous distribution, I get an error, although a different one then before.

> f:=piecewise(k>=1 and k<=3,1/3,0):

ND:=Distribution(PDF=unapply(f,k)):

X:=RandomVariable(ND):

Sample(X,5);

Error, (in Statistics:-Sample) 1.000300000 .. FAIL is an invalid range

 

I really have no idea what goes wrong.

Thanks for helping.

 

The maple tags didn't show nice. This is what I meant:

 

f:=simplify(piecewise(k>=kmin and k::integer, k^(-lambda)/ZetaII(lambda,kmin),0));
ND:=Distribution(PDF = unapply(f,k));
X:=RandomVariable(ND):
Sample(X,5);

 

I use Maple 12. Thank for your suggestion. By that I can at least change the colors of nodes and edges.
I suppose that it is impossible to change the form of the nodes as well? For me, it would be better if they were circles with a black boundary.

But thanks a lot for your reply.

It worked

Page 1 of 1