Skip to content

Commit

Permalink
Start param estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
teubert committed Oct 29, 2024
1 parent f5b9238 commit 9cdafff
Showing 1 changed file with 111 additions and 4 deletions.
115 changes: 111 additions & 4 deletions examples/2024PHMTutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1168,16 +1168,123 @@
"fig = results.outputs.plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Parameter Estimation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"times = dataset['absoluteTime']\n",
"inputs = [elem[1]['voltage'] * elem[1]['current'] for elem in dataset.iterrows()]\n",
"outputs = [{'v': elem[1]['voltage']} for elem in dataset.iterrows()]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def future_load(t, x=None):\n",
" power = np.interp(t, times, inputs)\n",
" return {'P': power}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dataset"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"result = m.simulate_to(30116.56, future_load, dt=1, save_freq=100)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from matplotlib import pyplot as plt\n",
"plt.plot(times, [z for z in dataset['voltage']])\n",
"plt.plot(results.times, [z['v'] for z in results.outputs])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m.parameters"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m['v_L'] = m['v_L']/4"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"inputs_reformatted = [{'v': elem[1]['voltage'] * elem[1]['current']} for elem in dataset.iterrows()]\n",
"keys = ['v_L', 'lambda', 'gamma', 'mu', 'beta', 'x0']\n",
"print('Model configuration before')\n",
"for key in keys:\n",
" print(\"-\", key, m[key])\n",
"print('Error: ', m.calc_error(times=times.to_list(), inputs=inputs_reformatted, outputs=outputs))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m.estimate_params(times=times.to_list(), inputs=inputs_reformatted, outputs=outputs, dt=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for key in keys:\n",
" print(\"-\", key, m[key])\n",
"print('Error: ', m.calc_error(times=times.to_list(), inputs=inputs_reformatted, outputs=outputs))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"current = [165/z['v'] for z in results.outputs]\n",
"import matplotlib.pyplot as plt\n",
"fig = plt.plot(current)\n",
"fig = results.inputs.plot()"
"results.outputs.plot()"
]
},
{
Expand Down

0 comments on commit 9cdafff

Please sign in to comment.