markov – Markov system building and description

class fiabilipy.Markovprocess(components, initstates)[source]

Initialize the markov process management of the system.

  • components (list) – the is the list of the components to manage
  • initstates (dict or list) – describes the initial state of the process, giving the initial probabilities of being in each situation


Let S be a system of two components A and B.

>>> from fiabilipy import Component
>>> A, B = Component('A', 1e-2), Component('B', 1e-6)
>>> comp = (A, B)
>>> init = [0.8, 0.1, 0.1, 0]
>>> process = Markovprocess(comp, init)
  • init[0] is the probability of having A and B working
  • init[1] is the probability of having A working and not B
  • init[2] is the probability of having B working and not A
  • init[3] is the probability of having neither A nor B working

In a general way init[i] is the probability of having:

>>> for c, state in enumerate(binary_repr(i, len(components))):
>>>     if state:
>>>         print('%s working' % components[c])
>>>     else:
>>>         print('%s not working' % components[c])

As initstates may be very sparse, it can be given through a dictionnary as follow:

>>> init = {}
>>> init[0] = 0.8
>>> init[1] = init[2] = 0.1

Print the content of the dot file needed to draw the markov process

Parameters:output (file-like object, optional) – If output is given, then the content is written into this file. output must have a write() method.


Please, see the Graphviz website to have more information about how to transform the ouput code into a nice picture.

value(t, statefunc=None)[source]

Compute the probability of being in some states.

  • t (float) – when the probability must be computed
  • state (function) – a function defining the state you want to know the probability


>>> A, B, C, D = [Component(i, 1e-3) for i in xrange(4)]
>>> comp = (A, B, C, D)
>>> process = Markovprocess(comp, {0:1})
>>> availablefunc = lambda x: (x[0] or x[1]) and (x[2] or x[3])
>>> process.value(100, statefunc=availablefunc)

So, at \(t = 100\), the probability for the system to be available is approximaltly 0.982.

If you want to know, the probability, at \(t = 1000\) that all the components work but the first one, you proceed like that

>>> allbutfirstfunc = lambda x: not x[0] and x[1] and x[2] and x[3]
>>> allbutfirststates = process.computestates(allbutfirstfunc)
>>> process.value(1000, states=allbutfirststates)