def map_parameter_estimate(self): res = self.pst.res assert res is not None # build the prior expectation parameter vector prior_expt = self.pst.parameter_data.loc[:,["parval1"]].copy() islog = self.pst.parameter_data.partrans == "log" prior_expt.loc[islog] = prior_expt.loc[islog].apply(np.log10) prior_expt = Matrix.from_dataframe(prior_expt) prior_expt.col_names = ["prior_expt"] # build the residual vector res_vec = Matrix.from_dataframe(res.loc[:,["residual"]]) # form the terms of Schur's complement b = self.parcov * self.jco.T c = ((self.jco * self.parcov * self.jco.T) + self.obscov).inv bc = Matrix((b * c).x, row_names=b.row_names, col_names=c.col_names) # calc posterior expectation upgrade = bc * res_vec upgrade.col_names = ["prior_expt"] post_expt = prior_expt + upgrade # post processing - back log transform post_expt = pd.DataFrame(data=post_expt.x,index=post_expt.row_names, columns=["post_expt"]) post_expt.loc[:,"prior_expt"] = prior_expt.x.flatten() post_expt.loc[islog,:] = 10.0**post_expt.loc[islog,:] # unc_sum = self.get_parameter_summary() # post_expt.loc[:,"standard_deviation"] = unc_sum.post_var.apply(np.sqrt) post_expt.sort_index(inplace=True) return post_expt
def map_parameter_estimate(self): res = self.pst.res assert res is not None # build the prior expectation parameter vector prior_expt = self.pst.parameter_data.loc[:,["parval1"]].copy() islog = self.pst.parameter_data.partrans == "log" prior_expt.loc[islog] = prior_expt.loc[islog].apply(np.log10) prior_expt = Matrix.from_dataframe(prior_expt) prior_expt.col_names = ["prior_expt"] # build the residual vector res_vec = Matrix.from_dataframe(res.loc[:,["residual"]]) # form the terms of Schur's complement b = self.parcov * self.jco.T c = ((self.jco * self.parcov * self.jco.T) + self.obscov).inv bc = Matrix((b * c).x, row_names=b.row_names, col_names=c.col_names) # calc posterior expectation upgrade = bc * res_vec upgrade.col_names = ["prior_expt"] post_expt = prior_expt + upgrade # post processing - back log transform post_expt = pd.DataFrame(data=post_expt.x,index=post_expt.row_names, columns=["post_expt"]) post_expt.loc[:,"prior_expt"] = prior_expt.x.flatten() post_expt.loc[islog,:] = 10.0**post_expt.loc[islog,:] # unc_sum = self.get_parameter_summary() # post_expt.loc[:,"standard_deviation"] = unc_sum.post_var.apply(np.sqrt) post_expt.sort_index(inplace=True) return post_expt
def map_parameter_estimate(self): res = self.pst.res assert res is not None # build the prior expectation parameter vector prior_expt = self.pst.parameter_data.loc[:, ["parval1"]].copy() islog = self.pst.parameter_data.partrans == "log" prior_expt.loc[islog] = prior_expt.loc[islog].apply(np.log10) prior_expt = Matrix.from_dataframe(prior_expt) prior_expt.col_names = ["prior_expt"] # build the residual vector res_vec = Matrix.from_dataframe(res.loc[:, ["residual"]]) # form the terms of Schur's complement b = self.parcov * self.jco.T c = ((self.jco * self.parcov * self.jco.T) + self.obscov).inv bc = Matrix((b * c).x, row_names=b.row_names, col_names=c.col_names) # calc posterior expectation term2 = bc * res_vec term2.col_names = ["prior_expt"] post_expt = prior_expt + term2 # post processing - back log transform post_expt = pd.DataFrame(data=post_expt.x, index=post_expt.row_names, columns=["post_expt"]) post_expt.loc[islog, :] = 10.0**post_expt.loc[islog, :] return post_expt
def map_forecast_estimate(self): assert self.forecasts is not None maps = {} islog = self.pst.parameter_data.partrans == "log" par_map = self.map_parameter_estimate par_map.loc[islog, :] = np.log10(par_map.loc[islog, :]) par_map = Matrix.from_dataframe(par_map) for forecast in self.forecasts: fname = forecast.col_names[0] pr = self.pst.res.loc[fname, "modelled"] maps[forecast.col_names[0]] = pr + (forecast.T * par_map).x[0, 0] return maps
def map_forecast_estimate(self): assert self.forecasts is not None islog = self.pst.parameter_data.partrans == "log" par_map = self.map_parameter_estimate par_map.loc[islog,:] = np.log10(par_map.loc[islog,:]) par_map = Matrix.from_dataframe(par_map) posts,priors = [],[] for forecast in self.forecasts: fname = forecast.col_names[0] pr = self.pst.res.loc[fname,"modelled"] priors.append(pr) posts.append(pr + (forecast.T * par_map).x[0, 0]) return pd.DataFrame(data=np.array([priors,posts]).transpose(), columns=["prior_expt","post_expt"], index=self.forecast_names)
def map_forecast_estimate(self): assert self.forecasts is not None islog = self.pst.parameter_data.partrans == "log" par_map = self.map_parameter_estimate par_map.loc[islog,:] = np.log10(par_map.loc[islog,:]) par_map = Matrix.from_dataframe(par_map.loc[:,["post_expt"]]) posts,priors = [],[] post_expt = (self.predictions.T * par_map).to_dataframe() for fname in self.forecast_names: #fname = forecast.col_names[0] pr = self.pst.res.loc[fname,"modelled"] priors.append(pr) posts.append(pr + post_expt.loc[fname,"post_expt"]) return pd.DataFrame(data=np.array([priors,posts]).transpose(), columns=["prior_expt","post_expt"], index=self.forecast_names)
def map_forecast_estimate(self): """ get the prior and posterior forecast (prediction) expectations. Returns ------- pandas.DataFrame : pandas.DataFrame dataframe with prior and posterior forecast expected values """ assert self.forecasts is not None islog = self.pst.parameter_data.partrans == "log" par_map = self.map_parameter_estimate par_map.loc[islog,:] = np.log10(par_map.loc[islog,:]) par_map = Matrix.from_dataframe(par_map.loc[:,["post_expt"]]) posts,priors = [],[] post_expt = (self.predictions.T * par_map).to_dataframe() for fname in self.forecast_names: #fname = forecast.col_names[0] pr = self.pst.res.loc[fname,"modelled"] priors.append(pr) posts.append(pr + post_expt.loc[fname,"post_expt"]) return pd.DataFrame(data=np.array([priors,posts]).transpose(), columns=["prior_expt","post_expt"], index=self.forecast_names)