Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Repair all uncertainty distributions. Fixes #104.
- Loading branch information
Showing
5 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
from ..uncertainty import get_uncertainty_class | ||
from ..utils import iterate_all_uncertainties | ||
import logging | ||
|
||
|
||
def repair_all_uncertainty_distributions(data): | ||
"""Repair all uncertainty distributions. | ||
Uses distribution-specific ``repair`` methods.""" | ||
for ds in data: | ||
for obj in iterate_all_uncertainties(ds): | ||
if not obj.get('uncertainty'): | ||
continue | ||
# TODO: Add detailed log message | ||
obj = get_uncertainty_class(obj).repair(obj) | ||
return data |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
from ocelot.transformations.parameterization.uncertainty import repair_all_uncertainty_distributions as repair | ||
import numpy as np | ||
|
||
|
||
def test_repair(): | ||
given = [{ | ||
'exchanges': [{ | ||
'amount': -4, | ||
'uncertainty': { | ||
'type': 'lognormal', | ||
'variance with pedigree uncertainty': 0.7 | ||
}, | ||
'pedigree matrix': {} | ||
}, { | ||
'amount': 0, | ||
'uncertainty': {'type': 'lognormal'} | ||
}] | ||
}] | ||
expected = [{ | ||
'exchanges': [{ | ||
'amount': -4, | ||
'pedigree matrix': {}, | ||
'uncertainty': { | ||
'type': 'lognormal', | ||
'mean': 4, | ||
'mu': np.log(4), | ||
'negative': True, | ||
'variance': 0.7, | ||
'variance with pedigree uncertainty': 0.7 | ||
}, | ||
}, { | ||
'amount': 0 | ||
}] | ||
}] | ||
assert repair(given) == expected |
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