tf.contrib.kernel_methods.RandomFourierFeatureMapper
Stay organized with collections
Save and categorize content based on your preferences.
Class that implements Random Fourier Feature Mapping (RFFM) in TensorFlow.
tf.contrib.kernel_methods.RandomFourierFeatureMapper(
input_dim, output_dim, stddev=1.0, seed=1, name=None
)
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.
Args |
input_dim
|
The dimension (number of features) of the tensors to be mapped.
|
output_dim
|
The output dimension of the mapping.
|
stddev
|
The standard deviation of the Gaussian kernel to be approximated.
The error of the classifier trained using this approximation is very
sensitive to this parameter.
|
seed
|
An integer used to initialize the parameters (\(\Omega\) and
\(b\)) of the mapper. For repeatable sequences across different
invocations of the mapper object (for instance, to ensure consistent
mapping both at training and eval/inference if these happen in
different invocations), set this to the same integer.
|
name
|
name for the mapper object.
|
Attributes |
input_dim
|
|
name
|
Returns a name for the RandomFourierFeatureMapper instance.
If the name provided in the constructor is None , then the object's unique
id is returned.
|
output_dim
|
Returns the output dimension of the mapping.
|
Methods
map
View source
map(
input_tensor
)
Maps each row of input_tensor using random Fourier features.
Args |
input_tensor
|
a Tensor containing input features. It's shape is
[batch_size, self._input_dim].
|
Returns |
A Tensor of shape [batch_size, self._output_dim] containing RFFM-mapped
features.
|
Raises |
InvalidShapeError
|
if the shape of the input_tensor is inconsistent with
expected input dimension.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2020-10-01 UTC."],[],[],null,["# tf.contrib.kernel_methods.RandomFourierFeatureMapper\n\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/kernel_methods/python/mappers/random_fourier_features.py#L33-L160) |\n\nClass that implements Random Fourier Feature Mapping (RFFM) in TensorFlow. \n\n tf.contrib.kernel_methods.RandomFourierFeatureMapper(\n input_dim, output_dim, stddev=1.0, seed=1, name=None\n )\n\nThe RFFM mapping is used to approximate the Gaussian (RBF) kernel: \n$$(exp(-\\|\\|x-y\\|\\|_2\\^2 / (2 \\* \\\\sigma\\^2))$$\n\nThe implementation of RFFM is based on the following paper:\n\"Random Features for Large-Scale Kernel Machines\" by Ali Rahimi and Ben Recht.\n(link: [https://people.eecs.berkeley.edu/\\~brecht/papers/07.rah.rec.nips.pdf](https://people.eecs.berkeley.edu/~brecht/papers/07.rah.rec.nips.pdf))\n\nThe mapping uses a matrix \\\\(\\\\Omega \\\\in R\\^{d x D}\\\\) and a bias vector\n\\\\(b \\\\in R\\^D\\\\) where \\\\(d\\\\) is the input dimension (number of dense input\nfeatures) and \\\\(D\\\\) is the output dimension (i.e., dimension of the feature\nspace the input is mapped to). Each entry of \\\\(\\\\Omega\\\\) is sampled i.i.d.\nfrom a (scaled) Gaussian distribution and each entry of \\\\(b\\\\) is sampled\nindependently and uniformly from \\[0, \\\\(2 \\* \\\\pi\\\\)\\].\n\nFor a single input feature vector \\\\(x \\\\in R\\^d\\\\), its RFFM is defined as: \n$$\\\\sqrt(2/D) \\* cos(x \\* \\\\Omega + b)$$\n\nwhere \\\\(cos\\\\) is the element-wise cosine function and \\\\(x, b\\\\) are\nrepresented as row vectors. The aforementioned paper shows that the linear\nkernel of RFFM-mapped vectors approximates the Gaussian kernel of the initial\nvectors.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input_dim` | The dimension (number of features) of the tensors to be mapped. |\n| `output_dim` | The output dimension of the mapping. |\n| `stddev` | The standard deviation of the Gaussian kernel to be approximated. The error of the classifier trained using this approximation is very sensitive to this parameter. |\n| `seed` | An integer used to initialize the parameters (\\\\(\\\\Omega\\\\) and \\\\(b\\\\)) of the mapper. For repeatable sequences across different invocations of the mapper object (for instance, to ensure consistent mapping both at training and eval/inference if these happen in different invocations), set this to the same integer. |\n| `name` | name for the mapper object. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input_dim` | \u003cbr /\u003e \u003cbr /\u003e |\n| `name` | Returns a name for the `RandomFourierFeatureMapper` instance. \u003cbr /\u003e If the name provided in the constructor is `None`, then the object's unique id is returned. |\n| `output_dim` | Returns the output dimension of the mapping. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `map`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/kernel_methods/python/mappers/random_fourier_features.py#L107-L160) \n\n map(\n input_tensor\n )\n\nMaps each row of input_tensor using random Fourier features.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------------|--------------------------------------------------------------------------------------|\n| `input_tensor` | a `Tensor` containing input features. It's shape is \\[batch_size, self._input_dim\\]. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A `Tensor` of shape \\[batch_size, self._output_dim\\] containing RFFM-mapped features. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|---------------------|-----------------------------------------------------------------------------------|\n| `InvalidShapeError` | if the shape of the `input_tensor` is inconsistent with expected input dimension. |\n\n\u003cbr /\u003e"]]