Skip to content

Commit

Permalink
Merge #120
Browse files Browse the repository at this point in the history
120: Modular emulator interface r=odunbar a=odunbar

## Purpose
Reduces the current Emulator interface dependence of Gaussian Processes. Now the GP can be swapped for another statistical emulator. 
 
## In the PR
- [x] New general `Emulator` class. This handles all the data manipulation e.g. Normalization, Standardization, Decorrelation
- [x] General interface functions for Emulator, `optimize_hyperparameters!`, `predict`
- [x] New `MachineLearningTool` type, 
- [x] Moved the Gaussian Processes into a `GaussianProcess <: MachineLearningTool` class
- [x] Example (e.g. `plot_GP`) to demonstrate the new interface
- [x] Unit tests
- [x] New doc strings.

## Additional change
Seems to be ongoing issues with unit testing Julia 1.5.4, so I have updated the Manifest, Docs.yml and Test.yml to Julia 1.6.X
 
## Changes to user experience:

Ingredients: 
```julia
gppackage = GPJL()
pred_type = YType()
GPkernel = ...
iopairs = PairedDataContainer(x_data,y_data)
```

### Old interface

Set up a `GaussianProcessEmulator` object
```julia 
    gp = GaussianProcess(
         iopairs,
         gppackage;
         GPkernel=GPkernel, 
         obs_noise_cov=nothing, 
         normalized=false, 
         noise_learn=true, 
	 truncate_svd=1.0, 
         standardize=false,
         prediction_type=pred_type, 
         norm_factor=nothing)
 ```
Then predict with it.
```julia
μ, σ² = GaussianProcessEmulator.predict(gp, new_inputs)
```
It is short, but it inherently is stuck to the Gaussian process framework. It also hides e.g. the training away, and we may wish to have this more open. The script below is more general, separating out which parameters are related to data processing and which relate to the specific ML tool.

### New interface
Setup a `GaussianProcess<:MachineLearningTool` object
```julia
 gp = GaussianProcess(
       gppackage;
       kernel=GPkernel,
       noise_learn=true,
       prediction_type=pred_type) 
```
and then create the general emulator type using `gp`
```julia
    em = Emulator(
        gp,
        iopairs,
        obs_noise_cov=nothing,
        normalize_inputs=false,
        standardize_outputs=false,
        truncate_svd=1.0)
```
Train and predict
```julia
Emulators.optimize_hyperparameters!(em)
μ, σ² = Emulators.predict(em, new_inputs)
```
### Adding a new `MachineLearningTool`
Include a new file `NewTool.jl` at the top of `Emulator.jl`
In this file define:
1. `struct NewTool <: MachineLearningTool` with constructor `NewTool(...)` to hold ML parameters and models
2. `function build_models!(NewTool,iopairs)` to build and store ML models. Called in Emulator constructor
3. `function optimize_hyperparameters!(NewTool)`to train the stored ML models. Called by method of same name in Emulator
4. `function predict(NewTool,new_inputs)` to predict with stored ML models Called by method of same name in Emulator


Co-authored-by: odunbar <odunbar@caltech.edu>
Co-authored-by: Tom Jackson <tom.jackson314@gmail.com>
  • Loading branch information
3 people authored Jan 21, 2022
2 parents 8723d4a + 61178bd commit c23c216
Show file tree
Hide file tree
Showing 30 changed files with 3,715 additions and 2,743 deletions.
21 changes: 11 additions & 10 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
env:
JULIA_VERSION: "1.5.4"
JULIA_VERSION: "1.6.2"
JULIA_MINOR_VERSION: "1.6"
OPENBLAS_NUM_THREADS: 1
GKSwstype: nul

Expand Down Expand Up @@ -29,7 +30,7 @@ steps:
mkdir examples/Lorenz/depot
export JULIA_DEPOT_PATH="$$(pwd)/examples/Lorenz/depot:$$JULIA_DEPOT_PATH"
julia --color=yes --project -e '
println("--- Instantiating Project")
using Pkg;
Expand All @@ -44,29 +45,29 @@ steps:
config: cpu
queue: central
slurm_ntasks: 1

- label: "Gaussian Process Emulator"
key: "gaussian_process_emulator"
command: |
export PYTHON="$$JULIA_DEPOT_PATH/conda/3/bin/python"
export PYTHONHOME="$$JULIA_DEPOT_PATH/conda/3/bin"
export CONDA_JL_HOME="$$JULIA_DEPOT_PATH/conda/3"
mkdir examples/GaussianProcessEmulator/depot
export JULIA_DEPOT_PATH="$$(pwd)/examples/GaussianProcessEmulator/depot:$JULIA_DEPOT_PATH"
mkdir examples/Emulator/GaussianProcess/depot
export JULIA_DEPOT_PATH="$$(pwd)/examples/Emulator/GaussianProcess/depot:$JULIA_DEPOT_PATH"
julia --color=yes --project -e '
println("--- Instantiating Project")
using Pkg;
Pkg.instantiate()
Pkg.activate("examples/GaussianProcessEmulator")
Pkg.activate("examples/Emulator/GaussianProcess")
Pkg.instantiate()
println("+++ Running Learn Noise")
include("examples/GaussianProcessEmulator/learn_noise.jl")
include("examples/Emulator/GaussianProcess/learn_noise.jl")
println("+++ Running PlotGP")
include("examples/GaussianProcessEmulator/plot_GP.jl")'
include("examples/Emulator/GaussianProcess/plot_GP.jl")'
artifact_paths:
- "examples/GaussianProcessEmulator/output/*.png"
- "examples/Emulator/GaussianProcess/output/*.png"
env:
PYTHON: "$$JULIA_DEPOT_PATH/conda/3/bin/python"
PYTHONHOME: "$$JULIA_DEPOT_PATH/conda/3/bin"
Expand All @@ -75,7 +76,7 @@ steps:
config: cpu
queue: central
slurm_ntasks: 1

- label: "Cloudy"
key: "cloudy"
command: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: 1.5.4
version: 1.6
- name: Cache artifacts
uses: actions/cache@v1
env:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Julia
uses: julia-actions/setup-julia@v1
with:
version: 1.5.4
version: 1.6

- name: Install Julia Project Packages
# we add this ENV varaible to force PyCall to download and use Conda rather than
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
- name: Set up Julia
uses: julia-actions/setup-julia@v1
with:
version: 1.5.4
version: 1.6

- name: Install Julia Project Packages
env:
Expand Down Expand Up @@ -119,7 +119,7 @@ jobs:
- name: Set up Julia
uses: julia-actions/setup-julia@v1
with:
version: 1.5.4
version: 1.6

- name: Install Julia Project Packages
env:
Expand Down
Loading

0 comments on commit c23c216

Please sign in to comment.