Package qubx :: Module model
[hide private]
[frames] | no frames]

Module model

source code

Hidden Markov model and math.

Copyright 2008-2015 Research Foundation State University of New York This file is part of QUB Express.

QUB Express is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

QUB Express is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License, named LICENSE.txt, in the QUB Express program directory. If not, see <http://www.gnu.org/licenses/>.


Version: 1.11.0

Classes [hide private]
  ConstraintsKinTable
  QubModel
Hidden Markov model, e.g.
  QubModels
Table-like collection of open model files.
  RandomNormalsSmallN
Generates batches of gaussian data; mean 0, std 1.
Functions [hide private]
 
GenerateEvents(model)
Yields (state, duration) of a Markov process, starting from fixed probabilities (model.states:Pr).
source code
 
GenerateEventsX(q, start_state)
Yields (state, duration) of a Markov process, starting from a particular state.
source code
 
GenerateSampleBunches(model, sampling, events)
Yields (sample_array, state_index), one event at a time, from a hidden Markov process.
source code
 
GenerateSampleBunchesX(events, sampling, amps, stds)
Yields (sample_array, state_index), one event at a time from a hidden Markov process.
source code
 
GenerateSamples(model, sampling, events)
Yields one sample at a time from a hidden Markov process.
source code
 
GetNewState(q, state)
Returns the next state, given the state it's coming from.
source code
 
K012ToModel(K0, K1, K2, model)
Copies rate constants from matrices K0 and K1 into model.rates.
source code
 
K01ToModel(K0, K1, model)
Copies rate constants from matrices K0 and K1 into model.rates.
source code
 
MeanFirstPassage(A, Peq, dt)
Returns the matrix M of mean first passage times M[i,j] between states i and j.
source code
 
ModelToClazz(model)
Returns the array([class of state s, for s in (0..nstate-1)]).
source code
 
ModelToFast(model, signal_names=[], on_status=<bound method _DevNull.write of <epydoc.docintrospecter._DevNu...)
Returns a new qubx.fast.model.Model.
source code
 
ModelToP0(model)
Returns the array[nstate] of fixed starting probabilities.
source code
 
ModelToQ(model, stimulus=None)
Returns the matrix Q of combined rate constants.
source code
 
ModelToRateMatrices(model, signal_names=[]) source code
 
ModelToRateMatricesP(model, signal_names=[])
Returns the (nstate x nstate) matrices (K0, K1, K2, Ligand, Voltage, Pressure).
source code
 
NewQubModel()
Returns a new QubModel with two states.
source code
 
OpenQubModel(path)
Reads a QMF file from disk and returns a QubModel.
source code
 
QtoA(Q, dt)
Returns the matrix A = exp( dt * Q ).
source code
 
QtoPe(Q)
Returns the array[nstate] of equilibrium probabilities.
source code
 
QtoQe(Q, clazz, td)
Returns the apparent rate constant matrix, given that events with duration <= td are not recorded.
source code
 
RandomLT(high)
Returns a uniform random number between 0 and high.
source code
 
RandomWeighted(weights)
Returns a random index into weights (number between 0 and len(weights)-1), with likelihood proportional to weights[i].
source code
 
append_clone_if(parent, node)
if node: parent.appendClone(node)
source code
 
dec_if_gt(n)
if x > n: return x-1; else: return x.
source code
 
fieldinfo_k_f(s) source code
 
fieldname_k0_f(sa, sb) source code
 
fieldname_k1_f(sa, sb) source code
 
fieldname_k2_f(sa, sb) source code
 
