Skip to content

Commit 2d2419a

Browse files
Merge pull request #6 from SciML/docs
Build a proper documentation
2 parents 3a0d213 + 3641d89 commit 2d2419a

File tree

10 files changed

+303
-129
lines changed

10 files changed

+303
-129
lines changed

.github/workflows/Documentation.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- 'release-'
8+
tags: '*'
9+
pull_request:
10+
schedule:
11+
- cron: '34 21 * * 4'
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: julia-actions/setup-julia@latest
18+
with:
19+
version: '1'
20+
- name: Install dependencies
21+
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
22+
- name: Build and deploy
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token
25+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
26+
run: julia --project=docs/ --code-coverage=user docs/make.jl
27+
- uses: julia-actions/julia-processcoverage@v1
28+
with:
29+
directories: src
30+
- uses: codecov/codecov-action@v3
31+
with:
32+
files: lcov.info

README.md

+10-129
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# SurrogatesBase.jl
22

3+
[![Join the chat at https://julialang.zulipchat.com #sciml-bridged](https://img.shields.io/static/v1?label=Zulip&message=chat&color=9558b2&labelColor=389826)](https://julialang.zulipchat.com/#narrow/stream/279055-sciml-bridged)
4+
[![Global Docs](https://img.shields.io/badge/docs-SciML-blue.svg)](https://docs.sciml.ai/SurrogatesBase/stable/)
5+
6+
[![codecov](https://codecov.io/gh/SciML/SurrogatesBase.jl/branch/master/graph/badge.svg?token=FwXaKBNW67)](https://codecov.io/gh/SciML/SurrogatesBase.jl)
7+
[![Build Status](https://github.com/SciML/SurrogatesBase.jl/workflows/CI/badge.svg)](https://github.com/SciML/SurrogatesBase.jl/actions?query=workflow%3ACI)
8+
9+
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor%27s%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
10+
[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)
11+
312
API for deterministic and stochastic surrogates.
413

514
Given data $((x_1, y_1), \ldots, (x_N, y_N))$ obtained by evaluating a function $y_i =
@@ -10,132 +19,4 @@ uses the data to approximate $f$ or some statistic of $p_{Y|X}$ (e.g. the mean),
1019
whereas a **stochastic surrogate** is a stochastic process (e.g. a [Gaussian process
1120
approximation](https://en.wikipedia.org/wiki/Gaussian_process_approximations)) that uses
1221
the data to approximate $f$ or $p_{Y|X}$ *and* quantify the uncertainty of the
13-
approximation.
14-
15-
## Deterministic Surrogates
16-
17-
Deterministic surrogates `s` are subtypes of `SurrogatesBase.AbstractDeterministicSurrogate`,
18-
which is a subtype of `Function`.
19-
20-
### Required methods
21-
22-
The method `update!(s, xs, ys)` **must** be implemented and the surrogate **must** be
23-
[callable](https://docs.julialang.org/en/v1/manual/methods/#Function-like-objects)
24-
`s(xs)`, where `xs` is a `Vector` of input points and `ys` is a `Vector` of corresponding evaluations.
25-
26-
Calling `update!(s, xs, ys)` refits the surrogate `s` to include evaluations `ys` at points `xs`.
27-
The result of `s(xs)` is a `Vector` of evaluations of the surrogate at points `xs`, corresponding to approximations of the underlying function at points `xs` respectively.
28-
29-
For single points `x` and `y`, call these methods via `update!(s, [x], [y])`
30-
and `s([x])`.
31-
32-
### Optional methods
33-
34-
If the surrogate `s` wants to expose current parameter values, the method `parameters(s)` **must** be implemented.
35-
36-
If the surrogate `s` has tunable hyperparameters, the methods
37-
`update_hyperparameters!(s, prior)` and `hyperparameters(s)` **must** be implemented.
38-
39-
Calling `update_hyperparameters!(s, prior)` updates the hyperparameters of the surrogate `s` by performing hyperparameter optimization using the information in `prior`. After the hyperparameters of `s` are updated, `s` is fit to past evaluations.
40-
Calling `hyperparameters(s)` returns current values of hyperparameters.
41-
42-
### Example
43-
44-
```julia
45-
using SurrogatesBase
46-
47-
struct RBF{T} <: AbstractDeterministicSurrogate
48-
scale::T
49-
centers::Vector{T}
50-
weights::Vector{T}
51-
end
52-
53-
(rbf::RBF)(xs) = [rbf.weights' * exp.(-rbf.scale * (x .- rbf.centers).^2)
54-
for x in xs]
55-
56-
function SurrogatesBase.update!(rbf::RBF, xs, ys)
57-
# Refit the surrogate by updating rbf.weights to include new
58-
# evaluations ys at points xs
59-
return rbf
60-
end
61-
62-
SurrogatesBase.parameters(rbf::RBF) = rbf.centers, rbf.weights
63-
64-
SurrogatesBase.hyperparameters(rbf::RBF) = rbf.scale
65-
66-
function SurrogatesBase.update_hyperparameters!(rbf::RBF, prior)
67-
# update rbf.scale and fit the surrogate by adapting rbf.weights
68-
return rbf
69-
end
70-
```
71-
72-
## Stochastic Surrogates
73-
74-
Stochastic surrogates `s` are subtypes of `SurrogatesBase.AbstractStochasticSurrogate`.
75-
76-
### Required methods
77-
78-
The methods `update!(s, xs, ys)` and `finite_posterior(s, xs)` **must** be implemented, where `xs` is a `Vector` of input points and `ys` is a `Vector` of corresponding observed samples.
79-
80-
Calling `update!(s, xs, ys)` refits the surrogate `s` to include observations `ys` at points `xs`.
81-
82-
For single points `x` and `y`, call the `update!(s, xs, ys)` via `update!(s, [x], [y])`.
83-
84-
Calling `finite_posterior(s, xs)` returns an object that provides methods for working with the finite
85-
dimensional posterior distribution at points `xs`.
86-
The following methods might be supported:
87-
88-
- `mean(finite_posterior(s,xs))` returns a `Vector` of posterior means at `xs`
89-
- `var(finite_posterior(s,xs))` returns a `Vector` of posterior variances at `xs`
90-
- `mean_and_var(finite_posterior(s,xs))` returns a `Tuple` consisting of a `Vector`
91-
of posterior means and a `Vector` of posterior variances at `xs`
92-
- `rand(finite_posterior(s,xs))` returns a `Vector`, which is a sample from the joint posterior at points `xs`
93-
94-
### Optional methods
95-
96-
If the surrogate `s` wants to expose current parameter values, the method `parameters(s)` **must** be implemented.
97-
98-
If the surrogate `s` has tunable hyper-parameters, the methods
99-
`update_hyperparameters!(s, prior)` and `hyperparameters(s)` **must** be implemented.
100-
101-
Calling `update_hyperparameters!(s, prior)` updates the hyperparameters of the surrogate `s` by performing hyperparameter optimization using the information in `prior`. After the hyperparameters of `s` are updated, `s` is fit to past samples.
102-
Calling `hyperparameters(s)` returns current values of hyperparameters.
103-
104-
105-
### Example
106-
107-
```julia
108-
using SurrogatesBase
109-
110-
mutable struct GaussianProcessSurrogate{D, R, GP, H <: NamedTuple} <: AbstractStochasticSurrogate
111-
xs::Vector{D}
112-
ys::Vector{R}
113-
gp_process::GP
114-
hyperparameters::H
115-
end
116-
117-
function SurrogatesBase.update!(g::GaussianProcessSurrogate, new_xs, new_ys)
118-
append!(g.xs, new_xs)
119-
append!(g.ys, new_ys)
120-
# condition the prior `g.gp_process` on new data to obtain a posterior
121-
# update g.gp_process to the posterior process
122-
return g
123-
end
124-
125-
function SurrogatesBase.finite_posterior(g::GaussianProcessSurrogate, xs)
126-
# Return a finite dimensional projection of g.gp_process at points xs.
127-
# The returned object GP_finite supports methods mean(GP_finite) and
128-
# var(GP_finite) for obtaining the vector of means and variances at points xs.
129-
end
130-
131-
SurrogatesBase.hyperparameters(g::GaussianProcessSurrogate) = g.hyperparameters
132-
133-
function SurrogatesBase.update_hyperparameters!(g::GaussianProcessSurrogate, prior)
134-
# Use prior on hyperparameters, e.g., parameters uniformly distributed
135-
# between an upper and lower bound, to perform hyperparameter optimization.
136-
# Set g.hyperparameters to the improved hyperparameters.
137-
# Fit a Gaussian process that uses the updated hyperparameters to past
138-
# samples and save it in g.gp_process.
139-
return g
140-
end
141-
```
22+
approximation.

docs/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
site/

docs/Project.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
SurrogatesBase = "89f642e6-4179-4274-8202-c11f4bd9a72c"
4+
5+
[compat]
6+
Documenter = "1"

docs/make.jl

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Documenter, SurrogatesBase
2+
3+
cp("./docs/Manifest.toml", "./docs/src/assets/Manifest.toml", force = true)
4+
cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true)
5+
6+
pages = [
7+
"Home" => "index.md",
8+
"interface.md",
9+
"api.md"
10+
]
11+
12+
ENV["GKSwstype"] = "100"
13+
14+
makedocs(modules = [SurrogatesBase],
15+
sitename = "SurrogatesBase.jl",
16+
clean = true,
17+
doctest = false,
18+
linkcheck = true,
19+
format = Documenter.HTML(assets = ["assets/favicon.ico"],
20+
canonical = "https://docs.sciml.ai/SurrogatesBase/stable/"),
21+
pages = pages)
22+
23+
deploydocs(repo = "github.com/SciML/SurrogatesBase.jl"; push_preview = true)

docs/src/api.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# API
2+
3+
```@autodocs
4+
Modules = [SurrogatesBase]
5+
```

docs/src/assets/favicon.ico

1.36 KB
Binary file not shown.

docs/src/assets/logo.png

26 KB
Loading

docs/src/index.md

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# SurrogatesBase.jl: A Common Interface for Surrogate Libraries
2+
3+
API for deterministic and stochastic surrogates.
4+
5+
Given data $((x_1, y_1), \ldots, (x_N, y_N))$ obtained by evaluating a function $y_i =
6+
f(x_i)$ or sampling from a conditional probability density $p_{Y|X}(Y = y_i|X = x_i)$,
7+
a **deterministic surrogate** is a function $s(x)$ (e.g. a [radial basis function
8+
interpolator](https://en.wikipedia.org/wiki/Radial_basis_function_interpolation)) that
9+
uses the data to approximate $f$ or some statistic of $p_{Y|X}$ (e.g. the mean),
10+
whereas a **stochastic surrogate** is a stochastic process (e.g. a [Gaussian process
11+
approximation](https://en.wikipedia.org/wiki/Gaussian_process_approximations)) that uses
12+
the data to approximate $f$ or $p_{Y|X}$ *and* quantify the uncertainty of the
13+
approximation.
14+
15+
## Installation
16+
17+
To install SurrogatesBase.jl, use the Julia package manager:
18+
19+
```julia
20+
using Pkg
21+
Pkg.add("SurrogatesBase")
22+
```
23+
24+
## Contributing
25+
26+
- Please refer to the
27+
[SciML ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://github.com/SciML/ColPrac/blob/master/README.md)
28+
for guidance on PRs, issues, and other matters relating to contributing to SciML.
29+
30+
- See the [SciML Style Guide](https://github.com/SciML/SciMLStyle) for common coding practices and other style decisions.
31+
- There are a few community forums:
32+
33+
+ The #diffeq-bridged and #sciml-bridged channels in the
34+
[Julia Slack](https://julialang.org/slack/)
35+
+ The #diffeq-bridged and #sciml-bridged channels in the
36+
[Julia Zulip](https://julialang.zulipchat.com/#narrow/stream/279055-sciml-bridged)
37+
+ On the [Julia Discourse forums](https://discourse.julialang.org)
38+
+ See also [SciML Community page](https://sciml.ai/community/)
39+
40+
## Reproducibility
41+
42+
```@raw html
43+
<details><summary>The documentation of this SciML package was built using these direct dependencies,</summary>
44+
```
45+
46+
```@example
47+
using Pkg # hide
48+
Pkg.status() # hide
49+
```
50+
51+
```@raw html
52+
</details>
53+
```
54+
55+
```@raw html
56+
<details><summary>and using this machine and Julia version.</summary>
57+
```
58+
59+
```@example
60+
using InteractiveUtils # hide
61+
versioninfo() # hide
62+
```
63+
64+
```@raw html
65+
</details>
66+
```
67+
68+
```@raw html
69+
<details><summary>A more complete overview of all dependencies and their versions is also provided.</summary>
70+
```
71+
72+
```@example
73+
using Pkg # hide
74+
Pkg.status(; mode = PKGMODE_MANIFEST) # hide
75+
```
76+
77+
```@raw html
78+
</details>
79+
```
80+
81+
```@eval
82+
using TOML
83+
using Markdown
84+
version = TOML.parse(read("../../Project.toml", String))["version"]
85+
name = TOML.parse(read("../../Project.toml", String))["name"]
86+
link_manifest = "https://github.com/SciML/" * name * ".jl/tree/gh-pages/v" * version *
87+
"/assets/Manifest.toml"
88+
link_project = "https://github.com/SciML/" * name * ".jl/tree/gh-pages/v" * version *
89+
"/assets/Project.toml"
90+
Markdown.parse("""You can also download the
91+
[manifest]($link_manifest)
92+
file and the
93+
[project]($link_project)
94+
file.
95+
""")
96+
```

0 commit comments

Comments
 (0)