src/estimagic/sensitivity/msm_sensitivity.py
def calculate_actual_sensitivity_to_noise(
    sensitivity_to_bias, weights, moments_cov, params_cov
):
    """calculate the actual sensitivity to noise.

    The sensitivity measure is calculated for each parameter wrt each moment.

    It answers the following question: How much precision would be lost if the kth
        moment was subjet to a little additional noise if "weights" is used as
        weighting matrix?

    Args:
        sensitivity_to_bias (np.ndarray or pandas.DataFrame): See
            ``calculate_sensitivity_to_bias`` for details.
        weights (np.ndarray or pandas.DataFrame): The weighting matrix used for
            msm estimation.
        moments_cov (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            empirical moments.
        params_cov (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            parameter estimates.

    Returns:
        np.ndarray or pd.DataFrame: Sensitivity measure with shape (n_params, n_moments)

    """
    if isinstance(sensitivity_to_bias, pd.DataFrame):
        sensitivity_to_bias = sensitivity_to_bias.to_numpy()

    _weights, _moments_cov, _params_cov, names = process_pandas_arguments(
        weights=weights, moments_cov=moments_cov, params_cov=params_cov
    )

    m3 = []

    for k in range(len(_weights)):
        mask_matrix_o = np.zeros(shape=_weights.shape)
        mask_matrix_o[k, k] = 1

        m3k = _sandwich(sensitivity_to_bias.T, mask_matrix_o)
        m3k = np.diagonal(m3k)

        m3.append(m3k)

    m3 = np.array(m3).T

    moments_variances = np.diagonal(_moments_cov)
    params_variances = np.diagonal(_params_cov)

    e3 = m3 / params_variances.reshape(-1, 1)
    e3 = e3 * moments_variances

    if names:
        e3 = pd.DataFrame(e3, index=names.get("params"), columns=names.get("moments"))

    return e3
calculate the actual sensitivity to noise.

    The sensitivity measure is calculated for each parameter wrt each moment.

    It answers the following question: How much precision would be lost if the kth
        moment was subjet to a little additional noise if "weights" is used as
        weighting matrix?

    Args:
        sensitivity_to_bias (np.ndarray or pandas.DataFrame): See
            ``calculate_sensitivity_to_bias`` for details.
        weights (np.ndarray or pandas.DataFrame): The weighting matrix used for
            msm estimation.
        moments_cov (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            empirical moments.
        params_cov (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            parameter estimates.

    Returns:
        np.ndarray or pd.DataFrame: Sensitivity measure with shape (n_params, n_moments)

    
calculate the actual sensitivity to noise.
The sensitivity measure is calculated for each parameter wrt each moment.


calculate the actual sensitivity to noise . The sensitivity measure is calculated for each parameter wrt each moment .
def calculate_actual_sensitivity_to_noise(
    sensitivity_to_bias, weights, moments_cov, params_cov
):
    if isinstance(sensitivity_to_bias, pd.DataFrame):
        sensitivity_to_bias = sensitivity_to_bias.to_numpy()
    _weights, _moments_cov, _params_cov, names = process_pandas_arguments(
        weights=weights, moments_cov=moments_cov, params_cov=params_cov
    )
    m3 = []
    for k in range(len(_weights)):
        mask_matrix_o = np.zeros(shape=_weights.shape)
        mask_matrix_o[k, k] = 1
        m3k = _sandwich(sensitivity_to_bias.T, mask_matrix_o)
        m3k = np.diagonal(m3k)
        m3.append(m3k)
    m3 = np.array(m3).T
    moments_variances = np.diagonal(_moments_cov)
    params_variances = np.diagonal(_params_cov)
    e3 = m3 / params_variances.reshape(-1, 1)
    e3 = e3 * moments_variances
    if names:
        e3 = pd.DataFrame(e3, index=names.get("params"), columns=names.get("moments"))
    return e3
def calculate_actual_sensitivity_to_noise ( sensitivity_to_bias , weights , moments_cov , params_cov ) : if isinstance ( sensitivity_to_bias , pd . DataFrame ) : sensitivity_to_bias = sensitivity_to_bias . to_numpy ( ) _weights , _moments_cov , _params_cov , names = process_pandas_arguments ( weights = weights , moments_cov = moments_cov , params_cov = params_cov ) m3 = [ ] for k in range ( len ( _weights ) ) : mask_matrix_o = np . zeros ( shape = _weights . shape ) mask_matrix_o [ k , k ] = 1 m3k = _sandwich ( sensitivity_to_bias . T , mask_matrix_o ) m3k = np . diagonal ( m3k ) m3 . append ( m3k ) m3 = np . array ( m3 ) . T moments_variances = np . diagonal ( _moments_cov ) params_variances = np . diagonal ( _params_cov ) e3 = m3 / params_variances . reshape ( - 1 , 1 ) e3 = e3 * moments_variances if names : e3 = pd . DataFrame ( e3 , index = names . get ( "params" ) , columns = names . get ( "moments" ) ) return e3
calculate the actual sensitivity to noise.
calculate the actual sensitivity to noise .
"""calculate the actual sensitivity to noise.

    The sensitivity measure is calculated for each parameter wrt each moment.

    It answers the following question: How much precision would be lost if the kth
        moment was subjet to a little additional noise if "weights" is used as
        weighting matrix?

    Args:
        sensitivity_to_bias (np.ndarray or pandas.DataFrame): See
            ``calculate_sensitivity_to_bias`` for details.
        weights (np.ndarray or pandas.DataFrame): The weighting matrix used for
            msm estimation.
        moments_cov (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            empirical moments.
        params_cov (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            parameter estimates.

    Returns:
        np.ndarray or pd.DataFrame: Sensitivity measure with shape (n_params, n_moments)

    """
np.ndarray or pd.DataFrame: Sensitivity measure with shape (n_params, n_moments)
np . ndarray or pd . DataFrame : Sensitivity measure with shape ( n_params n_moments )
sensitivity_to_bias
See
``calculate_sensitivity_to_bias`` for details.
See ` ` calculate_sensitivity_to_bias ` ` for details .
weights
The weighting matrix used for
msm estimation.
The weighting matrix used for msm estimation .
moments_cov
The covariance matrix of the
empirical moments.
The covariance matrix of the empirical moments .
params_cov
The covariance matrix of the
parameter estimates.
The covariance matrix of the parameter estimates .