Problem with random number simulation

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with random number simulation

AriGold
Hi this is my first post.  I am trying to run a simulation for a computer playing Von Neumann poker and adjusting it's expectation of an opponent's behavior according to how the opponent plays.  This program involves random generation of "hands" and shifting of parameters.  However, when I run the code, no errors come up, but the program doesn't do anything.  Could someone try running it?  And if ti does the same, could you tell me why it may be doing this

A few points of clarification: After each round, an uneven coin (90/10 probability) is flipped to see if the game continues (hence the while loop).  And every 10 hands, the noncomputer player changes strategy (hence the if...modulus 20 statement)
Thanks

lambda=0.8
game=1
count=0
a=0.1
b=0.7
x=numeric()
y=numeric()
xval=x
yval=y
while(game==1)
{
        count=count+1
        x[count]=runif(1,0,1)
        y[count]=runif(1,0,1)
        if ((count%%20)<10)
        {
                if (x[count] > 0.15 & x[count]< 0.65)
                {
                        if(x[count]>y[count])
                        {
                                xval[count]=2
                                yval[count]=0
                        }
                        else
                        {
                                yval[count]=2
                                xval[count]=0
                        }
       
                }
                else if (x[count]<=0.15)
                {
                        if(y[count]<a)
                        {
                                xval[count]=2
                                yval[count]=0
                        }
                        else if (y[count]>b)
                        {
                                xval[count]=-1
                                yval[count]=3
                        }
                        else if (y[count]a)
                        {
                                z=rbinom(1,1,0.5)
                                if(z>0.5)
                                {
                                        xval[count]=-1
                                        yval[count]=3
                                }
                                else
                                {
                                        xval[count]=2
                                        yval[count]=0
                                }
                        }
                        if(x[count]>0.1)
                        {
                                a=(1/lambda)*a
                        }
                }
                else if (x[count]>=0.65)
                {
                        if(y[count]<a)
                        {
                                xval[count]=2
                                yval[count]=0}
                        }
                        else if(y[count]>0.7)
                        {
                                if(x[count]>y[count])
                                {
                                        xval[count]=3
                                        yval[count]=-1
                                }
                                else
                                {
                                        yval[count]=3
                                        xval[count]=-1
                                }
                        }
                        else if(yval[count]<=b & yval[count]>=a)
                        {
                                z=rbinom(1,1,0.5)
                                if(z>0.5)
                                {
                                        yval[count]=-1
                                        xval[count]=3
                                }
                                else
                                {
                                        xval[count]=2
                                        yval[count]=0
                                }
                        }
                        if(x[count]<0.7)
                        {
                                b = 0.8*b
                        }
                }
        }
        if((count&&20)<=10)
        {
                if(x[count]>0.1 & x[count]<0.7)
                {
                        if(x[count] > y[count] )
                        {
                                xval[count]=2
                                yval[count]=0
                        }
                        else
                        {
                                yval[count]=2
                                xval[count]=0
                        }
                        if(x[count]<a)
                        {
                                a=0.8*a
                        }
                        if(x[count]>b)
                        {
                                b=(1/0.8)*b
                        }
                }
                else if (x[count]<=0.1)
                {
                        if(y[count]<a)
                        {
                                xval[count]=2
                                yval[count]=0
                        }
                        else if (y[count]>b)
                        {
                                xval[count]=-1
                                yval[count]=3
                        }
                        else
                        {
                                z=rbinom(1,1,0.5)
                                if(z>0.5)
                                {
                                        xval[count]=-1
                                        yval[count]=3
                                }
                                else
                                {
                                        xval[count]=2
                                        yval[count]=0
                                }
                        }
                }
        else if (x[count]>=0.7)
        {
                if(y[count]<a)
                {
                        xval[count]=2
                        yval[count]=0}
                }
                else if(y[count]>b)
                {
                        if(x[count]>y[count])
                        {
                                xval[count]=3
                                yval[count]=-1
                        }
                        else
                        {
                                yval[count]=3
                                xval[count]=-1
                        }
                }
                else if(y[count]<=b & y[count]>=a)
                {
                        z=rbinom(1,1,0.5)
                        if(z>0.5)
                        {
                                yval[count]=-1
                                xval[count]=3
                        }
                        else
                        {
                                xval[count]=2
                                yval[count]=0
                        }
                }



        }
        game = rbinom(1,1,0.9)
Reply | Threaded
Open this post in threaded view
|

Re: Problem with random number simulation

