DS4PS / cpp-527-spr-2020

Course shell for CPP 527 Foundations of Data Science II for Spring 2020.
http://ds4ps.org/cpp-527-spr-2020/
0 stars 1 forks source link

Request a Code-Through #1

Open lecy opened 4 years ago

lecy commented 4 years ago

If you are having trouble with a concept and would like a clarifying explanation, request a code-through for a concrete example explained in a short video.

You can make your request below. Try to be specific about the concept and where you are struggling.

TVK36692 commented 4 years ago

I do not know what happened, but I cannot even get the results of Lab-01 to return anything in R Studio i run something as simple as

+ create_game <- function( )
+ {
+     a.game <- sample( x=c("goat","goat","car"), size=3, replace=F )
+     return( a.game )
+ } 

and nothing comes up. no error, nothing. This has put me so far behind that I am close unenrolling.

lecy commented 4 years ago

Try this:

create_game <- function( )
{
     a.game <- sample( x=c("goat","goat","car"), size=3, replace=F )
     return( a.game )
} 
create_game()

The first lines create the function, but you need to call the function to create a new game.

Please let me know if that works. Happy to jump on a zoom call as well and walk through this.

TVK36692 commented 4 years ago

I had to send a } to end some previously unfinished function, i think. That ended up letting me run your code. I am now trying to run this:

> play_game <- function()
+ {
+     cash <- 10  
+     count <- 0 # set to zero
+     {while( cash > 0 )
+     {
+         cash <- cash +   
+             sample( c(-1,0,1), size=1 )
+         count <- count + 1
+     }
+         return( count )
+     }
+ }
> results <- numeric(10000)
> for( i in 1:10000 )
+ { results[i] <- play_game() }

It never returns. Is it just processing forever?

lecy commented 4 years ago

I added some notes on run-time on Yellowdig. This topic is beyond what you need for the labs in this class, but I wanted to introduce it since it is so central to data science (and also super interesting).

Here is how I was able to get the code to run - by adding a break statement in the while loop for those few cases that end up with REEEEEAAAALLLLY long runs. If you let your computer keep running for a couple of days it might get there. But this is a feasible solution.

The average (MEDIAN) time until bankruptcy is about 320 plays.

play_game <- function()
{
  cash <- 10  
  count <- 0 # set to zero

  while( cash > 0 )
  {
    cash <- cash +   
      sample( c(-1,0,1), size=1 )
    count <- count + 1

    # break from while loop
    # if winning streak too long 
    if( count > 10000 ){ break }
  }
  return( count )
}

start_time <- Sys.time()

######################
###                ###
###    SIM CODE    ###
###                ###
######################

results <- numeric(10000)
for( i in 1:10000 )
{
  results[i] <- play_game()
}

######################

end_time <- Sys.time()
end_time - start_time

summary( results )

image

lecy commented 4 years ago

It never returns. Is it just processing forever?

Once it's done running, do you have a returns vector with values?

ls()
summary( results )
TVK36692 commented 4 years ago

It never returns the > prompt

Best, TK


