1 from __future__
import absolute_import
2 from __future__
import division
3 from __future__
import print_function
4 from __future__
import unicode_literals
14 Implementation of random fourier feature map for feature processing. 16 Applies sqrt(2 / output_dims) * cos(wx+b), where: 17 output_dims is the output feature dimensions, and 18 wx + b applies FC using randomized, fixed weight and bias parameters 20 For more information, see the original paper: 21 https://people.eecs.berkeley.edu/~brecht/papers/07.rah.rec.nips.pdf 24 output_dims -- output feature dimensions 25 sigma -- bandwidth for the Gaussian kernel estimator 26 w_init -- initalization options for weight parameter 27 b_init -- initalization options for bias parameter 38 name=
'random_fourier_features',
41 super(RandomFourierFeatures, self).__init__(model, name, input_record,
43 assert isinstance(input_record,
schema.Scalar),
"Incorrect input type" 45 input_dims = input_record.field_type().shape[0]
46 assert input_dims >= 1,
"Expected input dimensions >= 1, got %s" \
49 assert self.
output_dims >= 1,
"Expected output dimensions >= 1, got %s" \
57 assert sigma > 0.0,
"Expected bandwidth > 0, got %s" % sigma
60 w_init = w_init
if w_init
else (
61 'GaussianFill', {
'mean': 0.0,
'std': 1.0 / sigma}
64 b_init = b_init
if b_init
else (
65 'UniformFill', {
'min': 0.0,
'max': 2 * np.pi}
71 optimizer=model.NoOptim)
76 optimizer=model.NoOptim)
78 def add_ops(self, net):
80 cosine_arg = net.FC(self.input_record.field_blobs() + [self.
w, self.
b],
81 net.NextScopedBlob(
"cosine_arg"))
84 new_feature_vec = net.Cos([cosine_arg],
85 net.NextScopedBlob(
'new_feature_vec'))
89 net.Scale([new_feature_vec],
90 self.output_schema.field_blobs(),
def get_next_blob_reference(self, name)
def create_param(self, param_name, shape, initializer, optimizer, ps_param=None, regularizer=None)