Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python35
/
lib64
/
python3.5
/
site-packages
/
sklearn
/
__pycache__
/
File Content:
kernel_approximation.cpython-35.pyc
��(X8F � @ s d Z d d l Z d d l Z d d l j Z d d l m Z d d l m Z d d l m Z d d l m Z m Z m Z d d l m Z d d l m Z d d l m Z Gd d � d e e � Z Gd d � d e e � Z Gd d � d e e � Z Gd d � d e e � Z d S)z The :mod:`sklearn.kernel_approximation` module implements several approximate kernel feature maps base on Fourier transforms. � N)�svd� )� BaseEstimator)�TransformerMixin)�check_array�check_random_state�as_float_array)�safe_sparse_dot)�check_is_fitted)�pairwise_kernelsc @ sI e Z d Z d Z d d d d d � Z d d d � Z d d d � Z d S)� RBFSamplera� Approximates feature map of an RBF kernel by Monte Carlo approximation of its Fourier transform. It implements a variant of Random Kitchen Sinks.[1] Read more in the :ref:`User Guide <rbf_kernel_approx>`. Parameters ---------- gamma : float Parameter of RBF kernel: exp(-gamma * x^2) n_components : int Number of Monte Carlo samples per original feature. Equals the dimensionality of the computed feature space. random_state : {int, RandomState}, optional If int, random_state is the seed used by the random number generator; if RandomState instance, random_state is the random number generator. Notes ----- See "Random Features for Large-Scale Kernel Machines" by A. Rahimi and Benjamin Recht. [1] "Weighted Sums of Random Kitchen Sinks: Replacing minimization with randomization in learning" by A. Rahimi and Benjamin Recht. (http://people.eecs.berkeley.edu/~brecht/papers/08.rah.rec.nips.pdf) g �?�d Nc C s | | _ | | _ | | _ d S)N)�gamma�n_components�random_state)�selfr r r � r �/kernel_approximation.py�__init__8 s zRBFSampler.__init__c C s� t | d d �} t | j � } | j d } t j d | j � | j d | | j f � | _ | j d d t j d | j �| _ | S)a� Fit the model with X. Samples random projection according to n_features. Parameters ---------- X : {array-like, sparse matrix}, shape (n_samples, n_features) Training data, where n_samples in the number of samples and n_features is the number of features. Returns ------- self : object Returns the transformer. � accept_sparse�csrr � �sizer ) r r r �shape�np�sqrtr Znormalr �random_weights_�uniform�pi�random_offset_)r �X�yr � n_featuresr r r �fit= s zRBFSampler.fitc C su t | d � t | d d �} t | | j � } | | j 7} t j | | � | t j d � t j | j � 9} | S)ap Apply the approximate feature map to X. Parameters ---------- X : {array-like, sparse matrix}, shape (n_samples, n_features) New data, where n_samples in the number of samples and n_features is the number of features. Returns ------- X_new : array-like, shape (n_samples, n_components) r r r g @) r r r r r r �cosr r )r r r! � projectionr r r � transformY s #zRBFSampler.transform)�__name__� __module__�__qualname__�__doc__r r# r&