-
Notifications
You must be signed in to change notification settings - Fork 9
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
Sectoral Certainty Equivalent Calculations Undefined (Appear as 0.0 or -0.0) #68
Conversation
md_values = save_md ? Dict((region=r, sector=s) => Array{Float64}(undef, n, length(_damages_years)) for r in regions, s in sectors) : nothing | ||
cpc_values = save_cpc ? Dict((region=r, sector=s) => Array{Float64}(undef, n, length(_damages_years)) for r in [:globe], s in [:total]) : nothing # just global and total for now | ||
|
||
norm_cpc_values_ce = certainty_equivalent ? Dict((region=r, sector=s, ew=dr.ew, ew_norm_region=dr.ew_norm_region) => Vector{Float64}(undef, n) for dr in discount_rates, r in regions, s in [:total]) : nothing |
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.
Remove dr_label
, prtp
, and eta
from the NamedTuple
s used as keys for the norm_cpc_values_ce
Dictionary element.
@@ -518,7 +534,7 @@ function post_trial_func(mcs::SimulationInstance, trialnum::Int, ntimesteps::Int | |||
intermediate_ce_scc = sum(df_ce .* total_mds[year_index:last_year_index]) | |||
intermediate_ce_scc_values[(region=:globe, sector=:total, dr_label=dr.label, prtp=dr.prtp, eta=dr.eta, ew=dr.ew, ew_norm_region=dr.ew_norm_region)][trialnum] = intermediate_ce_scc | |||
|
|||
norm_cpc_values_ce[(region=:globe, sector=:total, dr_label=dr.label, prtp=dr.prtp, eta=dr.eta, ew=dr.ew, ew_norm_region=dr.ew_norm_region)][trialnum] = cpc[year_index] | |||
norm_cpc_values_ce[(region=:globe, sector=:total, ew=dr.ew, ew_norm_region=dr.ew_norm_region)][trialnum] = cpc[year_index] |
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.
Remove fields from the NamedTuple
used as the key for norm_cpc_values_ce
Dictionary, we don't use these anymore as they create redundancy
@@ -676,7 +704,7 @@ function post_trial_func(mcs::SimulationInstance, trialnum::Int, ntimesteps::Int | |||
|
|||
if options.certainty_equivalent | |||
intermediate_ce_scc_values[(region=:globe, sector=:total, dr_label=dr.label, prtp=dr.prtp, eta=dr.eta, ew=dr.ew, ew_norm_region=dr.ew_norm_region)][trialnum] = total_utils | |||
norm_cpc_values_ce[(region=:globe, sector=:total, dr_label=dr.label, prtp=dr.prtp, eta=dr.eta, ew=dr.ew, ew_norm_region=dr.ew_norm_region)][trialnum] = base[pc_gdp_component_name, :pc_gdp][year_index,normalization_region_index] | |||
norm_cpc_values_ce[(region=:globe, sector=:total, ew=dr.ew, ew_norm_region=dr.ew_norm_region)][trialnum] = base[pc_gdp_component_name, :pc_gdp][year_index,normalization_region_index] |
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.
Remove fields from the NamedTuple
used as the key for norm_cpc_values_ce
Dictionary, we don't use these anymore as they create redundancy
src/scc.jl
Outdated
@@ -795,7 +830,7 @@ function post_trial_func(mcs::SimulationInstance, trialnum::Int, ntimesteps::Int | |||
|
|||
if options.certainty_equivalent | |||
intermediate_ce_scc_values[(region=:globe, sector=:total, dr_label=dr.label, prtp=dr.prtp, eta=dr.eta, ew=dr.ew, ew_norm_region=dr.ew_norm_region)][trialnum] = total_utils | |||
norm_cpc_values_ce[(region=:globe, sector=:total, dr_label=dr.label, prtp=dr.prtp, eta=dr.eta, ew=dr.ew, ew_norm_region=dr.ew_norm_region)][trialnum] = base[pc_gdp_component_name, :pc_gdp][year_index,normalization_region_index] | |||
norm_cpc_values_ce[(region=:globe, sector=:total, dr_label=dr.label, prtp=dr.prtp, eta=dr.eta, ew=dr.ew, ew_norm_region=dr.ew_norm_region)][trialnum] = base[net_cpc_component_name, :net_cpc][year_index,normalization_region_index] |
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.
Remove fields from the NamedTuple used as the key for norm_cpc_values_ce Dictionary, we don't use these anymore as they create redundancy AND bug fix to indexing with net_cpc instead of gdp
cpc_in_year_of_emission = norm_cpc_values_ce[k] | ||
|
||
# new key using all the same fields except making sector total | ||
k_sector_total = (region=k.region, sector=:total, ew=k.ew, ew_norm_region=k.ew_norm_region) |
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.
Create the slimmed-down key we will use for norm_cpc_values_ce
Dictionary
Ok @davidanthoff ready for review, I added in some testing and also fixes to comments and the README, but the only actual functional changes happen in |
Handles #67
The
norm_cpc_values_ce
in the payload had elements for eachs in sectors
, which were initialized toundef
, never filled in after that, and then accessed when computing certainty equivalent SCCs. That meant sectoral certainty equivalent SCCs often appeared as0.0
or-0.0
because of dividing by a very large or very small Float (the initialization number).Practically we used the full NamedTuple key for lookup ease, but there is no difference between sectors for
norm_cpc_values_ce
as we just use thetotal
sector for each one to look up the consumption per capita. The only unique characteristics are actually (1)region
(2)ew
and (3)ew_norm_region
.I think we should probably allocate only
norm_cpc_values_ce = certainty_equivalent ? Dict((region=r, sector=s, ew=dr.ew, ew_norm_region=dr.ew_norm_region) => Vector{Float64}(undef, n) for dr in discount_rates, r in regions, s in [:total]) : nothing
and use only those NamedTuple keys for saving the data needed for equity weighting.
To do:
skipmissing
-- throw a warning for visibility