-
Notifications
You must be signed in to change notification settings - Fork 17
Add grouped covariance input to get_statistics and optimize determine_efficient_order #181
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
Changes from 7 commits
03ccde1
effc713
6f3e155
ae7e893
db09540
6ad2404
2ff0804
e949bfd
18d77b5
8bc6672
093b24d
a13fd2d
291bf89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3207,7 +3207,7 @@ If occasionally binding constraints are present in the model, they are not taken | |
| - `mean` [Default: `Symbol[]`, Type: `Union{Symbol_input,String_input}`]: variables for which to show the mean of selected variables (the mean for the linearised solution is the NSSS). Inputs can be a variable name passed on as either a `Symbol` or `String` (e.g. `:y` or \"y\"), or `Tuple`, `Matrix` or `Vector` of `String` or `Symbol`. Any variables not part of the model will trigger a warning. `:all_excluding_auxiliary_and_obc` contains all shocks less those related to auxiliary variables and related to occasionally binding constraints (obc). `:all_excluding_obc` contains all shocks less those related to auxiliary variables. `:all` will contain all variables. | ||
| - `standard_deviation` [Default: `Symbol[]`, Type: `Union{Symbol_input,String_input}`]: variables for which to show the standard deviation of selected variables. Inputs can be a variable name passed on as either a `Symbol` or `String` (e.g. `:y` or \"y\"), or `Tuple`, `Matrix` or `Vector` of `String` or `Symbol`. Any variables not part of the model will trigger a warning. `:all_excluding_auxiliary_and_obc` contains all shocks less those related to auxiliary variables and related to occasionally binding constraints (obc). `:all_excluding_obc` contains all shocks less those related to auxiliary variables. `:all` will contain all variables. | ||
| - `variance` [Default: `Symbol[]`, Type: `Union{Symbol_input,String_input}`]: variables for which to show the variance of selected variables. Inputs can be a variable name passed on as either a `Symbol` or `String` (e.g. `:y` or \"y\"), or `Tuple`, `Matrix` or `Vector` of `String` or `Symbol`. Any variables not part of the model will trigger a warning. `:all_excluding_auxiliary_and_obc` contains all shocks less those related to auxiliary variables and related to occasionally binding constraints (obc). `:all_excluding_obc` contains all shocks less those related to auxiliary variables. `:all` will contain all variables. | ||
| - `covariance` [Default: `Symbol[]`, Type: `Union{Symbol_input,String_input}`]: variables for which to show the covariance of selected variables. Inputs can be a variable name passed on as either a `Symbol` or `String` (e.g. `:y` or \"y\"), or `Tuple`, `Matrix` or `Vector` of `String` or `Symbol`. Any variables not part of the model will trigger a warning. `:all_excluding_auxiliary_and_obc` contains all shocks less those related to auxiliary variables and related to occasionally binding constraints (obc). `:all_excluding_obc` contains all shocks less those related to auxiliary variables. `:all` will contain all variables. | ||
| - `covariance` [Default: `Symbol[]`, Type: `Union{Symbol_input,String_input}`]: variables for which to show the covariance of selected variables. Inputs can be a variable name passed on as either a `Symbol` or `String` (e.g. `:y` or \"y\"), or `Tuple`, `Matrix` or `Vector` of `String` or `Symbol`. For grouped covariance computation, pass a `Vector` of `Vector`s (e.g. `[[:y, :c], [:k, :i]]`) to compute covariances only within each group, returning a vector of covariance matrices. This allows more granular control over which covariances to compute. Any variables not part of the model will trigger a warning. `:all_excluding_auxiliary_and_obc` contains all variables less those related to auxiliary variables and related to occasionally binding constraints (obc). `:all_excluding_obc` contains all variables less those related to occasionally binding constraints. `:all` will contain all variables. | ||
| - `autocorrelation` [Default: `Symbol[]`, Type: `Union{Symbol_input,String_input}`]: variables for which to show the autocorrelation of selected variables. Inputs can be a variable name passed on as either a `Symbol` or `String` (e.g. `:y` or \"y\"), or `Tuple`, `Matrix` or `Vector` of `String` or `Symbol`. Any variables not part of the model will trigger a warning. `:all_excluding_auxiliary_and_obc` contains all shocks less those related to auxiliary variables and related to occasionally binding constraints (obc). `:all_excluding_obc` contains all shocks less those related to auxiliary variables. `:all` will contain all variables. | ||
| - `autocorrelation_periods` [Default: `1:5`, Type = `UnitRange{Int}`]: periods for which to return the autocorrelation of selected variables | ||
| - $ALGORITHM® | ||
|
|
@@ -3243,6 +3243,12 @@ get_statistics(RBC, RBC.parameter_values, parameters = RBC.parameters, standard_ | |
| # output | ||
| Dict{Symbol, AbstractArray{Float64}} with 1 entry: | ||
| :standard_deviation => [0.0266642, 0.264677, 0.0739325, 0.0102062] | ||
|
|
||
| # For grouped covariance (computing covariances only within specified groups): | ||
| get_statistics(RBC, RBC.parameter_values, covariance = [[:c, :k], [:q]]) | ||
|
||
| # output | ||
| Dict{Symbol, AbstractArray{Float64}} with 1 entry: | ||
| :covariance => Matrix{Float64}[[...2x2 covariance matrix for c and k...], [...1x1 matrix for q...]] | ||
| ``` | ||
| """ | ||
| function get_statistics(𝓂, | ||
|
|
@@ -3283,6 +3289,10 @@ function get_statistics(𝓂, | |
| var_var_idx = @ignore_derivatives parse_variables_input_to_index(variance, 𝓂.timings) | ||
|
|
||
| covar_var_idx = @ignore_derivatives parse_variables_input_to_index(covariance, 𝓂.timings) | ||
|
|
||
| # Check if covariance is grouped and parse groups | ||
| is_grouped_covar = @ignore_derivatives is_grouped_covariance_input(covariance) | ||
|
||
| covar_groups = @ignore_derivatives is_grouped_covar ? parse_covariance_groups(covariance, 𝓂.timings) : nothing | ||
|
|
||
| autocorr_var_idx = @ignore_derivatives parse_variables_input_to_index(autocorrelation, 𝓂.timings) | ||
|
|
||
|
|
@@ -3405,8 +3415,31 @@ function get_statistics(𝓂, | |
|
|
||
| # droptol!(covar_dcmp_sp,eps(Float64)) | ||
|
|
||
| # push!(ret,covar_dcmp_sp[covar_var_idx,covar_var_idx]) | ||
| ret[:covariance] = solved ? covar_dcmp_sp[covar_var_idx,covar_var_idx] : fill(Inf * sum(abs2,parameter_values),isnothing(covar_var_idx) ? 0 : length(covar_var_idx), isnothing(covar_var_idx) ? 0 : length(covar_var_idx)) | ||
| if is_grouped_covar | ||
| # Extract only the specified covariance groups (block diagonal structure) | ||
| if solved | ||
| # Return a vector of covariance matrices, one for each group | ||
| covar_result = Vector{Matrix{T}}(undef, length(covar_groups)) | ||
|
|
||
| for (i, group) in enumerate(covar_groups) | ||
| covar_result[i] = covar_dcmp_sp[group, group] | ||
| end | ||
|
|
||
| ret[:covariance] = covar_result | ||
| else | ||
| # Return vector of Inf-filled matrices | ||
| covar_result = Vector{Matrix{T}}(undef, length(covar_groups)) | ||
| for (i, group) in enumerate(covar_groups) | ||
| group_size = length(group) | ||
| covar_result[i] = fill(Inf * sum(abs2,parameter_values), group_size, group_size) | ||
| end | ||
| ret[:covariance] = covar_result | ||
| end | ||
| else | ||
| # Original behavior for non-grouped input | ||
| # push!(ret,covar_dcmp_sp[covar_var_idx,covar_var_idx]) | ||
| ret[:covariance] = solved ? covar_dcmp_sp[covar_var_idx,covar_var_idx] : fill(Inf * sum(abs2,parameter_values),isnothing(covar_var_idx) ? 0 : length(covar_var_idx), isnothing(covar_var_idx) ? 0 : length(covar_var_idx)) | ||
| end | ||
| end | ||
| if !(autocorrelation == Symbol[]) | ||
| # push!(ret,autocorr[autocorr_var_idx,:] ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot also allow for vector of tuples or tuples of tuples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added support for
Vector{Tuple{Symbol,Vararg{Symbol}}}andTuple{Tuple{Symbol,Vararg{Symbol}},Vararg{Tuple{Symbol,Vararg{Symbol}}}}(and their String equivalents). UpdatedSymbol_inputandString_inputtype definitions, and modifiedis_grouped_covariance_input,parse_covariance_groups, andparse_variables_input_to_indexto handle these formats. Commit: a13fd2d