def logarithmic_utility(self, quantities_by_good_pbk: GoodHoldings) -> float: """ Compute agent's utility given her utility function params and a good bundle. :param quantities_by_good_pbk: the good holdings (dictionary) with the identifier (key) and quantity (value) for each good :return: utility value """ result = logarithmic_utility(self.utility_params_by_good_pbk, quantities_by_good_pbk, self._quantity_shift) return result
def logarithmic_utility(self, quantities_by_good_id: GoodHoldings) -> float: """ Compute agent's utility given her utility function params and a good bundle. :param quantities_by_good_id: the good holdings (dictionary) with the identifier (key) and quantity (value) for each good :return: utility value """ enforce(self.is_initialized, "Preferences params not set!") result = logarithmic_utility( self.utility_params_by_good_id, quantities_by_good_id, self._quantity_shift ) return result
def test_logarithmic_utility(): """Test logarithmic utlity.""" assert (logarithmic_utility( utility_params_by_good_id={ "good_1": 0.2, "good_2": 0.8 }, quantities_by_good_id={ "good_1": 2, "good_2": 1 }, ) > 0), "Utility should be positive."
def get_score(self) -> float: """ Compute the score of the current state. The score is computed as the sum of all the utilities for the good holdings with positive quantity plus the money left. :return: the score. """ goods_score = logarithmic_utility(self.utility_params_by_good_id, self.quantities_by_good_id) money_score = linear_utility(self.exchange_params_by_currency_id, self.amount_by_currency_id) score = goods_score + money_score return score