mirror of
https://github.com/velocitatem/PHANTOM.git
synced 2026-05-31 08:33:36 +00:00
feature: refactored demand splitting and implementation
This commit is contained in:
@@ -1,30 +1,39 @@
|
||||
from sys import platform
|
||||
import numpy as np
|
||||
from .lib.demand import generate_demand, estimate_demand
|
||||
from .lib.demand import generate_demand_for_actor, estimate_demand
|
||||
from .lib.behavior import sample_behavior
|
||||
from logging import INFO, getLogger
|
||||
logger = getLogger(__name__)
|
||||
logger.setLevel(INFO)
|
||||
|
||||
|
||||
|
||||
class MarketEngine():
|
||||
"""implements separate demand distributions for humans and agents per Section 3.1.1"""
|
||||
|
||||
def __init__(self,
|
||||
alpha = 0.5,
|
||||
N = 100,
|
||||
demand_distribution = (50, 10),
|
||||
demand_sampling_function = np.random.normal):
|
||||
self.Nagents = int(N*alpha)
|
||||
self.Nhumans = int(N*(1-alpha))
|
||||
self.demand = (demand_sampling_function, demand_distribution)
|
||||
alpha: float,
|
||||
N: int,
|
||||
human_params: tuple,
|
||||
agent_params: tuple,
|
||||
demand_distribution = np.random.normal,
|
||||
noise_std: float = 1.0):
|
||||
# no defaults for D_H, D_A - force explicit experiment design
|
||||
self.alpha = alpha
|
||||
self.Nagents = int(N * alpha)
|
||||
self.Nhumans = int(N * (1 - alpha))
|
||||
self.human_params = human_params
|
||||
self.agent_params = agent_params
|
||||
self.noise_std = noise_std
|
||||
self.demand_dist = demand_distribution
|
||||
|
||||
def act(self, prices):
|
||||
demand = generate_demand(prices, *self.demand)
|
||||
sample_n = lambda n, human: [sample_behavior(demand, human=human) for _ in range(n)]
|
||||
human_t, agent_t = sample_n(self.Nhumans, True), sample_n(self.Nagents, False)
|
||||
trajectories = human_t + agent_t
|
||||
demand_estimate = estimate_demand(trajectories)
|
||||
return demand_estimate
|
||||
# generate separate demands d() per actor type
|
||||
demand_h = generate_demand_for_actor(prices, self.human_params, self.noise_std, distribution_method = self.demand_dist)
|
||||
demand_a = generate_demand_for_actor(prices, self.agent_params, self.noise_std, distribution_method = self.demand_dist)
|
||||
# sample behavior trajectories from each demand distribution
|
||||
human_t = [sample_behavior(demand_h, human=True) for _ in range(self.Nhumans)]
|
||||
agent_t = [sample_behavior(demand_a, human=False) for _ in range(self.Nagents)]
|
||||
return estimate_demand(human_t + agent_t)
|
||||
|
||||
def measure(self):
|
||||
pass
|
||||
@@ -60,7 +69,7 @@ class Limbo():
|
||||
|
||||
if __name__ == "__main__":
|
||||
platform = PricingEngine()
|
||||
market = MarketEngine()
|
||||
market = MarketEngine(alpha=0.3, N=100, human_params=(50, 10), agent_params=(45, 15))
|
||||
limbo = Limbo(platform, market)
|
||||
for _ in range(10):
|
||||
limbo.step()
|
||||
|
||||
Reference in New Issue
Block a user