Skip to content

Commit

Permalink
#Analysis of level of smoothness of the ML yield function using the g…
Browse files Browse the repository at this point in the history
…radient of the yield function
  • Loading branch information
Ronakshoghi committed Oct 13, 2023
1 parent 4de348d commit 9f14024
Showing 1 changed file with 0 additions and 78 deletions.
78 changes: 0 additions & 78 deletions examples/data_6d/Data_6D.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,84 +257,6 @@ def rgb_to_hex(rgb):
ax_leg.legend(handles=[handle1], loc="center")
plt.show()

ngrid = 100
xx, yy = np.meshgrid(np.linspace(-1, 1, ngrid), np.linspace(0, 2, ngrid))
yy *= mat_ml.scale_seq
xx *= np.pi
hh = np.c_[yy.ravel(), xx.ravel()]
Cart_hh = FE.sp_cart(hh)
zeros_array = np.zeros((ngrid*ngrid, 3))
Cart_hh_6D = np.hstack((Cart_hh, zeros_array))
grad_hh = mat_ml.calc_fgrad(Cart_hh_6D)
# 1. Compute gradient magnitudes for each grid point
grad_magnitudes = np.linalg.norm(grad_hh, axis=1)

# 2. Compute mean and standard deviation of gradient magnitudes
mean_grad_magnitude = np.mean(grad_magnitudes)
std_grad_magnitude = np.std(grad_magnitudes)
print(f"Mean Gradient Magnitude: {mean_grad_magnitude}")
print(f"Standard Deviation of Gradient Magnitudes: {std_grad_magnitude}")

# 3. Compute the change in gradient magnitudes between neighboring points
# For simplicity, let's calculate the change in magnitude between consecutive grid points
diff_grad_magnitudes = np.diff(grad_magnitudes)

# 4. Plotting
fig, ax = plt.subplots(2, 1, figsize=(10, 10))

# Plot of gradient magnitudes
ax[0].plot(grad_magnitudes, color='blue', label='Gradient Magnitude')
ax[0].axhline(mean_grad_magnitude, color='red', linestyle='--', label='Mean Magnitude')
ax[0].set_title("Gradient Magnitudes across Grid Points")
ax[0].legend()

# Plot of changes in gradient magnitudes
ax[1].plot(diff_grad_magnitudes, color='green', label='Change in Gradient Magnitude')
ax[1].axhline(0, color='red', linestyle='--')
ax[1].set_title("Change in Gradient Magnitudes between Neighboring Grid Points")
ax[1].legend()

plt.tight_layout()
plt.show()
fixed_yy = mat_ml.scale_seq # or any other constant value you want to use
ngrid = 1000
xx = np.linspace(-np.pi, np.pi, ngrid)
yy = np.full_like(xx, fixed_yy).reshape(-1, 1)
hh = np.c_[yy, xx]
Cart_hh = FE.sp_cart(hh)
zeros_array = np.zeros((ngrid, 3))
Cart_hh_6D = np.hstack((Cart_hh, zeros_array))
grad_hh = mat_ml.calc_fgrad(Cart_hh_6D)
# 1. Compute gradient magnitudes for each grid point
grad_magnitudes = np.linalg.norm(grad_hh, axis=1)

# 2. Compute mean and standard deviation of gradient magnitudes
mean_grad_magnitude = np.mean(grad_magnitudes)
std_grad_magnitude = np.std(grad_magnitudes)
print(f"Mean Gradient Magnitude: {mean_grad_magnitude}")
print(f"Standard Deviation of Gradient Magnitudes: {std_grad_magnitude}")

# 3. Compute the change in gradient magnitudes between neighboring points
# For simplicity, let's calculate the change in magnitude between consecutive grid points
diff_grad_magnitudes = np.diff(grad_magnitudes)

# 4. Plotting
fig, ax = plt.subplots(2, 1, figsize=(10, 10))

# Plot of gradient magnitudes
ax[0].plot(grad_magnitudes, color='blue', label='Gradient Magnitude')
ax[0].axhline(mean_grad_magnitude, color='red', linestyle='--', label='Mean Magnitude')
ax[0].set_title("Gradient Magnitudes across Grid Points")
ax[0].legend()

# Plot of changes in gradient magnitudes
ax[1].plot(diff_grad_magnitudes, color='green', label='Change in Gradient Magnitude')
ax[1].axhline(0, color='red', linestyle='--')
ax[1].set_title("Change in Gradient Magnitudes between Neighboring Grid Points")
ax[1].legend()

plt.tight_layout()
plt.show()

#Analysis of level of smoothness of the ML yield function using the gradient of the yield function
colors = ['blue', 'green', 'red', 'purple']
Expand Down

0 comments on commit 9f14024

Please sign in to comment.