markov-chains

Capacity Provisioning for Server Farms

浪子不回头ぞ 提交于 2020-01-16 17:07:52
问题 Suppose I have N M/M/1 queues in parallel where an arriving job is equally likely to join one of the N queues. We want to keep the probability for a job to wait less than 0.2. Given that we have an arrival rate of 400 jobs/second, and a processing times are exponentially distributed with mean 1 second, how many servers would be required? So my take on the question so far is: \lambda = 400 jobs/second \mu = 1 second \rho = (\lambda)/(k\mu) since we want to keep the probability of waiting less

Hidden markov model next state only depends on previous one state? What about previous n states?

孤人 提交于 2020-01-15 12:32:26
问题 I am working on a prototype framework. Basically I need to generate a model or profile for each individual's lifestyle based on some sensor data about him/her, such as GPS, motions, heart rate, surrounding environment readings, temperature etc. The proposed model or profile is a knowledge representation of an individual's lifestyle pattern. Maybe a graph with probabilities. I am thinking to use Hidden Markov Model to implement this. As the states in HMM can be Working, Sleeping, Leisure,

DTMC Markov Chain - How to get the stationary vector

不羁的心 提交于 2020-01-14 06:37:09
问题 For a Discrete Time Markov Chain problem, i have the following: 1) Transition matrix: 0.6 0.4 0.0 0.0 0.0 0.4 0.6 0.0 0.0 0.0 0.8 0.2 1.0 0.0 0.0 0.0 2) Initial probability vector: 1.0 0.0 0.0 0.0 So, i wrote the following SciLab code to get to the stationary vector: P = [0.6, 0.4, 0, 0; 0, 0.4, 0.6, 0; 0, 0, 0.8, 0.2; 1,0,0,0] PI = [1,0,0,0] R=PI*P count=0; for i = 1 : 35 // stationary vector is obtained at iteration 33, but i went futher to be sure R=R*P; count=count+1 disp("count = "

Generating Markov transition matrix in Python

半世苍凉 提交于 2020-01-10 08:59:20
问题 Imagine I have a series of 4 possible Markovian states (A, B, C, D): X = [A, B, B, C, B, A, D, D, A, B, A, D, ....] How can I generate a Markov transformation matrix using Python? The matrix must be 4 by 4, showing the probability of moving from each state to the other 3 states. I've been looking at many examples online but in all of them, the matrix is given, not calculated based on data. I also looked into hmmlearn but nowhere I read on how to have it spit out the transition matrix. Is

Generating Markov transition matrix in Python

旧街凉风 提交于 2020-01-10 08:59:08
问题 Imagine I have a series of 4 possible Markovian states (A, B, C, D): X = [A, B, B, C, B, A, D, D, A, B, A, D, ....] How can I generate a Markov transformation matrix using Python? The matrix must be 4 by 4, showing the probability of moving from each state to the other 3 states. I've been looking at many examples online but in all of them, the matrix is given, not calculated based on data. I also looked into hmmlearn but nowhere I read on how to have it spit out the transition matrix. Is

Proportions in Markov chain do not add up to 1

帅比萌擦擦* 提交于 2020-01-07 01:49:50
问题 I have following two-state Markov chain: pre<-cbind(c(rep("rain",100),rep("sun",100),rep("rain",100))) post<-cbind(c(rep("rain",50),rep("sun",70),rep("rain",100),rep("sun",80))) df<-cbind(pre,post) df<-as.data.frame(df) colnames(df)<-c("pre","post") states<-c("rain","sun") probsCase<-function(i,j){ sum(as.character(df$pre)==states[i] & as.character(df$post)==states[j])/sum(as.character(df$pre)==states[i]) } transitionMatrix<-outer(1:2,1:2,Vectorize(probsCase)) colnames(transitionMatrix)<

How can I make a discrete state Markov model with pymc?

℡╲_俬逩灬. 提交于 2019-12-31 22:21:44
问题 I am trying to figure out how to properly make a discrete state Markov chain model with pymc. As an example (view in nbviewer), lets make a chain of length T=10 where the Markov state is binary, the initial state distribution is [0.2, 0.8] and that the probability of switching states in state 1 is 0.01 while in state 2 it is 0.5 import numpy as np import pymc as pm T = 10 prior0 = [0.2, 0.8] transMat = [[0.99, 0.01], [0.5, 0.5]] To make the model, I make an array of state variables and an

R: Build second order transition matrix and score sequences

梦想的初衷 提交于 2019-12-24 10:37:37
问题 Other questions There is another question asking how to build a second order transition matrix, however the answer does not seem to produce a second order transition matrix. Second order transition matrix & scoring a sequence Let's use this dataset: set.seed(1) dat<-data.frame(replicate(20,sample(c("A", "B", "C","D"), size = 100, replace=TRUE))) What would be the best way to build a second order transition matrix such that I can easily score a new sequence I encounter as discussed here. For

Manual simulation of Markov Chain in R (2)

六眼飞鱼酱① 提交于 2019-12-24 07:50:37
问题 Consider the Markov chain with state space S = {1, 2} , transition matrix and initial distribution α = (1/2, 1/2) . Simulate 5 steps of the Markov chain (that is, simulate X 0 , X 1 , . . . , X 5 ). Repeat the simulation 100 times. My solution: states <- c(1, 2) alpha <- c(1, 1)/2 mat <- matrix(c(1/2, 1/2, 0, 1), nrow = 2, ncol = 2) nextX <- function(X, pMat) { probVec <- vector() if(X == states[1]) { probVec <- pMat[1,] } if(X==states[2]) { probVec <- pMat[2,] } return(sample(states, 1,

How to obtain transition probability matrix in matrix?

旧巷老猫 提交于 2019-12-24 01:37:30
问题 Suppose I have a sequence x= 1,3,3,1,2,1,4,2,3,1,4,2,4,4,4,3,1,2,5,1 and it has five states 1 3 2 4 5. I have to obtain transition probability matrix in MATLAB by this equation, probability= (Number of observation pairs x(t) & x(t+1), with x(t) in state i and x(t+1) in state j)/(Number of observation pairs x(t) & x(t+1), with x(t) in state i and x(t+1) in any one of the states 1......s). I tried by this code but it giving error x=[1 3 3 1 2 1 4 2 3 1 4 2 4 4 4 3 1 2 5 1] n = length(x)-1 p =