conditional_expect#
- skactiveml.pool.utils.conditional_expect(X, func, reg, method=None, quantile_method=None, n_integration_samples=10, quad_dict=None, random_state=None, vector_func=False)[source]#
Calculates the conditional expectation of a function depending on an index, the feature value, and the label for each sample in X, i.e., E[func(idx, x, Y)|X=x], where Y | X=x ~ reg.predict_target_distribution, for x in X.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
The samples where the expectation should be evaluated.
- funccallable
The function that transforms the random variable. The signature of the function must be of the form func(idx, x, y), where idx is such that X[idx] = x, x is the feature value, and y is the label.
- regProbabilisticRegressor
Predicts the target distribution over which the expectation is calculated.
- methodstring, optional, default=’gauss_hermite’
The method by which the expectation is computed.
- -‘assume_linear’ assumes E[func(Y)|X=x_eval] ~= func(E[Y|X=x_eval]) and
thereby only takes the function value at the expected y value.
- -‘monte_carlo’ Basic monte carlo integration. Taking the average
of randomly drawn samples. n_integration_samples specifies the number of monte carlo samples.
- -‘quantile’ Uses the quantile function to transform the integration
space into the interval from 0 to 1 and then uses the method from ‘quantile_method’ to calculate the integral. The number of integration points is specified by n_integration_samples.
- -‘gauss_hermite’ Uses Gauss-Hermite quadrature. This assumes Y | X
to be gaussian distributed. The number of evaluation points is given by n_integration_samples.
- -‘dynamic_quad’ uses scipy’s function expect on the rv_continuous
random variable of reg, which in turn uses a dynamic gaussian quadrature routine for calculating the integral. A random variable with zero standard deviation is evaluated at its mean instead. Performance is worse using a vector function.
- quantile_methodstring, default=’quadrature’
Specifies the integration methods used after the quantile transformation.
‘trapezoid’: Trapezoidal method for integration using evenly spaced samples.
‘simpson’: Simpson method for integration using evenly spaced samples.
‘average’: Taking the average value for integration using evenly spaced samples.
‘romberg’: Romberg method for integration. If n_integration_samples is not equal to 2**k + 1 for a natural number k, the number of samples used for integration is put to the smallest such number greater than n_integration_samples.
-‘quadrature’: Gaussian quadrature method for integration.
- n_integration_samplesint, default=10
The number of integration samples used in ‘quantile’, ‘monte_carlo’ and ‘gauss-hermite’.
- quad_dictdict, default=None
Further arguments for using scipy’s expect
- random_stateint or np.random.RandomState or None,default=None
Random state for fixing the number generation.
- vector_funcbool or str, default=False
If vector_func is True, the integration values are passed in vectorized form to func. If vector_func is ‘both’, the integration values might or might not be passed in vectorized form, depending on what is more efficient. The integration values are passed in vectorized form, means that in a call like func(idx, x, y) y is of the form (n_samples, n_integration_samples), x equals X and idx is an index map of X.
- Returns:
- expectationnumpy.ndarray of shape (n_samples)
The conditional expectation for each value applied.