Randomly sample n instances of a decision variable. Args: n: Number of samples. If None, sample a single variable. random_state: Random state for reproducibility. Returns: If n is int, array of shape (n,). If n is None, single object.
(
self,
n: Optional[int] = None,
random_state: object = None,
)
| 41 | |
| 42 | @default_random_state |
| 43 | def sample( |
| 44 | self, |
| 45 | n: Optional[int] = None, |
| 46 | random_state: object = None, |
| 47 | ) -> Union[object, np.ndarray]: |
| 48 | """Randomly sample n instances of a decision variable. |
| 49 | |
| 50 | Args: |
| 51 | n: Number of samples. If None, sample a single variable. |
| 52 | random_state: Random state for reproducibility. |
| 53 | |
| 54 | Returns: |
| 55 | If n is int, array of shape (n,). If n is None, single object. |
| 56 | """ |
| 57 | if n is None: |
| 58 | return self._sample(1, random_state=random_state)[0] |
| 59 | else: |
| 60 | return self._sample(n, random_state=random_state) |
| 61 | |
| 62 | def _sample( |
| 63 | self, |