-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6966fb3
commit ccaf1fe
Showing
22 changed files
with
526 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Distribution sampling | ||
|
||
ConsensusBasedX.jl also provides consensus-based sampling, [J. A. Carrillo, F. Hoffmann, A. M. Stuart, and U. Vaes (2022)](https://onlinelibrary.wiley.com/doi/10.1111/sapm.12470). The package exports `sample`, which behaves exactly as `minimise` in [Function minimisation](@ref). It assumes you have defined a function `f(x::AbstractVector)` that takes a single vector argumemt `x` of length `D = length(x)`. | ||
|
||
For instance, if `D = 2`, you can sample `exp(-f)` by running: | ||
```julia | ||
out = sample(f, D = 2, extended_output=true) | ||
out.sample | ||
``` | ||
[Full-code example](https://github.com/PdIPS/ConsensusBasedX.jl/blob/main/examples/basic_usage/sample_with_keywords.jl). | ||
|
||
!!! note | ||
You must always provide `D`. | ||
|
||
|
||
## Using a `config` object | ||
|
||
For more advanced usage, you will select several options. You can pass these as extra keyword arguments to `sample`, or you can create a `NamedTuple` called `config` and pass that: | ||
```julia | ||
config = (; D = 2, extended_output=true) | ||
out = sample(f, config) | ||
out.sample | ||
``` | ||
[Full-code example](https://github.com/PdIPS/ConsensusBasedX.jl/blob/main/examples/basic_usage/sample_with_config.jl). | ||
|
||
!!! note | ||
If you pass a `Dict` instead, it will be converted to a `NamedTuple` automatically. | ||
|
||
|
||
## Running on minimisation mode | ||
|
||
Consensus-based sampling can also be used for minimisation. If you want to run it in that mode, pass the option `CBS_mode = :minimise`. | ||
|
||
|
||
## Method reference | ||
|
||
```@index | ||
Pages = ["distribution_sampling.md"] | ||
``` | ||
|
||
```@docs | ||
ConsensusBasedX.sample | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using ConsensusBasedX | ||
|
||
f(x) = ConsensusBasedX.Ackley(x, shift = 1) | ||
|
||
config = (; D = 2, N = 20, CBS_mode = :minimise) | ||
sample(f, config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using ConsensusBasedX | ||
|
||
f(x) = ConsensusBasedX.Ackley(x, shift = 1) | ||
|
||
config = (; D = 2, N = 20, extended_output = true) | ||
out = sample(f, config) | ||
out.sample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using ConsensusBasedX | ||
|
||
f(x) = ConsensusBasedX.Ackley(x, shift = 1) | ||
|
||
out = sample(f, D = 2, N = 20, extended_output = true) | ||
out.sample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.