-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generated gh-pages for commit 58cbb5a
Merge: 252fc58 a024fbe Author: John Jakeman <[email protected]> Merge remote-tracking branch 'origin/devel'
- Loading branch information
Showing
361 changed files
with
102,772 additions
and
70,999 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
_downloads/059572d8fc6c0ec9b2cfc587871e72dc/plot_multioutput_acv.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"Add latex macros$$\\newcommand{\\V}[1]{{\\boldsymbol{#1}}}\\newcommand{mean}[1]{{\\mathbb{E}\\left[#1\\right]}}\\newcommand{var}[1]{{\\mathbb{V}\\left[#1\\right]}}\\newcommand{covar}[2]{\\mathbb{C}\\text{ov}\\left[#1,#2\\right]}\\newcommand{corr}[2]{\\mathbb{C}\\text{or}\\left[#1,#2\\right]}\\newcommand{argmin}{\\mathrm{argmin}}\\def\\rv{z}\\def\\reals{\\mathbb{R}}\\def\\rvset{{\\mathcal{Z}}}\\def\\pdf{\\rho}\\def\\rvdom{\\Gamma}\\def\\coloneqq{\\colon=}\\newcommand{norm}{\\lVert #1 \\rVert}\\def\\argmax{\\operatorname{argmax}}\\def\\ai{\\alpha}\\def\\bi{\\beta}\\newcommand{\\dx}[1]{\\;\\text{d}#1}\\newcommand{\\mat}[1]{{\\boldsymbol{\\mathrm{#1}}}}$$" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"\n# Multioutput Approximate Control Variates\n\nThis tutorial demonstrates how computing statistics for multiple outputs simultaneoulsy can improve the accuracy of ACV estimates of individual statistics when compared to ACV applied to each output separately.\n\nThe optimal control variate weights are obtained by minimizing the estimator covariance [RM1985]_.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\nimport matplotlib.pyplot as plt\n\nfrom pyapprox import multifidelity as mf\nfrom pyapprox.benchmarks import setup_benchmark\nfrom pyapprox.util.visualization import mathrm_labels, mathrm_label\n\nnp.random.seed(1)\nbenchmark = setup_benchmark(\"multioutput_model_ensemble\")\ncosts = np.array([1, 0.01, 0.001])\nnmodels = 3\n\ncov = benchmark.covariance\n\nlabels = ([r\"$(f_{0})_{%d}$\" % (ii+1) for ii in range(benchmark.nqoi)] +\n [r\"$(f_{2})_{%d}$\" % (ii+1) for ii in range(benchmark.nqoi)] +\n [r\"$(f_{2})_{%d}$\" % (ii+1) for ii in range(benchmark.nqoi)])\nax = plt.subplots(1, 1, figsize=(8, 6))[1]\n_ = mf.plot_correlation_matrix(\n mf.get_correlation_from_covariance(cov), ax=ax, model_names=labels,\n label_fontsize=20)\n\ntarget_cost = 10\nstat = mf.multioutput_stats[\"mean\"](benchmark.nqoi)\nstat.set_pilot_quantities(cov)\nest = mf.get_estimator(\"gmf\", stat, costs)\nest.allocate_samples(target_cost)\n\n# get covariance of just first qoi\nqoi_idx = [0]\ncov_0 = stat.get_pilot_quantities_subset(\n nmodels, benchmark.nqoi, [0, 1, 2], qoi_idx)[0]\nstat_0 = mf.multioutput_stats[\"mean\"](benchmark.nqoi)\nstat_0.set_pilot_quantities(cov_0)\nest_0 = mf.get_estimator(\"gmf\", stat_0, costs)\nest_0.allocate_samples(target_cost)\n\nest_labels = mathrm_labels([\"MOACV\", \"SOACV\"])\n\n# only works if qoi_idx = [0]\nfrom pyapprox.multifidelity.factory import ComparisonCriteria\nclass CustomComparisionCriteria(ComparisonCriteria):\n def __call__(self, est_covariance, est):\n return est_covariance[0, 0]\n\n\nax = plt.subplots(1, 1, figsize=(8, 6))[1]\n_ = mf.plot_estimator_variance_reductions(\n [est, est_0], est_labels, ax, criteria=CustomComparisionCriteria())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Video\nClick on the image below to view a video tutorial on multi-output approximate control variate Monte Carlo quadrature\n\n<img src=\"file://../../figures/multi-output-acv-thumbnail.png\" target=\"https://youtu.be/astvKKFh2yA?si=8vgmKRbjdhJYeUfq\">\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## References\n.. [RM1985] [Reuven Y. Rubinstein and Ruth Marcus. Efficiency of multivariate control variates in monte carlo simulation. Operations Research, 33(3):661\u2013677, 1985.](https://doi.org/10.48550/arXiv.2310.00125)\n\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.13" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
Binary file modified
BIN
+2.31 KB
(100%)
_downloads/07fcc19ba03226cd3d83d4e40ec44385/auto_examples_python.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.