changeset 9629:387026da0f94 octave-forge

improvements to the documentation
author mmarzolla
date Sun, 11 Mar 2012 16:44:18 +0000
parents d91fd1efc9bf
children 62abe47cdca8
files main/queueing/doc/markovchains.txi main/queueing/doc/queueing.html main/queueing/doc/queueing.pdf main/queueing/inst/ctmc.m
diffstat 4 files changed, 150 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/main/queueing/doc/markovchains.txi	Sun Mar 11 15:45:11 2012 +0000
+++ b/main/queueing/doc/markovchains.txi	Sun Mar 11 16:44:18 2012 +0000
@@ -60,11 +60,7 @@
 
 The transition probability matrix @math{\bf P} must satisfy the
 following two properties: (1) @math{P_{i, j} @geq{} 0} for all
-@math{i, j}, and (2) @math{\sum_{j=1}^N P_{i,j} = 1}. We denote with
-@math{{\bf \pi}(n) = (\pi_1(n), \pi_2(n), @dots{}, \pi_N(n) )} the
-@emph{state occupancy probability vector} at step
-@math{n}. @math{\pi_i(n)} denotes the probability that the system is
-in state @math{i} at step @math{n}.
+@math{i, j}, and (2) @math{\sum_{j=1}^N P_{i,j} = 1}. 
 
 @c
 @DOCSTRING(dtmc_check_P)
@@ -74,6 +70,11 @@
 @c
 @subsection State occupancy probabilities
 
+We denote with @math{{\bf \pi}(n) = (\pi_1(n), \pi_2(n), @dots{},
+\pi_N(n) )} the @emph{state occupancy probability vector} at step
+@math{n}. @math{\pi_i(n)} denotes the probability that the system is
+in state @math{i} at step @math{n}.
+
 Given the transition probability matrix @math{\bf P} and the initial
 state occupancy probability vector @math{{\bf \pi}(0) = (\pi_1(0),
 \pi_2(0), @dots{}, \pi_N(0))} at step 0, the state occupancy
@@ -97,7 +98,8 @@
 occupancy probability} @math{{\bf \pi} = \lim_{n \rightarrow +\infty}
 {\bf \pi}(n)}, which is independent from the initial state occupancy
 @math{{\bf \pi}(0)}. The stationary state occupancy probability vector
-@math{\bf \pi} satisfies @math{{\bf \pi} = {\bf \pi} {\bf P}}.
+@math{\bf \pi} satisfies @math{{\bf \pi} = {\bf \pi} {\bf P}}
+and @math{\sum_{i=1}^N \pi_i = 1}
 
 @c
 @DOCSTRING(dtmc)
@@ -148,6 +150,27 @@
 @node Continuous-Time Markov Chains
 @section Continuous-Time Markov Chains
 
+A stochastic process @math{@{X(t), t @geq{} 0@}} is a continuous-time
+Markov chain if, for all integers @math{n}, and for any sequence
+@math{t_0, t_1 , \ldots , t_n, t_{n+1}} such that @math{t_0 < t_1 <
+\ldots < t_n < t_{n+1}}, we have
+
+@iftex
+@tex
+$$P(X_{t_{n+1}} = x_{n+1}\ |\ X(t_n) = x_n, X(t_{n-1}) = x_{n-1}, \ldots, X(t_0) = x_0) = P(X(t_{n+1}) = x_{n+1}\ |\ X(t_n) = x_n)$$
+@end tex
+@end iftex
+@ifnottex
+@math{P(X_{n+1} = x_{n+1} | X_n = x_n, X_{n-1} = x_{n-1}, ..., X_0 = x_0) = P(X_{n+1} = x_{n+1} | X_n = x_n)}
+@end ifnottex
+
+A continuous-time Markov chain is defined according to an
+@emph{infinitesimal generator matrix} @math{{\bf Q} = [Q_{i,j}]} such
+that for each @math{i \neq j}, @math{Q_{i, j}} is the transition rate
+from state @math{i} to state @math{j}. The elements @math{Q_{i, i}}
+must be defined in such a way that the infinitesimal generator matrix
+@math{\bf Q} satisfies the property @math{\sum_{j=1}^N Q_{i,j} = 0}.
+
 @DOCSTRING(ctmc_check_Q)
 
 @menu
@@ -162,6 +185,37 @@
 @node State occupancy probabilities
 @subsection State occupancy probabilities
 