Daniel Nordlund-4
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]
> On Behalf Of AriGold
> Sent: Sunday, July 24, 2011 5:11 PM
> To: [hidden email]
> Subject: [R] Problem with random number simulation
>
> Hi this is my first post.  I am trying to run a simulation for a computer
> playing Von Neumann poker and adjusting it's expectation of an opponent's
> behavior according to how the opponent plays.  This program involves
> random
> generation of "hands" and shifting of parameters.  However, when I run the
> code, no errors come up, but the program doesn't do anything.  Could
> someone
> try running it?  And if ti does the same, could you tell me why it may be
> doing this
>
> A few points of clarification: After each round, an uneven coin (90/10
> probability) is flipped to see if the game continues (hence the while
> loop).
> And every 10 hands, the noncomputer player changes strategy (hence the
> if...modulus 20 statement)
> Thanks
>
> lambda=0.8
> game=1
> count=0
> a=0.1
> b=0.7
> x=numeric()
> y=numeric()
> xval=x
> yval=y
> while(game==1)
> {
>         count=count+1
>         x[count]=runif(1,0,1)
>         y[count]=runif(1,0,1)
>         if ((count%%20)<10)
>         {
>                 if (x[count] > 0.15 & x[count]< 0.65)
>                 {
>                         if(x[count]>y[count])
>                         {
>                                 xval[count]=2
>                                 yval[count]=0
>                         }
>                         else
>                         {
>                                 yval[count]=2
>                                 xval[count]=0
>                         }
>
>                 }
>                 else if (x[count]<=0.15)
>                 {
>                         if(y[count]&lt;a)
>                         {
>                                 xval[count]=2
>                                 yval[count]=0
>                         }
>                         else if (y[count]&gt;b)
>                         {
>                                 xval[count]=-1
>                                 yval[count]=3
>                         }
>                         else if (y[count]a)
>                         {
>                                 z=rbinom(1,1,0.5)
>                                 if(z>0.5)
>                                 {
>                                         xval[count]=-1
>                                         yval[count]=3
>                                 }
>                                 else
>                                 {
>                                         xval[count]=2
>                                         yval[count]=0
>                                 }
>                         }
>                         if(x[count]>0.1)
>                         {
>                                 a=(1/lambda)*a
>                         }
>                 }
>                 else if (x[count]>=0.65)
>                 {
>                         if(y[count]&lt;a)
>                         {
>                                 xval[count]=2
>                                 yval[count]=0}
>                         }
>                         else if(y[count]&gt;0.7)
>                         {
>                                 if(x[count]>y[count])
>                                 {
>                                         xval[count]=3
>                                         yval[count]=-1
>                                 }
>                                 else
>                                 {
>                                         yval[count]=3
>                                         xval[count]=-1
>                                 }
>                         }
>                         else if(yval[count]<=b & yval[count]>=a)
>                         {
>                                 z=rbinom(1,1,0.5)
>                                 if(z>0.5)
>                                 {
>                                         yval[count]=-1
>                                         xval[count]=3
>                                 }
>                                 else
>                                 {
>                                         xval[count]=2
>                                         yval[count]=0
>                                 }
>                         }
>                         if(x[count]<0.7)
>                         {
>                                 b = 0.8*b
>                         }
>                 }
>         }
>         if((count&&20)<=10)
>         {
>                 if(x[count]>0.1 & x[count]<0.7)
>                 {
>                         if(x[count] > y[count] )
>                         {
>                                 xval[count]=2
>                                 yval[count]=0
>                         }
>                         else
>                         {
>                                 yval[count]=2
>                                 xval[count]=0
>                         }
>                         if(x[count]&lt;a)
>                         {
>                                 a=0.8*a
>                         }
>                         if(x[count]&gt;b)
>                         {
>                                 b=(1/0.8)*b
>                         }
>                 }
>                 else if (x[count]<=0.1)
>                 {
>                         if(y[count]&lt;a)
>                         {
>                                 xval[count]=2
>                                 yval[count]=0
>                         }
>                         else if (y[count]&gt;b)
>                         {
>                                 xval[count]=-1
>                                 yval[count]=3
>                         }
>                         else
>                         {
>                                 z=rbinom(1,1,0.5)
>                                 if(z>0.5)
>                                 {
>                                         xval[count]=-1
>                                         yval[count]=3
>                                 }
>                                 else
>                                 {
>                                         xval[count]=2
>                                         yval[count]=0
>                                 }
>                         }
>                 }
>         else if (x[count]>=0.7)
>         {
>                 if(y[count]&lt;a)
>                 {
>                         xval[count]=2
>                         yval[count]=0}
>                 }
>                 else if(y[count]&gt;b)
>                 {
>                         if(x[count]>y[count])
>                         {
>                                 xval[count]=3
>                                 yval[count]=-1
>                         }
>                         else
>                         {
>                                 yval[count]=3
>                                 xval[count]=-1
>                         }
>                 }
>                 else if(y[count]<=b & y[count]>=a)
>                 {
>                         z=rbinom(1,1,0.5)
>                         if(z>0.5)
>                         {
>                                 yval[count]=-1
>                                 xval[count]=3
>                         }
>                         else
>                         {
>                                 xval[count]=2
>                                 yval[count]=0
>                         }
>                 }
>
>
>
>         }
>         game = rbinom(1,1,0.9)
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Problem-with-
> random-number-simulation-tp3691308p3691308.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