fieldname_k_f(ki, sa, sb) source code
Variables [hide private]
  ALLOW_THREADS = 1
  BUFSIZE = 8192
  CLIP = 0
  COLOR = defaultdict(<function <lambda> at 0x7fd137b1e1b8>, {0:...
  ERR_CALL = 3
  ERR_DEFAULT = 521
  ERR_IGNORE = 0
  ERR_LOG = 5
  ERR_PRINT = 4
  ERR_RAISE = 2
  ERR_WARN = 1
  FLOATING_POINT_SUPPORT = 1
  FPE_DIVIDEBYZERO = 1
  FPE_INVALID = 8
  FPE_OVERFLOW = 2
  FPE_UNDERFLOW = 4
  False_ = False
  Inf = inf
  Infinity = inf
  MAXDIMS = 32
  MAX_SAFENAME_LEN = 32
  MAY_SHARE_BOUNDS = 0
  MAY_SHARE_EXACT = -1
  MIN_TOTAL_RATE = 1e-09
  NAN = nan
  NINF = -inf
  NZERO = -0.0
  NaN = nan
  PINF = inf
  PZERO = 0.0
  RAISE = 2
  SHIFT_DIVIDEBYZERO = 0
  SHIFT_INVALID = 9
  SHIFT_OVERFLOW = 3
  SHIFT_UNDERFLOW = 6
  ScalarType = (<type 'int'>, <type 'float'>, <type 'complex'>, ...
  ShowDropped = False
  True_ = True
  UFUNC_BUFSIZE_DEFAULT = 8192
  UFUNC_PYVALS_NAME = 'UFUNC_PYVALS'
  UNSET_VALUE = 86738.82583
  WRAP = 1
  __package__ = 'qubx'
  absolute = <ufunc 'absolute'>
  add = <ufunc 'add'>
  arccos = <ufunc 'arccos'>
  arccosh = <ufunc 'arccosh'>
  arcsin = <ufunc 'arcsin'>
  arcsinh = <ufunc 'arcsinh'>
  arctan = <ufunc 'arctan'>
  arctan2 = <ufunc 'arctan2'>
  arctanh = <ufunc 'arctanh'>
  bitwise_and = <ufunc 'bitwise_and'>
  bitwise_not = <ufunc 'invert'>
  bitwise_or = <ufunc 'bitwise_or'>
  bitwise_xor = <ufunc 'bitwise_xor'>
  c_ = <numpy.lib.index_tricks.CClass object>
  cast = {<type 'numpy.bool_'>: <function <lambda> at 0x7fd1396e...
  cbrt = <ufunc 'cbrt'>
  ceil = <ufunc 'ceil'>
  conj = <ufunc 'conjugate'>
  conjugate = <ufunc 'conjugate'>
  copysign = <ufunc 'copysign'>
  cos = <ufunc 'cos'>
  cosh = <ufunc 'cosh'>
  deg2rad = <ufunc 'deg2rad'>
  degrees = <ufunc 'degrees'>
  divide = <ufunc 'divide'>
  e = 2.71828182846
  equal = <ufunc 'equal'>
  euler_gamma = 0.577215664902
  exp = <ufunc 'exp'>
  exp2 = <ufunc 'exp2'>
  expm1 = <ufunc 'expm1'>
  fabs = <ufunc 'fabs'>
  false = False
  floor = <ufunc 'floor'>
  floor_divide = <ufunc 'floor_divide'>
  fmax = <ufunc 'fmax'>
  fmin = <ufunc 'fmin'>
  fmod = <ufunc 'fmod'>
  frexp = <ufunc 'frexp'>
  greater = <ufunc 'greater'>
  greater_equal = <ufunc 'greater_equal'>
  hypot = <ufunc 'hypot'>
  index_exp = <numpy.lib.index_tricks.IndexExpression object>
  inf = inf
  infty = inf
  invert = <ufunc 'invert'>
  isfinite = <ufunc 'isfinite'>
  isinf = <ufunc 'isinf'>
  isnan = <ufunc 'isnan'>
  ldexp = <ufunc 'ldexp'>
  left_shift = <ufunc 'left_shift'>
  less = <ufunc 'less'>
  less_equal = <ufunc 'less_equal'>
  little_endian = True
  log = <ufunc 'log'>
  log10 = <ufunc 'log10'>
  log1p = <ufunc 'log1p'>
  log2 = <ufunc 'log2'>
  logaddexp = <ufunc 'logaddexp'>
  logaddexp2 = <ufunc 'logaddexp2'>
  logical_and = <ufunc 'logical_and'>
  logical_not = <ufunc 'logical_not'>
  logical_or = <ufunc 'logical_or'>
  logical_xor = <ufunc 'logical_xor'>
  maximum = <ufunc 'maximum'>
  mgrid = <numpy.lib.index_tricks.nd_grid object>
  minimum = <ufunc 'minimum'>
  mod = <ufunc 'remainder'>
  modf = <ufunc 'modf'>
  multiply = <ufunc 'multiply'>
  name_float = 'a number'
  name_int = 'an integer'
  nan = nan
  nbytes = {<type 'numpy.bool_'>: 1, <type 'numpy.timedelta64'>:...
  negative = <ufunc 'negative'>
  newaxis = None
hash(x)
  nextafter = <ufunc 'nextafter'>
  not_equal = <ufunc 'not_equal'>
  ogrid = <numpy.lib.index_tricks.nd_grid object>
  pi = 3.14159265359
  power = <ufunc 'power'>
  r_ = <numpy.lib.index_tricks.RClass object>
  rad2deg = <ufunc 'rad2deg'>
  radians = <ufunc 'radians'>
  rdbk = 'Expired.'
  rdbreak = 'supporting'
  rdname = 'qubfast.txt'
  reciprocal = <ufunc 'reciprocal'>
  remainder = <ufunc 'remainder'>
  right_shift = <ufunc 'right_shift'>
  rint = <ufunc 'rint'>
  s_ = <numpy.lib.index_tricks.IndexExpression object>
  sctypeDict = {0: <type 'numpy.bool_'>, 1: <type 'numpy.int8'>,...
  sctypeNA = {'?': 'Bool', 'B': 'UInt8', 'Bool': <type 'numpy.bo...
  sctypes = {'complex': [<type 'numpy.complex64'>, <type 'numpy....
  sign = <ufunc 'sign'>
  signbit = <ufunc 'signbit'>
  sin = <ufunc 'sin'>
  sinh = <ufunc 'sinh'>
  spacing = <ufunc 'spacing'>
  sqrt = <ufunc 'sqrt'>
  square = <ufunc 'square'>
  subtract = <ufunc 'subtract'>
  tan = <ufunc 'tan'>
  tanh = <ufunc 'tanh'>
  true = True
  true_divide = <ufunc 'true_divide'>
  trunc = <ufunc 'trunc'>
  typeDict = {0: <type 'numpy.bool_'>, 1: <type 'numpy.int8'>, 2...
  typeNA = {'?': 'Bool', 'B': 'UInt8', 'Bool': <type 'numpy.bool...
  typecodes = {'All': '?bhilqpBHILQPefdgFDGSUVOMm', 'AllFloat': ...
  valid_identifier = re.compile(r'^[A-Za-z_][A-Za-z_0-9]*$')
Function Details [hide private]

GenerateSampleBunchesX(events, sampling, amps, stds)

source code 

Yields (sample_array, state_index), one event at a time from a hidden Markov process.

Parameters:
  • amps - mean current of each state
  • stds - standard deviation of current in each state

MeanFirstPassage(A, Peq, dt)

source code 

Returns the matrix M of mean first passage times M[i,j] between states i and j.

>>> from  http://www.scopenvironment.org/downloadpubs/scope34/contents.html

Z = inv(I - A + col(1)*row(pEq)) FL[i][j] = (Z[j][j] - Z[i][j]) / pEq[j]

Parameters:
  • A - sampled transition probability matrix A = expm(dt * Q)
  • Peq - equilibrium probability vector
  • dt - sampling interval in seconds

Variables Details [hide private]

COLOR

Value:
defaultdict(<function <lambda> at 0x7fd137b1e1b8>, {0: (0, 0, 0), 1: (\
1, 0, 0), 2: (0, 0, 1), 3: (0, 1, 0), 4: (0, 1, 1), 5: (1, 1, 0), 6: (\
1, 0, 1), 7: (0.5, 0.0, 0.0), 8: (0.525, 0.32025, 0.013125000000000012\
), 9: (0.44550000000000006, 0.55, 0.027500000000000028), 10: (0.149499\
99999999994, 0.575, 0.04312499999999997), 11: (0.059999999999999984, 0\
.6, 0.2759999999999999), 12: (0.078125, 0.625, 0.625), 13: (0.09750000\
000000002, 0.3185, 0.65), 14: (0.22949999999999962, 0.1181250000000000\
4, 0.675), 15: (0.5879999999999999, 0.13999999999999996, 0.7), 16: (0.\
...

ScalarType

Value:
(<type 'int'>,
 <type 'float'>,
 <type 'complex'>,
 <type 'long'>,
 <type 'bool'>,
 <type 'str'>,
 <type 'unicode'>,
 <type 'buffer'>,
...

cast

Value:
{<type 'numpy.bool_'>: <function <lambda> at 0x7fd1396ed758>, <type 'n\
umpy.timedelta64'>: <function <lambda> at 0x7fd1396ed7d0>, <type 'nump\
y.float16'>: <function <lambda> at 0x7fd1396ed848>, <type 'numpy.uint8\
'>: <function <lambda> at 0x7fd1396ed8c0>, <type 'numpy.int8'>: <funct\
ion <lambda> at 0x7fd1396ed938>, <type 'numpy.object_'>: <function <la\
mbda> at 0x7fd1396ed9b0>, <type 'numpy.datetime64'>: <function <lambda\
> at 0x7fd1396eda28>, <type 'numpy.uint64'>: <function <lambda> at 0x7\
fd1396edaa0>, <type 'numpy.int64'>: <function <lambda> at 0x7fd1396edb\
...

nbytes

Value:
{<type 'numpy.bool_'>: 1, <type 'numpy.timedelta64'>: 8, <type 'numpy.\
float16'>: 2, <type 'numpy.uint8'>: 1, <type 'numpy.int8'>: 1, <type '\
numpy.object_'>: 8, <type 'numpy.datetime64'>: 8, <type 'numpy.uint64'\
>: 8, <type 'numpy.int64'>: 8, <type 'numpy.void'>: 0, <type 'numpy.co\
mplex256'>: 32, <type 'numpy.float128'>: 16, <type 'numpy.uint64'>: 8,\
 <type 'numpy.int64'>: 8, <type 'numpy.unicode_'>: 0, <type 'numpy.com\
plex128'>: 16, <type 'numpy.float64'>: 8, <type 'numpy.uint32'>: 4, <t\
ype 'numpy.int32'>: 4, <type 'numpy.string_'>: 0, <type 'numpy.complex\
...

sctypeDict

Value:
{0: <type 'numpy.bool_'>,
 1: <type 'numpy.int8'>,
 2: <type 'numpy.uint8'>,
 3: <type 'numpy.int16'>,
 4: <type 'numpy.uint16'>,
 5: <type 'numpy.int32'>,
 6: <type 'numpy.uint32'>,
 7: <type 'numpy.int64'>,
...

sctypeNA

Value:
{'?': 'Bool',
 'B': 'UInt8',
 'Bool': <type 'numpy.bool_'>,
 'Complex128': <type 'numpy.complex256'>,
 'Complex32': <type 'numpy.complex64'>,
 'Complex64': <type 'numpy.complex128'>,
 'D': 'Complex64',
 'Datetime64': <type 'numpy.datetime64'>,
...

sctypes

Value:
{'complex': [<type 'numpy.complex64'>,
             <type 'numpy.complex128'>,
             <type 'numpy.complex256'>],
 'float': [<type 'numpy.float16'>,
           <type 'numpy.float32'>,
           <type 'numpy.float64'>,
           <type 'numpy.float128'>],
 'int': [<type 'numpy.int8'>, <type 'numpy.int16'>, <type 'numpy.int32\
...

typeDict

Value:
{0: <type 'numpy.bool_'>,
 1: <type 'numpy.int8'>,
 2: <type 'numpy.uint8'>,
 3: <type 'numpy.int16'>,
 4: <type 'numpy.uint16'>,
 5: <type 'numpy.int32'>,
 6: <type 'numpy.uint32'>,
 7: <type 'numpy.int64'>,
...

typeNA

Value:
{'?': 'Bool',
 'B': 'UInt8',
 'Bool': <type 'numpy.bool_'>,
 'Complex128': <type 'numpy.complex256'>,
 'Complex32': <type 'numpy.complex64'>,
 'Complex64': <type 'numpy.complex128'>,
 'D': 'Complex64',
 'Datetime64': <type 'numpy.datetime64'>,
...

typecodes

Value:
{'All': '?bhilqpBHILQPefdgFDGSUVOMm',
 'AllFloat': 'efdgFDG',
 'AllInteger': 'bBhHiIlLqQpP',
 'Character': 'c',
 'Complex': 'FDG',
 'Datetime': 'Mm',
 'Float': 'efdg',
 'Integer': 'bhilqp',
...