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(ggplot2) | |
library(dplyr) | |
Andrews <- function(t, | |
Sepal.Length, Sepal.Width, | |
Petal.Length, Petal.Width,...){ | |
root2 <- sqrt(2) | |
sapply(t, function(t){Sepal.Length/root2 + | |
Sepal.Width*sin(t) + | |
Petal.Length*cos(t) + |
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(dplyr) | |
library(ggplot2) | |
set.seed(123) | |
fdf <- expand_grid(year=1:4, generation=1:4) %>% | |
mutate(mu=rnorm(16),sigma=abs(rnorm(16))) | |
layerfun <- split(fdf, interaction(fdf$year, fdf$generation)) %>% | |
lapply(function(x){ |
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
#1D | |
simLWR <- function(r, m, u0, | |
sys_noise=0, | |
obs_noise=0, | |
explicit=FALSE){ | |
n <- length(u0) | |
if(explicit){ | |
A <- diag(1-r,n) | |
A[cbind(2:n,1:(n-1))] <- r | |
}else{ |
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(gganimate) | |
library(dplyr) | |
th <- seq(-pi,pi,by=0.01) | |
a <- seq(1,6, by=0.1) | |
df <- data.frame(x=c(cos(outer(th,a))), | |
y=rep(sin(th), length(a)), | |
a=rep(a, each=length(th))) | |
ggplot(df, aes(x=x, y=y, group=a, colour=a))+ |
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(gganimate) | |
library(ggplot2) | |
#install.packages("gganimate") | |
diffeq <- function(u_ini, r, timestep){ | |
M <- nrow(u_ini) | |
N <- ncol(u_ini) | |
u_old <- u_ini | |
U <- array(0, dim=c(M,N,timestep+1)) | |
U[,,1] <- u_ini | |
tmp <- matrix(0,M,N) |
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(ggplot2) | |
library(reshape2) | |
library(patchwork) | |
diffeq <- function(r, u_ini, m, | |
sys_noise=0, | |
obs_noise=0, | |
implicit=FALSE){ | |
n <- length(u_ini) | |
if(implicit){ |
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
difueq <- function(u_ini, timestep){ | |
Deltat <-1/400 | |
Deltax <-1/10 | |
Deltay <-1/10 | |
r <- Deltat/(Deltax^2+Deltay^2) | |
M <- nrow(u_ini) | |
N <- ncol(u_ini) | |
u_old <- u_ini | |
U <- array(0, dim=c(M,N,timestep+1)) | |
U[,,1] <- u_ini |
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
module pelt | |
using Distributions | |
using Statistics | |
function costlpnorm(y, sta, en) | |
suby = y[sta:en] | |
muhat = mean(suby) | |
sigmahat = std(suby) | |
return -sum(x -> logpdf(Normal(muhat, sigmahat), x), suby) |
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(ggplot2) | |
library(tidyr) | |
library(tibble) | |
library(dplyr) | |
#library(pheatmap) | |
head(iris) | |
Y <- log(as.matrix(iris[,1:4])) | |
d <- dist(Y) | |
h <- hclust(d,method = "ward.D") |
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(ggplot2) | |
library(tidyr) | |
library(tibble) | |
library(dplyr) | |
library(pheatmap) | |
Y <- log(as.matrix(iris[,-5])) | |
drow <- rowMeans(sweep(Y,2,Y[1,])^2) | |
dcol <- colMeans(sweep(Y,1,Y[,1])^2) | |
df <- rowid_to_column(iris) %>% | |
mutate(rrow = order(drow)) %>% |