標準化したロトカ-ヴォルテラの変化シミュレーション

  • 予定パッケージ名
    • SphereAndSimplex
  • 関数名
    • StandardLotkaVolterra
  • タイトル
StandardLotkaVolterra
  • 説明
n種が、巡回の関係にあるとする。
種の食物連鎖の関係は、腐食も考慮すれば、巡回しているので、このように考える。
各種は「分子量」のように、栄養素に関してユニット数を持つ。
これは、DrawAttractor()の特殊な場合である。
  • 使用例
StandardLotkaVolterra(n=5)
  • ソース
StandardLotkaVolterra<-function(n=4,Nrep=30,Niter=1000,dt=0.01,us=NULL){
	if(is.null(us)){
		us<-rep(1,n)
		#us<-sample(1:10,n) # それぞれの種の単位Pあたり個体数
	}

# 捕食・被捕食関係の数Nrは種の数と同じ
Nr<-n
# 捕食・被捕食効率
ks<-runif(Nr)
ks<-rep(1,n)
# Inは被捕食種。1度の出会いで殺される個体数
# Playerは捕食・被捕食関係で参加する種とその個体数
# 今は1捕食個体と1被捕食個体の出会いとする
# Outは出会いの結果生じる種とその個体数
# 今は捕食者
In<-Player<-diag(n)
Out<-matrix(0,Nr,n)
for(i in 1:Nr){
	for(j in 1:n){
		if(j==i+1){
			Player[i,j]<-1
			Out[i,j]<-1
		}
	}
}
Player[Nr,1]<-Out[Nr,1]<-1

S<-1
P<-runif(1,min=0,max=(1/n)^n)

xssum<-NULL
col<-c()
for(rep in 1:Nrep){
	# ここから時系列シミュレーション
m<-matrix(0,Niter,n)
p<-rep(0,Niter)
p[1]<-0
for(i in 1:n){
	p[1]<-p[1]+us[i]*m[1,i]
}
m[1,]<-m[1,]/p[1]
p[1]<-0
for(i in 1:n){
	p[1]<-p[1]+us[i]*m[1,i]
}
library(MCMCpack)

#initloop<-TRUE
#while(initloop){
#	m[1,1]<-runif(1)
#	m[1,2]<-runif(1)
#	tmp1<-1-(m[1,1]+m[1,2])
#	tmp2<-tmp1^2-4*P/(m[1,1]*m[1,2])
#	if(tmp2>=0){
#		m[1,3]<-1/2*(tmp1+sqrt(tmp2))
#		m[1,4]<-1/2*(tmp1-sqrt(tmp2))
#		if(m[1,4]>0){
#			initloop<-FALSE
#		}
#	}
#	
#}
#m[1,]<-sample(m[1,])
m[1,]<-runif(n)
for(i in 2:Niter){
	m[i,]<-m[i-1,]
	for(j in 1:Nr){
		tmp<-ks[j]*dt
		pamountIn<-0
		pamountOut<-0
		for(k in 1:n){
			tmp<-tmp*m[i-1,k]^Player[j,k]
			pamountIn<-pamountIn+us[k]*In[j,k]
			pamountOut<-pamountOut+us[k]*Out[j,k]
		}

		for(k in 1:n){
			m[i,k]<-m[i,k]-In[j,k]*tmp+tmp*pamountIn/pamountOut*us[k]*Out[j,k]/pamountOut*Out[j,k]
		}
	}

	for(j in 1:n){
		p[i]<-p[i]+us[j]*m[i,j]
	}

}
#plot(p,type="l",ylim=c(0,2),main="保存量")
#plot(data.frame(m),cex=0.1)
xs<-matrix(0,Niter,n-1)
cv<-CategoryVector(n)
for(i in 1:Niter){
	for(j in 1:n){
		xs[i,]<-xs[i,]+m[i,j]*cv[j,]
	}
}
xssum<-rbind(xssum,xs)
col<-c(col,rep(rep,Niter))
}

plot3d(xssum[,1],xssum[,2],xssum[,3],col=col)

list(X=xssum,col=col)
}
  • Rdファイル
\name{StandardLotkaVolterra}
\alias{StandardLotkaVolterra}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
StandardLotkaVolterra
}
\description{
n種が、巡回の関係にあるとする。
種の食物連鎖の関係は、腐食も考慮すれば、巡回しているので、このように考える。
各種は「分子量」のように、栄養素に関してユニット数を持つ。
これは、DrawAttractor()の特殊な場合である。
}
\usage{
StandardLotkaVolterra(n=4)
}
%- maybe also 'usage' for other objects documented here.
\details{
%%  ~~ If necessary, more details than the description above ~~
}
\value{
\item{X}{matrix of No. time points x No. species representing No. species }
}
\references{
%% ~put references to the literature/web site here ~
}
\author{
%%  ~~who you are~~
}
\note{
%%  ~~further notes~~
}

%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
DrawAttractor
}
\examples{
n<-4
lv<-StandardLotkaVolterra(n)
plot3d(lv$X[,1],lv$X[,2],lv$X[,3],col=lv$col)

}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ ~kwd1 }
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line