+Similarly to the discrete case, we denote with @math{{\bf \pi}(t) =
+(\pi_1(t), \pi_2(t), @dots{}, \pi_N(t) )} the @emph{state occupancy
+probability vector} at time @math{t}. @math{\pi_i(t)} denotes the
+probability that the system is in state @math{i} at time @math{t @geq{} 0}.
+
+Given the infinitesimal generator matrix @math{\bf Q} and the initial
+state occupancy probability vector @math{{\bf \pi}(0) = (\pi_1(0),
+\pi_2(0), @dots{}, \pi_N(0))}, the state occupancy probability vector
+@math{{\bf \pi}(t)} at time @math{t} can be computed as:
+
+@iftex
+@tex
+$${\bf \pi}(t) = {\bf \pi}(0) \exp( {\bf Q} t )$$
+@end tex
+@end iftex
+@ifnottex
+@example
+@group
+\pi(t) = \pi(0) exp(Qt)
+@end group
+@end example
+@end ifnottex
+
+@noindent where @math{\exp( {\bf Q} t )} is the matrix exponential
+of @math{{\bf Q} t}. Under certain conditions, there exists a
+@emph{stationary state occupancy probability} @math{{\bf \pi} =
+\lim_{t \rightarrow +\infty} {\bf \pi}(t)}, which is independent from
+the initial state occupancy @math{{\bf \pi}(0)}. The stationary state
+occupancy probability vector @math{\bf \pi} satisfies 
+@math{{\bf \pi} {\bf Q} = {\bf 0}} and @math{\sum_{i=1}^N \pi_i = 1}.
+
 @DOCSTRING(ctmc)
 
 @noindent @strong{EXAMPLE}
@@ -195,7 +249,7 @@
 (L_1(t), L_2(t), \ldots L_N(t))} such that @math{L_i(t)} is the
 expected sojourn time in state @math{i} during the interval
 @math{[0,t)}, assuming that the initial occupancy probability at time
-0 was @math{{\bf \pi}(0)}. Then, @math{{\bf L}(t)} is the solution of
+0 was @math{{\bf \pi}(0)}. @math{{\bf L}(t)} is the solution of
 the following differential equation:
 
 @iftex
@@ -213,9 +267,26 @@
 @end example
 @end ifnottex
 
-The function @code{ctmc_exps} can be used to compute @math{{\bf
-L}(t)}, by using the @code{lsode} Octave function to solve the above
-linear differential equation.
+Alternatively, @math{{\bf L}(t)} can also be expressed in integral
+form as:
+
+@iftex
+@tex
+$$ {\bf L}(t) = \int_{u=0}^t {\bf \pi}(u) du$$
+@end tex
+@end iftex
+@ifnottex
+@example
+@group
+       / t
+L(t) = |      pi(u) du
+       / u=0
+@end group
+@end example
+@end ifnottex
+
+@noindent where @math{{\bf \pi}(t) = {\bf \pi}(0) \exp({\bf Q}t)} is
+the state occupancy probability at time @math{t}.
 
 @DOCSTRING(ctmc_exps)
 
@@ -225,7 +296,7 @@
 rate from state @math{i} to state @math{i+1} is @math{\lambda_i = i
 \lambda} (@math{i=1, 2, 3}), with @math{\lambda = 0.5}. The following
 code computes the expected sojourn time in state @math{i},
-given the initial occupancy probability @math{p_0=(1,0,0,0)}. 
+given the initial occupancy probability @math{{\bf \pi}_0=(1,0,0,0)}. 
 
 @example
 @group
--- a/main/queueing/doc/queueing.html	Sun Mar 11 15:45:11 2012 +0000
+++ b/main/queueing/doc/queueing.html	Sun Mar 11 16:44:18 2012 +0000
@@ -811,11 +811,7 @@
 
    <p>The transition probability matrix \bf P must satisfy the
 following two properties: (1) P_i, j &ge; 0 for all
-i, j, and (2) \sum_j=1^N P_i,j = 1. We denote with
-\bf \pi(n) = (\pi_1(n), \pi_2(n), <small class="dots">...</small>, \pi_N(n) ) the
-<em>state occupancy probability vector</em> at step
-n. \pi_i(n) denotes the probability that the system is
-in state i at step n.
+i, j, and (2) \sum_j=1^N P_i,j = 1.
 
    <p><a name="doc_002ddtmc_005fcheck_005fP"></a>
 
@@ -832,7 +828,12 @@
 
 <h4 class="subsection">4.1.1 State occupancy probabilities</h4>
 
-<p>Given the transition probability matrix \bf P and the initial
+<p>We denote with \bf \pi(n) = (\pi_1(n), \pi_2(n), <small class="dots">...</small>,
+\pi_N(n) ) the <em>state occupancy probability vector</em> at step
+n. \pi_i(n) denotes the probability that the system is
+in state i at step n.
+
+   <p>Given the transition probability matrix \bf P and the initial
 state occupancy probability vector \bf \pi(0) = (\pi_1(0),
 \pi_2(0), <small class="dots">...</small>, \pi_N(0)) at step 0, the state occupancy
 probability vector \bf \pi(n) at step n can be
