Re: Re: Mathematica gets stuck, only thing I can do is quit kernel
- To: mathgroup at smc.vnet.net
- Subject: [mg106873] Re: [mg106815] Re: Mathematica gets stuck, only thing I can do is quit kernel
- From: Anh Ngoc LAI <laianhngoc at yahoo.com>
- Date: Mon, 25 Jan 2010 05:09:54 -0500 (EST)
Hi, I stuck at 25. Without enter in your code, i found that if you drop out the If[RandomReal[]=A3alpha,... in your last definition run:={contributions=Table[0,{n}]; payoffs=Table[0,{n}]; contribute/@agents; shuffledagents=RandomSample[agents]; reward/@shuffledagents; AppendTo[contributionsovertime,Total[Ceiling[contributions]]]; Do[(*If[RandomReal[]=A3alpha,*)globalimitation[agents[[i]]](*;]*),{i,n}]; wmatrix*=(1-discount);} your program goes to 100 without problem. So that can come from this If or SeedRandom[91733], RandomReal[]. Hope that help. LAI. --- On Sun, 1/24/10, Anh Ngoc LAI <laianhngoc at yahoo.com> wrote: From: Anh Ngoc LAI <laianhngoc at yahoo.com> Subject: [mg106873] Re: [mg106815] Re: Mathematica gets stuck, only thing I can do is quit kernel To: "Matthias" <greiff at mac.com> Date: Sunday, January 24, 2010, 9:01 AM Hi, I stuck at 25. Without enter in your code, i found that if you drop out the If[RandomReal[]=A3alpha,... in your last definition run:={contributions=Table[0,{n}]; payoffs=Table[0,{n}]; contribute/@agents; shuffledagents=RandomSample[agents]; reward/@shuffledagents; AppendTo[contributionsovertime,Total[Ceiling[contributions]]]; Do[(*If[RandomReal[]=A3alpha,*)globalimitation[agents[[i]]](*;]*),{i,n}]; wmatrix*=(1-discount);} your program goes to 100 without problem. So that can come from this If or SeedRandom[91733], RandomReal[]. Hope that help. LAI. --- On Sun, 1/24/10, Matthias <greiff at mac.com> wrote: From: Matthias <greiff at mac.com> Subject: [mg106873] [mg106815] Re: Mathematica gets stuck, only thing I can do is quit kernel To: mathgroup at smc.vnet.net Date: Sunday, January 24, 2010, 5:40 AM Hi, thanks for the reply. Here is the code of my model. I tried to reduce it. With these settings for parameter and seed value the model stops after 25 iterations. If I change seed to SeedRandom[9173] it stops after 61 iterations but with SeedRandom[1] it somehow works. It would be a great help for me if you could copy the code into your Mathematica and see if it is the same problem on your machine. I'd really appreciate it. Cheers, Matthias _____________________________ (* parameters *) n = 100; c = 1; h = 0.1; rewardsize = 0.7; nrofrewards = 2; discount = 0.1; alpha = .9; prob = .1; (* functions *) setup := { contributionsovertime = {}; agents = Table[{i, RandomChoice[{{0, 0}, {1, 1}, {1, 0}}], RandomReal[]}, {i, n}]; wmatrix = Table[1, {n}, {n}]; Do[wmatrix[[j, j]] = 0;, {j, n}]; } pmatrix := N[Table[wmatrix[[i]]/Total[wmatrix[[i]]], {i, n}]] contribute[{id_, {0, s2_}, a_}] := {}; contribute[{id_, {1, s2_}, a_}] := {payoffs[[id]] -= c; contributions[[id]] += a;}; reward[{id_, {s1_, 0}, a_}] := {}; reward[{id_, {s1_, 1}, a_}] := Module[{choiceweights, nrofrewardsgiven, whomtoreward}, nrofrewardsgiven = Min[Length[Cases[Ceiling[contributions], Except[0]]], nrofrewards]; choiceweights = pmatrix[[id]] Ceiling[contributions]; If[Max[choiceweights] > 0, whomtoreward = RandomSample[choiceweights -> Range[n], nrofrewardsgiven]; Do[ wmatrix[[whomtoreward[[i]], id]] += rewardsize; payoffs[[whomtoreward[[i]]]] += rewardsize; payoffs[[id]] -= h; , {i, nrofrewardsgiven}];]; ] globalimitation[{id_, ___}] := Module[{best = RandomChoice[Flatten[Position[payoffs, Max[payoffs]]]]}, If[RandomReal[] > prob, If[Max[payoffs] > payoffs[[id]], agents[[id, 2]] = agents[[best, 2]];];, agents[[id, 2]] = RandomChoice[{{0, 0}, {1, 0}, {1, 1}}];] ] run := { contributions = Table[0, {n}]; payoffs = Table[0, {n}]; contribute /@ agents; shuffledagents = RandomSample[agents]; reward /@ shuffledagents; AppendTo[contributionsovertime, Total[Ceiling[contributions]]]; Do[ If[RandomReal[] <= alpha, globalimitation[agents[[i]]];]; , {i, n}]; wmatrix *= (1 - discount); } (* running the model *) Dynamic[t] SeedRandom[91733] setup; t = 0; Do[run; t++;, {100}]; =0A=0A=0A --0-756241319-1264341852=:76578 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Sun-Content-Length: 6937 <table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="= top" style="font: inherit;"><DIV id=yiv852402473> <DIV id=yiv852402473> <TABLE cellSpacing=0 cellPadding=0 border=0> <TBODY> <TR> <TD vAlign=top> <DIV>Hi,</DIV> <DIV> </DIV> <DIV>I stuck at 25.</DIV> <DIV> </DIV> <DIV>Without enter in your code, i found that if you drop out the <B><FONT = face=Courier></DIV> <DIV> </DIV> <DIV>If[RandomReal[]</FONT><FONT face=Mathematica1Mono>=A3</FONT><FONT fa= ce=Courier>alpha,...</FONT></DIV> <DIV></B> </DIV> <DIV>in your last definition </DIV> <DIV> </DIV><FONT face=Courier><STRONG><B><FONT face=Courier> <P align=left>run:={contributions=Table[0,{n}]; <P align=left>payoffs=Table[0,{n}]; <P align=left>contribute/@agents; <P align=left>shuffledagents=RandomSample[agents]; <P align=left>reward/@shuffledagents; <P align=left>AppendTo[contributionsovertime,Total[Ceiling[contributions]= ]]; <P align=left>Do[(*If[RandomReal[]</FONT><FONT face=Mathematica1Mono>= =A3</FONT><FONT face=Courier>alpha,*)globalimitation[agents[[i]]](*;]*),{= i,n}]; <DIV>wmatrix*=(1-discount);}</DIV></B></FONT></STRONG> <DIV> </DIV></FONT> <DIV>your program goes to 100 without problem. So that can come from this <= B><FONT face=Courier></DIV> <DIV>If or SeedRandom[91733], RandomReal[].</DIV></B></FONT> <DIV> </DIV> <DIV>Hope that help.</DIV> <DIV> </DIV> <DIV>LAI.</DIV></TD></TR></TBODY></TABLE><BR><BR>--- On <B>Sun, 1/24/10, An= h Ngoc LAI <I><laianhngoc at yahoo.com></I></B> wrote:<BR></DIV></DIV> <BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(= 16,16,255) 2px solid"><BR>From: Anh Ngoc LAI <laianhngoc at yahoo.com><B= R>Subject: Re: [mg106815] Re: Mathematica gets stuck, only thing I can do i= s quit kernel<BR>To: "Matthias" <greiff at mac.com><BR>Date: Sunday, Jan= uary 24, 2010, 9:01 AM<BR><BR> <DIV id=yiv852402473> <TABLE cellSpacing=0 cellPadding=0 border=0> <TBODY> <TR> <TD vAlign=top> <DIV>Hi,</DIV> <DIV> </DIV> <DIV>I stuck at 25.</DIV> <DIV> </DIV> <DIV>Without enter in your code, i found that if you drop out the <B><FONT = face=Courier></DIV> <DIV> </DIV> <DIV>If[RandomReal[]</FONT><FONT face=Mathematica1Mono>=A3</FONT><FONT fa= ce=Courier>alpha,...</FONT></DIV> <DIV></B> </DIV> <DIV>in your last definition </DIV> <DIV> </DIV><FONT face=Courier><STRONG><B><FONT face=Courier> <P align=left>run:={contributions=Table[0,{n}]; <P align=left>payoffs=Table[0,{n}]; <P align=left>contribute/@agents; <P align=left>shuffledagents=RandomSample[agents]; <P align=left>reward/@shuffledagents; <P align=left>AppendTo[contributionsovertime,Total[Ceiling[contributions]= ]]; <P align=left>Do[(*If[RandomReal[]</FONT><FONT face=Mathematica1Mono>= =A3</FONT><FONT face=Courier>alpha,*)globalimitation[agents[[i]]](*;]*),{= i,n}]; <DIV>wmatrix*=(1-discount);}</DIV></B></FONT></STRONG> <DIV> </DIV></FONT> <DIV>your program goes to 100 without problem. So that can come from this <= B><FONT face=Courier></DIV> <DIV>If or SeedRandom[91733], RandomReal[].</DIV></B></FONT> <DIV> </DIV> <DIV>Hope that help.</DIV> <DIV> </DIV> <DIV>LAI.</DIV> <DIV><BR>--- On <B>Sun, 1/24/10, Matthias <I><greiff at mac.com></I></B>= wrote:<BR></DIV> <BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(= 16,16,255) 2px solid"><BR>From: Matthias <greiff at mac.com><BR>Subject:= [mg106815] Re: Mathematica gets stuck, only thing I can do is quit kernel<= BR>To: mathgroup at smc.vnet.net<BR>Date: Sunday, January 24, 2010, 5:40 AM<BR= ><BR> <DIV class=plainMail>Hi,<BR><BR>thanks for the reply.<BR><BR>Here is the = code of my model. I tried to reduce it. With these<BR>settings for paramete= r and seed value the model stops after 25<BR>iterations. If I change seed t= o SeedRandom[9173] it stops after 61<BR>iterations but with SeedRandom[1] i= t somehow works.<BR><BR>It would be a great help for me if you could copy t= he code into your<BR>Mathematica and see if it is the same problem on your = machine. I'd<BR>really appreciate it.<BR><BR>Cheers,<BR><BR>Matthias<BR>___= __________________________<BR><BR>(* parameters *)<BR>n = 100;<BR>c = 1= ;<BR>h = 0.1;<BR>rewardsize = 0.7;<BR>nrofrewards = 2;<BR>discount = = 0.1;<BR>alpha = .9;<BR>prob = .1;<BR><BR>(* functions *)<BR>setup := = {<BR> contributionsovertime = {};<BR> agents =<BR> = ; Table[{i, RandomChoice[{{0, 0}, {1, 1}, {1, 0}}],<BR> &n= bsp; RandomReal[]}, {i, n}];<BR> wmatrix = Table[1, {n},= {n}];<BR> Do[wmatrix[[j, j]] = 0;, {j, n}];<BR> }<BR><BR>pmatrix := N[Tabl= e[wmatrix[[i]]/Total[wmatrix[[i]]], {i, n}]]<BR><BR>contribute[{id_, {0, s2= _}, a_}] := {};<BR><BR>contribute[{id_, {1, s2_}, a_}] := {payoffs[[id]= ] -= c;<BR> contributions[[id]] += a;};<BR><BR>reward[= {id_, {s1_, 0}, a_}] := {};<BR><BR>reward[{id_, {s1_, 1}, a_}] :=<BR>Mo= dule[{choiceweights, nrofrewardsgiven, whomtoreward},<BR> nrofrewards= given =<BR> Min[Length[Cases[Ceiling[contributions], Exc= ept[0]]],<BR> nrofrewards];<BR> choiceweights = pmatri= x[[id]] Ceiling[contributions];<BR> If[Max[choiceweights] > 0,<BR>= whomtoreward =<BR> RandomSample[choiceweig= hts -> Range[n], nrofrewardsgiven];<BR> Do[<BR> &= nbsp; wmatrix[[whomtoreward[[i]], id]] += rewardsize;<BR> pa= yoffs[[whomtoreward[[i]]]] += rewardsize;<BR> payoffs[[id]] = -= h;<BR> , {i, nrofrewardsgiven}];];<BR> ]<BR><BR>globalimi= tation[{id_, ___}] :=<BR>Module[{best =<BR> RandomChoice[F= latten[Position[payoffs, Max[payoffs]]]]},<BR> If[RandomReal[] > p= rob,<BR> If[Max[payoffs] > payoffs[[id]],<BR> &nb= sp; agents[[id, 2]] = agents[[best, 2]];];,<BR> &nb= sp;agents[[id, 2]] = RandomChoice[{{0, 0}, {1, 0}, {1, 1}}];]<BR> ]= <BR><BR>run := {<BR> contributions = Table[0, {n}];<BR> pay= offs = Table[0, {n}];<BR> contribute /@ agents;<BR> shuffleda= gents = RandomSample[agents];<BR> reward /@ shuffledagents;<BR>&nbs= p; AppendTo[contributionsovertime, Total[Ceiling[contributions]]];<BR> = ; Do[<BR> If[RandomReal[] <= alpha, globalimitation[a= gents[[i]]];];<BR> , {i, n}];<BR> wmatrix *= (1 - = discount);<BR> }<BR><BR>(* running the model *)<BR>Dynamic[t]<BR>SeedRandom[91733]<BR>setup;<BR>t = 0;<BR>Do[run; t++= ;, {100}];<BR><BR></DIV></BLOCKQUOTE></TD></TR></TBODY></TABLE><BR></DIV></= BLOCKQUOTE></td></tr></table><br>=0A=0A --0-756241319-1264341852=:76578--