Welcome to R-help.  The first thing you might want to do is read the posting guide (see immediately above).  Without any context, this looks suspiciously like school work.  If this is not school work then you might want to give some context for this task.  In addition, it would be beneficial if you commented your code and then told the list what it was that you expected to happen.  People are much more willing to help if you don't make them work so hard to figure out what you are trying to do.

Dan

Daniel Nordlund
Bothell, WA USA

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with random number simulation

AriGold
Hi,

I was just hoping someone could try running the program to see if they get any output.  This is independent research.  I just need to run this simulation to see how a computer could be manipulated given certain conditions in the Von Neumann game.

Currently, my code is not giving any errors, but there is no output either.  I type "x" afterwards and nothing happens.  

I can add comments but I don't know how to edit the original post.

Reply | Threaded
Open this post in threaded view
|

Re: Problem with random number simulation

PIKAL Petr
Hi

[hidden email] napsal dne 25.07.2011 05:23:51:

> Re: [R] Problem with random number simulation
>
> Hi,
>
> I was just hoping someone could try running the program to see if they
get
> any output.  This is independent research.  I just need to run this
> simulation to see how a computer could be manipulated given certain
> conditions in the Von Neumann game.
>
> Currently, my code is not giving any errors, but there is no output
either.
> I type "x" afterwards and nothing happens.


I got many errors the first one is

+                 {
+                         if(y[count]&lt;a)
Error: unexpected ';' in:
"                {
                        if(y[count]&lt;"
>                         {
+

And it is really difficult to debug such code in R. Maybe you could put it
in a function and try

?debug

to see what values you get in each line of code

Regards
Petr



>
> I can add comments but I don't know how to edit the original post.
>
>
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/Problem-with-
> random-number-simulation-tp3691308p3691619.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with random number simulation

Nordlund, Dan (DSHS/RDA)
> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Petr PIKAL
> Sent: Monday, July 25, 2011 9:05 AM
> To: AriGold
> Cc: [hidden email]
> Subject: Re: [R] Problem with random number simulation
>
> Hi
>
> [hidden email] napsal dne 25.07.2011 05:23:51:
>
> > Re: [R] Problem with random number simulation
> >
> > Hi,
> >
> > I was just hoping someone could try running the program to see if
> they
> get
> > any output.  This is independent research.  I just need to run this
> > simulation to see how a computer could be manipulated given certain
> > conditions in the Von Neumann game.
> >
> > Currently, my code is not giving any errors, but there is no output
> either.
> > I type "x" afterwards and nothing happens.
>
>
> I got many errors the first one is
>
> +                 {
> +                         if(y[count]&lt;a)
> Error: unexpected ';' in:
> "                {
>                         if(y[count]&lt;"
> >                         {
> +
>
> And it is really difficult to debug such code in R. Maybe you could put
> it
> in a function and try
>
> ?debug
>
> to see what values you get in each line of code
>
> Regards
> Petr
>
>
>
> >
> > I can add comments but I don't know how to edit the original post.
> >
> >
> >

I don't use Nabble, and I think that is the case for most of the people that _I_ find to be most knowledgeable and helpful.  When replying from Nabble, I think posts can be quoted, and comments could be added at that point.  Another problem with Nabble is that it sends HTML by default (I think), which is not appropriate for this list.  At least, that is the problem that Petr ran into above.  The error message that he ran into was due to a less than sign being sent as an html equivalent, &LT; , which obviously R will choke on.  Again, if the OP would follow the posting guide and "provide commented, minimal, self-contained, reproducible code" (that includes no HTML), someone may be willing and able to help.

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with random number simulation

Nordlund, Dan (DSHS/RDA)
> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Nordlund, Dan (DSHS/RDA)
> Sent: Monday, July 25, 2011 10:39 AM
> To: [hidden email]
> Subject: Re: [R] Problem with random number simulation
>
<<<snip>>>

>
> I don't use Nabble, and I think that is the case for most of the people
> that _I_ find to be most knowledgeable and helpful.  When replying from
> Nabble, I think posts can be quoted, and comments could be added at
> that point.  Another problem with Nabble is that it sends HTML by
> default (I think), which is not appropriate for this list.  At least,
> that is the problem that Petr ran into above.  The error message that
> he ran into was due to a less than sign being sent as an html
> equivalent, &LT; , which obviously R will choke on.  Again, if the OP
> would follow the posting guide and "provide commented, minimal, self-
> contained, reproducible code" (that includes no HTML), someone may be
> willing and able to help.
>

Upon reading my own post, I realized that I left out a phrase that made it read like I was denigrating the knowledge and helpfulness of anyone using Nabble.   That was not my intent.  I intended to write

I don't use Nabble, and I think that is the case for most of the people _on R-help_
that _I_ find to be most knowledgeable and helpful.

There may well be some very knowledge and helpful people posting to R-help from Nabble, but the people whose posts I regularly read don't happen to use Nabble.  And there have been a few posts of late where people posting from Nabble either don't care to, or can't figure out how to follow the posting guidelines when using Nabble.  'Nuff said.

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.