@@ -844,7 +845,8 @@
 occupancy probability</em> \bf \pi = \lim_n \rightarrow +\infty
 \bf \pi(n), which is independent from the initial state occupancy
 \bf \pi(0). The stationary state occupancy probability vector
-\bf \pi satisfies \bf \pi = \bf \pi \bf P.
+\bf \pi satisfies \bf \pi = \bf \pi \bf P
+and \sum_i=1^N \pi_i = 1
 
    <p><a name="doc_002ddtmc"></a>
 
@@ -1009,7 +1011,21 @@
 
 <h3 class="section">4.2 Continuous-Time Markov Chains</h3>
 
-<p><a name="doc_002dctmc_005fcheck_005fQ"></a>
+<p>A stochastic process {X(t), t &ge; 0} is a continuous-time
+Markov chain if, for all integers n, and for any sequence
+t_0, t_1 , \ldots , t_n, t_n+1 such that t_0 &lt; t_1 &lt;
+\ldots &lt; t_n &lt; t_n+1, we have
+
+   <p>P(X_n+1 = x_n+1 | X_n = x_n, X_n-1 = x_n-1, ..., X_0 = x_0) = P(X_n+1 = x_n+1 | X_n = x_n)
+
+   <p>A continuous-time Markov chain is defined according to an
+<em>infinitesimal generator matrix</em> \bf Q = [Q_i,j] such
+that for each i \neq j, Q_i, j is the transition rate
+from state i to state j. The elements Q_i, i
+must be defined in such a way that the infinitesimal generator matrix
+\bf Q satisfies the property \sum_j=1^N Q_i,j = 0.
+
+   <p><a name="doc_002dctmc_005fcheck_005fQ"></a>
 
 <div class="defun">
 &mdash; Function File: [<var>result</var> <var>err</var>] = <b>ctmc_check_Q</b> (<var>Q</var>)<var><a name="index-ctmc_005fcheck_005fQ-16"></a></var><br>
@@ -1041,11 +1057,31 @@
 
 <h4 class="subsection">4.2.1 State occupancy probabilities</h4>
 
-<p><a name="doc_002dctmc"></a>
+<p>Similarly to the discrete case, we denote with \bf \pi(t) =
+(\pi_1(t), \pi_2(t), <small class="dots">...</small>, \pi_N(t) ) the <em>state occupancy
+probability vector</em> at time t. \pi_i(t) denotes the
+probability that the system is in state i at time t &ge; 0.
+
+   <p>Given the infinitesimal generator matrix \bf Q and the initial
+state occupancy probability vector \bf \pi(0) = (\pi_1(0),
+\pi_2(0), <small class="dots">...</small>, \pi_N(0)), the state occupancy probability vector
+\bf \pi(t) at time t can be computed as:
+
+<pre class="example">     \pi(t) = \pi(0) exp(Qt)
+</pre>
+   <p class="noindent">where \exp( \bf Q t ) is the matrix exponential
+of \bf Q t. Under certain conditions, there exists a
+<em>stationary state occupancy probability</em> \bf \pi =
+\lim_t \rightarrow +\infty \bf \pi(t), which is independent from
+the initial state occupancy \bf \pi(0). The stationary state
+occupancy probability vector \bf \pi satisfies
+\bf \pi \bf Q = \bf 0 and \sum_i=1^N \pi_i = 1.
+
+   <p><a name="doc_002dctmc"></a>
 
 <div class="defun">
 &mdash; Function File: <var>p</var> = <b>ctmc</b> (<var>Q</var>)<var><a name="index-ctmc-18"></a></var><br>
-&mdash; Function File: <var>p</var> = <b>ctmc</b> (<var>Q, t. q0</var>)<var><a name="index-ctmc-19"></a></var><br>
+&mdash; Function File: <var>p</var> = <b>ctmc</b> (<var>Q, t. p0</var>)<var><a name="index-ctmc-19"></a></var><br>
 <blockquote>
         <p><a name="index-Markov-chain_002c-continuous-time-20"></a><a name="index-Continuous-time-Markov-chain-21"></a><a name="index-Markov-chain_002c-state-occupancy-probabilities-22"></a><a name="index-Stationary-probabilities-23"></a>
 With a single argument, compute the stationary state occupancy
