Skip to content

Commit

Permalink
Internal change.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 348203170
  • Loading branch information
jereliu authored and edward-bot committed Dec 18, 2020
1 parent 043899e commit 4fc2d75
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions edward2/tensorflow/layers/random_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
https://people.eecs.berkeley.edu/~brecht/papers/07.rah.rec.nips.pdf
"""
import math
from edward2.tensorflow import initializers

import tensorflow.compat.v2 as tf


_SUPPORTED_LIKELIHOOD = ('binary_logistic', 'poisson', 'gaussian')


Expand Down Expand Up @@ -66,7 +69,7 @@ def __init__(self,
gp_cov_ridge_penalty=1e-6,
scale_random_features=True,
return_random_features=False,
use_custom_random_features=False,
use_custom_random_features=True,
custom_random_features_initializer=None,
custom_random_features_activation=None,
l2_regularization=0.,
Expand Down Expand Up @@ -121,7 +124,7 @@ def __init__(self,

self.normalize_input = normalize_input
self.gp_input_scale = 1. / tf.sqrt(gp_kernel_scale)
self.gp_feature_scale = 2. / tf.sqrt(float(num_inducing))
self.gp_feature_scale = tf.sqrt(2. / float(num_inducing))

self.scale_random_features = scale_random_features
self.return_random_features = return_random_features
Expand All @@ -144,12 +147,12 @@ def __init__(self,
self.gp_cov_likelihood = gp_cov_likelihood

if self.use_custom_random_features:
# Use classic Random Fourier Feature by default.
# Use orthogonal random features by default.
self.random_features_bias_initializer = tf.random_uniform_initializer(
minval=0., maxval=2. * math.pi)
if self.custom_random_features_initializer is None:
self.custom_random_features_initializer = tf.initializers.random_normal(
stddev=1.)
self.custom_random_features_initializer = (
initializers.OrthogonalRandomFeatures(stddev=1.0))
if self.custom_random_features_activation is None:
self.custom_random_features_activation = tf.math.cos

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

# Posterior precision matrix for the GP' random feature coefficients.
# Posterior precision matrix for the GP's random feature coefficients.
self.initial_precision_matrix = (
self.ridge_penalty * tf.eye(gp_feature_dim, dtype=self.dtype))

Expand Down

0 comments on commit 4fc2d75

Please sign in to comment.