Swap commented code blocks for optional plots
"Progress plots" of M vs A plots in the aggregate shocks model now only display if the economy has a 'plot_verbose' attribute set.
@@ -1226,14 +1226,17 @@ class CobbDouglasEconomy(Market):
self.intercept_prev = intercept
self.slope_prev = slope
- # Plot aggregate resources vs aggregate savings for this run and print the new parameters
+ # Print the new parameters
if verbose:
print('intercept=' + str(intercept) + ', slope=' + str(slope) + ', r-sq=' + str(r_value**2))
- #plot_start = discard_periods
- #plt.xlabel('log(MaggNow)')
- #plt.ylabel('log(AaggNow)')
- #plt.plot(logMagg[plot_start:],logAagg[plot_start:],'.k')
- #plt.show()
+
+ # Plot aggregate resources vs aggregate savings for this run
+ if hasattr(self, 'verbose_plot'):
+ plot_start = discard_periods
+ plt.xlabel('log(MaggNow)')
+ plt.ylabel('log(AaggNow)')
+ plt.plot(logMagg[plot_start:],logAagg[plot_start:],'.k')
+ plt.show()
return AggShocksDynamicRule(AFunc)
@@ -1725,9 +1728,8 @@ class CobbDouglasMarkovEconomy(CobbDouglasEconomy):
for i in range(self.MrkvArray.shape[0]):
these = i == MrkvHist
slope, intercept, r_value, p_value, std_err = stats.linregress(logMagg[these], logAagg[these])
- if verbose:
- #plt.plot(logMagg[these],logAagg[these],'.')
- pass
+ if hasattr(self, 'plot_verbose'):
+ plt.plot(logMagg[these],logAagg[these],'.')
# Make a new aggregate savings rule by combining the new regression parameters
# with the previous guess
@@ -1740,11 +1742,14 @@ class CobbDouglasMarkovEconomy(CobbDouglasEconomy):
self.intercept_prev[i] = intercept
self.slope_prev[i] = slope
- # Plot aggregate resources vs aggregate savings for this run and print the new parameters
+ # Print the new parameters
if verbose:
print('intercept=' + str(self.intercept_prev) +
', slope=' + str(self.slope_prev) + ', r-sq=' + str(rSq_list))
- # plt.show()
+
+ # Plot aggregate resources vs aggregate savings for this run
+ if hasattr(self, 'plot_verbose'):
+ plt.show()
return AggShocksDynamicRule(AFunc_list)
