Skip to content

Commit

Permalink
new fvgp docstrings and got rid of unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusMNoack committed Nov 2, 2023
1 parent a55df44 commit c496b88
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 77 deletions.
98 changes: 48 additions & 50 deletions fvgp/fvgp.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#!/usr/bin/env python
import dask.distributed as distributed
from loguru import logger
import numpy as np
import math
import warnings
import itertools
import time
from functools import partial
from .gp import GP


Expand Down Expand Up @@ -228,27 +222,27 @@ def __init__(
output_number,
x_data,
y_data,
init_hyperparameters = None,
hyperparameter_bounds = None,
output_positions = None,
noise_variances = None,
compute_device = "cpu",
gp_kernel_function = None,
gp_deep_kernel_layer_width = 5,
gp_kernel_function_grad = None,
gp_noise_function = None,
gp_noise_function_grad = None,
gp_mean_function = None,
gp_mean_function_grad = None,
sparse_mode = False,
gp2Scale = False,
gp2Scale_dask_client = None,
gp2Scale_batch_size = 10000,
normalize_y = False,
store_inv = True,
ram_economy = False,
args = None,
info = False,
init_hyperparameters=None,
hyperparameter_bounds=None,
output_positions=None,
noise_variances=None,
compute_device="cpu",
gp_kernel_function=None,
gp_deep_kernel_layer_width=5,
gp_kernel_function_grad=None,
gp_noise_function=None,
gp_noise_function_grad=None,
gp_mean_function=None,
gp_mean_function_grad=None,
sparse_mode=False,
gp2Scale=False,
gp2Scale_dask_client=None,
gp2Scale_batch_size=10000,
normalize_y=False,
store_inv=True,
ram_economy=False,
args=None,
info=False,
):

self.orig_input_space_dim = input_space_dim
Expand Down Expand Up @@ -302,25 +296,25 @@ def __init__(
self.iset_dim,
x_data,
y_data,
init_hyperparameters = init_hps,
hyperparameter_bounds = hyperparameter_bounds,
noise_variances = noise_variances,
compute_device = compute_device,
gp_kernel_function = gp_kernel_function,
gp_kernel_function_grad = gp_kernel_function_grad,
gp_mean_function = gp_mean_function,
gp_mean_function_grad = gp_mean_function_grad,
gp_noise_function = gp_noise_function,
gp_noise_function_grad = gp_noise_function_grad,
sparse_mode = sparse_mode,
gp2Scale = gp2Scale,
gp2Scale_dask_client = gp2Scale_dask_client,
gp2Scale_batch_size = gp2Scale_batch_size,
store_inv = store_inv,
normalize_y = normalize_y,
ram_economy = ram_economy,
args = args,
info = info)
init_hyperparameters=init_hps,
hyperparameter_bounds=hyperparameter_bounds,
noise_variances=noise_variances,
compute_device=compute_device,
gp_kernel_function=gp_kernel_function,
gp_kernel_function_grad=gp_kernel_function_grad,
gp_mean_function=gp_mean_function,
gp_mean_function_grad=gp_mean_function_grad,
gp_noise_function=gp_noise_function,
gp_noise_function_grad=gp_noise_function_grad,
sparse_mode=sparse_mode,
gp2Scale=gp2Scale,
gp2Scale_dask_client=gp2Scale_dask_client,
gp2Scale_batch_size=gp2Scale_batch_size,
store_inv=store_inv,
normalize_y=normalize_y,
ram_economy=ram_economy,
args=args,
info=info)

################################################################################################
def update_gp_data(
Expand All @@ -343,14 +337,18 @@ def update_gp_data(
y_data : np.ndarray
The values of the data points. Shape (V,Do).
output_positions : np.ndarray, optional
A 3-D numpy array of shape (U x output_number x output_dim), so that for each measurement position, the outputs
A 3-D numpy array of shape (U x output_number x output_dim), so that
for each measurement position, the outputs
are clearly defined by their positions in the output space.
The default is np.array([[0],[1],[2],[3],...,[output_number - 1]]) for each
point in the input space. The default is only permissible if output_dim is 1.
noise_variances : np.ndarray, optional
An numpy array defining the uncertainties in the data `y_data` in form of a point-wise variance. Shape (y_data).
Note: if no variances are provided here, the noise_covariance callable will be used; if the callable is not provided the noise variances
will be set to `abs(np.mean(y_data) / 100.0`. If you provided a noise function, the noise_variances will be ignored.
An numpy array defining the uncertainties in the data `y_data`
in form of a point-wise variance. Shape (y_data).
Note: if no variances are provided here, the noise_covariance callable
will be used; if the callable is not provided the noise variances
will be set to `abs(np.mean(y_data)) / 100.0`. If you provided a noise function,
the noise_variances will be ignored.
"""
self.fvgp_x_data = np.array(x_data)
self.fvgp_y_data = np.array(y_data)
Expand Down
47 changes: 20 additions & 27 deletions fvgp/gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import time
import warnings
from scipy.sparse import csc_matrix
#from scipy.sparse import coo_matrix
from scipy.sparse.linalg import splu
#from scipy.sparse.linalg import cg
#from scipy.sparse.linalg import cgs
from scipy.sparse.linalg import minres
import dask.distributed as distributed
import numpy as np
Expand All @@ -18,37 +15,13 @@
from .mcmc import mcmc
from hgdl.hgdl import HGDL
from .gp2Scale import gp2Scale as gp2S
#from dask.distributed import Variable
from dask.distributed import Client
from scipy.stats import norm
from imate import logdet
#import gc


# TODO:


def make_1d_x_pred(b, res=100): # pragma: no cover
"""
This is a purely convenience-driven function calculating prediction points
on a ed grid.
Parameters
----------
b : np.ndarray
A numpy array of shape (2) defineing lower and upper bounds
res : int, optional
Resolution. Default = 100
Return
------
prediction points : np.ndarray
"""

x_pred = np.linspace(b[0], b[1], res).reshape(res, -1)
return x_pred


class GP():
"""
This class provides all the tools for a single-task Gaussian Process (GP).
Expand Down Expand Up @@ -2812,6 +2785,26 @@ def make_2d_x_pred(self, bx, by, resx=100, resy=100): # pragma: no cover
x_pred = np.array(list(product(x, y)))
return x_pred

def make_1d_x_pred(self, b, res=100): # pragma: no cover
"""
This is a purely convenience-driven function calculating prediction points
on a 1d grid.
Parameters
----------
b : np.ndarray
A numpy array of shape (2) defineing lower and upper bounds
res : int, optional
Resolution. Default = 100
Return
------
prediction points : np.ndarray
"""

x_pred = np.linspace(b[0], b[1], res).reshape(res, -1)
return x_pred

def _in_bounds(self, v, bounds):
if any(v < bounds[:, 0]) or any(v > bounds[:, 1]): return False
return True
Expand Down

0 comments on commit c496b88

Please sign in to comment.