code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def test_get_all_accuracy_metrics_returns(get_test_set): """Test if correct accuracy metrics are returned.""" y_pred, y_std, y_true = get_test_set met_dict = get_all_accuracy_metrics(y_pred, y_true) met_keys = met_dict.keys() assert len(met_keys) == 6 met_str_list = ["mae", "rmse", "mdae", "mar...
Test if correct accuracy metrics are returned.
test_get_all_accuracy_metrics_returns
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics.py
MIT
def test_get_all_average_calibration_returns(get_test_set): """Test if correct average calibration metrics are returned.""" n_bins = 20 met_dict = get_all_average_calibration(*get_test_set, n_bins) met_keys = met_dict.keys() assert len(met_keys) == 3 met_str_list = ["rms_cal", "ma_cal", "miscal...
Test if correct average calibration metrics are returned.
test_get_all_average_calibration_returns
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics.py
MIT
def test_get_all_adversarial_group_calibration_returns(get_test_set): """Test if correct adversarial group calibration metrics are returned.""" n_bins = 20 met_dict = get_all_adversarial_group_calibration(*get_test_set, n_bins) met_keys = met_dict.keys() assert len(met_keys) == 2 met_str_list =...
Test if correct adversarial group calibration metrics are returned.
test_get_all_adversarial_group_calibration_returns
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics.py
MIT
def test_get_all_sharpness_metrics_returns(get_test_set): """Test if correct sharpness metrics are returned.""" y_pred, y_std, y_true = get_test_set met_dict = get_all_sharpness_metrics(y_std) met_keys = met_dict.keys() assert len(met_keys) == 1 assert "sharp" in met_keys
Test if correct sharpness metrics are returned.
test_get_all_sharpness_metrics_returns
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics.py
MIT
def test_get_all_scoring_rule_metrics_returns(get_test_set): """Test if correct scoring rule metrics are returned.""" resolution = 99 scaled = True met_dict = get_all_scoring_rule_metrics(*get_test_set, resolution, scaled) met_keys = met_dict.keys() assert len(met_keys) == 4 met_str_list = ...
Test if correct scoring rule metrics are returned.
test_get_all_scoring_rule_metrics_returns
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics.py
MIT
def test_get_all_metrics_returns(get_test_set): """Test if correct metrics are returned by get_all_metrics function.""" met_dict = get_all_metrics(*get_test_set) met_keys = met_dict.keys() assert len(met_keys) == 5 met_str_list = [ "accuracy", "avg_calibration", "adv_group_c...
Test if correct metrics are returned by get_all_metrics function.
test_get_all_metrics_returns
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics.py
MIT
def test_prediction_error_metric_fields(get_test_set): """Test if prediction error metrics have correct fields.""" y_pred, y_std, y_true = get_test_set met_dict = prediction_error_metrics(y_pred, y_true) met_keys = met_dict.keys() assert len(met_keys) == 6 met_str_list = ["mae", "rmse", "mdae",...
Test if prediction error metrics have correct fields.
test_prediction_error_metric_fields
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_accuracy.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_accuracy.py
MIT
def test_prediction_error_metric_values(get_test_set): """Test if prediction error metrics have correct values.""" y_pred, y_std, y_true = get_test_set met_dict = prediction_error_metrics(y_pred, y_true) print(met_dict) assert met_dict["mae"] > 0.21 and met_dict["mae"] < 0.22 assert met_dict["rm...
Test if prediction error metrics have correct values.
test_prediction_error_metric_values
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_accuracy.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_accuracy.py
MIT
def test_sharpness_on_test_set(supply_test_set): """Test sharpness on the test set for some dummy values.""" _, test_std, _ = supply_test_set assert np.abs(sharpness(test_std) - 0.648074069840786) < 1e-6
Test sharpness on the test set for some dummy values.
test_sharpness_on_test_set
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_calibration.py
MIT
def test_root_mean_squared_calibration_error_on_test_set(supply_test_set): """Test root mean squared calibration error on some dummy values.""" test_rmsce_nonvectorized_interval = root_mean_squared_calibration_error( *supply_test_set, num_bins=100, vectorized=False, recal_model=N...
Test root mean squared calibration error on some dummy values.
test_root_mean_squared_calibration_error_on_test_set
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_calibration.py
MIT
def test_mean_absolute_calibration_error_on_test_set(supply_test_set): """Test mean absolute calibration error on some dummy values.""" test_mace_nonvectorized_interval = mean_absolute_calibration_error( *supply_test_set, num_bins=100, vectorized=False, recal_model=None, ...
Test mean absolute calibration error on some dummy values.
test_mean_absolute_calibration_error_on_test_set
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_calibration.py
MIT
def test_adversarial_group_calibration_on_test_set(supply_test_set): """Test adversarial group calibration on test set for some dummy values.""" test_out_interval = adversarial_group_calibration( *supply_test_set, cali_type="mean_abs", prop_type="interval", num_bins=100, ...
Test adversarial group calibration on test set for some dummy values.
test_adversarial_group_calibration_on_test_set
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_calibration.py
MIT
def test_miscalibration_area_on_test_set(supply_test_set): """Test miscalibration area on some dummy values.""" test_miscal_area_nonvectorized_interval = miscalibration_area( *supply_test_set, num_bins=100, vectorized=False, recal_model=None, prop_type="interval" ) ...
Test miscalibration area on some dummy values.
test_miscalibration_area_on_test_set
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_calibration.py
MIT
def test_vectorization_for_proportion_list_on_test_set(supply_test_set): """Test vectorization in get_proportion_lists on the test set for some dummy values.""" ( test_exp_props_nonvec_interval, test_obs_props_nonvec_interval, ) = get_proportion_lists( *supply_test_set, num_bins=100,...
Test vectorization in get_proportion_lists on the test set for some dummy values.
test_vectorization_for_proportion_list_on_test_set
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_calibration.py
MIT
def test_get_proportion_lists_vectorized_on_test_set(supply_test_set): """Test get_proportion_lists_vectorized on the test set for some dummy values.""" ( test_exp_props_interval, test_obs_props_interval, ) = get_proportion_lists_vectorized( *supply_test_set, num_bins=100, recal_mode...
Test get_proportion_lists_vectorized on the test set for some dummy values.
test_get_proportion_lists_vectorized_on_test_set
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_calibration.py
MIT
def test_get_proportion_lists_on_test_set(supply_test_set): """Test get_proportion_lists on the test set for some dummy values.""" test_exp_props_interval, test_obs_props_interval = get_proportion_lists( *supply_test_set, num_bins=100, recal_model=None, prop_type="interval" ) assert len(test_exp...
Test get_proportion_lists on the test set for some dummy values.
test_get_proportion_lists_on_test_set
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_calibration.py
MIT
def test_get_proportion_in_interval_on_test_set(supply_test_set): """Test get_proportion_in_interval on the test set for some dummy values.""" test_quantile_value_list = [ (0.0, 0.0), (0.25, 0.0), (0.5, 0.0), (0.75, 0.3333333333333333), (1.0, 1.0), ] for test_q, t...
Test get_proportion_in_interval on the test set for some dummy values.
test_get_proportion_in_interval_on_test_set
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_calibration.py
MIT
def test_get_prediction_interval_on_test_set(supply_test_set): """Test get_prediction_interval on the test set for some dummy values.""" test_quantile_value_list = [ ( 0.01, np.array([1.00125335, 2.00626673, 3.01253347]), np.array([0.99874665, 1.99373327, 2.98746653])...
Test get_prediction_interval on the test set for some dummy values.
test_get_prediction_interval_on_test_set
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_calibration.py
MIT
def test_nll_gaussian_on_one_pt(): """Sanity check by testing one point at mean of gaussian.""" y_pred = np.array([0]) y_true = np.array([0]) y_std = np.array([1 / np.sqrt(2 * np.pi)]) assert np.abs(nll_gaussian(y_pred, y_std, y_true)) < 1e-6
Sanity check by testing one point at mean of gaussian.
test_nll_gaussian_on_one_pt
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_scoring_rule.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_scoring_rule.py
MIT
def test_check_score_on_one_pt(): """Sanity check to show that check score is minimized (i.e. 0) if data occurs at the exact requested quantile.""" y_pred = np.array([0]) y_true = np.array([1]) y_std = np.array([1]) score = check_score( y_pred=y_pred, y_std=y_std, y_true=...
Sanity check to show that check score is minimized (i.e. 0) if data occurs at the exact requested quantile.
test_check_score_on_one_pt
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_scoring_rule.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_scoring_rule.py
MIT
def test_interval_score_on_one_pt(): """Sanity check on interval score. For one point in the center of the distribution and intervals one standard deviation and two standard deviations away, should return ((1 std) * 2 + (2 std) * 2) / 2 = 3. """ y_pred = np.array([0]) y_true = np.array([0]) ...
Sanity check on interval score. For one point in the center of the distribution and intervals one standard deviation and two standard deviations away, should return ((1 std) * 2 + (2 std) * 2) / 2 = 3.
test_interval_score_on_one_pt
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_metrics_scoring_rule.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_metrics_scoring_rule.py
MIT
def test_recal_model_mace_criterion_on_test_set(supply_test_set): """ Test recalibration on mean absolute calibration error on the test set for some dummy values. """ test_mace = mean_absolute_calibration_error( *supply_test_set, num_bins=100, vectorized=True, recal_model=None ) test...
Test recalibration on mean absolute calibration error on the test set for some dummy values.
test_recal_model_mace_criterion_on_test_set
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_recalibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_recalibration.py
MIT
def test_recal_model_rmce_criterion_on_test_set(supply_test_set): """ Test recalibration on root mean squared calibration error on the test set for some dummy values. """ test_rmsce = root_mean_squared_calibration_error( *supply_test_set, num_bins=100, vectorized=True, recal_model=None )...
Test recalibration on root mean squared calibration error on the test set for some dummy values.
test_recal_model_rmce_criterion_on_test_set
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_recalibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_recalibration.py
MIT
def test_recal_model_miscal_area_criterion_on_test_set(supply_test_set): """ Test recalibration on miscalibration area on the test set for some dummy values. """ test_miscal_area = miscalibration_area( *supply_test_set, num_bins=100, vectorized=True, recal_model=None ) test_exp_props...
Test recalibration on miscalibration area on the test set for some dummy values.
test_recal_model_miscal_area_criterion_on_test_set
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_recalibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_recalibration.py
MIT
def test_optimize_recalibration_ratio_mace_criterion(supply_test_set): """ Test standard deviation recalibration on mean absolute calibration error on the test set for some dummy values. """ random.seed(0) np.random.seed(seed=0) y_pred, y_std, y_true = supply_test_set ma_cal_ratio = opt...
Test standard deviation recalibration on mean absolute calibration error on the test set for some dummy values.
test_optimize_recalibration_ratio_mace_criterion
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_recalibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_recalibration.py
MIT
def test_optimize_recalibration_ratio_rmce_criterion(supply_test_set): """ Test standard deviation recalibration on root mean squared calibration error on the test set for some dummy values. """ random.seed(0) np.random.seed(seed=0) y_pred, y_std, y_true = supply_test_set rms_cal_ratio ...
Test standard deviation recalibration on root mean squared calibration error on the test set for some dummy values.
test_optimize_recalibration_ratio_rmce_criterion
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_recalibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_recalibration.py
MIT
def test_optimize_recalibration_ratio_miscal_area_criterion(supply_test_set): """ Test standard deviation recalibration on miscalibration area on the test set for some dummy values. """ random.seed(0) np.random.seed(seed=0) y_pred, y_std, y_true = supply_test_set miscal_ratio = optimize...
Test standard deviation recalibration on miscalibration area on the test set for some dummy values.
test_optimize_recalibration_ratio_miscal_area_criterion
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_recalibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_recalibration.py
MIT
def test_get_std_recalibrator(supply_test_set): """ Test get_std_recalibration on the test set for some dummy values. """ random.seed(0) np.random.seed(seed=0) y_pred, y_std, y_true = supply_test_set test_quantile_prop_list = [ (0.01, 0.00, 0.00), (0.25, 0.06, 0.00), ...
Test get_std_recalibration on the test set for some dummy values.
test_get_std_recalibrator
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_recalibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_recalibration.py
MIT
def test_filter_subset(get_test_set): """Test if filter_subset returns correct number of subset elements.""" y_pred, y_std, y_true, _ = get_test_set _test_n_subset = 2 [y_pred, y_std, y_true] = filter_subset([y_pred, y_std, y_true], _test_n_subset) assert len(y_pred) == _test_n_subset assert len...
Test if filter_subset returns correct number of subset elements.
test_filter_subset
python
uncertainty-toolbox/uncertainty-toolbox
tests/test_viz.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/tests/test_viz.py
MIT
def synthetic_arange_random( num_points: int = 10, ) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]: """Dataset of evenly spaced points and identity function (with some randomization). This function returns predictions and predictive uncertainties (given as standard deviations) from some hypo...
Dataset of evenly spaced points and identity function (with some randomization). This function returns predictions and predictive uncertainties (given as standard deviations) from some hypothetical uncertainty model, along with true input x and output y data points. Args: num_points: The numbe...
synthetic_arange_random
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/data.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/data.py
MIT
def synthetic_sine_heteroscedastic( n_points: int = 10, ) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]: """Return samples from "synthetic sine" heteroscedastic noisy function. This returns a synthetic dataset which can be used to train and assess a predictive uncertainty model. Args: ...
Return samples from "synthetic sine" heteroscedastic noisy function. This returns a synthetic dataset which can be used to train and assess a predictive uncertainty model. Args: n_points: The number of data points in the set. Returns: - Predicted output points y. - Predictive ...
synthetic_sine_heteroscedastic
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/data.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/data.py
MIT
def get_all_accuracy_metrics( y_pred: np.ndarray, y_true: np.ndarray, verbose: bool = True, ) -> Dict[str, float]: """Compute all accuracy metrics. Args: y_pred: 1D array of the predicted means for the held out dataset. y_true: 1D array of the true labels in the held out dataset. ...
Compute all accuracy metrics. Args: y_pred: 1D array of the predicted means for the held out dataset. y_true: 1D array of the true labels in the held out dataset. verbose: Activate verbose mode. Returns: The evaluations for all accuracy related metrics.
get_all_accuracy_metrics
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics.py
MIT
def get_all_average_calibration( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, num_bins: int, verbose: bool = True, ) -> Dict[str, float]: """Compute all metrics for average calibration. Args: y_pred: 1D array of the predicted means for the held out dataset. y_s...
Compute all metrics for average calibration. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of he predicted standard deviations for the held out dataset. y_true: 1D array of the true labels in the held out dataset. num_bins: The number of bin...
get_all_average_calibration
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics.py
MIT
def get_all_adversarial_group_calibration( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, num_bins: int, verbose: bool = True, ) -> Dict[str, Dict[str, np.ndarray]]: """Compute all metrics for adversarial group calibration. Args: y_pred: 1D array of the predicted means f...
Compute all metrics for adversarial group calibration. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of he predicted standard deviations for the held out dataset. y_true: 1D array of the true labels in the held out dataset. num_bins: The num...
get_all_adversarial_group_calibration
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics.py
MIT
def get_all_sharpness_metrics( y_std: np.ndarray, verbose: bool = True, ) -> Dict[str, float]: """Compute all sharpness metrics Args: y_std: 1D array of he predicted standard deviations for the held out dataset. verbose: Activate verbose mode. Returns: The evaluations for a...
Compute all sharpness metrics Args: y_std: 1D array of he predicted standard deviations for the held out dataset. verbose: Activate verbose mode. Returns: The evaluations for all sharpness metrics.
get_all_sharpness_metrics
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics.py
MIT
def get_all_scoring_rule_metrics( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, resolution: int, scaled: bool, verbose: bool = True, ) -> Dict[str, float]: """Compute all scoring rule metrics Args: y_pred: 1D array of the predicted means for the held out dataset. ...
Compute all scoring rule metrics Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of he predicted standard deviations for the held out dataset. y_true: 1D array of the true labels in the held out dataset. resolution: The number of quantiles to ...
get_all_scoring_rule_metrics
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics.py
MIT
def get_all_metrics( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, num_bins: int = 100, resolution: int = 99, scaled: bool = True, verbose: bool = True, ) -> Dict[str, Any]: """Compute all metrics. Args: y_pred: 1D array of the predicted means for the held out d...
Compute all metrics. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of he predicted standard deviations for the held out dataset. y_true: 1D array of the true labels in the held out dataset. num_bins: The number of bins to use for discretizat...
get_all_metrics
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics.py
MIT
def prediction_error_metrics( y_pred: np.ndarray, y_true: np.ndarray, ) -> Dict[str, float]: """Get all prediction error metrics. Args: y_pred: 1D array of the predicted means for the held out dataset. y_true: 1D array of the true labels in the held out dataset. Returns: A ...
Get all prediction error metrics. Args: y_pred: 1D array of the predicted means for the held out dataset. y_true: 1D array of the true labels in the held out dataset. Returns: A dictionary with Mean average error ('mae'), Root mean squared error ('rmse'), Median absolute error ...
prediction_error_metrics
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_accuracy.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_accuracy.py
MIT
def sharpness(y_std: np.ndarray) -> float: """Return sharpness (a single measure of the overall confidence). Args: y_std: 1D array of the predicted standard deviations for the held out dataset. Returns: A single scalar which quantifies the average of the standard deviations. """ # ...
Return sharpness (a single measure of the overall confidence). Args: y_std: 1D array of the predicted standard deviations for the held out dataset. Returns: A single scalar which quantifies the average of the standard deviations.
sharpness
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_calibration.py
MIT
def root_mean_squared_calibration_error( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, num_bins: int = 100, vectorized: bool = False, recal_model: IsotonicRegression = None, prop_type: str = "interval", ) -> float: """Root mean squared calibration error. Args: y...
Root mean squared calibration error. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of the predicted standard deviations for the held out dataset. y_true: 1D array of the true labels in the held out dataset. num_bins: number of discretization...
root_mean_squared_calibration_error
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_calibration.py
MIT
def mean_absolute_calibration_error( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, num_bins: int = 100, vectorized: bool = False, recal_model: IsotonicRegression = None, prop_type: str = "interval", ) -> float: """Mean absolute calibration error; identical to ECE. Args:...
Mean absolute calibration error; identical to ECE. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of the predicted standard deviations for the held out dataset. y_true: 1D array of the true labels in the held out dataset. num_bins: number of ...
mean_absolute_calibration_error
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_calibration.py
MIT
def adversarial_group_calibration( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, cali_type: str, prop_type: str = "interval", num_bins: int = 100, num_group_bins: int = 10, draw_with_replacement: bool = False, num_trials: int = 10, num_group_draws: int = 10, verb...
Adversarial group calibration. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of the predicted standard deviations for the held out dataset. y_true: 1D array of the true labels in the held out dataset. cali_type: type of calibration error to ...
adversarial_group_calibration
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_calibration.py
MIT
def miscalibration_area_from_proportions( exp_proportions: np.ndarray, obs_proportions: np.ndarray ) -> float: """Miscalibration area from expected and observed proportions lists. This function returns the same output as `miscalibration_area` directly from a list of expected proportions (the proportion...
Miscalibration area from expected and observed proportions lists. This function returns the same output as `miscalibration_area` directly from a list of expected proportions (the proportion of data that you expect to observe within prediction intervals) and a list of observed proportions (the proportion da...
miscalibration_area_from_proportions
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_calibration.py
MIT
def get_proportion_lists_vectorized( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, num_bins: int = 100, recal_model: Any = None, prop_type: str = "interval", ) -> Tuple[np.ndarray, np.ndarray]: """Arrays of expected and observed proportions Returns the expected proportions ...
Arrays of expected and observed proportions Returns the expected proportions and observed proportion of points falling into intervals corresponding to a range of quantiles. Computations here are vectorized for faster execution, but this function is not suited when there are memory constraints. Arg...
get_proportion_lists_vectorized
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_calibration.py
MIT
def get_proportion_lists( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, num_bins: int = 100, recal_model: IsotonicRegression = None, prop_type: str = "interval", ) -> Tuple[np.ndarray, np.ndarray]: """Arrays of expected and observed proportions Return arrays of expected and...
Arrays of expected and observed proportions Return arrays of expected and observed proportions of points falling into intervals corresponding to a range of quantiles. Computations here are not vectorized, in case there are memory constraints. Args: y_pred: 1D array of the predicted means for t...
get_proportion_lists
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_calibration.py
MIT
def get_proportion_in_interval( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, quantile: float ) -> float: """For a specified quantile, return the proportion of points falling into an interval corresponding to that quantile. Args: y_pred: 1D array of the predicted means for the held...
For a specified quantile, return the proportion of points falling into an interval corresponding to that quantile. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of the predicted standard deviations for the held out dataset. y_true: 1D array of t...
get_proportion_in_interval
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_calibration.py
MIT
def get_proportion_under_quantile( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, quantile: float, ) -> float: """Get the proportion of data that are below the predicted quantile. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array...
Get the proportion of data that are below the predicted quantile. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of the predicted standard deviations for the held out dataset. y_true: 1D array of the true labels in the held out dataset. quant...
get_proportion_under_quantile
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_calibration.py
MIT
def get_prediction_interval( y_pred: np.ndarray, y_std: np.ndarray, quantile: np.ndarray, recal_model: Optional[IsotonicRegression] = None, ) -> Namespace: """Return the centered predictional interval corresponding to a quantile. For a specified quantile level q (must be a float, or a singleton...
Return the centered predictional interval corresponding to a quantile. For a specified quantile level q (must be a float, or a singleton), return the centered prediction interval corresponding to the pair of quantiles at levels (0.5-q/2) and (0.5+q/2), i.e. interval that has nominal coverage equal to q...
get_prediction_interval
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_calibration.py
MIT
def get_quantile( y_pred: np.ndarray, y_std: np.ndarray, quantile: np.ndarray, recal_model: Optional[IsotonicRegression] = None, ) -> float: """Return the value corresponding with a quantile. For a specified quantile level q (must be a float, or a singleton), return the quantile prediction,...
Return the value corresponding with a quantile. For a specified quantile level q (must be a float, or a singleton), return the quantile prediction, i.e. bound that has nominal coverage below the bound equal to q. Args: y_pred: 1D array of the predicted means for the held out dataset. y...
get_quantile
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_calibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_calibration.py
MIT
def nll_gaussian( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, scaled: bool = True, ) -> float: """Negative log likelihood for a gaussian. The negative log likelihood for held out data (y_true) given predictive uncertainty with mean (y_pred) and standard-deviation (y_std). ...
Negative log likelihood for a gaussian. The negative log likelihood for held out data (y_true) given predictive uncertainty with mean (y_pred) and standard-deviation (y_std). Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of the predicted standard d...
nll_gaussian
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_scoring_rule.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_scoring_rule.py
MIT
def crps_gaussian( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, scaled: bool = True, ) -> float: """The negatively oriented continuous ranked probability score for Gaussians. Computes CRPS for held out data (y_true) given predictive uncertainty with mean (y_pred) and standard-...
The negatively oriented continuous ranked probability score for Gaussians. Computes CRPS for held out data (y_true) given predictive uncertainty with mean (y_pred) and standard-deviation (y_std). Each test point is given equal weight in the overall score over the test set. Negatively oriented means a ...
crps_gaussian
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_scoring_rule.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_scoring_rule.py
MIT
def check_score( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, scaled: bool = True, start_q: float = 0.01, end_q: float = 0.99, resolution: int = 99, ) -> float: """The negatively oriented check score. Computes the negatively oriented check score for held out data (y_tr...
The negatively oriented check score. Computes the negatively oriented check score for held out data (y_true) given predictive uncertainty with mean (y_pred) and standard-deviation (y_std). Each test point and each quantile is given equal weight in the overall score over the test set and list of quantil...
check_score
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_scoring_rule.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_scoring_rule.py
MIT
def interval_score( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, scaled: bool = True, start_p: float = 0.01, end_p: float = 0.99, resolution: int = 99, ) -> float: """The negatively oriented interval score. Compute the negatively oriented interval score for held out da...
The negatively oriented interval score. Compute the negatively oriented interval score for held out data (y_true) given predictive uncertainty with mean (y_pred) and standard-deviation (y_std). Each test point and each percentile is given equal weight in the overall score over the test set and list of ...
interval_score
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/metrics_scoring_rule.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/metrics_scoring_rule.py
MIT
def get_q_idx(exp_props: np.ndarray, q: float) -> int: """Utility function which outputs the array index of an element. Gets the (approximate) index of a specified probability value, q, in the expected proportions array. Used as a utility function in isotonic regression recalibration. Args: ex...
Utility function which outputs the array index of an element. Gets the (approximate) index of a specified probability value, q, in the expected proportions array. Used as a utility function in isotonic regression recalibration. Args: exp_props: 1D array of expected probabilities. q: a spec...
get_q_idx
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/recalibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/recalibration.py
MIT
def iso_recal( exp_props: np.ndarray, obs_props: np.ndarray, ) -> IsotonicRegression: """Recalibration algorithm based on isotonic regression. Fits and outputs an isotonic recalibration model that maps observed probabilities to expected probabilities. This mapping provides the necessary adjustm...
Recalibration algorithm based on isotonic regression. Fits and outputs an isotonic recalibration model that maps observed probabilities to expected probabilities. This mapping provides the necessary adjustments to produce better calibrated outputs. Args: exp_props: 1D array of expected probabi...
iso_recal
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/recalibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/recalibration.py
MIT
def optimize_recalibration_ratio( y_mean: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, criterion: str = "ma_cal", optimizer_bounds: Tuple[float, float] = (1e-2, 1e2), ) -> float: """Scale factor which uniformly recalibrates predicted standard deviations. Searches via black-box optimiz...
Scale factor which uniformly recalibrates predicted standard deviations. Searches via black-box optimization the standard deviation scale factor (opt_ratio) which produces the best recalibration, i.e. updated standard deviation can be written as opt_ratio * y_std. Args: y_mean: 1D array of the...
optimize_recalibration_ratio
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/recalibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/recalibration.py
MIT
def get_std_recalibrator( y_mean: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, criterion: str = "ma_cal", optimizer_bounds: Tuple[float, float] = (1e-2, 1e2), ) -> Callable[[np.ndarray], np.ndarray]: """Standard deviation recalibrator. Computes the standard deviation recalibration rat...
Standard deviation recalibrator. Computes the standard deviation recalibration ratio and returns a function which takes in an array of uncalibrated standard deviations and returns an array of recalibrated standard deviations. Args: y_mean: 1D array of the predicted means for the recalibration ...
get_std_recalibrator
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/recalibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/recalibration.py
MIT
def get_quantile_recalibrator( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, ) -> Callable[[np.ndarray, np.ndarray, Union[float, np.ndarray]], np.ndarray]: """Quantile recalibrator. Fits an isotonic regression recalibration model and returns a function which takes in the mean and s...
Quantile recalibrator. Fits an isotonic regression recalibration model and returns a function which takes in the mean and standard deviation predictions and a specified quantile level, and returns the recalibrated quantile. Args: y_pred: 1D array of the predicted means for the recalibration da...
get_quantile_recalibrator
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/recalibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/recalibration.py
MIT
def get_interval_recalibrator( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, ) -> Callable[[np.ndarray, np.ndarray, Union[float, np.ndarray]], np.ndarray]: """Prediction interval recalibrator. Fits an isotonic regression recalibration model and returns a function which takes in the...
Prediction interval recalibrator. Fits an isotonic regression recalibration model and returns a function which takes in the mean and standard deviation predictions and a specified centered interval coverage level, and returns the recalibrated interval. Args: y_pred: 1D array of the predicted m...
get_interval_recalibrator
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/recalibration.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/recalibration.py
MIT
def assert_is_flat_same_shape(*args: Any) -> Union[bool, NoReturn]: """Check if inputs are all same-length 1d numpy.ndarray. Args: args: the numpy arrays to check. Returns: True if all arrays are flat and the same shape, or else raises assertion error. """ assert len(args) > 0 ...
Check if inputs are all same-length 1d numpy.ndarray. Args: args: the numpy arrays to check. Returns: True if all arrays are flat and the same shape, or else raises assertion error.
assert_is_flat_same_shape
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/utils.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/utils.py
MIT
def assert_is_positive(*args: Any) -> Union[bool, NoReturn]: """Assert that all numpy arrays are positive. Args: args: the numpy arrays to check. Returns: True if all elements in all arrays are positive values, or else raises assertion error. """ assert len(args) > 0 for arr in...
Assert that all numpy arrays are positive. Args: args: the numpy arrays to check. Returns: True if all elements in all arrays are positive values, or else raises assertion error.
assert_is_positive
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/utils.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/utils.py
MIT
def trapezoid_area( xl: np.ndarray, al: np.ndarray, bl: np.ndarray, xr: np.ndarray, ar: np.ndarray, br: np.ndarray, absolute: bool = True, ) -> Numeric: """ Calculate the area of a vertical-sided trapezoid, formed connecting the following points: (xl, al) - (xl, bl) - (xr, br...
Calculate the area of a vertical-sided trapezoid, formed connecting the following points: (xl, al) - (xl, bl) - (xr, br) - (xr, ar) - (xl, al) This function considers the case that the edges of the trapezoid might cross, and explicitly accounts for this. Args: xl: The x coordinate of ...
trapezoid_area
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/utils.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/utils.py
MIT
def intersection( p1: Tuple[Numeric, Numeric], p2: Tuple[Numeric, Numeric], p3: Tuple[Numeric, Numeric], p4: Tuple[Numeric, Numeric], ) -> Tuple[Numeric, Numeric]: """ Calculate the intersection of two lines between four points, as defined in https://en.wikipedia.org/wiki/Line%E2%80%93line_i...
Calculate the intersection of two lines between four points, as defined in https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection. This is an array option and works can be used to calculate the intersections of entire arrays of points at the same time. Args: p1: The point (x1, y1), ...
intersection
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/utils.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/utils.py
MIT
def plot_xy( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, x: np.ndarray, n_subset: Union[int, None] = None, ylims: Union[Tuple[float, float], None] = None, xlims: Union[Tuple[float, float], None] = None, num_stds_confidence_bound: int = 2, leg_loc: Union[int, str] = 3, ...
Plot one-dimensional inputs with associated predicted values, predictive uncertainties, and true values. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of the predicted standard deviations for the held out dataset. y_true: 1D array of the true la...
plot_xy
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/viz.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/viz.py
MIT
def plot_intervals( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, n_subset: Union[int, None] = None, ylims: Union[Tuple[float, float], None] = None, num_stds_confidence_bound: int = 2, ax: Union[matplotlib.axes.Axes, None] = None, ) -> matplotlib.axes.Axes: """Plot predictio...
Plot predictions and predictive intervals versus true values. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of the predicted standard deviations for the held out dataset. y_true: 1D array of the true labels in the held out dataset. n_subset:...
plot_intervals
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/viz.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/viz.py
MIT
def plot_intervals_ordered( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, n_subset: Union[int, None] = None, ylims: Union[Tuple[float, float], None] = None, num_stds_confidence_bound: int = 2, ax: Union[matplotlib.axes.Axes, None] = None, ) -> matplotlib.axes.Axes: """Plot p...
Plot predictions and predictive intervals versus true values, with points ordered by true value along x-axis. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of the predicted standard deviations for the held out dataset. y_true: 1D array of the tr...
plot_intervals_ordered
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/viz.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/viz.py
MIT
def plot_calibration( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, n_subset: Union[int, None] = None, curve_label: Union[str, None] = None, vectorized: bool = True, exp_props: Union[np.ndarray, None] = None, obs_props: Union[np.ndarray, None] = None, ax: Union[matplotli...
Plot the observed proportion vs prediction proportion of outputs falling into a range of intervals, and display miscalibration area. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of the predicted standard deviations for the held out dataset. y_t...
plot_calibration
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/viz.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/viz.py
MIT
def plot_adversarial_group_calibration( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, n_subset: Union[int, None] = None, cali_type: str = "mean_abs", curve_label: Union[str, None] = None, group_size: Union[np.ndarray, None] = None, score_mean: Union[np.ndarray, None] = None,...
Plot adversarial group calibration plots by varying group size from 0% to 100% of dataset size and recording the worst calibration occurred for each group size. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of the predicted standard deviations for the h...
plot_adversarial_group_calibration
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/viz.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/viz.py
MIT
def plot_sharpness( y_std: np.ndarray, n_subset: Union[int, None] = None, ax: Union[matplotlib.axes.Axes, None] = None, ) -> matplotlib.axes.Axes: """Plot sharpness of the predictive uncertainties. Args: y_std: 1D array of the predicted standard deviations for the held out dataset. ...
Plot sharpness of the predictive uncertainties. Args: y_std: 1D array of the predicted standard deviations for the held out dataset. n_subset: Number of points to plot after filtering. ax: matplotlib.axes.Axes object. Returns: matplotlib.axes.Axes object with plot added.
plot_sharpness
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/viz.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/viz.py
MIT
def plot_residuals_vs_stds( y_pred: np.ndarray, y_std: np.ndarray, y_true: np.ndarray, n_subset: Union[int, None] = None, ax: Union[matplotlib.axes.Axes, None] = None, ) -> matplotlib.axes.Axes: """Plot absolute value of the prediction residuals versus standard deviations of the predictive u...
Plot absolute value of the prediction residuals versus standard deviations of the predictive uncertainties. Args: y_pred: 1D array of the predicted means for the held out dataset. y_std: 1D array of the predicted standard deviations for the held out dataset. y_true: 1D array of the true...
plot_residuals_vs_stds
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/viz.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/viz.py
MIT
def filter_subset(input_list: List[List[Any]], n_subset: int) -> List[List[Any]]: """Keep only n_subset random indices from all lists given in input_list. Args: input_list: list of lists. n_subset: Number of points to plot after filtering. Returns: List of all input lists with size...
Keep only n_subset random indices from all lists given in input_list. Args: input_list: list of lists. n_subset: Number of points to plot after filtering. Returns: List of all input lists with sizes reduced to n_subset.
filter_subset
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/viz.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/viz.py
MIT
def set_style(style_str: str = "default") -> NoReturn: """Set the matplotlib plotting style. Args: style_str: string for style file. """ if style_str == "default": plt.style.use((pathlib.Path(__file__).parent / "matplotlibrc").resolve())
Set the matplotlib plotting style. Args: style_str: string for style file.
set_style
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/viz.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/viz.py
MIT
def save_figure( file_name: str = "figure", ext_list: Union[list, str, None] = None, white_background: bool = True, ) -> NoReturn: """Save matplotlib figure for all extensions in ext_list. Args: file_name: name of saved image file. ext_list: list of strings (or single string) denoti...
Save matplotlib figure for all extensions in ext_list. Args: file_name: name of saved image file. ext_list: list of strings (or single string) denoting file type. white_background: set background of image to white if True.
save_figure
python
uncertainty-toolbox/uncertainty-toolbox
uncertainty_toolbox/viz.py
https://github.com/uncertainty-toolbox/uncertainty-toolbox/blob/master/uncertainty_toolbox/viz.py
MIT
def image_transform(self, images, lm): """ param: images: -- PIL image lm: -- numpy array """ W,H = images.size if np.mean(lm) == -1: lm = (self.lm3d_std[:, :2]+1)/2. lm = np.concatenate( [lm[:...
param: images: -- PIL image lm: -- numpy array
image_transform
python
OpenTalker/video-retalking
third_part/face3d/coeff_detector.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/coeff_detector.py
Apache-2.0
def __init__(self, opt): """Initialize the class; save the options in the class Parameters: opt (Option class)-- stores all the experiment flags; needs to be a subclass of BaseOptions """ self.opt = opt # self.root = opt.dataroot self.current_epoch = 0
Initialize the class; save the options in the class Parameters: opt (Option class)-- stores all the experiment flags; needs to be a subclass of BaseOptions
__init__
python
OpenTalker/video-retalking
third_part/face3d/data/base_dataset.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/data/base_dataset.py
Apache-2.0
def default_flist_reader(flist): """ flist format: impath label\nimpath label\n ...(same to caffe's filelist) """ imlist = [] with open(flist, 'r') as rf: for line in rf.readlines(): impath = line.strip() imlist.append(impath) return imlist
flist format: impath label impath label ...(same to caffe's filelist)
default_flist_reader
python
OpenTalker/video-retalking
third_part/face3d/data/flist_dataset.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/data/flist_dataset.py
Apache-2.0
def __init__(self, opt): """Initialize this dataset class. Parameters: opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions """ BaseDataset.__init__(self, opt) self.lm3d_std = load_lm3d(opt.bfm_folder) ...
Initialize this dataset class. Parameters: opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions
__init__
python
OpenTalker/video-retalking
third_part/face3d/data/flist_dataset.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/data/flist_dataset.py
Apache-2.0
def __getitem__(self, index): """Return a data point and its metadata information. Parameters: index (int) -- a random integer for data indexing Returns a dictionary that contains A, B, A_paths and B_paths img (tensor) -- an image in the input domain ...
Return a data point and its metadata information. Parameters: index (int) -- a random integer for data indexing Returns a dictionary that contains A, B, A_paths and B_paths img (tensor) -- an image in the input domain msk (tensor) -- its correspondi...
__getitem__
python
OpenTalker/video-retalking
third_part/face3d/data/flist_dataset.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/data/flist_dataset.py
Apache-2.0
def modify_commandline_options(parser, is_train): """Add new dataset-specific options, and rewrite default values for existing options. Parameters: parser -- original option parser is_train (bool) -- whether training phase or test phase. You can use this flag to add tra...
Add new dataset-specific options, and rewrite default values for existing options. Parameters: parser -- original option parser is_train (bool) -- whether training phase or test phase. You can use this flag to add training-specific or test-specific options. Returns: ...
modify_commandline_options
python
OpenTalker/video-retalking
third_part/face3d/data/template_dataset.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/data/template_dataset.py
Apache-2.0
def __init__(self, opt): """Initialize this dataset class. Parameters: opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions A few things can be done here. - save the options (have been done in BaseDataset) - get image paths an...
Initialize this dataset class. Parameters: opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions A few things can be done here. - save the options (have been done in BaseDataset) - get image paths and meta information of the dataset. ...
__init__
python
OpenTalker/video-retalking
third_part/face3d/data/template_dataset.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/data/template_dataset.py
Apache-2.0
def __getitem__(self, index): """Return a data point and its metadata information. Parameters: index -- a random integer for data indexing Returns: a dictionary of data with their names. It usually contains the data itself and its metadata information. Step 1: ...
Return a data point and its metadata information. Parameters: index -- a random integer for data indexing Returns: a dictionary of data with their names. It usually contains the data itself and its metadata information. Step 1: get a random image path: e.g., path = sel...
__getitem__
python
OpenTalker/video-retalking
third_part/face3d/data/template_dataset.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/data/template_dataset.py
Apache-2.0
def find_dataset_using_name(dataset_name): """Import the module "data/[dataset_name]_dataset.py". In the file, the class called DatasetNameDataset() will be instantiated. It has to be a subclass of BaseDataset, and it is case-insensitive. """ dataset_filename = "data." + dataset_name + "_datase...
Import the module "data/[dataset_name]_dataset.py". In the file, the class called DatasetNameDataset() will be instantiated. It has to be a subclass of BaseDataset, and it is case-insensitive.
find_dataset_using_name
python
OpenTalker/video-retalking
third_part/face3d/data/__init__.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/data/__init__.py
Apache-2.0
def create_dataset(opt, rank=0): """Create a dataset given the option. This function wraps the class CustomDatasetDataLoader. This is the main interface between this package and 'train.py'/'test.py' Example: >>> from data import create_dataset >>> dataset = create_dataset(opt) ...
Create a dataset given the option. This function wraps the class CustomDatasetDataLoader. This is the main interface between this package and 'train.py'/'test.py' Example: >>> from data import create_dataset >>> dataset = create_dataset(opt)
create_dataset
python
OpenTalker/video-retalking
third_part/face3d/data/__init__.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/data/__init__.py
Apache-2.0
def __init__(self, opt, rank=0): """Initialize this class Step 1: create a dataset instance given the name [dataset_mode] Step 2: create a multi-threaded data loader. """ self.opt = opt dataset_class = find_dataset_using_name(opt.dataset_mode) self.dataset = data...
Initialize this class Step 1: create a dataset instance given the name [dataset_mode] Step 2: create a multi-threaded data loader.
__init__
python
OpenTalker/video-retalking
third_part/face3d/data/__init__.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/data/__init__.py
Apache-2.0
def __init__(self, opt): """Initialize the BaseModel class. Parameters: opt (Option class)-- stores all the experiment flags; needs to be a subclass of BaseOptions When creating your custom class, you need to implement your own initialization. In this fucntion, you should f...
Initialize the BaseModel class. Parameters: opt (Option class)-- stores all the experiment flags; needs to be a subclass of BaseOptions When creating your custom class, you need to implement your own initialization. In this fucntion, you should first call <BaseModel.__init__(self, ...
__init__
python
OpenTalker/video-retalking
third_part/face3d/models/base_model.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/base_model.py
Apache-2.0
def setup(self, opt): """Load and print networks; create schedulers Parameters: opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions """ if self.isTrain: self.schedulers = [networks.get_scheduler(optimizer, opt) for optimiz...
Load and print networks; create schedulers Parameters: opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions
setup
python
OpenTalker/video-retalking
third_part/face3d/models/base_model.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/base_model.py
Apache-2.0
def update_learning_rate(self): """Update learning rates for all the networks; called at the end of every epoch""" for scheduler in self.schedulers: if self.opt.lr_policy == 'plateau': scheduler.step(self.metric) else: scheduler.step() lr ...
Update learning rates for all the networks; called at the end of every epoch
update_learning_rate
python
OpenTalker/video-retalking
third_part/face3d/models/base_model.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/base_model.py
Apache-2.0
def get_current_visuals(self): """Return visualization images. train.py will display these images with visdom, and save the images to a HTML""" visual_ret = OrderedDict() for name in self.visual_names: if isinstance(name, str): visual_ret[name] = getattr(self, name)[:...
Return visualization images. train.py will display these images with visdom, and save the images to a HTML
get_current_visuals
python
OpenTalker/video-retalking
third_part/face3d/models/base_model.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/base_model.py
Apache-2.0
def get_current_losses(self): """Return traning losses / errors. train.py will print out these errors on console, and save them to a file""" errors_ret = OrderedDict() for name in self.loss_names: if isinstance(name, str): errors_ret[name] = float(getattr(self, 'loss_...
Return traning losses / errors. train.py will print out these errors on console, and save them to a file
get_current_losses
python
OpenTalker/video-retalking
third_part/face3d/models/base_model.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/base_model.py
Apache-2.0
def save_networks(self, epoch): """Save all the networks to the disk. Parameters: epoch (int) -- current epoch; used in the file name '%s_net_%s.pth' % (epoch, name) """ if not os.path.isdir(self.save_dir): os.makedirs(self.save_dir) save_filename = 'epo...
Save all the networks to the disk. Parameters: epoch (int) -- current epoch; used in the file name '%s_net_%s.pth' % (epoch, name)
save_networks
python
OpenTalker/video-retalking
third_part/face3d/models/base_model.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/base_model.py
Apache-2.0
def __patch_instance_norm_state_dict(self, state_dict, module, keys, i=0): """Fix InstanceNorm checkpoints incompatibility (prior to 0.4)""" key = keys[i] if i + 1 == len(keys): # at the end, pointing to a parameter/buffer if module.__class__.__name__.startswith('InstanceNorm') and ...
Fix InstanceNorm checkpoints incompatibility (prior to 0.4)
__patch_instance_norm_state_dict
python
OpenTalker/video-retalking
third_part/face3d/models/base_model.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/base_model.py
Apache-2.0
def load_networks(self, epoch): """Load all the networks from the disk. Parameters: epoch (int) -- current epoch; used in the file name '%s_net_%s.pth' % (epoch, name) """ if self.opt.isTrain and self.opt.pretrained_name is not None: load_dir = os.path.join(self....
Load all the networks from the disk. Parameters: epoch (int) -- current epoch; used in the file name '%s_net_%s.pth' % (epoch, name)
load_networks
python
OpenTalker/video-retalking
third_part/face3d/models/base_model.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/base_model.py
Apache-2.0
def print_networks(self, verbose): """Print the total number of parameters in the network and (if verbose) network architecture Parameters: verbose (bool) -- if verbose: print the network architecture """ print('---------- Networks initialized -------------') for nam...
Print the total number of parameters in the network and (if verbose) network architecture Parameters: verbose (bool) -- if verbose: print the network architecture
print_networks
python
OpenTalker/video-retalking
third_part/face3d/models/base_model.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/base_model.py
Apache-2.0
def set_requires_grad(self, nets, requires_grad=False): """Set requies_grad=Fasle for all the networks to avoid unnecessary computations Parameters: nets (network list) -- a list of networks requires_grad (bool) -- whether the networks require gradients or not """ ...
Set requies_grad=Fasle for all the networks to avoid unnecessary computations Parameters: nets (network list) -- a list of networks requires_grad (bool) -- whether the networks require gradients or not
set_requires_grad
python
OpenTalker/video-retalking
third_part/face3d/models/base_model.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/base_model.py
Apache-2.0
def compute_shape(self, id_coeff, exp_coeff): """ Return: face_shape -- torch.tensor, size (B, N, 3) Parameters: id_coeff -- torch.tensor, size (B, 80), identity coeffs exp_coeff -- torch.tensor, size (B, 64), expression coeffs ""...
Return: face_shape -- torch.tensor, size (B, N, 3) Parameters: id_coeff -- torch.tensor, size (B, 80), identity coeffs exp_coeff -- torch.tensor, size (B, 64), expression coeffs
compute_shape
python
OpenTalker/video-retalking
third_part/face3d/models/bfm.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/bfm.py
Apache-2.0
def compute_texture(self, tex_coeff, normalize=True): """ Return: face_texture -- torch.tensor, size (B, N, 3), in RGB order, range (0, 1.) Parameters: tex_coeff -- torch.tensor, size (B, 80) """ batch_size = tex_coeff.shape[0] face_tex...
Return: face_texture -- torch.tensor, size (B, N, 3), in RGB order, range (0, 1.) Parameters: tex_coeff -- torch.tensor, size (B, 80)
compute_texture
python
OpenTalker/video-retalking
third_part/face3d/models/bfm.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/bfm.py
Apache-2.0
def compute_norm(self, face_shape): """ Return: vertex_norm -- torch.tensor, size (B, N, 3) Parameters: face_shape -- torch.tensor, size (B, N, 3) """ v1 = face_shape[:, self.face_buf[:, 0]] v2 = face_shape[:, self.face_buf[:, 1]] ...
Return: vertex_norm -- torch.tensor, size (B, N, 3) Parameters: face_shape -- torch.tensor, size (B, N, 3)
compute_norm
python
OpenTalker/video-retalking
third_part/face3d/models/bfm.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/bfm.py
Apache-2.0
def compute_color(self, face_texture, face_norm, gamma): """ Return: face_color -- torch.tensor, size (B, N, 3), range (0, 1.) Parameters: face_texture -- torch.tensor, size (B, N, 3), from texture model, range (0, 1.) face_norm -- torch.tens...
Return: face_color -- torch.tensor, size (B, N, 3), range (0, 1.) Parameters: face_texture -- torch.tensor, size (B, N, 3), from texture model, range (0, 1.) face_norm -- torch.tensor, size (B, N, 3), rotated face normal gamma ...
compute_color
python
OpenTalker/video-retalking
third_part/face3d/models/bfm.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/bfm.py
Apache-2.0
def compute_rotation(self, angles): """ Return: rot -- torch.tensor, size (B, 3, 3) pts @ trans_mat Parameters: angles -- torch.tensor, size (B, 3), radian """ batch_size = angles.shape[0] ones = torch.ones([batch_size, 1])...
Return: rot -- torch.tensor, size (B, 3, 3) pts @ trans_mat Parameters: angles -- torch.tensor, size (B, 3), radian
compute_rotation
python
OpenTalker/video-retalking
third_part/face3d/models/bfm.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/bfm.py
Apache-2.0
def to_image(self, face_shape): """ Return: face_proj -- torch.tensor, size (B, N, 2), y direction is opposite to v direction Parameters: face_shape -- torch.tensor, size (B, N, 3) """ # to image_plane face_proj = face_shape @ self.pe...
Return: face_proj -- torch.tensor, size (B, N, 2), y direction is opposite to v direction Parameters: face_shape -- torch.tensor, size (B, N, 3)
to_image
python
OpenTalker/video-retalking
third_part/face3d/models/bfm.py
https://github.com/OpenTalker/video-retalking/blob/master/third_part/face3d/models/bfm.py
Apache-2.0