Skip to content
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

Implement correlated random number generation #1069

Merged
merged 40 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
eefce12
[gulpy] first implementation
mtazzari Jul 5, 2022
a8f89de
[gulpy] implementing correlated rng
mtazzari Jul 5, 2022
d8215d8
[wip] implementing correlated rng
mtazzari Jul 6, 2022
614dd3d
[wip]
mtazzari Jul 12, 2022
d407089
[gulpy] working implementation of the correlated random values
mtazzari Jul 15, 2022
579910b
Merge branch 'develop' into feature/correlated_rng
mtazzari Jul 15, 2022
5417f9b
minor cleanup
mtazzari Jul 15, 2022
5ad10f9
[gulpy] Update docstrings for random module functions
mtazzari Jul 22, 2022
4f564a1
Merge branch 'develop' into feature/correlated_rng
mtazzari Aug 1, 2022
2066aa2
[gulpy] remove unused generate_correlated_hash
mtazzari Aug 2, 2022
f0311c0
[gulpy] introduce --ignore-correlation flag
mtazzari Aug 2, 2022
1709cee
set hashed_group_id to True by default, cleanup
mtazzari Aug 3, 2022
2222be2
adding haahing patch
maxwellflitton Aug 8, 2022
2c0d5e3
adding haahing patch
maxwellflitton Aug 8, 2022
6621208
Merge branch 'develop' into hashing-investigation
mtazzari Aug 10, 2022
e8cf544
Merge branch 'develop' into feature/correlated_rng
mtazzari Aug 11, 2022
bb05858
[gulpy] minor cleanup files.py parameter on same line
mtazzari Aug 11, 2022
e593f0c
[gulpy] run correlation only if rho>0
mtazzari Aug 11, 2022
fbf1689
updating hashing
maxwellflitton Aug 11, 2022
d611869
[gulpy] improve flow depending on corr definitions
mtazzari Aug 12, 2022
82fb79c
Disable GroupID hashing for acceptance tests (#1094)
sambles Aug 12, 2022
fee427e
Update group_id_cols default in get_gul_input_items
mtazzari Aug 12, 2022
45f8779
Hashing investigation (#1096)
maxwellflitton Aug 12, 2022
461621f
[gul_inputs] bugfix don't modify inplace
mtazzari Aug 12, 2022
77245a3
Update test_summaries.py to not rely on "loc_id" as default for group…
sambles Aug 12, 2022
bf500be
Always create a correlations.bin, if missing model_settings file is b…
sambles Aug 23, 2022
fd210e2
Merge branch 'develop' of https://github.com/OasisLMF/OasisLMF into h…
maxwellflitton Aug 24, 2022
2b3d202
adding peril_correlation_group for valid_oasis_group_cols
maxwellflitton Sep 5, 2022
f7cb1ab
adding peril_correlation_group for valid_oasis_group_cols
maxwellflitton Sep 5, 2022
7d772fb
appending peril_correlation_group to columns if correlations group is…
maxwellflitton Sep 5, 2022
e6ac89e
adding peril_correlation_group column to hashing of group IDs if corr…
maxwellflitton Sep 7, 2022
823add8
updating hashing group ID
maxwellflitton Sep 15, 2022
ff9f568
updating to accomodate non-correlations
maxwellflitton Sep 20, 2022
32a5f66
fixxing run
maxwellflitton Sep 21, 2022
d60deb2
fixing empty correlations df write header if empty correlations
maxwellflitton Sep 21, 2022
1fc5651
Merge branch 'develop' into feature/correlated_rng
sambles Oct 3, 2022
e95dac6
Remove empty file
sambles Oct 3, 2022
62c805f
Add missing defaults to get_gul_input_items (backwards compatible)
sambles Oct 3, 2022
5f6933a
Fix Group_id valid column check
sambles Oct 3, 2022
44e43f2
Force retest
sambles Oct 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Disable GroupID hashing for acceptance tests (#1094)
* Update expected acceptance tests

* Revert "Update expected acceptance tests"

This reverts commit ad0907f.

* Default "hashed_group_id" to false in exposure run

* Move hashed_group_id=F default from "RunExposure" to "RunFmTest"

* Fix/pip compile (#1097)

* Only install pip-tools before pip-compile

* Try pinning flake8

* Revert "Try pinning flake8"

This reverts commit d845d5b.

* Try pinning virtualenv

* add --upgrade to pip install pip-tools

* Fix test_get_dataframe__from_csv_file__set_col_defaults_option_and_use_defaults_ and run with falsifying example

* Remove falsifying example

Co-authored-by: Marco Tazzari <6020226+mtazzari@users.noreply.github.com>
  • Loading branch information
sambles and mtazzari authored Aug 12, 2022
commit 82fb79c01861ef77dedbf5f60c9712c14bdbb2d5
3 changes: 1 addition & 2 deletions .github/workflows/oasislmf-unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ jobs:
- name: Install pip-tools
run: |
python -m pip install --upgrade pip
pip install pip-tools

pip install --upgrade pip-tools
- name: Pip Compile
run: |
rm -f requirements.txt
Expand Down
6 changes: 5 additions & 1 deletion oasislmf/computation/run/exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class RunExposure(ComputationStep):
{'name': 'fmpy_low_memory', 'default': False, 'type': str2bool, 'const':True, 'nargs':'?', 'help': 'use memory map instead of RAM to store loss array (may decrease performance but reduce RAM usage drastically)'},
{'name': 'fmpy_sort_output', 'default': True, 'type': str2bool, 'const': True, 'nargs': '?', 'help': 'order fmpy output by item_id'},
{'name': 'stream_type', 'flag':'-t', 'default': 2, 'type':int, 'help': 'Set the IL input stream type, 2 = default loss stream, 1 = deprecated cov/item stream'},
{"name": "hashed_group_id", "default": True, "type": str2bool, "const": False, 'nargs': '?', "help": "Hashes the group_id in the items.bin"},
{'name': 'net_ri', 'default': True},
{'name': 'include_loss_factor', 'default': True},
{'name': 'print_summary', 'default': True},
Expand Down Expand Up @@ -120,6 +121,7 @@ def run(self):
oed_info_csv=ri_info_fp,
oed_scope_csv=ri_scope_fp,
keys_data_csv=keys_fp,
hashed_group_id=self.hashed_group_id,
).run()

# 3. Run Deterministic Losses
Expand Down Expand Up @@ -312,6 +314,7 @@ class RunFmTest(ComputationStep):
{'name': 'fmpy_low_memory', 'default': False, 'type': str2bool, 'const': True, 'nargs': '?', 'help': 'use memory map instead of RAM to store loss array (may decrease performance but reduce RAM usage drastically)'},
{'name': 'fmpy_sort_output', 'default': True, 'type': str2bool, 'const': True, 'nargs': '?', 'help': 'order fmpy output by item_id'},
{'name': 'update_expected', 'default': False},
{'name': 'hashed_group_id', 'default': False},
{'name': 'expected_output_dir', 'default': "expected"},
]

Expand Down Expand Up @@ -408,7 +411,8 @@ def execute_test_case(self, test_case):
num_subperils=self.num_subperils,
fmpy=self.fmpy,
fmpy_low_memory=self.fmpy_low_memory,
fmpy_sort_output=self.fmpy_sort_output
fmpy_sort_output=self.fmpy_sort_output,
hashed_group_id=self.hashed_group_id,
).run()

expected_data_dir = os.path.join(test_dir, self.expected_output_dir)
Expand Down
2 changes: 2 additions & 0 deletions tests/fm/test_fm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def setUp(self):
self.test_cases_fp = os.path.join(sys.path[0], 'validation')
self.update_expected = False
self.keep_output = True
self.hashed_group_id = False

def run_test(self, test_case, fmpy=False, subperils=1, expected_dir="expected"):
with tempfile.TemporaryDirectory() as tmp_run_dir:
Expand All @@ -35,6 +36,7 @@ def run_test(self, test_case, fmpy=False, subperils=1, expected_dir="expected"):
num_subperils=subperils,
test_tolerance=0.001,
expected_output_dir=expected_dir,
hashed_group_id=self.hashed_group_id,
)