From: Jesse Lecy notifications@github.com Sent: Monday, January 27, 2020 4:12:40 PM To: DS4PS/cpp-527-spr-2020 cpp-527-spr-2020@noreply.github.com Cc: TVK36692 tkemper@asu.edu; Comment comment@noreply.github.com Subject: Re: [DS4PS/cpp-527-spr-2020] Request a Code-Through (#1)

It never returns. Is it just processing forever?

Once it's done running, do you have a returns vector with values?

ls() summary( results )

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_DS4PS_cpp-2D527-2Dspr-2D2020_issues_1-3Femail-5Fsource-3Dnotifications-26email-5Ftoken-3DAM6SG63J6LPUGZ3DSVU3GDDQ75S6RA5CNFSM4KF7EPF2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKBNSAY-23issuecomment-2D579000579&d=DwMCaQ&c=l45AxH-kUV29SRQusp9vYR0n1GycN4_2jInuKy6zbqQ&r=ohfErKdN3oEzCcL-NjgCvLc-_BXUvFM3vACaimeAqGw&m=wAx5H1oQbQ8lu0L5tdVBrf2UVu06BFVV_vugBfnfR3I&s=-XIUAHfwk0vuy1jR40oNJuytmFH420HzLYNpK0Yd3WU&e=, or unsubscribehttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AM6SG65QVBDPLPGWARP6TBLQ75S6RANCNFSM4KF7EPFQ&d=DwMCaQ&c=l45AxH-kUV29SRQusp9vYR0n1GycN4_2jInuKy6zbqQ&r=ohfErKdN3oEzCcL-NjgCvLc-_BXUvFM3vACaimeAqGw&m=wAx5H1oQbQ8lu0L5tdVBrf2UVu06BFVV_vugBfnfR3I&s=6RNFPpVyJUXpQDJ7Q74c1ZQZ7f0k-BKRClY67vf_p6U&e=.

lecy commented 4 years ago

That is weird. Here is what I get:

It takes a little over a minute for it to run on my computer when the break is included.

> play_game <- function()
+ {
+   cash <- 10  
+   count <- 0 # set to zero
+ 
+   while( cash > 0 )
+   {
+     cash <- cash +   
+       sample( c(-1,0,1), size=1 )
+     count <- count + 1
+ 
+     # break from while loop
+     # if winning streak too long 
+     if( count > 10000 ){ break }
+   }
+   return( count )
+ }
> 
> 
> 
> 
> start_time <- Sys.time()
> 
> ######################
> ###                ###
> ###    SIM CODE    ###
> ###                ###
> ######################
> 
> results <- numeric(10000)
> for( i in 1:10000 )
+ {
+   results[i] <- play_game()
+ }
> 
> ######################
> 
> end_time <- Sys.time()
> end_time - start_time
Time difference of 1.286855 mins
> 
> summary( results )
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
     12     112     324    1808    1424   10001 
> 
TVK36692 commented 4 years ago

I was able to get this to run in 1.45 minutes. I will need to read up on the break. Thank you!

Best, TK [star2color]

From: Jesse Lecy notifications@github.com Reply-To: DS4PS/cpp-527-spr-2020 reply@reply.github.com Date: Monday, January 27, 2020 at 6:46 PM To: DS4PS/cpp-527-spr-2020 cpp-527-spr-2020@noreply.github.com Cc: Tod Kemper tkemper@asu.edu, Comment comment@noreply.github.com Subject: Re: [DS4PS/cpp-527-spr-2020] Request a Code-Through (#1)

That is weird. Here is what I get:

It takes a little over a minute for it to run on my computer when the break is included.

play_game <- function()

start_time <- Sys.time()

######################

SIM CODE

######################

results <- numeric(10000)

for( i in 1:10000 )

######################

end_time <- Sys.time()

end_time - start_time

Time difference of 1.286855 mins

summary( results )

Min. 1st Qu. Median Mean 3rd Qu. Max.

 12     112     324    1808    1424   10001

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_DS4PS_cpp-2D527-2Dspr-2D2020_issues_1-3Femail-5Fsource-3Dnotifications-26email-5Ftoken-3DAM6SG6YUT5LGCJE7FFGJAFLQ76E5DA5CNFSM4KF7EPF2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKBXJPA-23issuecomment-2D579040444&d=DwMCaQ&c=l45AxH-kUV29SRQusp9vYR0n1GycN4_2jInuKy6zbqQ&r=ohfErKdN3oEzCcL-NjgCvLc-_BXUvFM3vACaimeAqGw&m=T-qzDanNjoC1x6Sej2YDr4zqMDD0HuGeDIF4wdBzcbk&s=qznQZ27zLfWzJsEagzE_9JGCX3pgPOxdxYJoHpJ_iLQ&e=, or unsubscribehttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AM6SG67EEUSI2LM5WBUET5TQ76E5DANCNFSM4KF7EPFQ&d=DwMCaQ&c=l45AxH-kUV29SRQusp9vYR0n1GycN4_2jInuKy6zbqQ&r=ohfErKdN3oEzCcL-NjgCvLc-_BXUvFM3vACaimeAqGw&m=T-qzDanNjoC1x6Sej2YDr4zqMDD0HuGeDIF4wdBzcbk&s=NLNWDlCcxMHyQrmWffTnAwW_O7ekcNko6ifVSKzxNpg&e=.