CliMA / CliMA/EnsembleKalmanProcesses.jl

Finally remove anonymous functions in bounds

Open
#551 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
125
Forks
24
Avg merge
1d 18h
Merged PRs (30d)
5

Description

## Issue
The following construction of bounds is neat but leads to the primary instability of reconstructing EKP priors with JLD2 https://github.com/CliMA/EnsembleKalmanProcesses.jl/blob/4f777393f0e5946ac4ba556fa0ef5949530e0596/src/ParameterDistributions.jl#L176-L185

The reason this arises is a long time ago - there was an un-julia-like decision, which somehow lead to an avoidance of clear dispatch

## A possible solution (Dispatch)

Create the structs
```julia
struct BoundedAbove{FT} <: ConstraintType
upper_bound::FT
end
```
Create the methods
```julia
function c_to_u(c::BoundedAbove, x)
log(c.upper_bound - x)
end

function jacobian(c::BoundedAbove, x)
1.0 / (c.upper_bound - x)
end

function u_to_c(c::BoundedAbove, x)
c.upper_bound - exp(x)
end
```
This would need to be changed in just a few places (exclusively in ParameterDistributions.jl, and FunctionParameterDistributions.jl) where we explicitly call `c.c_to_u` e.g.,
https://github.com/CliMA/EnsembleKalmanProcesses.jl/blob/4f777393f0e5946ac4ba556fa0ef5949530e0596/src/ParameterDistributions.jl#L794-L802

It may also mean that `Constraint` will not be a parameterized type, but rather the abstract type

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in ParameterDistributions.jl, especially the bounds construction around lines 176-185 and the c.c_to_u calls around lines 794-802, then inspect the corresponding uses in FunctionParameterDistributions.jl. Replace the anonymous-function bounds with dispatch-based constraint structs and methods, while preserving reconstruction of EKP priors with JLD2.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.