Skip to content

Commit dab461b

Browse files
authored
Remove more code! (#134)
1 parent c122771 commit dab461b

25 files changed

Lines changed: 282 additions & 555 deletions

Project.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ version = "0.1.0"
44
authors = ["Caleb Derrickson (@CalebDerrickson), Alexis Montoison (@amontoison)", "Chris Geoga (@cgeoga)"]
55

66
[deps]
7-
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
87
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
98
NLPModels = "a4795742-8479-5a88-8948-cc11e1c8c1a6"
10-
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
119
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1210

1311
[weakdeps]
1412
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
13+
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
1514
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1615
Vecchia = "8d73829f-f4b0-474a-9580-cecc8e084068"
1716

1817
[extensions]
19-
VecchiaMLECUDAExt = "CUDA"
18+
VecchiaMLECUDAExt = ["CUDA", "KernelAbstractions"]
2019
VecchiaMLEVecchiaExt = ["StaticArrays", "Vecchia"]
2120

2221
[compat]
@@ -33,7 +32,6 @@ NLPModels = "0.21.5"
3332
NLPModelsIpopt = "0.10.4, 0.11"
3433
NLPModelsJuMP = "0.13.2"
3534
NLPModelsTest = "0.10.2"
36-
Random = "1.10"
3735
SparseArrays = "1.10"
3836
Test = "1.10"
3937
UnoSolver = "0.1.9"

README.md

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,3 @@ julia> ]
2222
pkg> add https://github.com/exanauts/VecchiaMLE.jl.git
2323
pkg> test VecchiaMLE
2424
```
25-
26-
## Configuration
27-
28-
The struct `VecchiaMLEInput` is available for the user to specify their analysis. At the minimum, we require the following:
29-
30-
```
31-
* k::Int # Number of conditioning points per point for the Vecchia Approximation.
32-
* samples::Matrix{Float64} # Matrix of samples (each row is a sample).
33-
```
34-
Other options may be passed as keyword arguments. Such options are:
35-
36-
```
37-
* ptset::AbstractVector # The locations of the analysis. May be passed as a matrix or vector of vectors.
38-
* rowsL::AbstractVector # The sparsity pattern rows of L if the user gives one. MUST BE IN CSC FORMAT!
39-
* colptrL::AbstractVector # The column pointer of L if the user gives one. MUST BE IN CSC FORMAT!
40-
* sparsityGeneration # The method by which to generate a sparsity pattern. See SPARSITY_GEN.
41-
* metric::Distances.metric # The metric by which nearest neighbors are determined. Defaults to Euclidean.
42-
```
43-
44-
## Usage
45-
46-
Once the user has initialized an instance of `VecchiaMLEInput`, they may pass it to `sparsity_pattern` to recover the inverse cholesky.
47-
48-
## Getting samples from a covariance matrix
49-
50-
```
51-
n = 100 # Dimension of Covariance matrix
52-
number_of_samples = 100 # Analysis samples number
53-
params = [5.0, 0.2, 2.25] # Parameters for Matern matrix. See BesselK.jl.
54-
ptset = VecchiaMLE.generate_safe_xyGrid(n) # Generates 100 equiparitioned points on [0, 10] x [0, 10].
55-
MatCov = VecchiaMLE.generate_MatCov(params, ptset) # size n x n.
56-
samples = VecchiaMLE.generate_samples(MatCov, number_of_samples) # Generate samples.
57-
```

docs/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
MadNLP = "2621e9c9-9eb4-46b1-8089-e8c72242dfb6"
34
NLPModelsIpopt = "f4238b75-b362-5c4c-b852-0801c9a21d71"
5+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
46
VecchiaMLE = "499233a1-c46f-47cc-ab67-5a37788e9870"
7+
Vecchia = "8d73829f-f4b0-474a-9580-cecc8e084068"
58

69
[compat]
710
Documenter = "1.0"

docs/make.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ makedocs(
88
prettyurls = get(ENV, "CI", nothing) == "true",
99
collapselevel = 1),
1010
sitename = "VecchiaMLE.jl",
11-
pages = ["Home" => "index.md",
12-
"API" => "api.md",
13-
"Vecchia model" => "vecchia_model.md",
14-
"Tutorials" => "how_to_run.md"]
11+
pages = ["Home" => "index.md"], # "Tutorials" => "vecchia_model.md"
1512
)
1613

1714
deploydocs(

docs/src/api.md

Lines changed: 0 additions & 41 deletions
This file was deleted.

docs/src/how_to_run.md

Lines changed: 0 additions & 51 deletions
This file was deleted.

docs/src/vecchia_model.md

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ using NLPModelsIpopt
66
77
n = 400
88
number_of_samples = 100
9-
10-
params = [5.0, 0.2, 2.25, 0.25]
11-
ptset = VecchiaMLE.generate_safe_xyGrid(n)
12-
MatCov = generate_MatCov(params, ptset)
13-
samples = generate_samples(MatCov, number_of_samples)
9+
samples = ...
1410
1511
P = ones(n, n)
1612
P = tril(P)
@@ -29,11 +25,7 @@ using NLPModelsIpopt
2925
3026
n = 400
3127
number_of_samples = 100
32-
33-
params = [5.0, 0.2, 2.25, 0.25]
34-
ptset = VecchiaMLE.generate_safe_xyGrid(n)
35-
MatCov = generate_MatCov(params, ptset)
36-
samples = generate_samples(MatCov, number_of_samples)
28+
samples = ...
3729
3830
P = ones(n, n)
3931
P = triu(P)
@@ -43,3 +35,50 @@ nlp_U = VecchiaModel(I, J, samples; format=:coo, uplo=:U)
4335
output = ipopt(nlp_U)
4436
U = recover_factor(nlp_U, output.solution)
4537
```
38+
39+
```@example Vecchia
40+
using VecchiaMLE
41+
using Vecchia
42+
using StaticArrays
43+
using LinearAlgebra
44+
45+
# Generate some fake data with an exponential covariance function.
46+
# Note that each _column_ of sim is an iid replicate, in keeping with formatting
47+
# standards of the many R packages for GPs. In this demonstration, n is small
48+
# and the number of replicates is large to demonstrate asymptotic correctness.
49+
pts = rand(SVector{2,Float64}, 100)
50+
z = randn(length(pts), 1000)
51+
K = Symmetric([exp(-norm(x-y)) for x in pts, y in pts])
52+
sim = cholesky(K).L * z
53+
54+
# Create a VecchiaModel using the options specified by Vecchia.jl, in
55+
# particular choosing an ordering (in this case RandomOrdering()) and a
56+
# conditioning set design (in this case KNNConditioning(10)). This also returns
57+
# the permutation for you to use with subsequent data operations. See the docs
58+
# and myriad extensions of Vecchia.jl for more information on ordering and
59+
# conditioning set design options.
60+
(perm, nlp) = VecchiaModel(pts, sim, RandomOrdering(), KNNConditioning(10);
61+
lvar_diag=fill(inv(sqrt(1.0)), length(pts)),
62+
uvar_diag=fill(inv(sqrt(1e-2)), length(pts)),
63+
lambda=1e-3)
64+
65+
# Now bring in some optimizers and fit the nonparametric model. This gives a U
66+
# such that Σ^{-1} ≈ U*U', where Σ is the covariance matrix for each column of sim.
67+
using MadNLP
68+
result = madnlp(nlp; tol=1e-10)
69+
U = UpperTriangular(recover_factor(nlp, result.solution))
70+
71+
# KL divergence from the true covariance:
72+
K_perm = K[perm, perm]
73+
kl = (tr(U'*K_perm*U) - length(pts)) + (-2*logdet(U) - logdet(K_perm))
74+
75+
# compare that with what you get from a parametric Vecchia model using the
76+
# correct kernel and the same permutation.
77+
para_vecchia = VecchiaApproximation(pts[perm], (x,y,p)->exp(-norm(x-y)), sim[perm,:];
78+
ordering=NoPermutation())
79+
para_U = rchol(para_vecchia, Float64[]).U
80+
para_kl = (tr(para_U'*K_perm*para_U) - length(pts)) + (-2*logdet(para_U) - logdet(K_perm))
81+
82+
println("KL divergence with true parametric kernel: ", para_kl)
83+
println("KL divergence with nonparametric estimator: ", kl)
84+
```

examples/Project.toml

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/with_vecchia.jl

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)