Skip to content

Commit

Permalink
MarkovChain: Change simulate_values to simulate
Browse files Browse the repository at this point in the history
- Add simulate_indices which return indices
  • Loading branch information
oyamad committed Apr 11, 2016
1 parent f0c681f commit 05e8ad8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions quantecon/markov/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,11 @@ def cdfs1d(self):
self._cdfs1d = cdfs1d
return self._cdfs1d

def simulate(self, ts_length, init=None, num_reps=None, random_state=None):
def simulate_indices(self, ts_length, init=None, num_reps=None,
random_state=None):
"""
Simulate time series of state transitions.
Simulate time series of state transitions, where state indices
are returned.
Parameters
----------
Expand Down Expand Up @@ -539,18 +541,17 @@ def simulate(self, ts_length, init=None, num_reps=None, random_state=None):
else:
return X

def simulate_values(self, ts_length, init_value=None, num_reps=None,
random_state=None):
def simulate(self, ts_length, init=None, num_reps=None, random_state=None):
"""
Simulate time series of state transitions, but return the values
in `state_values` instead of the state indices.
Simulate time series of state transitions, where the states are
annotated with their values (if `state_values` is not None).
Parameters
----------
ts_length : scalar(int)
Length of each simulation.
init_value : scalar or array_like, optional(default=None)
init : scalar or array_like, optional(default=None)
Initial state values(s). If None, the initial state is
randomly drawn.
Expand All @@ -571,12 +572,12 @@ def simulate_values(self, ts_length, init_value=None, num_reps=None,
the `simulate` method for more information.
"""
if init_value is not None:
init_idx = self.get_index(init_value)
if init is not None:
init_idx = self.get_index(init)
else:
init_idx = None
X = self.simulate(ts_length, init=init_idx, num_reps=num_reps,
random_state=random_state)
X = self.simulate_indices(ts_length, init=init_idx, num_reps=num_reps,
random_state=random_state)

# Annotate states
if self.state_values is not None:
Expand Down
2 changes: 1 addition & 1 deletion quantecon/markov/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def test_simulate(self):
mc = self.mc_periodic_dict['mc']
ts_length = 6

methods = ['simulate', 'simulate_values']
methods = ['simulate_indices', 'simulate']

init_idx = 0
inits = [init_idx, self.state_values[init_idx]]
Expand Down

0 comments on commit 05e8ad8

Please sign in to comment.