nonconvexopt / pytorch-ssge Goto Github PK
View Code? Open in Web Editor NEWUnofficial PyTorch Reimplementation of the Spectral Stein Gradient Estimator, compatiable to use gpytorch kernel modules.
License: MIT License
Unofficial PyTorch Reimplementation of the Spectral Stein Gradient Estimator, compatiable to use gpytorch kernel modules.
License: MIT License
Hi,
First of all thanks for this wonderful implementation.
I am now trying to work a simple example of using SSGE for estimating score function for N(0, 1) function. Please find below my code:
import torch
import gpytorch
from ssge import SSGE
def test_gaussian():
import matplotlib.pyplot as plt
plt.style.use('seaborn')
dist = torch.distributions.normal.Normal(
torch.tensor(0.0), torch.tensor(1.0)
)
kernel = gpytorch.kernels.RBFKernel()
# estimator = SSGE(gpytorch.kernels.ScaleKernel(gpytorch.kernels.RBFKernel()))
estimator = SSGE(
gpytorch.kernels.ScaleKernel(gpytorch.kernels.RBFKernel()),
noise=1e-4
)
sample = dist.sample((100, 1))
logp = dist.log_prob(sample)
sample.requires_grad_(True)
estimator.fit(sample)
# test_points = dist.sample((25, 1))
test_points = torch.linspace(-2, +2, 250)
test_points.requires_grad_(True)
grad_the = -test_points
grad_est = estimator(test_points)
# Plot results
fig, ax = plt.subplots(1, 1)
ax.scatter(sample.detach().numpy(), logp.detach().numpy(),
marker='o', s=2.0, label='Sample points')
ax.plot(test_points.detach().numpy(), grad_the.detach().numpy(),
c='red', lw=1, label=r"$\nabla_x")
ax.plot(test_points.detach().numpy(), grad_est.detach().numpy(),
c='blue', lw=1, label=r"$\hat{\nabla_x}")
plt.savefig("out/test_gaussian.png")
test_gaussian()
However, when I run the example, the estimated gradients are very much different than the actual ones. (See the figure attached)
How this can be improved?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.