Fix wealth distribution histogram issue by correcting wealth calculation and improving data handling
This commit is contained in:
@@ -309,25 +309,27 @@ class EconomicSimulation:
|
||||
if not self.agents:
|
||||
return [], []
|
||||
|
||||
# Get current total wealth for all agents (capital + consumption)
|
||||
# Get current total wealth for all agents using the correct method
|
||||
wealth_values = []
|
||||
for agent in self.agents:
|
||||
if agent.wealth_history and agent.consumption_history:
|
||||
total_wealth = agent.wealth_history[-1] + agent.consumption_history[-1]
|
||||
else:
|
||||
total_wealth = agent.initial_capital + agent.initial_consumption
|
||||
total_wealth = agent.get_total_wealth()
|
||||
wealth_values.append(total_wealth)
|
||||
|
||||
if not wealth_values:
|
||||
return [], []
|
||||
|
||||
# Debug logging
|
||||
print(f"DEBUG: Wealth values - count: {len(wealth_values)}, min: {min(wealth_values)}, max: {max(wealth_values)}")
|
||||
|
||||
# Calculate histogram bins
|
||||
min_wealth = min(wealth_values)
|
||||
max_wealth = max(wealth_values)
|
||||
|
||||
if min_wealth == max_wealth:
|
||||
# All agents have same wealth
|
||||
return [f"${min_wealth:.0f}"], [len(wealth_values)]
|
||||
result = [f"${min_wealth:.0f}"], [len(wealth_values)]
|
||||
print(f"DEBUG: All agents have same wealth - labels: {result[0]}, counts: {result[1]}")
|
||||
return result
|
||||
|
||||
# Create bins
|
||||
bin_width = (max_wealth - min_wealth) / num_bins
|
||||
@@ -355,6 +357,7 @@ class EconomicSimulation:
|
||||
if bin_start <= wealth < bin_end:
|
||||
bin_counts[i] += 1
|
||||
|
||||
print(f"DEBUG: Histogram result - labels: {bin_labels}, counts: {bin_counts}")
|
||||
return bin_labels, bin_counts
|
||||
|
||||
def update_parameters(self, new_parameters: SimulationParameters):
|
||||
|
Reference in New Issue
Block a user