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

Implement dependent parameters feature for FreeParameters #271

Merged
merged 20 commits into from Jun 9, 2022

Conversation

glwagner
Copy link
Member

@glwagner glwagner commented Jun 2, 2022

Usage is something like

priors = (a=Normal(0, 1), b=Normal(0, 1)) # free parameters
c(p) = p.a + p.b # compute a third dependent parameter `c` as a function of `a` and `b`
parameters = FreeParameters(priors, dependent_parameters=(; c))

Closes #269

@glwagner glwagner requested a review from navidcy June 4, 2022 18:36
Copy link
Collaborator

@navidcy navidcy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create another simple example in FreeParameters docstring that demonstrates the dependent_parameters kwarg?


observation_map(::VectorNormMap, observations) = reshape([0], 1, 1)
output_map_str(::ConcatenatedVectorNormMap) = "ConcatenatedVectorNormMap"
observation_map(::ConcatenatedVectorNormMap, observations) = reshape([0], 1, 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit further down there is a redefinition of this method:

observation_map(map::ConcatenatedVectorNormMap, observations) = hcat(0.0)

which one we want?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it because of this that docs fail?

** incremental compilation may be fatally broken for this module **

@navidcy
Copy link
Collaborator

navidcy commented Jun 5, 2022

We also need to update show(io::IO, p::FreeParameters)

@navidcy
Copy link
Collaborator

navidcy commented Jun 5, 2022

I gave it a crack but it could be done better :)

julia> priors == Normal(1e-4, 1e-5), κ = Normal(1e-3, 1e-5))
(ν = Normal{Float64}=0.0001, σ=1.0e-5), κ = Normal{Float64}=0.001, σ=1.0e-5))

julia> free_parameters = FreeParameters(priors)
FreeParameters with 2 parameters
├── names: (, )
├── priors: Dict{Symbol, Any}
│   ├── ν => Normal{Float64}=0.0001, σ=1.0e-5)
│   └── κ => Normal{Float64}=0.001, σ=1.0e-5)
└── dependent parameters: Dict{Symbol, Any}

julia> c(p) = p.ν + p.κ # compute a third dependent parameter `c` as a function of `ν` and `κ`
c (generic function with 1 method)

julia> free_parameters_with_a_dependent = FreeParameters(priors, dependent_parameters=(; c))
FreeParameters with 2 parameters and 1 dependent parameters
├── names: (, )
├── priors: Dict{Symbol, Any}
│   ├── ν => Normal{Float64}=0.0001, σ=1.0e-5)
│   └── κ => Normal{Float64}=0.001, σ=1.0e-5)
└── dependent parameters: Dict{Symbol, Any}
    └── c => c

@navidcy
Copy link
Collaborator

navidcy commented Jun 5, 2022

@navidcy
Copy link
Collaborator

navidcy commented Jun 5, 2022

I gave it a crack but it could be done better :)

julia> priors == Normal(1e-4, 1e-5), κ = Normal(1e-3, 1e-5))
(ν = Normal{Float64}=0.0001, σ=1.0e-5), κ = Normal{Float64}=0.001, σ=1.0e-5))

julia> free_parameters = FreeParameters(priors)
FreeParameters with 2 parameters
├── names: (, )
├── priors: Dict{Symbol, Any}
│   ├── ν => Normal{Float64}=0.0001, σ=1.0e-5)
│   └── κ => Normal{Float64}=0.001, σ=1.0e-5)
└── dependent parameters: Dict{Symbol, Any}

julia> c(p) = p.ν + p.κ # compute a third dependent parameter `c` as a function of `ν` and `κ`
c (generic function with 1 method)

julia> free_parameters_with_a_dependent = FreeParameters(priors, dependent_parameters=(; c))
FreeParameters with 2 parameters and 1 dependent parameters
├── names: (, )
├── priors: Dict{Symbol, Any}
│   ├── ν => Normal{Float64}=0.0001, σ=1.0e-5)
│   └── κ => Normal{Float64}=0.001, σ=1.0e-5)
└── dependent parameters: Dict{Symbol, Any}
    └── c => c

it'd be nice if we can print something related to the dependent parameters... but I don't know what? if c was defined as a function then there is nothing to print out...

@glwagner
Copy link
Member Author

glwagner commented Jun 5, 2022

it'd be nice if we can print something related to the dependent parameters... but I don't know what? if c was defined as a function then there is nothing to print out...

we can use Oceananigans' prettysummary to print function information. But as you say this doesn't give much additional info; it just prints the name of the function and optionally how many methods are defined for it.

@navidcy
Copy link
Collaborator

navidcy commented Jun 8, 2022

I'll try to build the docs locally to see if I run into same issue(s).

@navidcy navidcy self-requested a review June 8, 2022 23:51
@navidcy navidcy added the 🤥 enhancement New feature or request label Jun 8, 2022
@navidcy navidcy merged commit c94bc6e into main Jun 9, 2022
@navidcy navidcy deleted the glw/dependent-parameters branch June 9, 2022 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤥 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Dependent parameters" feature for FreeParameters
2 participants