This page was generated from
docs\source\notebooks/hoffman_fit.ipynb.
Configuring the Hoffman failure criterion by fitting to experimental data#
[1]:
from sigmaepsilon.solid.material import HoffmanFailureCriterion
import numpy as np
inputs = [
[-1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 0, -1, 0, 0, 0],
[0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, -1, 0],
[0, 0, 0, 0, 0, 1],
[-1, 0.2, 0, 0, 0, 0],
[0.2, 1, 0, 0, 0, 0],
[-1, 0, 0.2, 0, 0, 0],
]
inputs = np.array(inputs, dtype=float)
outputs = np.ones(len(inputs))
failure_obj = HoffmanFailureCriterion()
Parameter fitting with a Binary Genetic Algorithm#
[2]:
params = failure_obj.fit(
inputs,
outputs,
solver_params=dict(nPop=100, length=12),
penalty=1e12,
tol=0.1,
n_iter=100,
ranges=[[-10, 10] for _ in range(9)],
method="bga",
)
failure_obj.params = params
params
[2]:
(-0.9694749694749696,
-3.0647130647130645,
0.808302808302809,
8.686202686202687,
-4.378510378510379,
-4.349206349206349,
1.2380952380952372,
-2.5274725274725274,
1.0378510378510377)
[3]:
prediction = failure_obj.utilization(stresses=inputs)
max_error = np.max(np.abs(prediction - outputs))
total_error = np.sum(np.sqrt((prediction - outputs) ** 2))
max_error, total_error
[3]:
(0.6043478260869566, 1.9910851099808313)
[4]:
prediction
[4]:
array([1.02121238, 1.20985704, 0.40580257, 0.80769231, 0.39565217,
0.96352941, 1.20067546, 1.01013493, 0.87811824])
Parameter fitting with Scipy’s Nelder-Mead method#
[5]:
params = failure_obj.fit(
inputs,
outputs,
penalty=1e12,
tol=0.1,
method="Nelder-Mead",
x0=[-1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 0.2, 0.2, 0.2],
)
failure_obj.params = params
params
[5]:
(-1.007322989181017,
2.1576353611607075,
-0.1541917498510884,
0.9728903373271577,
-0.9949634593134442,
0.30283382032188944,
0.35151153576340144,
0.4327118607825844,
0.44137317208707544)
[6]:
prediction = failure_obj.utilization(stresses=inputs)
max_error = np.max(np.abs(prediction - outputs))
total_error = np.sum(np.sqrt((prediction - outputs) ** 2))
max_error, total_error
[6]:
(3.311006678188673, 7.380983890058536)
[7]:
prediction
[7]:
array([ 0.98936093, 1.20858211, 1.02177759, 2.84485685, -2.31100668,
2.26565651, 0.92597216, 0.35965563, 1.00409288])