petermenegay: Create a 2x2 array of numbers with the following values, [0, .10, .05], [.10, 0, .10], and [0, .05, 0] GitHub Copilot: ### [policy_fixed_point.py](file:///C:/A/PeerVerity/policy_system_ai/policy_fixed_point.py) Add a 2x2 array of numbers with the specified values. ```python # ...existing code... import numpy as np array_2x2 = np.array([[0, 0.10, 0.05], [0.10, 0, 0.10], [0, 0.05, 0]]) # ...existing code... ``` Made changes. petermenegay: Add print statements for all the EFF values GitHub Copilot: ### [policy_fixed_point.py](file:///C:/A/PeerVerity/policy_system_ai/policy_fixed_point.py) Add print statements for all the EFF values. ```python # ...existing code... print(EFF[0][0]) print(EFF[0][1]) print(EFF[0][2]) print(EFF[1][0]) print(EFF[1][1]) print(EFF[1][2]) print(EFF[2][0]) print(EFF[2][1]) print(EFF[2][2]) # ...existing code... ``` Made changes. petermenegay: Do the calculation for IMP over and over until IMP converges to some value. GitHub Copilot: ### [policy_fixed_point.py](file:///C:/A/PeerVerity/policy_system_ai/policy_fixed_point.py) Modify the code to perform the calculation for IMP until it converges. ```python # ...existing code... tolerance = 1e-6 max_iterations = 1000 for _ in range(max_iterations): new_IMP = IWM + np.dot(EFFtrans, IMP) if np.allclose(new_IMP, IMP, atol=tolerance): break IMP = new_IMP print('Converged IMP = ', IMP) # ...existing code... ``` Made changes. petermenegay: Prevent IMP from going over 100. That is, if it is greater than 100, make it equal to 100. GitHub Copilot: ### [policy_fixed_point.py](file:///C:/A/PeerVerity/policy_system_ai/policy_fixed_point.py) Modify the code to prevent IMP from going over 100. ```python # ...existing code... tolerance = 1e-6 max_iterations = 1000 IMPmax_value = 100.0 for _ in range(max_iterations): new_IMP = IWM + np.dot(EFF, IMP) new_IMP = np.clip(new_IMP, None, IMPmax_value) # Ensure IMP does not exceed 100 if np.allclose(new_IMP, IMP, atol=tolerance): break IMP = new_IMP print('Converged IMP = ', IMP) # ...existing code... ``` Made changes. petermenegay: Below where it says #Design of Experiments, set up the code to vary the EXPEND values to see how VOTHAPtot changes. Vary EXPEND between 0 and CTA. GitHub Copilot: ### [policy_fixed_point.py](file:///C:/A/PeerVerity/policy_system_ai/policy_fixed_point.py) Set up the code to vary the EXPEND values between 0 and CTA to see how VOTHAPtot changes. ```python # ...existing code... #Design of Experiments # Vary the EXPEND values and see how VOTHAPtot changes EXPEND_ranges = [np.linspace(0, cta, num=5) for cta in CTA] for exp1 in EXPEND_ranges[0]: for exp2 in EXPEND_ranges[1]: for exp3 in EXPEND_ranges[2]: EXPEND_test = np.array([exp1, exp2, exp3]) VOTHAPtot = voter_happiness(P, Pb, EFF, IMPmax, CTA, EXPEND_test, EXPENDnom) print(f'EXPEND = {EXPEND_test}, VOTHAPtot = {VOTHAPtot}') # ...existing code... ``` Made changes. petermenegay: Comment out all the print statements except the last one GitHub Copilot: ### [policy_fixed_point.py](file:///C:/A/PeerVerity/policy_system_ai/policy_fixed_point.py) Comment out all the print statements except the last one. ```python # ...existing code... def voter_happiness(P, Pb, EFF, IMPmax, CTA, EXPEND, EXPENDnom): #Calculate the total priority and the cost per point for each policy Ptot = np.sum(P) + Pb #Total priority (sum of policy priorities and budget priority) CPP = CTA/IMPmax #Cost per point for each policy # print('CPP = ', CPP) EXPENDtot = EXPENDb = np.sum(EXPEND) #Total expenditure on policies #EXPENDtot = EXPENDb = 0.0 IWM = EXPEND/CPP #Improvement with money -- how much improvement is achieved solely through expenditure # print('IWM = ', IWM) #The voter is most happy if no money is spent on any policy, thus giving IMPmax for the budget # beyond that happiness decreases linearly with expenditure IMPb = IMPmax - (IMPmax/EXPENDnom)*EXPENDtot #Improvement from budget IMP = IWM #initial IMP tolerance = 1e-6 max_iterations = 1000 for _ in range(max_iterations): new_IMP = IWM + np.dot(EFF, IMP) new_IMP = np.clip(new_IMP, None, IMPmax) # Ensure IMP does not exceed 100 if np.allclose(new_IMP, IMP, atol=tolerance): break IMP = new_IMP # print('Converged IMP = ', IMP) VOTHAP = IMP*P/Ptot #Voter's happiness from each policy # print('VOTHAP = ', VOTHAP) # print('IMPb = ', IMPb) VOTHAPb = IMPb*Pb/Ptot #Voter's happiness from budget # print('VOTHAPb = ', VOTHAPb) VOTHAPtot = np.sum(VOTHAP) + VOTHAPb # print('VOTHAPtot = ', VOTHAPtot) return VOTHAPtot # ...existing code... print('VOTHAPtot = ', VOTHAPtot) #Design of Experiments # Vary the EXPEND values and see how VOTHAPtot changes EXPEND_ranges = [np.linspace(0, cta, num=5) for cta in CTA] for exp1 in EXPEND_ranges[0]: for exp2 in EXPEND_ranges[1]: for exp3 in EXPEND_ranges[2]: EXPEND_test = np.array([exp1, exp2, exp3]) VOTHAPtot = voter_happiness(P, Pb, EFF, IMPmax, CTA, EXPEND_test, EXPENDnom) print(f'EXPEND = {EXPEND_test}, VOTHAPtot = {VOTHAPtot}') # ...existing code... ``` Made changes. petermenegay: For the last print statement, print out just the values with tabs to separate them. Print the headers of the table at the top, eg EXPEND[0], EXPEND[1], etc and VOTHAPtot GitHub Copilot: ### [policy_fixed_point.py](file:///C:/A/PeerVerity/policy_system_ai/policy_fixed_point.py) Modify the last print statement to print out just the values with tabs to separate them, and print the headers of the table at the top. ```python # ...existing code... #Design of Experiments # Vary the EXPEND values and see how VOTHAPtot changes EXPEND_ranges = [np.linspace(0, cta, num=5) for cta in CTA] # Print headers print("EXPEND[0]\tEXPEND[1]\tEXPEND[2]\tVOTHAPtot") for exp1 in EXPEND_ranges[0]: for exp2 in EXPEND_ranges[1]: for exp3 in EXPEND_ranges[2]: EXPEND_test = np.array([exp1, exp2, exp3]) VOTHAPtot = voter_happiness(P, Pb, EFF, IMPmax, CTA, EXPEND_test, EXPENDnom) print(f'{exp1}\t{exp2}\t{exp3}\t{VOTHAPtot}') # ...existing code... ``` Made changes. petermenegay: Also add the total expenditure to the printed table GitHub Copilot: ### [policy_fixed_point.py](file:///C:/A/PeerVerity/policy_system_ai/policy_fixed_point.py) Add the total expenditure to the printed table. ```python # ...existing code... #Design of Experiments # Vary the EXPEND values and see how VOTHAPtot changes EXPEND_ranges = [np.linspace(0, cta, num=5) for cta in CTA] # Print headers print("EXPEND[0]\tEXPEND[1]\tEXPEND[2]\tTotal EXPEND\tVOTHAPtot") for exp1 in EXPEND_ranges[0]: for exp2 in EXPEND_ranges[1]: for exp3 in EXPEND_ranges[2]]: EXPEND_test = np.array([exp1, exp2, exp3]) total_expend = np.sum(EXPEND_test) VOTHAPtot = voter_happiness(P, Pb, EFF, IMPmax, CTA, EXPEND_test, EXPENDnom) print(f'{exp1}\t{exp2}\t{exp3}\t{total_expend}\t{VOTHAPtot}') # ...existing code... ``` Made changes. petermenegay: Write out the table to a file GitHub Copilot: ### [policy_fixed_point.py](file:///C:/A/PeerVerity/policy_system_ai/policy_fixed_point.py) Write out the table to a file. ```python # ...existing code... #Design of Experiments # Vary the EXPEND values and see how VOTHAPtot changes EXPEND_ranges = [np.linspace(0, cta, num=5) for cta in CTA] # Open file to write the table with open('vothap_results.txt', 'w') as file: # Write headers file.write("EXPEND[0]\tEXPEND[1]\tEXPEND[2]\tTotalEXPEND\tVOTHAPtot\n") for exp1 in EXPEND_ranges[0]: for exp2 in EXPEND_ranges[1]: for exp3 in EXPEND_ranges[2]: EXPEND_test = np.array([exp1, exp2, exp3]) total_expend = np.sum(EXPEND_test) VOTHAPtot = voter_happiness(P, Pb, EFF, IMPmax, CTA, EXPEND_test, EXPENDnom) file.write(f'{exp1}\t{exp2}\t{exp3}\t{total_expend}\t{VOTHAPtot}\n') # ...existing code... ``` Made changes. petermenegay: In addition to printing, write out the results to a file GitHub Copilot: ### [policy_fixed_point.py](file:///C:/A/PeerVerity/policy_system_ai/policy_fixed_point.py) In addition to printing, write out the results to a file. ```python # ...existing code... #Design of Experiments # Vary the EXPEND values and see how VOTHAPtot changes EXPEND_ranges = [np.linspace(0, cta, num=5) for cta in CTA] # Open file to write the table with open('vothap_results.txt', 'w') as file: # Write headers file.write("EXPEND[0]\tEXPEND[1]\tEXPEND[2]\tTotalEXPEND\tVOTHAPtot\n") print("EXPEND[0]\tEXPEND[1]\tEXPEND[2]\tTotalEXPEND\tVOTHAPtot") for exp1 in EXPEND_ranges[0]: for exp2 in EXPEND_ranges[1]: for exp3 in EXPEND_ranges[2]: EXPEND_test = np.array([exp1, exp2, exp3]) total_expend = np.sum(EXPEND_test) VOTHAPtot = voter_happiness(P, Pb, EFF, IMPmax, CTA, EXPEND_test, EXPENDnom) result_line = f'{exp1}\t{exp2}\t{exp3}\t{total_expend}\t{VOTHAPtot}\n' file.write(result_line) print(result_line.strip()) # ...existing code... ``` Made changes. petermenegay: Instead of varying EXPEND in a full factorial manner, vary it randomly. Use 200 points. GitHub Copilot: ### [policy_fixed_point.py](file:///C:/A/PeerVerity/policy_system_ai/policy_fixed_point.py) Vary EXPEND randomly using 200 points. ```python # ...existing code... #Design of Experiments # Vary the EXPEND values randomly and see how VOTHAPtot changes num_points = 200 EXPEND_ranges = [np.random.uniform(0, cta, num_points) for cta in CTA] # Open file to write the table with open('vothap_results.txt', 'w') as file: # Write headers file.write("EXPEND[0]\tEXPEND[1]\tEXPEND[2]\tTotalEXPEND\tVOTHAPtot\n") print("EXPEND[0]\tEXPEND[1]\tEXPEND[2]\tTotalEXPEND\tVOTHAPtot") for i in range(num_points): exp1 = EXPEND_ranges[0][i] exp2 = EXPEND_ranges[1][i] exp3 = EXPEND_ranges[2][i] EXPEND_test = np.array([exp1, exp2, exp3]) total_expend = np.sum(EXPEND_test) VOTHAPtot = voter_happiness(P, Pb, EFF, IMPmax, CTA, EXPEND_test, EXPENDnom) result_line = f'{exp1}\t{exp2}\t{exp3}\t{total_expend}\t{VOTHAPtot}\n' file.write(result_line) print(result_line.strip()) # ...existing code... ``` Made changes. petermenegay: Add a plot of total expenditure on the x-axis and total voter happiness on the y-axis. GitHub Copilot: ### [policy_fixed_point.py](file:///C:/A/PeerVerity/policy_system_ai/policy_fixed_point.py) Add a plot of total expenditure on the x-axis and total voter happiness on the y-axis. ```python # ...existing code... import matplotlib.pyplot as plt #Design of Experiments # Vary the EXPEND values randomly and see how VOTHAPtot changes num_points = 200 EXPEND_ranges = [np.random.uniform(0, cta, num_points) for cta in CTA] total_expenditures = [] vothap_totals = [] # Open file to write the table with open('vothap_results.txt', 'w') as file: # Write headers file.write("EXPEND[0]\tEXPEND[1]\tEXPEND[2]\tTotalEXPEND\tVOTHAPtot\n") print("EXPEND[0]\tEXPEND[1]\tEXPEND[2]\tTotalEXPEND\tVOTHAPtot") for i in range(num_points): exp1 = EXPEND_ranges[0][i] exp2 = EXPEND_ranges[1][i] exp3 = EXPEND_ranges[2][i] EXPEND_test = np.array([exp1, exp2, exp3]) total_expend = np.sum(EXPEND_test) VOTHAPtot = voter_happiness(P, Pb, EFF, IMPmax, CTA, EXPEND_test, EXPENDnom) result_line = f'{exp1}\t{exp2}\t{exp3}\t{total_expend}\t{VOTHAPtot}\n' file.write(result_line) print(result_line.strip()) total_expenditures.append(total_expend) vothap_totals.append(VOTHAPtot) # Plotting the results plt.scatter(total_expenditures, vothap_totals) plt.xlabel('Total Expenditure') plt.ylabel('Total Voter Happiness') plt.title('Total Expenditure vs Total Voter Happiness') plt.grid(True) plt.show() # ...existing code... ``` Made changes. petermenegay: Add code to find the Pareto frontier of the results, that is the points that represent the highest voter happiness for each cost. Write the pareto frontier points out to a file and plot them on the same graph as the total results. GitHub Copilot: ### [policy_fixed_point.py](file:///C:/A/PeerVerity/policy_system_ai/policy_fixed_point.py) Add code to find the Pareto frontier of the results, write the Pareto frontier points to a file, and plot them on the same graph as the total results. ```python # ...existing code... def find_pareto_frontier(costs, values): sorted_indices = np.argsort(costs) pareto_costs = [] pareto_values = [] max_value = -np.inf for idx in sorted_indices: cost = costs[idx] value = values[idx] if value > max_value: pareto_costs.append(cost) pareto_values.append(value) max_value = value return pareto_costs, pareto_values #Design of Experiments # Vary the EXPEND values randomly and see how VOTHAPtot changes num_points = 200 EXPEND_ranges = [np.random.uniform(0, cta, num_points) for cta in CTA] total_expenditures = [] vothap_totals = [] # Open file to write the table with open('vothap_results.txt', 'w') as file: # Write headers file.write("EXPEND[0]\tEXPEND[1]\tEXPEND[2]\tTotalEXPEND\tVOTHAPtot\n") print("EXPEND[0]\tEXPEND[1]\tEXPEND[2]\tTotalEXPEND\tVOTHAPtot") for i in range(num_points): exp1 = EXPEND_ranges[0][i] exp2 = EXPEND_ranges[1][i] exp3 = EXPEND_ranges[2][i] EXPEND_test = np.array([exp1, exp2, exp3]) total_expend = np.sum(EXPEND_test) VOTHAPtot = voter_happiness(P, Pb, EFF, IMPmax, CTA, EXPEND_test, EXPENDnom) result_line = f'{exp1}\t{exp2}\t{exp3}\t{total_expend}\t{VOTHAPtot}\n' file.write(result_line) print(result_line.strip()) total_expenditures.append(total_expend) vothap_totals.append(VOTHAPtot) # Find Pareto frontier pareto_costs, pareto_values = find_pareto_frontier(total_expenditures, vothap_totals) # Write Pareto frontier to a file with open('pareto_frontier.txt', 'w') as pareto_file: pareto_file.write("TotalEXPEND\tVOTHAPtot\n") for cost, value in zip(pareto_costs, pareto_values): pareto_file.write(f'{cost}\t{value}\n') # Plotting the results plt.scatter(total_expenditures, vothap_totals, label='Total Results') plt.plot(pareto_costs, pareto_values, color='red', label='Pareto Frontier') plt.xlabel('Total Expenditure') plt.ylabel('Total Voter Happiness') plt.title('Total Expenditure vs Total Voter Happiness') plt.legend() plt.grid(True) plt.show() # ...existing code... ``` Made changes. petermenegay: Instead of a red line to connect the Pareto frontier points, just identify the Pareto points using a different color. GitHub Copilot: ### [policy_fixed_point.py](file:///C:/A/PeerVerity/policy_system_ai/policy_fixed_point.py) Identify the Pareto frontier points using a different color instead of connecting them with a red line. ```python # ...existing code... # Plotting the results plt.scatter(total_expenditures, vothap_totals, label='Total Results') plt.scatter(pareto_costs, pareto_values, color='red', label='Pareto Frontier') plt.xlabel('Total Expenditure') plt.ylabel('Total Voter Happiness') plt.title('Total Expenditure vs Total Voter Happiness') plt.legend() plt.grid(True) plt.show() # ...existing code... ``` Made changes.