diff --git a/docs/source/_tutorials/tutorial10paramdmd.html b/docs/source/_tutorials/tutorial10paramdmd.html index ad9ba43c9..8282efa9f 100644 --- a/docs/source/_tutorials/tutorial10paramdmd.html +++ b/docs/source/_tutorials/tutorial10paramdmd.html @@ -16065,7 +16065,7 @@
def relative_error(x_est, x_true):
- """Helper function for calculating the relative error.
-
- """
+ """Helper function for calculating the relative error."""
return np.linalg.norm(x_est - x_true) / np.linalg.norm(x_true)
fig, ax = plt.subplots(1, 1)
ax.scatter(
- true_eigenvalues.real, true_eigenvalues.imag,
- 100, label='True Eigenvalues', color='k')
-ax.scatter(np.real(optdmd.eigs), np.imag(optdmd.eigs), label='optDMD', marker='s')
-ax.scatter(np.real(bopdmd.eigs), np.imag(bopdmd.eigs), label='BOP-DMD', marker='>')
-ax.scatter(np.real(dmd.eigs), np.imag(dmd.eigs), label='exact DMD')
-ax.set_xlabel('Real part')
-ax.set_ylabel('Imag part')
+ true_eigenvalues.real,
+ true_eigenvalues.imag,
+ 100,
+ label="True Eigenvalues",
+ color="k",
+)
+ax.scatter(
+ np.real(optdmd.eigs), np.imag(optdmd.eigs), label="optDMD", marker="s"
+)
+ax.scatter(
+ np.real(bopdmd.eigs), np.imag(bopdmd.eigs), label="BOP-DMD", marker=">"
+)
+ax.scatter(np.real(dmd.eigs), np.imag(dmd.eigs), label="exact DMD")
+ax.set_xlabel("Real part")
+ax.set_ylabel("Imag part")
ax.legend()
ax.set_ylim(-2, 2)
ax.set_xlim(-2, 2)
ax.grid()
-ax.axhline(0, color='0.6')
-ax.axvline(0, color='0.6')
-ax.set_title('Eigenvalues of DMD, optDMD, BOPDMD')
+ax.axhline(0, color="0.6")
+ax.axvline(0, color="0.6")
+ax.set_title("Eigenvalues of DMD, optDMD, BOPDMD")
plt.show()
print('Uncertainty in the BOPDMD eigenvalues={:.02f}'.format(bopdmd.eigenvalues_std[0]))
+print(
+ "Uncertainty in the BOPDMD eigenvalues={:.02f}".format(
+ bopdmd.eigenvalues_std[0]
+ )
+)
# Compare to the eigenvalue error
-re = relative_error(
- bopdmd.eigs,
- true_eigenvalues
-)
-print('Error in the BOPDMD eigenvalues={:.03f}'.format(re))
+re = relative_error(bopdmd.eigs, true_eigenvalues)
+print("Error in the BOPDMD eigenvalues={:.03f}".format(re))
plt.plot(time, dmd.dynamics.real.T / dmd.amplitudes.real, label='Exact DMD')
+plt.plot(time, dmd.dynamics.real.T / dmd.amplitudes.real, label="Exact DMD")
# We have to carefully format the markers since the BOP-DMD, optDMD,
# and true data are hard to distinguish otherwise.
-plt.plot(time, bopdmd.dynamics.real.T / bopdmd.amplitudes.real,
- marker='o', markersize=10, markerfacecolor='none', label='bopdmd')
-plt.plot(time, optdmd.dynamics.real.T / optdmd.amplitudes.real,
- marker='o', markerfacecolor='none', label='optdmd')
-plt.plot(time, np.exp(true_eigenvalues * time).real, 'k-.', label='True dynamics')
+plt.plot(
+ time,
+ bopdmd.dynamics.real.T / bopdmd.amplitudes.real,
+ marker="o",
+ markersize=10,
+ markerfacecolor="none",
+ label="bopdmd",
+)
+plt.plot(
+ time,
+ optdmd.dynamics.real.T / optdmd.amplitudes.real,
+ marker="o",
+ markerfacecolor="none",
+ label="optdmd",
+)
+plt.plot(
+ time, np.exp(true_eigenvalues * time).real, "k-.", label="True dynamics"
+)
plt.legend()
-plt.gca().set_xlabel('Time (-)')
-plt.gca().set_ylabel('Normalized Dynamics (-)')
+plt.gca().set_xlabel("Time (-)")
+plt.gca().set_ylabel("Normalized Dynamics (-)")
plt.show()
@@ -15098,7 +15634,7 @@ Time Dynamics
-
@@ -15140,94 +15676,117 @@ Time Dynamics# Plot the original data without noise for both the training
# and forecast periods.
ax.plot(
- time, data_clean.mean(axis=(0, 1)).real,
- label='clean data', color='k', marker='o', ls='None'
+ time,
+ data_clean.mean(axis=(0, 1)).real,
+ label="clean data",
+ color="k",
+ marker="o",
+ ls="None",
)
ax.plot(
- time_forecast, data_forecast.mean(axis=(0, 1)).real,
- color='k', marker='.', ls='None'
+ time_forecast,
+ data_forecast.mean(axis=(0, 1)).real,
+ color="k",
+ marker=".",
+ ls="None",
)
# Plot the BOP-DMD reconstruction and forecast.
ax.plot(
- time, bopdmd.reconstructed_data.mean(axis=0).real,
- label='bopdmd', color='b', marker='o', ls='None'
+ time,
+ bopdmd.reconstructed_data.mean(axis=0).real,
+ label="bopdmd",
+ color="b",
+ marker="o",
+ ls="None",
)
ax.plot(
- time_forecast, forecast_mean.mean(axis=0).real,
- color='b', marker='.', ls='None'
+ time_forecast,
+ forecast_mean.mean(axis=0).real,
+ color="b",
+ marker=".",
+ ls="None",
)
# Plot the exact DMD reconstruction and forecast.
ax.plot(
- time, dmd.reconstructed_data.mean(axis=0).real,
- label='dmd', color='r', marker='o', ls='None'
+ time,
+ dmd.reconstructed_data.mean(axis=0).real,
+ label="dmd",
+ color="r",
+ marker="o",
+ ls="None",
)
ax.plot(
- time_forecast, dmd_forecast.reconstructed_data.mean(axis=0).real,
- color='r', marker='.', ls='None'
+ time_forecast,
+ dmd_forecast.reconstructed_data.mean(axis=0).real,
+ color="r",
+ marker=".",
+ ls="None",
)
# Format the subplot.
ax.legend()
-ax.set_ylabel('Amplitude (-)')
-ax.set_title('Mean Spatial Amptlitude')
-ax.axhline(0, color='0.6')
+ax.set_ylabel("Amplitude (-)")
+ax.set_title("Mean Spatial Amptlitude")
+ax.axhline(0, color="0.6")
ax.grid()
# Indicate the training and forecast intervals.
-ax.axvline(time_forecast[0], ls='--', color='k')
-ax.text(
- np.mean(time_forecast), 0.3, 'forecast data',
- transform=ax.transData
-)
-ax.text(
- np.mean(time), 0.3, 'training data',
- transform=ax.transData
-)
+ax.axvline(time_forecast[0], ls="--", color="k")
+ax.text(np.mean(time_forecast), 0.3, "forecast data", transform=ax.transData)
+ax.text(np.mean(time), 0.3, "training data", transform=ax.transData)
# The lower subplots shows the error in the spatial means.
ax = axes[1]
# Spatial mean error in the BOP-DMD.
ax.plot(
- time, bopdmd.reconstructed_data.mean(axis=0).real - data_clean.mean(axis=(0, 1)).real,
- color='b', marker='o', ls='None'
+ time,
+ bopdmd.reconstructed_data.mean(axis=0).real
+ - data_clean.mean(axis=(0, 1)).real,
+ color="b",
+ marker="o",
+ ls="None",
)
ax.plot(
- time_forecast, forecast_mean.mean(axis=0).real - data_forecast.mean(axis=(0, 1)).real,
- color='b', marker='.', ls='None'
+ time_forecast,
+ forecast_mean.mean(axis=0).real - data_forecast.mean(axis=(0, 1)).real,
+ color="b",
+ marker=".",
+ ls="None",
)
# Spatial mean error in the exact DMD.
ax.plot(
- time, dmd.reconstructed_data.mean(axis=0).real - data_clean.mean(axis=(0, 1)).real,
- color='r', marker='o', ls='None'
+ time,
+ dmd.reconstructed_data.mean(axis=0).real
+ - data_clean.mean(axis=(0, 1)).real,
+ color="r",
+ marker="o",
+ ls="None",
)
ax.plot(
time_forecast,
- dmd_forecast.reconstructed_data.mean(axis=0).real - data_forecast.mean(axis=(0, 1)).real,
- color='r', marker='.', ls='None'
+ dmd_forecast.reconstructed_data.mean(axis=0).real
+ - data_forecast.mean(axis=(0, 1)).real,
+ color="r",
+ marker=".",
+ ls="None",
)
# Format the subplot.
-ax.set_ylabel('Error (-)')
-ax.set_xlabel('Time (-)')
-ax.set_title('Error in Mean Spatial Amptlitude')
-ax.axhline(0, color='0.6')
+ax.set_ylabel("Error (-)")
+ax.set_xlabel("Time (-)")
+ax.set_title("Error in Mean Spatial Amptlitude")
+ax.axhline(0, color="0.6")
ax.grid()
# Indicate the training and forecast intervals.
-ax.axvline(time_forecast[0], ls='--', color='k')
-ax.text(
- np.mean(time_forecast), 0.0025, 'forecast data',
- transform=ax.transData
-)
-ax.text(
- np.mean(time), 0.0025, 'training data',
- transform=ax.transData
-)
+ax.axvline(time_forecast[0], ls="--", color="k")
+ax.text(np.mean(time_forecast), 0.0025, "forecast data", transform=ax.transData)
+ax.text(np.mean(time), 0.0025, "training data", transform=ax.transData)
fig.tight_layout()
plt.show()
@@ -15252,7 +15811,7 @@ Time Dynamics
-
@@ -15288,9 +15847,9 @@ Time Dynamicsdmd_forecast.reconstructed_data.reshape(
x1grid.shape[0], x1grid.shape[1], len(time_forecast)
),
- data_forecast
+ data_forecast,
)
-print('Relative Error of the DMD forecast: {:0.2f}'.format(re))
+print("Relative Error of the DMD forecast: {:0.2f}".format(re))
re = relative_error(
- forecast_mean.reshape(
- x1grid.shape[0], x1grid.shape[1], len(time_forecast)
- ),
- data_forecast
+ forecast_mean.reshape(x1grid.shape[0], x1grid.shape[1], len(time_forecast)),
+ data_forecast,
)
-print('Relative Error of the BOP-DMD forecast: {:0.2f}'.format(re))
+print("Relative Error of the BOP-DMD forecast: {:0.2f}".format(re))
dmd_spatial_modes = dmd.modes.reshape(x1grid.shape).real * dmd.amplitudes.real fig, ax = plt.subplots(1, 1) -c = ax.pcolormesh(dmd_spatial_modes - spatial_modes, vmin=-sigma, vmax=sigma, cmap='RdBu_r') +c = ax.pcolormesh( + dmd_spatial_modes - spatial_modes, vmin=-sigma, vmax=sigma, cmap="RdBu_r" +) cbar = fig.colorbar(c) -cbar.set_label('Error') +cbar.set_label("Error") ax.set_title( - 'Error in Exact DMD w/ opt Spatial Modes\nRelative Error={:.2f}'.format( + "Error in Exact DMD w/ opt Spatial Modes\nRelative Error={:.2f}".format( relative_error(dmd_spatial_modes, spatial_modes) ) ) -ax.set_ylabel('Dim 2 (-)') -ax.set_xlabel('Dim 1 (-)') +ax.set_ylabel("Dim 2 (-)") +ax.set_xlabel("Dim 1 (-)") plt.show()
bopdmd_spatial_modes = bopdmd.modes.reshape(x1grid.shape).real * bopdmd.amplitudes.real
+bopdmd_spatial_modes = (
+ bopdmd.modes.reshape(x1grid.shape).real * bopdmd.amplitudes.real
+)
fig, ax = plt.subplots(1, 1)
-c = ax.pcolormesh(bopdmd_spatial_modes - spatial_modes, vmin=-sigma, vmax=sigma, cmap='RdBu_r')
+c = ax.pcolormesh(
+ bopdmd_spatial_modes - spatial_modes, vmin=-sigma, vmax=sigma, cmap="RdBu_r"
+)
cbar = fig.colorbar(c)
-cbar.set_label('Error')
+cbar.set_label("Error")
ax.set_title(
- 'Error in BOP-DMD Spatial Modes\nRelative Error={:.2f}'.format(
+ "Error in BOP-DMD Spatial Modes\nRelative Error={:.2f}".format(
relative_error(bopdmd_spatial_modes, spatial_modes)
)
)
-ax.set_ylabel('Dim 2 (-)')
-ax.set_xlabel('Dim 1 (-)')
+ax.set_ylabel("Dim 2 (-)")
+ax.set_xlabel("Dim 1 (-)")
plt.show()
@@ -15496,7 +16059,7 @@ Spatial Modes
-
@@ -15536,10 +16099,10 @@ Spatial Mode uncertainty)
)
cbar = fig.colorbar(c)
-cbar.set_label('Uncertainty (-)')
-ax.set_title('BOP-DMD Spatial Modes Uncertainty')
-ax.set_ylabel('Dim 2 (-)')
-ax.set_xlabel('Dim 1 (-)')
+cbar.set_label("Uncertainty (-)")
+ax.set_title("BOP-DMD Spatial Modes Uncertainty")
+ax.set_ylabel("Dim 2 (-)")
+ax.set_xlabel("Dim 1 (-)")
fig.tight_layout()
plt.show()