Discretize the true problem

When the true problem is stage-wise independent continuous or Markovian continuous , it needs to be discretized.

Stage-wise independent continuous problem

The stage-wise independent continuous demand process can be discretized simply by specifying the sample size and the random seed.

from msppy.utils.examples import construct_nvic
nvic = construct_nvic()
nvic.discretize(random_state=888, n_samples=100)

Markovian continuous problem

The following snippet discretizes the Markovian uncertainty by a ten dimensional Markov chain using stochastic approximation method (stochastic gradient descent) with 1000 iterations.

from msppy.utils.examples import construct_nvm
nvm = construct_nvm()
nvm.discretize(n_Markov_states=10, n_sample_paths=1000, method='SA');

Module Reference

msppy.msp.MSLP.discretize(self, n_samples=None, random_state=None, replace=True, n_Markov_states=None, method='SA', n_sample_paths=None, Markov_states=None, transition_matrix=None, int_flag=0)

Discretize Markovian continuous uncertainty by k-means or (robust) stochasitic approximation.

Parameters:
  • n_samples (int, optional, default=None) – number of i.i.d. samples to generate for stage-wise independent randomness.
  • random_state (None | int | instance of RandomState, optional, default=None) – If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by numpy.random.
  • replace (bool, optional, default=True) – Indicates generating i.i.d. samples with/without replacement for stage-wise independent randomness.
  • n_Markov_states (list | int, optional, default=None) – If list, it specifies different dimensions of Markov state space over time. Length of the list should equal length of the Markovian uncertainty. If int, it specifies dimensions of Markov state space. Note: If the uncertainties are int, trained Markov states will be rounded to integers, and duplicates will be removed. In such cases, there is no guaranttee that the number of Markov states is n_Markov_states.
  • method (binary, optional, default=0) – ‘input’: the approximating Markov chain is given by user input ( through specifying Markov_states and transition_matrix) ‘SAA’: use k-means to train Markov chain. ‘SA’: use stochastic approximation to train Markov chain. ‘RSA’: use robust stochastic approximation to train Markov chain.
  • n_sample_paths (int, optional, default=None) – number of sample paths to train the Markov chain.
  • Markov_states/transition_matrix (matrix-like, optional, default=None) – The user input of approximating Markov chain.