def __init__(self, samples, ref=None, conf=0.95): r""" Constructs a sampled HMSM Parameters ---------- samples : list of HMSM Sampled HMSM objects ref : HMSM Single-point estimator, e.g. containing a maximum likelihood HMSM. If not given, the sample mean will be used. conf : float, optional, default=0.95 Confidence interval. By default two-sigma (95.4%) is used. Use 95.4% for two sigma or 99.7% for three sigma. """ # validate input assert is_iterable( samples), 'samples must be a list of MSM objects, but is not.' assert isinstance( samples[0], _HMSM), 'samples must be a list of MSM objects, but is not.' # construct superclass 1 _SampledModel.__init__(self, samples, conf=conf) # construct superclass 2 if ref is None: Pref = self.sample_mean('P') pobsref = self.sample_mean('pobs') _HMSM.__init__(self, Pref, pobsref, dt_model=samples[0].dt_model) else: _HMSM.__init__(self, ref.transition_matrix, ref.observation_probabilities, dt_model=ref.dt_model)
def _estimate_param_scan_worker(estimator, params, X, evaluate, evaluate_args, failfast): """ Method that runs estimation for several parameter settings. Defined as a worker for Parallelization """ # run estimation model = None try: # catch any exception estimator.estimate(X, **params) model = estimator.model except: e = sys.exc_info()[1] if isinstance(estimator, Loggable): estimator.logger.warning("Ignored error during estimation: %s" % e) if failfast: raise # re-raise else: pass # just return model=None # deal with results res = [] # deal with result if evaluate is None: # we want full models res.append(model) # we want to evaluate function(s) of the model elif _types.is_iterable(evaluate): values = [] # the function values the model for ieval, name in enumerate(evaluate): # get method/attribute name and arguments to be evaluated name = evaluate[ieval] args = () if evaluate_args is not None: args = evaluate_args[ieval] # wrap single arguments in an iterable again to pass them. if _types.is_string(args): args = (args, ) # evaluate try: # try calling method/property/attribute value = _call_member(estimator.model, name, failfast, *args) # couldn't find method/property/attribute except AttributeError as e: if failfast: raise e # raise an AttributeError else: value = None # we just ignore it and return None values.append(value) # if we only have one value, unpack it if len(values) == 1: values = values[0] res.append(values) else: raise ValueError('Invalid setting for evaluate: ' + str(evaluate)) if len(res) == 1: res = res[0] return res
def _estimate_param_scan_worker(estimator, params, X, evaluate, evaluate_args, failfast): # run estimation model = estimator.estimate(X, **params) # deal with results res = [] # deal with result if evaluate is None: # we want full models res.append(model) # we want to evaluate function(s) of the model elif _types.is_iterable(evaluate): values = [] # the function values the model for ieval in range(len(evaluate)): # get method/attribute name and arguments to be evaluated name = evaluate[ieval] args = None if evaluate_args is not None: args = evaluate_args[ieval] # evaluate try: # try calling method/property/attribute value = _call_member(model, name, args=args) # couldn't find method/property/attribute except AttributeError as e: if failfast: raise e # raise an AttributeError else: value = None # we just ignore it and return None values.append(value) # if we only have one value, unpack it if len(values) == 1: values = values[0] else: raise ValueError('Invalid setting for evaluate: ' + str(evaluate)) if len(res) == 1: res = res[0] return res
def __init__(self, samples, ref=None, conf=0.95): r""" Constructs a sampled MSM Parameters ---------- samples : list of MSM Sampled MSM objects ref : obj of type :class:`pyemma.msm.MaximumLikelihoodMSM` or :class:`pyemma.msm.BayesianMSM` Single-point estimator, e.g. containing a maximum likelihood or mean MSM conf : float, optional, default=0.95 Confidence interval. By default two-sigma (95.4%) is used. Use 95.4% for two sigma or 99.7% for three sigma. """ # validate input assert is_iterable( samples), 'samples must be a list of MSM objects, but is not.' assert isinstance( samples[0], MSM), 'samples must be a list of MSM objects, but is not.' # construct superclass 1 SampledModel.__init__(self, samples, conf=conf) # construct superclass 2 if ref is None: Pref = self.sample_mean('P') MSM.__init__(self, Pref, dt_model=samples[0].dt_model, neig=samples[0].neig, ncv=samples[0].ncv) else: MSM.__init__(self, ref.Pref, pi=ref.pi, reversible=ref.reversible, dt_model=ref.dt_model, neig=ref.neig, ncv=ref.ncv)