PCAClassifier

Histogram classification based on principal component analysis

It is basically a wrapper for a sklearn.decomposition.PCA instance.



[class] PCAClassifier

comments:

histogram classification based on principal component analysis  
it is basically a wrapper for a sklearn.decomposition.PCA instance.  

⤷ __init__

full signature:

def __init__( self, ncomponents=None, svd_solver='auto', loss_type='mse', nmax=10 )  

comments:

initializer  
input arguments:  
- ncomponents: number of PCA components (aka clusters aka basis vectors) to use in the decomposition  
- svd_solver: solver method to extract the PCA components  
  note: both ncomponents and svd_solver are arguments passed down to sklearn.decomposition.PCA,  
        see https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html  
- loss_type: choose from 'mse' (mean-squared-error) or 'chi2' (chi squared error)  
- nmax: number of largest elements to keep in error calculation  
TODO: add keyword arguments to pass down to sklearn.decomposition.PCA  

⤷ train

full signature:

def train( self, histograms )  

comments:

train the PCA model on a given set of input histograms  
input arguments:  
- histograms: a numpy array of shape (nhists,nbins) or (nhists,nybins,nxbins) that will be used to fit a PCA model  

⤷ set_nmax

full signature:

def set_nmax( self, nmax )  

comments:

set number of largest elements to keep in mean square error calculation  
useful to quickly re-evaluate the model with different nmax without retraining  
input arguments:  
- nmax: number of largest elements to keep in mean square error calculation  

⤷ set_loss_type

full signature:

def set_loss_type( self, loss_type )  

comments:

set loss type  
useful to quickly re-evaluate the model with different loss without retraining  
input arguments:  
- loss_type: choose from 'mse' (mean-squared-error) or 'chi2' (chi squared error)  

⤷ evaluate

full signature:

def evaluate( self, histograms )  

comments:

classify the given histograms based on the MSE with respect to their reconstructed version  
input arguments:  
- histograms: numpy array of shape (nhists,nbins) or (nhists,nybins,nxbins)  

⤷ get_components

full signature:

def get_components( self )  

comments:

return the PCA components (aka cluster centers aka basis vectors)  
output:  
a numpy array of shape (ncomponents,nbins) or (ncomponents,nybins,nxbins)  

⤷ reconstruct

full signature:

def reconstruct( self, histograms )  

comments:

return the PCA reconstruction for a given set of histograms  
input arguments:  
- histograms: numpy array of shape (nhists,nbins) or (nhists,nybins,nxbins)