This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gen.fibmorse = function(start = c(0), depth = 1){ | |
# check inputs | |
if(class(start) != "numeric"){ | |
print("Input not a numeric vector!") | |
stop(); | |
} | |
for(val in start){ | |
if(!(val %in% c(0,1)) ){ | |
print(paste("Encountered non 0/1 value in vector:",val)) | |
stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mse = function(v1,v2){ | |
se = (v2 - v1)^2 | |
mse = mean(se) | |
return(mse) | |
} | |
# See http://en.wikipedia.org/wiki/Forecast_skill for info on forecasting skill. | |
# One thing I don't like about the vanilla method is that the domain is (-Inf,1] which is kind of hard to understand. | |
# The Rossignol method, or Rossignol's Modified Forecasting Skill (RMFS) changes this to be [-1,1] which is easier to understand. Use it by setting type="rossignol". | |
fskill = function(data,type="vanilla"){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calibrated p-values | |
# ------------------- | |
# See https://stat.duke.edu/courses/Spring10/sta122/Labs/Lab6.pdf | |
# and http://www.uv.es/sestio/TechRep/tr14-03.pdf | |
alpha.p = function(p){ | |
val = 1 + (-exp(1)*p*log(p))^-1 | |
return(val^-1) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prev.value = function(str){ | |
if(str == "01") return("0") | |
if(str %in% c("0","10")) return("1") | |
return(NULL) | |
} | |
tokenize = function(str,prev.tokens=c("")){ | |
if(str == "") return(""); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# simulate pvalue fallacy | |
# See https://stat.duke.edu/courses/Spring10/sta122/Labs/Lab6.pdf | |
# and https://stat.duke.edu/~berger/applet2/applet.pdf | |
sim.pval = function(pi = 0.5, theta.input = 1, sigma.input = 1, n = 100, max = 1000){ | |
alpha = 0 | |
beta = 0 | |
while(alpha + beta < max){ | |
rand = runif(1) | |
if(rand > pi){ | |
theta = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f1 = function(n){ | |
x = double(n) | |
for(i in 1:n) x[i] = runif(1) | |
return(x) | |
} | |
f2 = function(n){ | |
x = c() | |
for(i in 1:n) x = c(x,runif(1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curve(dnorm(x,0,1),-5,5) | |
curve(dnorm(x,1,1),-5,5,add=TRUE) | |
arrows(0,0.2,1,0.2) | |
abline(v=0,lty=2) | |
abline(v=1,lty=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## solve stauf painting puzzle | |
get.move = function(val){ | |
move = c(0,0,0,0,0,0,0,0,0) | |
if(val == 1) move = c(1,1,0,1,1,0,0,0,0) | |
if(val == 2) move = c(1,1,1,0,0,0,0,0,0) | |
if(val == 3) move = c(0,1,1,0,1,1,0,0,0) | |
if(val == 4) move = c(1,0,0,1,0,0,1,0,0) | |
if(val == 5) move = c(0,1,0,1,1,1,0,1,0) | |
if(val == 6) move = c(0,0,1,0,0,1,0,0,1) | |
if(val == 7) move = c(0,0,0,1,1,0,1,1,0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.quantamagazine.org/20150722-solution-information-from-randomness/ | |
n = 1000 | |
vals = runif(n) # values shown by opened hand | |
g = runif(n) # g values | |
highest = sample(c(TRUE,FALSE),n,replace=TRUE) # was the value in the opened hand the higher value of the two hands? | |
# one of two things happens | |
# 1) g is less than the value you chose, you stay, and you are right | |
# 2) g is greater than the value you chose, you switched, and you were right | |
# other cases are failures (add 0 to s) so don't care about them since they are recoverable via n-s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f = function(expr){ | |
x = c(13,26,2,4,6,3,9,12,8,10,5,15,18,14,7,21,24,16) | |
failure = FALSE | |
for(i in seq_along(x)){ | |
result = eval(expr) | |
if(length(result) != 1) next | |
print(sprintf("%s, %s, %s",i,x[i],result)) | |
if(result != x[i]){ | |
failure = TRUE | |
break |
OlderNewer