def discrete_outcomes(self, n_max: int = None, astype: Type['Outcome'] = dict) -> List['Outcome']: """ A discrete set of outcomes that spans the outcome space Args: n_max: The maximum number of outcomes to return. If None, all outcomes will be returned for discrete issues and *100* if any of the issues was continuous astype: A type to cast the resulting outcomes to. Returns: List[Outcome]: List of `n` or less outcomes """ if self.outcomes is not None: return self.outcomes if self.__discrete_outcomes is None: if all(issue.is_discrete() for issue in self.issues): self.__discrete_outcomes = Issue.sample( issues=self.issues, n_outcomes=n_max, astype=astype, with_replacement=False, fail_if_not_enough=False) else: self.__discrete_outcomes = Issue.sample( issues=self.issues, n_outcomes=n_max if n_max is not None else 100, astype=astype, with_replacement=False, fail_if_not_enough=False) return self.__discrete_outcomes
def random_outcomes( self, n: int = 1, astype: Type[Outcome] = None ) -> List["Outcome"]: """Returns random offers. Args: n: Number of outcomes to generate astype: The type to use for the generated outcomes Returns: A list of outcomes (in the type specified using `astype`) of at most n outcomes. Remarks: - If the number of outcomes `n` cannot be satisfied, a smaller number will be returned - Sampling is done without replacement (i.e. returned outcomes are unique). """ if astype is None: astype = self.ami.outcome_type if self.ami.issues is None or len(self.ami.issues) == 0: raise ValueError("I do not have any issues to generate offers from") return Issue.sample( issues=self.issues, n_outcomes=n, astype=astype, with_replacement=False, fail_if_not_enough=False, )
def equiprobable_thresholds(cls, n: int, ufun: "UtilityFunction", issues: List[Issue], n_samples: int = 1000) -> List[float]: """ Generates thresholds for the n given levels where levels are equally likely approximately Args: n: Number of scale levels (one side) ufun: The utility function to use issues: The issues to generate the thresholds for n_samples: The number of samples to use during the process """ samples = list( Issue.sample(issues, n_samples, with_replacement=False, fail_if_not_enough=False)) n_samples = len(samples) diffs = [] for i, first in enumerate(samples): n_diffs = min(10, n_samples - i - 1) for second in sample(samples[i + 1:], k=n_diffs): diffs.append(abs(ufun.compare_real(first, second))) diffs = np.array(diffs) hist, edges = np.histogram(diffs, bins=n + 1) return edges[1:-1].tolist()
def random_outcomes(self, n: int = 1, astype: Type[Outcome] = dict) -> List['Outcome']: """Returns random offers""" if self.info.issues is None or len(self.info.issues) == 0: raise ValueError( 'I do not have any issues to generate offers from') return Issue.sample(issues=self.issues, n_outcomes=n, astype=astype, with_replacement=False, fail_if_not_enough=False)
def random( cls, issues: List["Issue"], reserved_value=(0.0, 1.0), normalized=True, max_n_outcomes: int = 10000, ): outcomes = (Issue.enumerate(issues) if Issue.num_outcomes(issues) <= max_n_outcomes else Issue.sample(issues, max_n_outcomes, with_replacement=False, fail_if_not_enough=False)) return UtilityFunction.generate_random(1, outcomes)[0]