-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KF code for BM type of black dot with simulation data and read data
- Loading branch information
mu
authored
May 23, 2019
0 parents
commit 64e0b49
Showing
11 changed files
with
1,221 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
source('Data_real.r') | ||
|
||
postate<-read.csv(file="KappaState2019-05-16.txt",sep="",header=FALSE) | ||
|
||
end=max(dim(postate) ) | ||
burnin = 7000 #30000 | ||
mstate<-apply(postate[burnin:end,],2,mean) | ||
|
||
|
||
#max( ax[-which( is.na(ax) ) ] ) | ||
#min( ax[-which( is.na(ax) ) ] ) | ||
|
||
pl_state = mstate | ||
pl_state[which(pl_state>1.5)] = 17 # BM | ||
pl_state[which(pl_state<1.5)] = 19 # OU | ||
#pl_state[which( is.na(ax) ) ] = NA | ||
|
||
pl_state = matrix(c(pl_state),ncol=5) | ||
|
||
break_seconds = 1.5 | ||
|
||
#animation_plot<-function( break_seconds) | ||
#{ | ||
plot(0,0,xlim=c(-1,57),ylim=c(-1,45),xlab="x-dimension",ylab="y-dimension",col='white') | ||
|
||
for(qq in 1:46) | ||
{ | ||
lines( ax[qq,1],ay[qq,1],type="p",pch= pl_state[qq,1] ,col="red",cex=1.5 ) | ||
lines( ax[qq,2],ay[qq,2],type="p",pch= pl_state[qq,2],col="blue",cex=1.5 ) | ||
lines( ax[qq,3],ay[qq,3],type="p",pch= pl_state[qq,3],col="forestgreen",cex=1.5 ) | ||
lines( ax[qq,4],ay[qq,4],type="p",pch= pl_state[qq,4],col="black" ,cex=1.5 ) | ||
lines( ax[qq,5],ay[qq,5],type="p",pch= pl_state[qq,5],col="purple" ,cex=1.5 ) | ||
|
||
Sys.sleep(break_seconds) | ||
lines( ax[qq,1],ay[qq,1],type="p",pch= pl_state[qq,1],col="white",cex=2 ) | ||
lines( ax[qq,2],ay[qq,2],type="p",pch= pl_state[qq,2],col="white",cex=2 ) | ||
lines( ax[qq,3],ay[qq,3],type="p",pch= pl_state[qq,3],col="white",cex=2 ) | ||
lines( ax[qq,4],ay[qq,4],type="p",pch= pl_state[qq,4],col="white",cex=2 ) | ||
lines( ax[qq,5],ay[qq,5],type="p",pch= pl_state[qq,5],col="white",cex=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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
|
||
|
||
library(mvtnorm) | ||
library(Matrix) | ||
set.seed(3809) | ||
|
||
# Read data | ||
|
||
raw <- read.csv("regular.scaled.njaarke.csv") ## datafile | ||
raw <- raw[-1,-1] | ||
|
||
dates <- as.POSIXct(raw[,1], tz = "GMT") | ||
raw <- cbind(dates, raw[,-1]) | ||
|
||
# time difference between obs | ||
diff_t <- diff(as.numeric(raw[,1]))/ 3600 # time in mins. Use /3600 to use diff in hours | ||
dt=diff_t[1] | ||
|
||
xy <- as.matrix(raw[,-1]) | ||
nai <- ncol(xy)/2 | ||
Nsamp = | ||
alen <- nrow(xy) | ||
|
||
animaly<-xy[,2*(1:nai)] / 20 # All y coordinates for each individual | ||
animalx<-xy[,2*(1:nai)-1] / 20 # All x coordinates for each individual | ||
|
||
# Coordinates for the black dot as an average of all other individuals. | ||
black_x <- mean(na.omit(animalx[1,])) | ||
black_y <- mean(na.omit(animaly[1,])) | ||
|
||
# Initial parameter values | ||
theta_x <- mean(animalx[1,][!is.na(animalx[1,])]) | ||
theta_y <- mean(animaly[1,][!is.na(animaly[1,])]) | ||
theta <- c(theta_x,theta_y) | ||
|
||
swlamda=c(0.1,0.5) | ||
|
||
## rename the data for inferencing code | ||
ax = animalx | ||
ay = animaly | ||
all_t = seq(0,(alen-1)*2 ,dt) | ||
all_s = matrix(c(1), nrow = alen, ncol = nai+1 ) ## nai+1 for animal and black dot | ||
sw_ind = matrix(c("SP"),nrow = alen) | ||
|
||
#black = rbind(black_x,black_y) | ||
#mxsamp = max(all_t) | ||
|
||
deltat = dt | ||
|
||
|
||
|
||
|
||
|
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
Oops, something went wrong.