class_docstr: Generator for Thompson sampling.
  
  The generator performs Thompson sampling on the data passed in via `fit`.
  Arms are given weight proportional to the probability that they are
  winners, according to Monte Carlo simulations.
class_docstr_tok: ["Generator","for","Thompson","sampling",".","The","generator","performs","Thompson","sampling","on","the","data","passed","in","via","`","fit","`",".","Arms","are","given","weight","proportional","to","the","probability","that","they","are","winners",",","according","to","Monte","Carlo","simulations","."]
code: def _generate_weights(
      self,
      objective_weights: np.ndarray,
      outcome_constraints: Optional[
          Tuple[np.ndarray, np.ndarray]
      ] = None,
  ) -> List[float]:
      samples, fraction_all_infeasible = self._produce_samples(
          num_samples=self.num_samples,
          objective_weights=objective_weights,
          outcome_constraints=outcome_constraints,
      )
      if fraction_all_infeasible > 0.99:
          raise ModelError(TS_NO_FEASIBLE_ARMS_ERROR)
  
      num_valid_samples = samples.shape[1]
      while num_valid_samples < self.num_samples:
          num_additional_samples = (
              self.num_samples - num_valid_samples
          ) / (1 - fraction_all_infeasible)
          num_additional_samples = int(
              np.maximum(num_additional_samples, 100)
          )
          new_samples, _ = self._produce_samples(
              num_samples=num_additional_samples,
              objective_weights=objective_weights,
              outcome_constraints=outcome_constraints,
          )
          samples = np.concatenate([samples, new_samples], axis=1)
          num_valid_samples = samples.shape[1]
  
      winner_indices = np.argmax(samples, axis=0)  # (num_samples,)
      winner_counts = np.zeros(len(self.X))  # (k,)
      for index in winner_indices:
          winner_counts[index] += 1
      weights = winner_counts / winner_counts.sum()
      return weights.tolist()
  
imports: import hashlib
  import json
  from typing import Dict, List, Optional, Tuple
  import numpy
  from ax.core.types import TGenMetadata, TParamValue, TParamValueList
  from ax.exceptions.constants import TS_MIN_WEIGHT_ERROR, TS_NO_FEASIBLE_ARMS_ERROR
  from ax.exceptions.model import ModelError
  from ax.models.discrete_base import DiscreteModel
  from ax.models.types import TConfig
  from ax.utils.common.docutils import copy_doc
label_desc: Use image node_id 5 for calling the ThompsonSampler obj's underlying member method code with example usage: obj._generate_weights(objective_weights, outcome_constraints) and returns: weights