Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add low rank modified mass matrix adaptation #133

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ notebooks/*.hpp
perf.data*
wheels
.vscode/
*~
14 changes: 7 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file.

## [0.13.0] - 2024-07-05

### Features

- Add low rank modified mass matrix adaptation (Adrian Seyboldt)


## [0.12.0] - 2024-06-29

### Features
Expand Down Expand Up @@ -45,11 +52,6 @@ All notable changes to this project will be documented in this file.
- Add progress bar on terminal (Adrian Seyboldt)


### Miscellaneous Tasks

- Prepare release (Adrian Seyboldt)


## [0.11.0] - 2024-05-29

### Bug Fixes
Expand Down Expand Up @@ -78,8 +80,6 @@ All notable changes to this project will be documented in this file.

- Update python dependencies (Adrian Seyboldt)

- Prepare release (Adrian Seyboldt)


### Refactor

Expand Down
74 changes: 37 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nutpie"
version = "0.12.0"
version = "0.13.0"
authors = [
"Adrian Seyboldt <[email protected]>",
"PyMC Developers <[email protected]>",
Expand All @@ -22,7 +22,7 @@ name = "_lib"
crate-type = ["cdylib"]

[dependencies]
nuts-rs = "0.11.0"
nuts-rs = "0.12.0"
numpy = "0.21.0"
ndarray = "0.15.6"
rand = "0.8.5"
Expand All @@ -33,7 +33,7 @@ rayon = "1.9.0"
arrow = { version = "52.0.0", default-features = false, features = ["ffi"] }
anyhow = "1.0.72"
itertools = "0.13.0"
bridgestan = "2.4.1"
bridgestan = "2.5.0"
rand_distr = "0.4.3"
smallvec = "1.11.0"
upon = { version = "0.8.1", default-features = false, features = [] }
Expand Down
2 changes: 1 addition & 1 deletion cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ commit_parsers = [
{ message = "^refactor", group = "Refactor" },
{ message = "^style", group = "Styling" },
{ message = "^test", group = "Testing" },
{ message = "^chore\\(release\\): prepare for", skip = true },
{ message = "^chore: Prepare", skip = true },
{ message = "^chore", group = "Miscellaneous Tasks" },
{ body = ".*security", group = "Security" },
]
Expand Down
22 changes: 21 additions & 1 deletion python/nutpie/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def sample(
seed: Optional[int],
save_warmup: bool,
progress_bar: bool,
low_rank_modified_mass_matrix: bool = False,
init_mean: Optional[np.ndarray],
return_raw_trace: bool,
blocking: Literal[True],
Expand All @@ -478,6 +479,7 @@ def sample(
seed: Optional[int],
save_warmup: bool,
progress_bar: bool,
low_rank_modified_mass_matrix: bool = False,
init_mean: Optional[np.ndarray],
return_raw_trace: bool,
blocking: Literal[False],
Expand All @@ -495,6 +497,7 @@ def sample(
seed: Optional[int] = None,
save_warmup: bool = True,
progress_bar: bool = True,
low_rank_modified_mass_matrix: bool = False,
init_mean: Optional[np.ndarray] = None,
return_raw_trace: bool = False,
blocking: bool = True,
Expand Down Expand Up @@ -569,6 +572,19 @@ def sample(
for the progress bar (eg CSS).
progress_rate: int, default=500
Rate in ms at which the progress should be updated.
low_rank_modified_mass_matrix: bool, default=False
Allow adaptation to some posterior correlations using
a low-rank updated mass matrix. This is *experimental*
and details about this will probably change in the next
release.
mass_matrix_eigval_cutoff: float > 1, defaul=100
Ignore eigenvalues between cutoff and 1/cutoff in the
low-rank modified mass matrix estimate. Higher values
lead to worse correclation fitting, but increase
the performance of leapfrog steps.
mass_matrix_gamma: float > 0, default=1e-5
Regularisation parameter for the eigenvalues. Only
applicable with low_rank_modified_mass_matrix=True.
**kwargs
Pass additional arguments to nutpie._lib.PySamplerArgs

Expand All @@ -577,7 +593,11 @@ def sample(
trace : arviz.InferenceData
An ArviZ ``InferenceData`` object that contains the samples.
"""
settings = _lib.PyDiagGradNutsSettings(seed)

if low_rank_modified_mass_matrix:
settings = _lib.PyNutsSettings.LowRank(seed)
else:
settings = _lib.PyNutsSettings.Diag(seed)
settings.num_tune = tune
settings.num_draws = draws
settings.num_chains = chains
Expand Down
12 changes: 6 additions & 6 deletions src/pyfunc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl PyVariable {
let field = Arc::new(Field::new("item", DataType::Boolean, false));
DataType::FixedSizeList(field, tensor_type.size() as i32)
}
ExpandDtype::ArrayFloat64 { tensor_type } => {
ExpandDtype::ArrayFloat64 { tensor_type: _ } => {
let field = Arc::new(Field::new("item", DataType::Float64, true));
DataType::List(field)
}
Expand Down Expand Up @@ -303,11 +303,11 @@ impl ExpandDtype {
#[getter]
fn shape(&self) -> Option<Vec<usize>> {
match self {
Self::BooleanArray {tensor_type} => { Some(tensor_type.shape.iter().cloned().collect()) },
Self::ArrayFloat64 {tensor_type} => { Some(tensor_type.shape.iter().cloned().collect()) },
Self::ArrayFloat32 {tensor_type} => { Some(tensor_type.shape.iter().cloned().collect()) },
Self::ArrayInt64 {tensor_type} => { Some(tensor_type.shape.iter().cloned().collect()) },
_ => { None },
Self::BooleanArray { tensor_type } => Some(tensor_type.shape.iter().cloned().collect()),
Self::ArrayFloat64 { tensor_type } => Some(tensor_type.shape.iter().cloned().collect()),
Self::ArrayFloat32 { tensor_type } => Some(tensor_type.shape.iter().cloned().collect()),
Self::ArrayInt64 { tensor_type } => Some(tensor_type.shape.iter().cloned().collect()),
_ => None,
}
}
}
Expand Down
Loading