flexcode.post_processing
Module Contents
Functions
|
Normalizes conditional density estimates to be non-negative and |
|
Normalizes a density estimate to be non-negative and integrate to |
|
Sharpens conditional density estimates. |
|
Chooses the sharpen parameter by minimizing cde loss. |
|
Removes bumps in conditional density estimates |
|
Removes bumps in conditional density estimates. |
|
Chooses the bump threshold which minimizes cde loss. |
- normalize(cde_estimates, tol=1e-06, max_iter=200)[source]
Normalizes conditional density estimates to be non-negative and integrate to one.
Assumes densities are evaluated on the unit grid.
- Parameters:
cde_estimates – a numpy array or matrix of conditional density estimates.
tol – float, the tolerance to accept for abs(area - 1).
max_iter – int, the maximal number of search iterations.
- Returns:
the normalized conditional density estimates.
- Return type:
numpy array or matrix.
- _normalize(density, tol=1e-06, max_iter=500)[source]
Normalizes a density estimate to be non-negative and integrate to one.
Assumes density is evaluated on the unit grid.
- Parameters:
density – a numpy array of density estimates.
z_grid – an array, the grid points at the density is estimated.
tol – float, the tolerance to accept for abs(area - 1).
max_iter – int, the maximal number of search iterations.
- Returns:
the normalized density estimate.
- Return type:
numpy array.
- sharpen(cde_estimates, alpha)[source]
Sharpens conditional density estimates.
Assumes densities are evaluated on the unit grid.
- Parameters:
cde_estimates – a numpy array or matrix of conditional density estimates.
alpha – float, the exponent to which the estimate is raised.
- Returns:
the sharpened conditional density estimate.
- Return type:
numpy array or matrix.
- choose_sharpen(cde_estimates, z_grid, true_z, alpha_grid)[source]
Chooses the sharpen parameter by minimizing cde loss.
- Parameters:
cde_estimates – a numpy matrix of conditional density estimates
true_z – an array of the true z values corresponding to the cde_estimates.
alpha_grid – an array of candidate sharpen parameter values.
- Returns:
the sharpen parameter value from alpha_grid which minimizes cde loss.
- Return type:
float
- remove_bumps(cde_estimates, delta)[source]
Removes bumps in conditional density estimates
Assumes that cde_estimates are on the unit grid.
- Parameters:
cde_estimates – a numpy array or matrix of conditional density estimates.
delta – float, the threshold for bump removal
- Returns:
the conditional density estimates with bumps removed
- Return type:
numpy array or matrix
- _remove_bumps(density, delta)[source]
Removes bumps in conditional density estimates.
Assumes estimates are on the unit grid.
- Parameters:
density – a numpy array of conditional density estimate.
delta – float, the threshold for bump removal.
- Returns:
the conditional density estimate with bumps removed.
- Return type:
numpy array.
- choose_bump_threshold(cde_estimates, z_grid, true_z, delta_grid)[source]
Chooses the bump threshold which minimizes cde loss.
- Parameters:
cde_estimates – a numpy array or matrix of conditional density estimates.
z_grid – an array, the grid points at which the density is estimated.b
true_z – the true z values corresponding to the conditional
denstity estimates. :param delta_grid: an array of candidate bump threshold values :returns: the bump threshold value from delta_grid which minimizes CDE loss :rtype: float