LostTech.TensorFlow : API Documentation

Type RandomFourierFeatureMapper

Namespace tensorflow.contrib.kernel_methods

Parent PythonObjectContainer

Interfaces DenseKernelMapper, IRandomFourierFeatureMapper

Class that implements Random Fourier Feature Mapping (RFFM) in TensorFlow.

The RFFM mapping is used to approximate the Gaussian (RBF) kernel: $$(exp(-||x-y||_2^2 / (2 * \sigma^2))$$

The implementation of RFFM is based on the following paper: "Random Features for Large-Scale Kernel Machines" by Ali Rahimi and Ben Recht. (link: https://people.eecs.berkeley.edu/~brecht/papers/07.rah.rec.nips.pdf)

The mapping uses a matrix \\(\Omega \in R^{d x D}\\) and a bias vector \\(b \in R^D\\) where \\(d\\) is the input dimension (number of dense input features) and \\(D\\) is the output dimension (i.e., dimension of the feature space the input is mapped to). Each entry of \\(\Omega\\) is sampled i.i.d. from a (scaled) Gaussian distribution and each entry of \\(b\\) is sampled independently and uniformly from [0, \\(2 * \pi\\)].

For a single input feature vector \\(x \in R^d\\), its RFFM is defined as: $$\sqrt(2/D) * cos(x * \Omega + b)$$

where \\(cos\\) is the element-wise cosine function and \\(x, b\\) are represented as row vectors. The aforementioned paper shows that the linear kernel of RFFM-mapped vectors approximates the Gaussian kernel of the initial vectors.

Methods

Properties

Public instance methods

Tensor map(IGraphNodeBase input_tensor)

Maps each row of input_tensor using random Fourier features.
Parameters
IGraphNodeBase input_tensor
a `Tensor` containing input features. It's shape is [batch_size, self._input_dim].
Returns
Tensor
A `Tensor` of shape [batch_size, self._output_dim] containing RFFM-mapped features.

object map_dyn(object input_tensor)

Maps each row of input_tensor using random Fourier features.
Parameters
object input_tensor
a `Tensor` containing input features. It's shape is [batch_size, self._input_dim].
Returns
object
A `Tensor` of shape [batch_size, self._output_dim] containing RFFM-mapped features.

Public properties

int input_dim get;

object input_dim_dyn get;

string name get;

Returns a name for the `RandomFourierFeatureMapper` instance.

If the name provided in the constructor is `None`, then the object's unique id is returned.

object name_dyn get;

Returns a name for the `RandomFourierFeatureMapper` instance.

If the name provided in the constructor is `None`, then the object's unique id is returned.

int output_dim get;

Returns the output dimension of the mapping.

object output_dim_dyn get;

Returns the output dimension of the mapping.

object PythonObject get;