@@ -1080,7 +1116,7 @@
 satisfies the equation p\bf Q = 0 and \sum_i=1^N p_i = 1. 
 If this function is invoked with three arguments, <var>p</var><code>(i)</code>
 is the probability that the system is in state i at time <var>t</var>,
-given the initial occupancy probabilities <var>q0</var>.
+given the initial occupancy probabilities <var>p0</var>.
 
         </dl>
 
@@ -1152,16 +1188,22 @@
 (L_1(t), L_2(t), \ldots L_N(t)) such that L_i(t) is the
 expected sojourn time in state i during the interval
 [0,t), assuming that the initial occupancy probability at time
-0 was \bf \pi(0). Then, \bf L(t) is the solution of
+0 was \bf \pi(0). \bf L(t) is the solution of
 the following differential equation:
 
 <pre class="example">      dL
       --(t) = L(t) Q + pi(0),    L(0) = 0
       dt
 </pre>
-   <p>The function <code>ctmc_exps</code> can be used to compute \bf
-L(t), by using the <code>lsode</code> Octave function to solve the above
-linear differential equation.
+   <p>Alternatively, \bf L(t) can also be expressed in integral
+form as:
+
+<pre class="example">            / t
+     L(t) = |      pi(u) du
+            / u=0
+</pre>
+   <p class="noindent">where \bf \pi(t) = \bf \pi(0) \exp(\bf Qt) is
+the state occupancy probability at time t.
 
    <p><a name="doc_002dctmc_005fexps"></a>
 
@@ -1212,7 +1254,7 @@
 rate from state i to state i+1 is \lambda_i = i
 \lambda (i=1, 2, 3), with \lambda = 0.5. The following
 code computes the expected sojourn time in state i,
-given the initial occupancy probability p_0=(1,0,0,0).
+given the initial occupancy probability \bf \pi_0=(1,0,0,0).
 
 <pre class="example"><pre class="verbatim">      lambda = 0.5;
       N = 4;
Binary file main/queueing/doc/queueing.pdf has changed
--- a/main/queueing/inst/ctmc.m	Sun Mar 11 15:45:11 2012 +0000
+++ b/main/queueing/inst/ctmc.m	Sun Mar 11 16:44:18 2012 +0000
@@ -18,7 +18,7 @@
 ## -*- texinfo -*-
 ##
 ## @deftypefn {Function File} {@var{p} =} ctmc (@var{Q})
-## @deftypefnx {Function File} {@var{p} =} ctmc (@var{Q}, @var{t}. @var{q0})
+## @deftypefnx {Function File} {@var{p} =} ctmc (@var{Q}, @var{t}. @var{p0})
 ##
 ## @cindex Markov chain, continuous time
 ## @cindex Continuous time Markov chain
@@ -63,7 +63,7 @@
 ## satisfies the equation @math{p{\bf Q} = 0} and @math{\sum_{i=1}^N p_i = 1}.
 ## If this function is invoked with three arguments, @code{@var{p}(i)}
 ## is the probability that the system is in state @math{i} at time @var{t},
-## given the initial occupancy probabilities @var{q0}.
+## given the initial occupancy probabilities @var{p0}.
 ##
 ## @end table
 ##
@@ -72,7 +72,7 @@
 ## Author: Moreno Marzolla <marzolla(at)cs.unibo.it>
 ## Web: http://www.moreno.marzolla.name/
 
-function q = ctmc( Q, t, q0 )
+function q = ctmc( Q, t, p0 )
 
   persistent epsilon = 10*eps;
 
@@ -91,17 +91,17 @@
   endif
 
   if ( nargin > 2 )
-    ( isvector(q0) && length(q0) == N && all(q0>=0) && abs(sum(q0)-1.0)<epsilon ) || \
-        usage( "q0 must be a probability vector" );   
-    q0 = q0(:)'; # make q0 a row vector
+    ( isvector(p0) && length(p0) == N && all(p0>=0) && abs(sum(p0)-1.0)<epsilon ) || \
+        usage( "p0 must be a probability vector" );   
+    p0 = p0(:)'; # make p0 a row vector
   else
-    q0 = ones(1,N) / N;
+    p0 = ones(1,N) / N;
   endif
 
   if ( nargin == 1 )
     q = __ctmc_steady_state( Q );
   else
-    q = __ctmc_transient(Q, t, q0 );
+    q = __ctmc_transient(Q, t, p0 );
   endif
 
 endfunction
@@ -132,8 +132,8 @@
 endfunction
 
 ## Helper function, compute transient probability
-function q = __ctmc_transient( Q, t, q0 )
-  q = q0*expm(Q*t);
+function q = __ctmc_transient( Q, t, p0 )
+  q = p0*expm(Q*t);
 endfunction
 
 %!test