afeddersen

444 Reputation

7 Badges

11 years, 149 days
I study psychology and economics with a very quantitative approach to each. I specialised on statistical methods, quantitative diagnostics, portfoio analysis and econometrics. Furthermore I am interested (and above that theoretically and empirlcally involved) in poker, chess and performing arts.

MaplePrimes Activity


These are answers submitted by afeddersen

You may try x[i] if i is meant to be a subscript of x.

After restart: everything worked well.

The problem occured after

assume(mu>0,sigma>0):

When this line is preceded, Maple gives another output.

The same occurs when

assume(mu::real, sigma>0):

is preceded.

Thank you Alec for explaining your EV calculating code in more detail - that helped a lot to understand and implement new code!

Thank you Erik for showing how to use the C code at least in this special case. This helps me to have a go at those more efficient ways of carrying out MC simulations. Up to now I was not familliar with using any external C code. 

Thank you for showing how to calculate the EVs, though I will need some time to understand some of the commands you used (e.g. the sequence of 'convert' commands).

Anyway, for more complex problems MCS might be easier, than calculating the exact EVs.

Thanks pagan.

Without using the compiler by just using Arrays instead of lists and eliminate the concatenations, I saved 50% of the time.

I restructured as follows:

restart;
with(Statistics):
interface(rtablesize=12):
L := Array([2, 2, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]):
Y := Array(1..6,[seq(0,i=2..7)]):
X := Array(1..6,[seq(0,i=2..7)]):
n:=792000:
Digits:=2:
st:=time():
for i to n do
L:=Shuffle(L):
E1:=add(L[j],j=1..5):
X[E1-1] := X[E1-1]+1:
E2:=add(L[j],j=6..10):
Y[E1-1] := Y[E1-1] + E2:
end do:
time()-st;


Now the time needed is 30. Before it was 60.

I don´t know, why my comment above was displayed so bad.

Thanks pagan.
Without using the compiler by just using Arrays instead of lists and eliminate the concatenations, I saved 50% of the time.
I restructured as follows:

restart;
with(Statistics):
interface(rtablesize=12):
L := Array([2, 2, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]):
Y := Array(1..6,[seq(0,i=2..7)]):
X := Array(1..6,[seq(0,i=2..7)]):
n:=792000:
Digits:=2:
st:=time():
for i to n do
L:=Shuffle(L):
E1:=add(L[j],j=1..5):
X[E1-1] := X[E1-1]+1:
E2:=add(L[j],j=6..10):
Y[E1-1] := Y[E1-1] + E2:
end do:
time()-st;


Now the time needed is 30. Before it was 60.

Thank you very much.

That helped a lot.

I see.

Is there a way to access that first solution by some kind of code, without retyping that whole expression?

First of all I´d like to thank you for all the comments on that topic.

I am eager to learn, especially about efficiency in Maple, since I plan to do more MC simulations in the future.

Besides the fact that my results also looked pretty random, when I added the assignments (X1..X7:=0) 'alec' suggested above and my mistake about somehow reverting the order of the theoretical distribution, here is what I intended:

I tried to simulate a card game, where the numbers represent card values.

When I began, I tried to use stacks, since they firstly seemed to be structured like card decks.

Unfortunately I was not able to shuffle these stacks efficiently, i.e. without converting them primarily into another data structure (i.e. a list or an Array), since a list or an Array can be suffled by using the Statistics: -Shuffle command.

Now I switched over to represent the card deck a priori as list.

The MC simulation above was just a first test to let Maple calculate expected values of the sum of the card values of the second five cards drawn depending on the sum of the card values of the first five cards drawn. That way I can check whether the code does the right thing, before going on to more complex questions.

The problem is I have yet much to learn about how to code my intentions most efficiently in Maple.

Therefore I am very thankful for any suggestions, hints and the critisism on my approaches.

 

Thank you. That helped very much.

Thx Robert Israel,

once again you enlightened me.

Thanks for your help, but neither did it work with Maple 12.01, nor could I find any help for the h´keyword 'UseAssumptions'.

Seems strange. Any idea what to do?

Thanks for clarification on that point.
In the meantime I realized, that there is also an interdependency between mu and sigma, as both are functions of n and p.
We obtain sigma = sqrt(mu*(1-p)).

Now if I use adequate numbers (i.e. ones that account for the functional relationship between mu and sigma), such as phi=.2, p=.5, mu=2, sigma=1, then it works and both expressions are identical.
Anyway, if I use other 'adequate' numbers, such as phi=.2, p=.75, mu=2, sigma=.5, then again it doesn´t work.

Is there a way to solve that problem?

First of all I´ll have to admit that I feel a bit sheepish about the displayed problem. Obviously, the way I presented the problem, it is none, because one expression is conditional on 'n' and the other is conditional on 'p'.
Indeed I carried out both ways, but I didn´t wonder, why their results weren´t identical.
Anyway, I made a mistake. Here´s the 'real' problem:
 

I started with the following expression:

k := n*(phi+ln(-1/(-exp(phi)+exp(phi)*p-p)))/phi;

 

and four equations:

{p=mu/n};

{n=mu/p};

{p = (1/2)*(n+sqrt(n^2-4*n*sigma^2))/n};

{n=-((sigma)^(2))/(p*(p-1))};
 

Afterwards I carried out two substitution steps:

1. Substitute mu/n for p in k and store the return as j.

j:=subs({p=mu/n},k);
 

2. Substitute -((sigma)^(2))/(p*(p-1)) for n in j.

m1:=subs({n=-((sigma)^(2))/(p*(p-1))},j);



Then I carried out the same two steps in reversed order i.e.:

1. Substitute -((sigma)^(2))/(p*(p-1)) for n in k and store the return as j.

j:=subs({p = (1/2)*(n+sqrt(n^2-4*n*sigma^2))/n},k);

 

2. Substitute mu/n for p in k and store the return as j.

m2:=subs({n=mu/p},j);

 

Now the problem is that m1 and m2 are not identical:

for i to 2 do


M||i:=unapply(m||i,p,phi,mu,sigma);


evalf(M||i(0.2,0.5,2,1));


end do;



 

 

Thanks for introducing the 'unapply' command to me.

This is a very elegant way to check.

1 2 Page 1 of 2