IdentityFocusFunction

class unit_averaging.focus_function.IdentityFocusFunction[source]

Bases: BaseFocusFunction

Convenience class for creating an identity focus function.

In some cases the individual estimates are scalar and are directly the focus parameters. This class makes it easy to work with such scenarios. It implements an identity map:

\[\mu(\theta_i) = \theta_i\]

In contrast to BaseFocusFunction and InlineFocusFunction, this class requires no arguments.

Note: IdentityFocusFunction can only be used with scalar individual estimates.

Example

>>> from unit_averaging import IdentityFocusFunction
>>> import numpy as np
>>> # Estimate
>>> identity_focus = IdentityFocusFunction()
>>> result = identity_focus.focus_function(np.array([1.0]))
>>> print(result)  # Output: 2.0
>>> grad = identity_focus.gradient(np.array([43.0]))
>>> print(grad)  # Output: [1.0]

Methods

focus_function(ind_estimate)[source]

Compute the focus function for a given estimate.

This method applies the focus function transformation to an individual estimate. The focus function defines the parameter of interest that the unit averaging process aims to estimate.

Parameters:

ind_estimate (float | np.floating[Any] | np.ndarray) – Individual specific estimate. Can be a scalar or an array-like object.

Returns:

Scalar result of applying the focus function to the input estimate.

Return type:

float | np.floating[Any]

gradient(ind_estimate)[source]

Compute the gradient of the focus function for a given estimate.

This method calculates the gradient (vector of first derivatives) of the focus function with respect to the input estimate. The gradient is used in the optimization process to determine the optimal weights for unit averaging.

Parameters:

ind_estimate (float | np.floating[Any] | np.ndarray) – Individual specific estimate. Can be a scalar or an array-like object.

Returns:

Vector of first derivatives of the focus function with respect to the input estimate. The shape of the array should match the shape of the input estimate.

Return type:

np.ndarray