R/CIBforecast.R

Defines functions CIBforecast

Documented in CIBforecast

#' CIBforecast
#'
#' A function for analysis stochastic transition matrices, and outputting the main statistics about them.
#' @keywords CIB
#' @export
#' @param Transitions A stochastic transition matrix (rows are presumed to add to 1). Can be generated by any of the function referenced in \code{\link{CIBTransitionCalculators}}
#' @note \code{\link{MakeScoreMatrix}} is probably the function you will need directly after this.
#' @return A list containing a long term forcast vector (a vector of probabilities of world states), a number representing the entropy of this vector, and a number representing the entropy production.
#' @author Alastair Jamieson Lane. <aja107@@math.ubc.ca>
#' @examples
#' data(ExampleCIBdata)
#' boltzTrans<-LocalBoltzmann(ExampleCIBdata)
#' forecast<- CIBforecast(boltzTrans)
#' 


CIBforecast<-function(Transitions){
  Eigs<-eigen(t(Transitions))
  
  if(abs(prod((Eigs[[1]])))>10^-8){
     Eigs<-Re(Eigs[[2]]%*%((Re(Eigs[[1]])>(1-10^-6))*solve(Eigs[[2]], (rep(1, nrow(Transitions))))))
  }else{
    Eigs<-(rep(1, nrow(Transitions)));
    for(iii in 1:500){
      Eigs<-t(Transitions)%*%Eigs;
    }
    Eigs<-(t(Transitions)%*%Eigs + Eigs)/2;
    Eigs<-(t(Transitions)%*%Eigs + Eigs)/2;
    Eigs<-(t(Transitions)%*%Eigs + Eigs)/2;
    Eigs<-(t(Transitions)%*%Eigs + Eigs)/2; #blur cycles a bit, so that Periodicity has small impact on our thing.
  }
  rownames(Eigs)<-colnames(Transitions)
  colnames(Eigs)<-c('')
  Entropy<- -colSums(Eigs*log(Eigs + 10^-100))
  Entropy<-Entropy[[1]]
  EntropyProduction<- -colSums(Eigs*rowSums(Transitions*log(Transitions+10^-100)))
  EntropyProduction<-EntropyProduction[[1]]
  ReturnList<- list(Eigs,Entropy,EntropyProduction)
}
alastair-JL/StochasticCIB documentation built on July 27, 2023, 1:12 a.m.