Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

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>&nbsp;</DIV>
<DIV>I stuck at 25.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Without enter in your code, i found that if you drop out the <B><FONT =
face=Courier></DIV>
<DIV>&nbsp;</DIV>
<DIV>If[RandomReal[]</FONT><FONT face=Mathematica1Mono>=A3</FONT><FONT fa=
ce=Courier>alpha,...</FONT></DIV>
<DIV></B>&nbsp;</DIV>
<DIV>in your last definition </DIV>
<DIV>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV>Hope that help.</DIV>
<DIV>&nbsp;</DIV>
<DIV>LAI.</DIV></TD></TR></TBODY></TABLE><BR><BR>--- On <B>Sun, 1/24/10, An=
h Ngoc LAI <I>&lt;laianhngoc at yahoo.com&gt;</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 &lt;laianhngoc at yahoo.com&gt;<B=
R>Subject: Re: [mg106815] Re: Mathematica gets stuck, only thing I can do i=
s quit kernel<BR>To: "Matthias" &lt;greiff at mac.com&gt;<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>&nbsp;</DIV>
<DIV>I stuck at 25.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Without enter in your code, i found that if you drop out the <B><FONT =
face=Courier></DIV>
<DIV>&nbsp;</DIV>
<DIV>If[RandomReal[]</FONT><FONT face=Mathematica1Mono>=A3</FONT><FONT fa=
ce=Courier>alpha,...</FONT></DIV>
<DIV></B>&nbsp;</DIV>
<DIV>in your last definition </DIV>
<DIV>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV>Hope that help.</DIV>
<DIV>&nbsp;</DIV>
<DIV>LAI.</DIV>
<DIV><BR>--- On <B>Sun, 1/24/10, Matthias <I>&lt;greiff at mac.com&gt;</I></B>=
 wrote:<BR></DIV>
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(=
16,16,255) 2px solid"><BR>From: Matthias &lt;greiff at mac.com&gt;<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>&nbsp; contributionsovertime = {};<BR>&nbsp; agents =<BR>&nbsp=
;&nbsp;&nbsp;Table[{i, RandomChoice[{{0, 0}, {1, 1}, {1, 0}}],<BR>&nbsp; &n=
bsp;&nbsp;&nbsp;RandomReal[]}, {i, n}];<BR>&nbsp; wmatrix = Table[1, {n},=
 {n}];<BR>&nbsp;
 Do[wmatrix[[j, j]] = 0;, {j, n}];<BR>&nbsp; }<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>&nbsp;&nbsp;&nbsp;contributions[[id]] += a;};<BR><BR>reward[=
{id_, {s1_, 0}, a_}] := {};<BR><BR>reward[{id_, {s1_, 1}, a_}] :=<BR>Mo=
dule[{choiceweights, nrofrewardsgiven, whomtoreward},<BR>&nbsp; nrofrewards=
given =<BR>&nbsp;&nbsp;&nbsp;Min[Length[Cases[Ceiling[contributions], Exc=
ept[0]]],<BR>&nbsp; &nbsp; nrofrewards];<BR>&nbsp; choiceweights = pmatri=
x[[id]] Ceiling[contributions];<BR>&nbsp; If[Max[choiceweights] &gt; 0,<BR>=
&nbsp;&nbsp;&nbsp;whomtoreward =<BR>&nbsp; &nbsp; RandomSample[choiceweig=
hts -&gt; Range[n], nrofrewardsgiven];<BR>&nbsp;&nbsp;&nbsp;Do[<BR>&nbsp; &=
nbsp; wmatrix[[whomtoreward[[i]], id]] += rewardsize;<BR>&nbsp; &nbsp; pa=
yoffs[[whomtoreward[[i]]]] += rewardsize;<BR>&nbsp; &nbsp; payoffs[[id]] =
-= h;<BR>&nbsp;
 &nbsp; , {i, nrofrewardsgiven}];];<BR>&nbsp;&nbsp;&nbsp;]<BR><BR>globalimi=
tation[{id_, ___}] :=<BR>Module[{best =<BR>&nbsp; &nbsp; RandomChoice[F=
latten[Position[payoffs, Max[payoffs]]]]},<BR>&nbsp; If[RandomReal[] &gt; p=
rob,<BR>&nbsp;&nbsp;&nbsp;If[Max[payoffs] &gt; payoffs[[id]],<BR>&nbsp; &nb=
sp;&nbsp;&nbsp;agents[[id, 2]] = agents[[best, 2]];];,<BR>&nbsp;&nbsp;&nb=
sp;agents[[id, 2]] = RandomChoice[{{0, 0}, {1, 0}, {1, 1}}];]<BR>&nbsp; ]=
<BR><BR>run := {<BR>&nbsp; contributions = Table[0, {n}];<BR>&nbsp; pay=
offs = Table[0, {n}];<BR>&nbsp; contribute /@ agents;<BR>&nbsp; shuffleda=
gents = RandomSample[agents];<BR>&nbsp; reward /@ shuffledagents;<BR>&nbs=
p; AppendTo[contributionsovertime, Total[Ceiling[contributions]]];<BR>&nbsp=
; Do[<BR>&nbsp;&nbsp;&nbsp;If[RandomReal[] &lt;= alpha, globalimitation[a=
gents[[i]]];];<BR>&nbsp;&nbsp;&nbsp;, {i, n}];<BR>&nbsp; wmatrix *= (1 - =
discount);<BR>&nbsp; }<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--


  • Prev by Date: Re: Using "If" and "NDSolve" together
  • Next by Date: Re: Re: looping
  • Previous by thread: Re: Mathematica gets stuck, only thing I can do is quit kernel
  • Next by thread: Re: Mathematica gets stuck, only thing I can do is quit kernel