-
Notifications
You must be signed in to change notification settings - Fork 2
Fix SOE with lognormal distribution #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2d11249
Ignore virtual environment venv (#43)
justushelo bf93d74
Fix code style and end-of-file issues (#43)
justushelo acc0f66
Fix sensitivity indices to match Matlab SOE calculation.
justushelo 6495b61
Fix variable selection logic and match MATLAB state formation
justushelo dcc7fd7
Update fix of sensitivity_indices.py, add tests for Issue #43 and edi…
justushelo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -35,3 +35,6 @@ sdist/* | |
| docs/html | ||
| docs/jupyter_execute | ||
| app.html | ||
|
|
||
| # Virtual environment | ||
| venv/ | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,29 @@ | ||
| import numpy as np | ||
| import pandas as pd | ||
| from scipy.stats import qmc, uniform, lognorm | ||
| import simdec as sd | ||
|
|
||
|
|
||
| def test_decomposition_default(): | ||
| m = 13 | ||
| sampler = qmc.Sobol(d=2, scramble=True, seed=42) | ||
| sample = sampler.random_base2(m=m) | ||
|
|
||
| # deposit_0: uniform(500, 1500) | ||
| deposit_0 = uniform.ppf(sample[:, 0], loc=500, scale=1000) | ||
|
|
||
| # interest_rate: lognormal | ||
| sigma = 0.5 | ||
| mu = np.log(0.01) + sigma**2 | ||
| interest_rate = lognorm.ppf(sample[:, 1], s=sigma, scale=np.exp(mu)) | ||
|
|
||
| deposit_20 = deposit_0 * (1 + interest_rate) ** 20 | ||
|
|
||
| inputs = pd.DataFrame({"deposit_0": deposit_0, "interest_rate": interest_rate}) | ||
| output = pd.Series(deposit_20, name="deposit_20") | ||
| indices = sd.sensitivity_indices(inputs=inputs, output=output) | ||
| si = indices.si | ||
| res = sd.decomposition(inputs=inputs, output=output, sensitivity_indices=si) | ||
|
|
||
| assert len(res.var_names) == 2 | ||
| assert res.var_names == ["deposit_0", "interest_rate"] |
This file contains hidden or 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,37 @@ | ||
| import numpy as np | ||
| import numpy.testing as npt | ||
| import pandas as pd | ||
| from scipy.stats import qmc, uniform, lognorm | ||
| import simdec as sd | ||
|
|
||
| # Testing fix for issue #43 | ||
|
|
||
|
|
||
| def test_sensitivity_indices_43(): | ||
| m = 13 | ||
| sampler = qmc.Sobol(d=2, scramble=True, seed=42) | ||
| sample = sampler.random_base2(m=m) | ||
|
|
||
| # deposit_0: uniform(500, 1500) | ||
| deposit_0 = uniform.ppf(sample[:, 0], loc=500, scale=1000) | ||
|
|
||
| # interest_rate: lognormal | ||
| sigma = 0.5 | ||
| mu = np.log(0.01) + sigma**2 | ||
| interest_rate = lognorm.ppf(sample[:, 1], s=sigma, scale=np.exp(mu)) | ||
|
|
||
| deposit_20 = deposit_0 * (1 + interest_rate) ** 20 | ||
|
|
||
| inputs = pd.DataFrame({"deposit_0": deposit_0, "interest_rate": interest_rate}) | ||
| output = pd.Series(deposit_20, name="deposit_20") | ||
|
|
||
| res = sd.sensitivity_indices(inputs, output) | ||
|
|
||
| # MATLAB Results | ||
| expected_si = np.array([0.7101, 0.2739]) | ||
| expected_foe = np.array([0.7028, 0.2666]) | ||
| expected_soe_12 = 0.0146 | ||
|
|
||
| npt.assert_allclose(res.si, expected_si, atol=3e-2) | ||
| npt.assert_allclose(res.first_order, expected_foe, atol=3e-2) | ||
| npt.assert_allclose(res.second_order[0, 1], expected_soe_12, atol=1e-2) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.