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
library(PolynomF) | |
n <- 10 | |
f <- function(x) sin(2 * pi * x) | |
x <- seq(0, 1, length=n) | |
y <- f(x) + rnorm(n, sd=0.2) | |
plot(data.frame(x, y)) |
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
# | |
# Let's look at how the different models generalize between different datasets | |
# | |
n.training <- 10 | |
n.test <- 100 | |
error.function <- function(y, y.pred) sum((y.pred - y)^2) / 2 | |
e.rms <- function(y, y.pred) sqrt(2 * error.function(y=y, y.pred=y.pred) / length(y)) |
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
# | |
# Let's look at how the different models generalize between different datasets | |
# | |
n.training <- 10 | |
n.test <- 100 | |
error.function <- function(y, y.pred) sum((y.pred - y)^2) / 2 | |
e.rms <- function(y, y.pred) sqrt(2 * error.function(y=y, y.pred=y.pred) / length(y)) |
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
A = [1 1; 1 2; 1 3; 1 4]; b = [2 1 1 1]'; | |
[m, n] = size(A); | |
C = A' * A; c = A' *b; bb = b'*b; | |
Cbar = [C c; c' bb]; | |
Gbar = chol(Cbar)'; | |
G = Gbar(1:2, 1:2); z = Gbar(3, 1:2)'; rho = Gbar(3, 3); | |
x = G'\z |
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
actions <- c("N", "S", "E", "W") | |
x <- 1:4 | |
y <- 1:3 | |
rewards <- matrix(rep(0, 12), nrow=3) | |
rewards[2, 2] <- NA | |
rewards[1, 4] <- 1 | |
rewards[2, 4] <- -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
bellman.update <- function(action, state, values, gamma=1) { | |
state.transition.prob <- transition[[action]] | |
q <- rep(0, length(state.transition.prob)) | |
for(i in 1:length(state.transition.prob)) { | |
new.state <- act(names(state.transition.prob)[i], state) | |
q[i] <- (state.transition.prob[i] * (rewards[state["y"], state["x"]] + (gamma * values[new.state["y"], new.state["x"]]))) | |
} | |
sum(q) | |
} |
OlderNewer