Skip to content

Commit 6a90b6c

Browse files
jereliuedward-bot
authored andcommitted
Internal change.
PiperOrigin-RevId: 348203170
1 parent 043899e commit 6a90b6c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

edward2/tensorflow/layers/random_feature.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
https://people.eecs.berkeley.edu/~brecht/papers/07.rah.rec.nips.pdf
2424
"""
2525
import math
26+
from edward2.tensorflow import initializers
27+
2628
import tensorflow.compat.v2 as tf
2729

30+
2831
_SUPPORTED_LIKELIHOOD = ('binary_logistic', 'poisson', 'gaussian')
2932

3033

@@ -66,7 +69,7 @@ def __init__(self,
6669
gp_cov_ridge_penalty=1e-6,
6770
scale_random_features=True,
6871
return_random_features=False,
69-
use_custom_random_features=False,
72+
use_custom_random_features=True,
7073
custom_random_features_initializer=None,
7174
custom_random_features_activation=None,
7275
l2_regularization=0.,
@@ -121,7 +124,7 @@ def __init__(self,
121124

122125
self.normalize_input = normalize_input
123126
self.gp_input_scale = 1. / tf.sqrt(gp_kernel_scale)
124-
self.gp_feature_scale = 2. / tf.sqrt(float(num_inducing))
127+
self.gp_feature_scale = tf.sqrt(2. / float(num_inducing))
125128

126129
self.scale_random_features = scale_random_features
127130
self.return_random_features = return_random_features
@@ -144,12 +147,12 @@ def __init__(self,
144147
self.gp_cov_likelihood = gp_cov_likelihood
145148

146149
if self.use_custom_random_features:
147-
# Use classic Random Fourier Feature by default.
150+
# Use orthogonal random features by default.
148151
self.random_features_bias_initializer = tf.random_uniform_initializer(
149152
minval=0., maxval=2. * math.pi)
150153
if self.custom_random_features_initializer is None:
151-
self.custom_random_features_initializer = tf.initializers.random_normal(
152-
stddev=1.)
154+
self.custom_random_features_initializer = (
155+
initializers.OrthogonalRandomFeatures(stddev=1.0))
153156
if self.custom_random_features_activation is None:
154157
self.custom_random_features_activation = tf.math.cos
155158

@@ -289,7 +292,7 @@ def build(self, input_shape):
289292
if isinstance(gp_feature_dim, tf.compat.v1.Dimension):
290293
gp_feature_dim = gp_feature_dim.value
291294

292-
# Posterior precision matrix for the GP' random feature coefficients.
295+
# Posterior precision matrix for the GP's random feature coefficients.
293296
self.initial_precision_matrix = (
294297
self.ridge_penalty * tf.eye(gp_feature_dim, dtype=self.dtype))
295298

0 commit comments

Comments
 (0)