def test_invalid_ctor_args(self): with self.assertRaises(ValueError): # not row stochastic DiscreteOutputModel( np.array([[0.5, 0.3, 0.2, 0.1], [0.5, 0.3, 0.2, 0.0]])) # no-op: this does not raise DiscreteOutputModel(np.array([[0., 1., 0., 0.], [1., 0., 0., 0.]]), prior=np.random.normal(size=(2, 4)).astype( np.float64)) with self.assertRaises(ValueError): # prior has wrong shape, raise DiscreteOutputModel(np.array([[0., 1., 0., 0.], [1., 0., 0., 0.]]), prior=np.random.normal(size=(2, 5)).astype( np.float64))
def __init__( self, transition_model, output_model: Union[np.ndarray, OutputModel], initial_distribution: Optional[np.ndarray] = None, likelihoods: Optional[np.ndarray] = None, state_probabilities: Optional[List[np.ndarray]] = None, initial_count: Optional[np.ndarray] = None, hidden_state_trajectories: Optional[Iterable[np.ndarray]] = None, stride: Union[int, str] = 1, observation_symbols: Optional[np.ndarray] = None, observation_symbols_full: Optional[np.ndarray] = None): super().__init__() if isinstance(transition_model, np.ndarray): from deeptime.markov.msm import MarkovStateModel transition_model = MarkovStateModel(transition_model) if isinstance(output_model, np.ndarray): output_model = DiscreteOutputModel(output_model) if transition_model.n_states != output_model.n_hidden_states: raise ValueError("Transition model must describe hidden states") if initial_distribution is None: # uniform initial_distribution = np.ones( transition_model.n_states) / transition_model.n_states if initial_distribution.shape[0] != transition_model.n_states: raise ValueError( "Initial distribution over hidden states must be of length {}". format(transition_model.n_states)) self._transition_model = transition_model self._output_model = output_model self._initial_distribution = initial_distribution self._likelihoods = likelihoods self._state_probabilities = state_probabilities self._initial_count = initial_count self._hidden_state_trajectories = hidden_state_trajectories if observation_symbols is None and output_model.n_observable_states >= 0: observation_symbols = np.arange(output_model.n_observable_states) observation_symbols_full = observation_symbols self._observation_symbols = observation_symbols self._observation_symbols_full = observation_symbols_full if not (isinstance(stride, Integral) or (isinstance(stride, str) and stride == 'effective')): raise ValueError( "Stride argument must either be an integer value or 'effective', " "but was: {}".format(stride)) self._stride = stride