コード例 #1
0
ファイル: 04_run_gpr.py プロジェクト: zhouxm4/ihme-modeling
                'superregional': 1,
                'regional': 2,
                'national': 3
            }

            if amp in mad_lvl_map.keys():
                amp = sdata["mad_level_%s" %
                            mad_lvl_map[amp]].unique()[0] * 1.4826
            else:
                amp = float(amp)

            # Run GPR
            fit = gpr.fit_gpr(sdata,
                              amp,
                              obs_variable='ln_dr',
                              obs_var_variable='data_var',
                              scale=5,
                              draws=0,
                              diff_degree=2)
            """
            Convert back to normal space

                Approximate back-transformed variance using the delta method:
                G(X) = G(mu) + (X-mu)G'(mu) (approximately)
                Var(G(X)) = Var(X)*[G'(mu)]^2 (approximately)

                Examples:
                    For G(X) = Invlogit(X)
                    ... Invlogit'(p) = e^x/[(e^x+1)^2]
                    ... so Var(Logit(X)) = Var(X) * e^2x / [(e^x+1)^4]
                    For G(X) = exp(X)
コード例 #2
0
ファイル: gpr.py プロジェクト: zhusui/ihme-modeling
## Set Scale
scale = int(params['gpr_scale'])

## If parallel, subset
if parallel == 1:
    df = df.loc[(df.location_id >= loc_start) & (df.location_id <= loc_end)]

#################################
### Run GPR
#################################

groups = df.groupby(by=['location_id', 'sex_id', 'age_group_id'])
df = groups.apply(lambda x: gpr.fit_gpr(x,
                                        obs_variable='data',
                                        obs_var_variable='variance',
                                        mean_variable='st',
                                        amp=x['st_amp'].values[0] * 1.4826,
                                        scale=scale,
                                        draws=draws))

#################################
### Save
#################################

## Clean
if draws == 0:
    df = df[[
        'location_id', 'year_id', 'age_group_id', 'sex_id', 'gpr_mean',
        'gpr_lower', 'gpr_upper'
    ]]
else: