- 時系列データでアトラクタが再構成できるのは、曲線における、Moving frameが時間遅れデータから作られることと、ある意味同じこと
- こちらの実例
- まず、多変量時系列データを作り(こちらのデータ作成法)、そこから、1変量を選んで、sikpT飛ばしのJOk次元時間遅れ座標系データを作って、それをプロットしている
CategoryVector<-
function (nc = 3)
{
df <- nc - 1
d <- df + 1
diagval <- 1:d
diagval <- sqrt((df + 1)/df) * sqrt((df - diagval + 1)/(df -
diagval + 2))
others <- -diagval/(df - (0:(d - 1)))
m <- matrix(rep(others, df + 1), nrow = df + 1, byrow = TRUE)
diag(m) <- diagval
m[upper.tri(m)] <- 0
as.matrix(m[, 1:df])
}
TangentDist<-function(R,MaxX){
tmax<-atan(MaxX)
tan(atan(R)/(pi/2)*tmax)
}
minind<-function(x){
which(x==min(x))[1]
}
minindval<-function(x){
list(ind=minind(x),v=min(x))
}
Sphere2Simplex<-function(x){
if(!is.matrix(x)){
x<-matrix(x,nr=1)
}
n<-length(x[1,])
cv<-CategoryVector(n+1)
X<-x%*%t(cv)
MinIndVal<-matrix(unlist(apply(X,1,minindval)),ncol=2,byrow=TRUE)
r<-sqrt(apply(x^2,1,sum))
tmpr<-TangentDist(r,1)
tmpRatio<-tmpr/(1/(n))
tmpk<-1+tmpRatio
ratio<-(tmpr^2/apply(abs(x)^tmpk,1,sum))^(1/tmpk)
x*ratio
}
xs<-matrix(0,100,3)
xs[1,]<-c(0,0,1)
for(i in 2:100){
xs[i,]<-xs[i-1,]*1.1
}
xsc<-Sphere2Simplex(xs)
plot(xsc[,1])
library(rgl)
NormalBase<-function(n){
I<-X<-diag(rep(1,n))
thetas<-runif(n*(n-1)/2)*2*pi
T<-matrix(0,n,n)
T[lower.tri(T)]<-thetas
for(i in 1:(n-1)){
for(j in (i+1):n){
R<-I
R[i,i]<-R[j,j]<-cos(T[j,i])
R[i,j]<-sin(T[j,i])
R[j,i]<--R[i,j]
X<-R%*%X
}
}
X
}
n<-3
np<-2
p<-matrix(rnorm(np*n),np,n)
Niter<-1000
dt<-0.01
dists<-c()
for(i in 1:(np-1)){
for(j in (i+1):np){
dists<-c(dists,sqrt((p[i,]-p[j,])^2))
}
}
Rs<-runif(np,min=0,max=max(dists)/2)
dimRots<-sample(2:n,np,replace=TRUE)
RotsSub<-NULL
RotsSubInv<-NULL
Rots<-NULL
e.outs<-NULL
Rdts<-NULL
for(i in 1:np){
RotsSub[[i]]<-NormalBase(n)
RotsSubInv[[i]]<-solve(RotsSub[[i]])
Rots[[i]]<-diag(rep(1,n))
Rots[[i]][1:dimRots[i],1:dimRots[i]]<-NormalBase(dimRots[i])
e.outs[[i]]<-eigen(Rots[[i]])
Rdts[[i]]<-(e.outs[[i]][[2]])%*%diag((e.outs[[i]][[1]])^dt)%*%solve(e.outs[[i]][[2]])
}
Nrep<-1
xssum<-NULL
col<-c()
xssum<-p
col<-rep(2,np)
k2<-3
fracattraction<-0
for(rep in 1:Nrep){
xs<-matrix(0,Niter,n)
xs[1,]<-rnorm(n)
for(i in 2:Niter){
v<-rep(0,n)
vs<-matrix(0,np,n)
vsRot<-vs
for(j in 1:np){
tmp<-xs[i-1,]-p[j,]
tmp<-RotsSub[[j]]%*%tmp
tmpvs<--tmp
tmpL<-sqrt(sum(tmpvs[1:dimRots[j]]^2))
tmpvs[1:dimRots[j]]<-(tmpL-Rs[j])/tmpL*tmpvs[1:dimRots[j]]
vs[j,]<-RotsSubInv[[j]]%*%tmpvs
vsRot[j,]<-Re((RotsSubInv[[j]])%*%(Rdts[[j]]%*%(tmp)))-(xs[i-1,]-p[j,])
}
tmpl<-sqrt(apply(vs^2,1,sum))
stvs<-sign(tmpl)*vs/tmpl^k2
tmpv<-apply(stvs,2,sum)
tmpv<-tmpv/sqrt(sum(tmpv^2))
v<-fracattraction*tmpv*(cumprod(tmpl)[length(tmpl)])*dt
vsRot<-vsRot/tmpl
tmpvRot<-apply(vsRot,2,sum)
v<-v+tmpvRot
xs[i,]<-xs[i-1,]+v
}
xssum<-rbind(xssum,xs)
col<-c(col,rep(rep,Niter))
}
cex<-rep(0.1,length(col))
cex[1:Nrep]<-3
plot3d(xssum[,1],xssum[,2],xssum[,3],col=col)
filename<-"attractor"
M <- par3d("userMatrix")
play3d( par3dinterp( userMatrix=list(M,
rotate3d(M, pi/2, 1, 0, 0),
rotate3d(M, pi/2, 0, 1, 0) ) ),
duration=4 )
SimplexXs<-Sphere2Simplex(xssum)
SimplexXs<-SimplexXs+1/(n-1)
plot3d(SimplexXs[,1],SimplexXs[,2],SimplexXs[,3],col=col)
JOk<-3
skipT<-4
tmpn<-length(SimplexXs[,1])+1-((JOk-1)*(skipT+1))
JOM<-matrix(0,tmpn,JOk)
cn<-1
for(i in 1:JOk){
tmp<-(i-1)*skipT+1
JOM[,i]<- SimplexXs[tmp:(tmpn+tmp-1),cn]
}
plot3d(JOM[,1],JOM[,2],JOM[,3])
vvv<-0.5
yy<-SimplexXs+matrix(rnorm(length(SimplexXs),sd=sqrt(var(c(SimplexXs)))*vvv),ncol=length(SimplexXs[1,]))
zz<-yy
for(i in 1:length(yy[1,])){
zz[,i]<-filter(yy[,i],rep(1,10)/10)
}
plot3d(yy[,1],yy[,2],yy[,3])
plot3d(zz[,1],zz[,2],zz[,3])
par(mfcol=c(1,3))
matplot(SimplexXs,ylim=c(min(SimplexXs),max(SimplexXs)))
matplot(yy,ylim=c(min(SimplexXs),max(SimplexXs)))
matplot(zz,ylim=c(min(SimplexXs),max(SimplexXs)))
par(mfcol=c(1,1))