Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Gauss-Legendre Quadrature Fourier features #64

Draft
wants to merge 22 commits into
base: develop
Choose a base branch
from

Conversation

ltiao
Copy link
Collaborator

@ltiao ltiao commented Dec 15, 2021

No description provided.

Copy link
Member

@vdutor vdutor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR - the code structure makes a lot of sense. I believe two things are missing right now:

  1. a README in the fourier_features directory outlining the different methods and in which scenarios they can be used. This can be very brief as long as it is practical. We could use tables or diagrams for this.
  2. It looks like there are no tests for a few of the GaussianQuadrature features?

if tf.reduce_any(tf.less(kernel.lengthscales, 1e-1)):
warnings.warn(
"Quadrature Fourier feature approximation of kernels "
"with small lengthscale lead to unexpected behaviors!"
"Fourier feature approximation of kernels with small "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add what you mean by "small".

Comment on lines +126 to +131
class QuadratureFourierFeatures(GaussHermiteQuadratureFourierFeatures):
"""
Alias for `GaussHermiteQuadratureFourierFeatures`.
"""

pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class QuadratureFourierFeatures(GaussHermiteQuadratureFourierFeatures):
"""
Alias for `GaussHermiteQuadratureFourierFeatures`.
"""
pass
QuadratureFourierFeatures = GaussHermiteQuadratureFourierFeatures
""" Alias for `GaussHermiteQuadratureFourierFeatures` """

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe explain why we have this alias in place? Is this the most common and recommended quadrature rule?

def __init__(self, kernel: gpflow.kernels.Kernel, n_components: int, **kwargs: Mapping):
"""
:param kernel: kernel to approximate using a set of Fourier bases.
:param n_components: number of components (e.g. Monte Carlo samples,
quadrature nodes, etc.) used to numerically approximate the kernel.
"""
super(FourierFeaturesBase, self).__init__(**kwargs)
assert isinstance(
kernel, self.SUPPORTED_KERNELS
), f"Only the following kernels are supported: {self.SUPPORTED_KERNELS}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: You could make this message more informative by specifying which kernel the user used.


def _compute_bases(self, inputs: TensorType) -> tf.Tensor:
"""
Compute basis functions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: the word "compute" made me first think the function would return a functor with the basis functions.

Suggested change
Compute basis functions.
Evaluate the 2L^D number of basis functions at `inputs`.

from gpflux.types import ShapeType


class QuadratureFourierFeaturesBase(FourierFeaturesBase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please give a type and short description of self.factors as it is being used in _compute_constant.

Suggested change
class QuadratureFourierFeaturesBase(FourierFeaturesBase):
class QuadratureFourierFeaturesBase(FourierFeaturesBase):
factors: Type
"""Description"""



class QuadratureFourierFeatures(FourierFeaturesBase):
class GaussianQuadratureFourierFeatures(QuadratureFourierFeaturesBase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class GaussianQuadratureFourierFeatures(QuadratureFourierFeaturesBase):
class GaussianQuadratureFourierFeatures(QuadratureFourierFeaturesBase):
""" Base class for `GaussHermiteQuadratureFourierFeatures` and `GaussLegendreQuadratureFourierFeatures`.

super(QuadratureFourierFeatures, self).__init__(kernel, n_components, **kwargs)


class GaussHermiteQuadratureFourierFeatures(GaussianQuadratureFourierFeatures):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a reference to which maths this class implements?

def _compute_bases(self, inputs: TensorType) -> tf.Tensor:
"""
Compute basis functions.
class GaussLegendreQuadratureFourierFeatures(GaussianQuadratureFourierFeatures):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a reference to which maths this class implements?

from gpflux.types import ShapeType


class SimpsonQuadratureFourierFeatures(QuadratureFourierFeaturesBase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a reference to which maths this class implements?



class QuasiRandomFourierFeatures(RandomFourierFeatures):

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants