MRCpy.phi
.BasePhi
- class MRCpy.phi.BasePhi(n_classes, fit_intercept=True, one_hot=False)[source]
Base class for feature mappings
The class provides a base for different feature mapping functions that can be used with the MRC. This class provides definition for some utility functions that are used by the MRCs in the library. It corresponds to the usual identity feature map referred to as Linear feature map.
To see an example of how to extend the class
BasePhi
to implement yout own feature mapping see this example.Note
This is a base class for all the feature mappings. To create a new feature mapping that can be used with MRC objects, the user can extend this class and then implement the functions -
The above functions are principal components for different feature transformation. Apart from these functions, the users can also re-define other functions in this class according to their need.
The definition of
fit
andtransform
in this class correspond to the usual identity feature map referred to as Linear feature map.The
transform
function is only used by theeval_xy
function of this class to get the one-hot encoded features. If the user defines his owneval_xy
function that returns the features directly without the need oftransform
function, then thetransform
function can be omitted.See also
For more information about MRC, one can refer to the following resources:
- Parameters:
- n_classes
int
Number of classes in the dataset
- fit_intercept
bool
, default =True
Whether to calculate the intercept. If set to false, no intercept will be used in calculations (i.e. data is expected to be already centered)
- one_hot
bool
, default =False
Controls the method used for evaluating the features of the given instances in the binary case. Only applies in the binary case, namely, only when there are two classes. When set to true, one-hot-encoding will be used. If set to false a more efficient shorcut will be performed.
- n_classes
- Attributes:
Methods
est_exp
(X, Y)Average value of \(\phi(x,y)\) in the supervised dataset (X,Y).
est_std
(X, Y)Standard deviation of \(\phi(x,y)\) in the supervised dataset (X,Y).
eval_x
(X)Evaluates the one-hot encoded features of the given instances i.e., X, \(\phi(x,y)\), x \(\in\) X and all the labels.
eval_xy
(X, Y)Evaluates the one-hot encoded features of the given instances i.e., X, \(\phi(x,y)\), x \(\in\) X and y \(\in\) Y.
fit
(X[, Y])Performs training stage.
transform
(X)Transform the given instances to the features.
- est_exp(X, Y)[source]
Average value of \(\phi(x,y)\) in the supervised dataset (X,Y). Used in the learning stage to estimate the expectation of \(\phi(x,y)\), denoted by \({\tau}\)
- est_std(X, Y)[source]
Standard deviation of \(\phi(x,y)\) in the supervised dataset (X,Y). Used in the learning stage to estimate the variance in the expectation of \(\phi(x,y)\), denoted by \(\lambda\)
- eval_x(X)[source]
Evaluates the one-hot encoded features of the given instances i.e., X, \(\phi(x,y)\), x \(\in\) X and all the labels. The output is 3D matrix that is composed of 2D matrices corresponding to each of the instance. These 2D matrices are the one-hot encodings of the instances’ features corresponding to all the possible labels in the data.
- Parameters:
- Returns:
- phi
array
-like of shape (
n_samples
,n_classes
,n_features
*n_classes
)Matrix containing the one-hot encoding for all the classes for each of the instances given.
- phi
- eval_xy(X, Y)[source]
Evaluates the one-hot encoded features of the given instances i.e., X, \(\phi(x,y)\), x \(\in\) X and y \(\in\) Y. The encodings are calculated, corresponding to the given labels, which is used by the learning stage for estimating the expectation of \(\phi(x,y)\).
- Parameters:
- Returns:
- phi
array
-like of shape (
n_samples
,n_features
*n_classes
)Matrix containing the one-hot encoding with respect to the labels given for all the instances.
- phi
- fit(X, Y=None)[source]
Performs training stage.
Learns the required hyperparameters for the feature mapping transformation from the training instances and set the length of the feature mapping (one-hot encoded) obtained from the
eval_xy
function.Note
If a user implements
fit
function in his own feature mapping, then it is recommended to call thisfit
function at the end of his own function to automatically set the length of the feature mapping. Thisfit
function can be called in a subclass as follows -super().fit(X,Y)
Feature mappings implemented in this library follow this same approach.