self.assertTrue(result)
Expand Down
4 changes: 3 additions & 1 deletion tests/fm/test_fmpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def setUp(self):
self.test_cases_fp = os.path.join(sys.path[0], 'validation')
self.update_expected = False
self.keep_output = True
self.hashed_group_id = False

def run_test(self, test_case, fmpy=False, subperils=1, expected_dir="expected"):
with tempfile.TemporaryDirectory() as tmp_run_dir:
Expand All @@ -37,6 +38,7 @@ def run_test(self, test_case, fmpy=False, subperils=1, expected_dir="expected"):
num_subperils=subperils,
test_tolerance=0.001,
expected_output_dir=expected_dir,
hashed_group_id=self.hashed_group_id,
)
self.assertTrue(result)

Expand Down Expand Up @@ -91,4 +93,4 @@ def test_issues_2_subperils(self):
self.run_test('issues', fmpy=True, subperils=2, expected_dir="expected_subperils")

def test_insurance_policy_coverage_2_subperils(self):
self.run_test('insurance_policy_coverage',fmpy=True, subperils=2, expected_dir="expected_subperils")
self.run_test('insurance_policy_coverage',fmpy=True, subperils=2, expected_dir="expected_subperils")
3 changes: 3 additions & 0 deletions tests/utils/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
get_timestamp,
get_utctimestamp,
get_location_df,
PANDAS_DEFAULT_NULL_VALUES,
)

from oasislmf.utils.defaults import (
Expand Down Expand Up @@ -541,10 +542,12 @@ def test_get_dataframe__from_csv_file_with_mixed_case_cols__set_col_defaults_opt
try:
df = pd.DataFrame(data)
df.to_csv(path_or_buf=fp, columns=df.columns, encoding='utf-8', index=False)
df['STR_COL'] = df['STR_COL'].map(lambda x: np.nan if x in PANDAS_DEFAULT_NULL_VALUES else x)
fp.close()

expected = df.copy(deep=True)
expected.columns = expected.columns.str.lower()

for col, default in defaults.items():
expected.loc[:, col.lower()].fillna(defaults[col], inplace=True)

Expand Down