MCPcopy Create free account
hub / github.com/Cantera/cantera / analyze_errors

Function analyze_errors

samples/python/onedim/flame_speed_convergence_analysis.py:300–359  ·  view source on GitHub ↗

If we assume that the final answer, with a very fine grid, has actually converged and is is the "truth", then we can find out how large the errors were in the previous values, and compare these with our estimated errors. This will show if our estimates are reasonable, or conserv

(grids, speeds, true_speed)

Source from the content-addressed store, hash-verified

298# are reasonable, or conservative, or too optimistic.
299
300def analyze_errors(grids, speeds, true_speed):
301 """
302 If we assume that the final answer, with a very fine grid,
303 has actually converged and is is the "truth", then we can
304 find out how large the errors were in the previous values,
305 and compare these with our estimated errors.
306 This will show if our estimates are reasonable, or conservative, or too optimistic.
307 """
308 true_speed_estimates = np.full_like(speeds, np.nan)
309 total_percent_error_estimates = np.full_like(speeds, np.nan)
310 actual_extrapolated_percent_errors = np.full_like(speeds, np.nan)
311 actual_raw_percent_errors = np.full_like(speeds, np.nan)
312 for i in range(3, len(grids)):
313 print(grids[: i + 1])
314 true_speed_estimate, total_percent_error_estimate = extrapolate_uncertainty(
315 grids[: i + 1], speeds[: i + 1], plot=False
316 )
317 actual_extrapolated_percent_error = (
318 abs(true_speed_estimate - true_speed) / true_speed
319 )
320 actual_raw_percent_error = abs(speeds[i] - true_speed) / true_speed
321 print(
322 "Actual extrapolated error (with hindsight) "
323 f"{actual_extrapolated_percent_error:.1%}"
324 )
325 print(f"Actual raw error (with hindsight) {actual_raw_percent_error:.1%}")
326
327 true_speed_estimates[i] = true_speed_estimate
328 total_percent_error_estimates[i] = total_percent_error_estimate
329 actual_extrapolated_percent_errors[i] = actual_extrapolated_percent_error
330 actual_raw_percent_errors[i] = actual_raw_percent_error
331 print()
332
333 fig, ax = plt.subplots()
334 ax.loglog(grids, actual_raw_percent_errors * 100, "o-", label="raw error")
335 ax.loglog(
336 grids,
337 actual_extrapolated_percent_errors * 100,
338 "o-",
339 label="extrapolated error",
340 )
341 ax.loglog(
342 grids, total_percent_error_estimates * 100, "o-", label="estimated error"
343 )
344 ax.set(xlabel="Grid size", ylabel="Error in flame speed (%)")
345 ax.legend()
346 ax.set_title(flame.get_refine_criteria())
347 ax.get_yaxis().set_major_formatter(matplotlib.ticker.PercentFormatter())
348 flame.get_refine_criteria()
349
350 data = pd.DataFrame(
351 data={
352 "actual error in raw value": actual_raw_percent_errors * 100,
353 "actual error in extrapolated value": actual_extrapolated_percent_errors
354 * 100,
355 "estimated error": total_percent_error_estimates * 100,
356 },
357 index=grids,

Calls 3

lenFunction · 0.85
extrapolate_uncertaintyFunction · 0.85
get_refine_criteriaMethod · 0.80

Tested by

no test coverage detected