chore: better wrapping amd more performant

This commit is contained in:
2026-01-29 10:01:53 +01:00
parent 6e06081d60
commit 772772b5b9
3 changed files with 162 additions and 25 deletions

View File

@@ -8,7 +8,8 @@ def generate_demand(prices, distribution_method = np.random.normal, distribution
product_valuations = distribution_method(*distribution_params, size=len(prices))
# assumption 2: demand decreases as price increases, following a simple linear model
demand = np.maximum(0, product_valuations - prices) # demand cannot be negative
demand = demand / np.sum(demand) * 100 # normalize to total demand of 1000 units so demand output is within [0, 100]
total = np.sum(demand)
demand = demand / total * 100 if total > 0 else demand # normalize to percentage, avoid div by zero
logger.info(f"Generated demand for prices {prices}: {demand} with valuations from distribution {distribution_params}")
return demand