1

ロジスティック分布関数の不動点を見つけて、さまざまなパラメーター値で不動点がどのように変化するかを判断しようとしています。コードは次のようになります。

nfxp.reps <- 0
err <- 10
p <- seq(0, 1, by = 0.0001)
pold <- p
gamma <- 6
k <- 3
while (err > 1E-12) {
  nfxp.reps <- nfxp.reps + 1
  if (nfxp.reps > 999) { 
    stop("The number of NFXP reps needs to be increased. \n")
  } 
  pnew <- plogis(-k + gamma * pold) 
  err <- max(abs(pnew - pold))
  pold <- pnew
}

上記のコードは、上記のパラメーターの選択で非常にうまく機能します: gamma と k - 3 つの固定点、2 つの安定点、1 つの不安定点 (p=0.5) を見つけます。ただし、上記のパラメーターを不均等に変更すると、中央の固定点が 0.5 より上または下にある場合、次のようになります。

gamma<-7
k<-3

ループは、p=0.3225 である中央の固定点を見つけることができません (ガンマ=7 の場合、k=3)

4

4 に答える 4

1

コードを新しい関数に再配置します。

p.fixed <- function(p0,tol = 1E-9,max.iter = 100,k=3,gamma=7,verbose=F){
  pold <- p0
  pnew <-  plogis(-k + gamma * pold) 
  iter <- 1
    while ((abs(pnew - pold) > tol) && (iter < max.iter)){
      pold <- pnew
      pnew <- plogis(-k + gamma * pold) 
      iter <- iter + 1
      if(verbose)
         cat("At iteration", iter, "value of p is:", pnew, "\n")
    }
    if (abs(pnew - pold) > tol) {
      cat("Algorithm failed to converge")
      return(NULL)
    }
    else {
      cat("Algorithm converged, in :" ,iter,"iterations \n")
      return(pnew)
    }
}

いくつかのテスト:

p.fixed(0.2,k=3,gamma=7)
Algorithm converged, in : 30 iterations 
[1] 0.08035782
> p.fixed(0.2,k=5,gamma=5)
Algorithm converged, in : 7 iterations 
[1] 0.006927088
> p.fixed(0.2,k=5,gamma=5,verbose=T)
At iteration 2 value of p is: 0.007318032 
At iteration 3 value of p is: 0.006940548 
At iteration 4 value of p is: 0.006927551 
At iteration 5 value of p is: 0.006927104 
At iteration 6 value of p is: 0.006927089 
At iteration 7 value of p is: 0.006927088 
Algorithm converged, in : 7 iterations 
[1] 0.006927088
于 2013-03-06T22:55:23.597 に答える