def eq_vs_mean_price(self) -> Tuple[List[str], np.ndarray]: """ Compute the mean price of each good and display it together with the equilibrium price. :return: a matrix of shape (2, nb_goods), where every column i contains the prices of the good. """ nb_transactions = len(self.game.transactions) eq_prices = self.game.initialization.eq_prices nb_goods = len(eq_prices) result = np.zeros((2, nb_goods), dtype=np.float32) result[0, :] = np.asarray(eq_prices, dtype=np.float32) prices_by_transactions = np.zeros((nb_transactions + 1, nb_goods), dtype=np.float32) # initial prices prices_by_transactions[0, :] = np.asarray(0, dtype=np.float32) temp_game = Game(self.game.configuration, self.game.initialization) for idx, tx in enumerate(self.game.transactions): temp_game.settle_transaction(tx) prices_by_transactions[idx + 1, :] = np.asarray( temp_game.get_prices(), dtype=np.float32) denominator = (prices_by_transactions != 0).sum(0) result[1, :] = np.true_divide(prices_by_transactions.sum(0), denominator) result[1, denominator == 0] = 0 result = np.transpose(result) return self.game.configuration.good_names, result
def price_history(self) -> np.ndarray: """Get the price history.""" nb_transactions = len(self.game.transactions) nb_goods = self.game.configuration.nb_goods result = np.zeros((nb_transactions + 1, nb_goods), dtype=np.float32) temp_game = Game(self.game.configuration, self.game.initialization) # initial prices result[0, :] = np.asarray(0, dtype=np.float32) for idx, tx in enumerate(self.game.transactions): temp_game.settle_transaction(tx) result[idx + 1, :] = np.asarray(temp_game.get_prices(), dtype=np.float32) return result