Untitled

 avatar
unknown
plain_text
a month ago
2.9 kB
2
Indexable
import matplotlib.pyplot as plt

# 1. The dataset provided
premiums = [
    0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0,
    3.2, 3.4, 3.6, 3.8, 4.0, 4.2, 4.4, 4.6, 4.8, 5.0, 5.2, 5.4, 5.6, 5.8, 6.0,
    6.2, 6.4, 6.6, 6.8, 7.0, 7.2, 7.4, 7.6, 7.8, 8.0, 8.2, 8.4, 8.6, 8.8, 9.0,
    9.2, 9.4, 9.6, 9.8, 10.0, 10.2, 10.4, 10.6, 10.8, 11.0, 11.2, 11.4, 11.6,
    11.8, 12.0, 12.2, 12.4, 12.6, 12.8, 13.0, 13.2, 13.4, 13.6, 13.8, 14.0,
    14.2, 14.4, 14.6, 14.8, 15.0, 15.2, 15.4, 15.6, 15.8, 16.0, 16.2, 16.4,
    16.6, 16.8, 17.0, 17.2, 17.4, 17.6, 17.8, 18.0, 18.2, 18.4, 18.6, 18.8,
    19.0, 19.2, 19.4, 19.6, 19.8, 20.0
]

costs = [
    593.47, 590.29, 587.32, 584.61, 582.18, 580.05, 578.22, 576.70, 575.45,
    574.46, 573.69, 573.13, 572.72, 572.41, 572.10, 571.66, 570.88, 569.50,
    567.25, 563.92, 559.47, 553.98, 547.62, 540.42, 532.23, 522.64, 511.06,
    496.68, 478.40, 454.51, 422.27, 377.30, 313.09, 225.79, 140.70, 106.30,
    103.33, 106.06, 109.47, 113.00, 116.59, 120.25, 123.97, 127.75, 131.60,
    135.51, 139.50, 143.56, 147.70, 151.92, 156.22, 160.60, 165.07, 169.64,
    174.30, 179.06, 183.92, 188.89, 193.97, 199.16, 204.47, 209.91, 215.47,
    221.16, 226.99, 232.97, 239.09, 245.36, 251.79, 258.39, 265.16, 272.10,
    279.23, 286.55, 294.07, 301.79, 309.73, 317.88, 326.26, 334.88, 343.75,
    352.87, 362.26, 371.92, 381.86, 392.10, 402.64, 413.51, 424.70, 436.23,
    448.12, 460.37, 473.01, 486.04, 499.48, 513.34, 527.65, 542.41, 557.65,
    573.38
]

# Track the optimal point based on the data provided
best_const_premium = 7.4
best_const_cost = 103.33

# From the PDF's Policy Benchmark Comparison Table, the Optimal MDP best expected cost is roughly 95.79
v_opt_start = 95.79 

# 2. Visualization
print("\nGenerating full Cost Function Plot...")
fig, ax = plt.subplots(figsize=(10, 6))

# Plot the curve for the constant policies
ax.plot(premiums, costs, marker='o', markersize=4, linestyle='-', 
        color='tab:blue', linewidth=2, label='Constant Policies')

# Highlight the bottom of the U-shape (The best constant premium)
ax.plot(best_const_premium, best_const_cost, marker='*', markersize=15, 
        color='tab:red', label=f'Best Constant Premium (P={best_const_premium})')

# Add a dashed line for the true, dynamically optimal policy
ax.axhline(y=v_opt_start, color='tab:green', linestyle='--', linewidth=2.5, 
           label='Optimal Dynamic Policy (Baseline)')

ax.set_title('Expected Discounted Cost of Constant Policies\nStarting from State ($G_0=0, P_{t-1}=10$)', fontsize=14)
ax.set_xlabel('Constant Premium Charged ($P$)', fontsize=12)
ax.set_ylabel('Expected Discounted Cost ($V$)', fontsize=12)

# Graph formatting
ax.grid(alpha=0.3)
ax.legend(fontsize=11)

# NOTE: ax.set_ylim() has been deliberately removed so matplotlib autoscales 
# to show the entire vertical span of the data (from ~95 up to ~593).

plt.tight_layout()
plt.show()
Editor is loading...
Leave a Comment