gcubed.data.database_validator

This class validates the database of a G-Cubed model by checking the consistency of various variables and their relationships.

class DatabaseValidator(gcubed.base.Base):

Overview

Provides convenience methods for all classes.

All G-Cubed classes inherit from this base class.

DatabaseValidator( model_configuration: gcubed.model_configuration.ModelConfiguration, sym_data: gcubed.sym_data.SymData, parameters: gcubed.model_parameters.parameters.Parameters, data: pandas.DataFrame, results_folder: pathlib.Path = None, log_differences: bool = False)

Overview

Initialize the DatabaseValidator class by setting the model property.

Arguments

  • model_configuration : An instance of ModelConfiguration containing the model configuration.
  • sym_data : An instance of SymData containing the symbolic data for the model.
  • parameters : An instance of Parameters containing the model parameters.
  • data : A DataFrame containing the model self.data.
  • results_folder : The folder where the results will be saved. Defaults to None.
  • log_differences : A boolean indicating whether to log differences as they are found. Defaults to False.

Exceptions

  • AssertionError : If the input parameters are not valid.

  • AssertionError : If the data is empty or does not contain valid year columns.

results_folder: pathlib.Path

Overview

Get the results folder where the validation results will be saved.

Returns

  • Path : The path to the results folder.
log_differences: bool

Overview

Check if differences should be logged.

Returns

  • bool : True if differences should be logged, False otherwise.
save_results: bool

Overview

Check if the results should be saved.

Returns

  • bool : True if the results folder is set, False otherwise.

Overview

Get the model configuration.

Returns

  • ModelConfiguration : The model configuration of the G-Cubed model.

Overview

Get the symbolic data property of the model.

Returns

  • SymData : The symbolic data of the G-Cubed model.

Overview

Get the parameters property of the model.

Returns

  • Parameters : The parameters of the G-Cubed model.
data: pandas.DataFrame

Overview

Get the data to be validated.

Returns

  • pd.DataFrame : The data of the G-Cubed model.
first_year: str

Overview

Get the first year of the data.

Returns

  • str : The first year of the G-Cubed model data.
last_year: str

Overview

Get the last year of the data.

Returns

  • str : The last year of the G-Cubed model data.
all_years: List[str]

Overview

Get the years of the data.

Returns

  • List[str] : The self.years of the G-Cubed model data.
all_years_except_first: List[str]

Overview

Get all years except the first.

Returns

  • List[str] : The self.t_plus_1_years of the G-Cubed model data.
all_years_except_last: List[str]

Overview

Get all years except the last

Returns

  • List[str] : The self.t_minus_1_years of the G-Cubed model data.
names: pandas.Index

Overview

Get the names of the data index.

Returns

  • pd.Index : The names of the G-Cubed model data index.
def matching_variables(self, prefix: str) -> pandas.Index:

Overview

Get the names of the data index that match a given prefix.

Arguments

  • prefix : The prefix to match against the data index names.

Returns

  • pd.Index : The names of the G-Cubed model data index that match the prefix.
def has_variables_with_prefix(self, prefix: str) -> bool:

Overview

Check if the data contains variables that match a given prefix.

Arguments

  • prefix : The prefix to match against the data index names.

Returns

  • bool : True if the variables are in the model and in the data, False otherwise.
def has_all_parameters(self, parameter_names: List[str]) -> bool:

Overview

Check if the model has all the specified parameters.

Arguments

  • parameter_names : A list of parameter names to check.

Returns

  • bool : True if all parameters are present, False otherwise.
def has_all_variables(self, variable_prefixes: List[str]) -> bool:

Overview

Check if the data contains variables with each of the prefixes.

Arguments

  • variable_prefixes : A list of prefixes to match against the data index names.

Returns

  • bool : True if all prefixes are matched to variables.
def variable_data(self, prefix: str, years: List[str]) -> pandas.DataFrame:

Overview

Get the data for a specific variable prefix and years.

Arguments

  • prefix : The prefix of the variable to match against the data index names.
  • years : The years for which to retrieve the data.

Returns

  • pd.DataFrame : The data for the specified variable prefix and years.
def check_equality( self, a: pandas.DataFrame, b: pandas.DataFrame, atol=0.0001, rtol=0.0001) -> bool:

Overview

Check that the two dataframes are equal, within chosen levels of precision.

Arguments

  • a : The first dataframe to compare.
  • b : The second dataframe to compare.
  • atol : The absolute tolerance between the elements. Defaults to 1e-8.
  • rtol : The relative tolerance between the elements. Defaults to 1e-5.

Returns

  • True if the dataframes are equal.
zeros: pandas.DataFrame

Overview

Create a DataFrame with a single row containing zeros for each year in the model.

These are a useful benchmark for checking totals sum to zero.

Returns

A DataFrame with a single row named "ZEROS()" and columns for each year.

def validate_BOND_with_DEFI(self) -> bool:

Overview

lead(BOND) = DEFI + BOND*(1-labgrow) - PBAG ;

Returns

  • None : This function does not return anything, it only performs validation checks.
def validate_INV_with_TOB_and_TPA(self) -> bool:

Overview

```sym INV = ( (1+.5*(TOB-1))*(TOB-1)CAP/phi )forei + ( (1+.5(TPA-1))(TPA-1)CAP/phi )(1-forei) + SHKI ;

def validate_JNV_with_INV(self) -> bool:

Overview

JNV = ( INV + (phi/2)*(base_jk^2)*CAP )/(1+phi*base_jk) ;
def validate_CAP_with_JNV(self) -> bool:

Overview

Check capital accumulation

lead(CAP) = JNV + (1-delta-labgrow)*CAP
def validate_TOB_with_LAM(self) -> bool:

Overview

TOB  = LAM  * exp(PRID-PRII) / (1-TITC) ;
def validate_TPA_with_TOB(self) -> bool:

Overview

lead(TPA)  = TPA  + adapt*( TOB  - TPA  ) ;
def validate_PRII(self) -> bool:

Overview

Region-wide price paid by the sectors for raw capital.

PRII = cd_oR*( delta_oR(k)*PRKY
            + delta_oR(l)*WAGE
            + delta_oR(e)*PRIE
            + delta_oR(m)*PROI
            - delta_oR(l)*SHLY
            )
    + (1-cd_oR)*ln( delta_oR(k)*exp(PRKY     )^(1-sigma_oR)
                + delta_oR(l)*exp(WAGE-SHLY)^(1-sigma_oR)
                + delta_oR(e)*exp(PRIE)^(1-sigma_oR)
                + delta_oR(m)*exp(PROI     )^(1-sigma_oR)
                ) / (1-sigma_oR*(1-cd_oR))
    - SHYY ;
def validate_ASSE(self) -> bool:

Overview

Validate the ASSE variable in the G-Cubed model database by checking its consistency with other variables.

lead(ASSE) = ASSE*( 1-labgrow(owner) ) + ( ashr*ABUY + aeye*(CURR(owner)-ABUY) ) / exp(REXN(currency)) ;
def validate_TBAL(self) -> bool:

Overview

Check that the TBAL variables summed across regions equal zero.

def validate_TBAU(self) -> bool:

Overview

Check that the TBAU variables summed across regions equal zero.

def validate_IRAS(self) -> bool:

Overview

Check that the IRAS variables summed across regions equal zero.

def validate_CURR(self) -> bool:

Overview

Check that the CURR variables summed across regions equal zero.

def validate_CURN(self) -> bool:

Overview

Check that the CURN variables summed across regions equal zero.

def validate_EXQT_with_IMQT(self) -> bool:

Overview

Check that the sum of the EXQT values across regions equals the sum of the IMQT values across regions

def validate_IMQT_with_IMQ(self) -> bool:

Overview

Check that the sum of the IMQ values across goods equals IMQT value for a region

def validate_WAGE_with_WAGG(self) -> bool:

Overview

Check that

WAGE == WAGG
def validate_PRCT(self) -> bool:

Overview

def validate_PRID_with_PRDL(self) -> bool:

Overview

def validate_PRCO_with_PRCOL(self) -> bool:

Overview

Validate the PRCO variable in the G-Cubed model database by checking its consistency with other variables.

def validate_INTF_with_INTN_and_PRID(self) -> bool:

Overview

INTF = INTN - (lead(log(PRID)) - log(PRID))

def validate_INTR_with_INTF(self) -> bool:

Overview

Check that INTR and INTF are equal.

def validate_INFP_with_PRID(self) -> bool:

Overview

Validate the INFP variable.

INFP = 100 * (log(PRID) - log(PRDL))
def validate_INFL_with_PRCT(self) -> bool:

Overview

Validate the INFL variable in the G-Cubed model database by checking its consistency with other variables.

def validate_INFL_with_INFP(self) -> bool:

Overview

def validate_INFL_with_INFCL(self) -> bool:

Overview

Check similarity of INFL and INFCL inflation rates

def validate_INFCL_with_PRCO(self) -> bool:

Overview

Validate the INFCL variable in the G-Cubed model database by checking its consistency with other variables.

def validate_INFP_with_INFCL(self) -> bool:

Overview

Validate the INFP variable in the G-Cubed model database by checking its consistency with other variables.

def validate_WAGE_INFLATION(self) -> bool:

Overview

Validate the WAGE_INFLATION variable in the G-Cubed model database by checking its consistency with other variables.

def validate_OUTP_with_OUTL(self) -> bool:

Overview

Validate the OUTP variable in the G-Cubed model database by checking its consistency with other variables.

def validate_LAM(self) -> bool:

Overview

LEAD(LAM) = (1+INTR+RISE+delta)*LAM
          - (1-TCOR)*(PRK/PRID)
          - (1-TITC)*(PRII/PRID)*(phi/2)*(JNV/CAP)^2 ;
def validate_EPRC_with_INFL(self) -> bool:
def validate_EPRC_with_PRCT(self) -> bool:

Overview

EPRC = lead(PRCT) - PRCT
def validate_EYGR_with_OUTP(self) -> bool:

Overview

Validate the EYGR variable in the G-Cubed model database by checking its consistency with other variables.

EYGR = 100 * (log(lead(OUTP)) - log(OUTP))
def validate_WELH(self) -> bool:

Overview

Validate the WELH variable in the G-Cubed model database by checking its consistency with other variables.

lead(WELH) = (
       (1 + RISW + RISH + INTR - labgrow)*WELH
     - TRAN
     + TAXH
     + TAXL
     - ( exp(WAGE)*(IITL+CNPL) + exp(WAGG)*GOVL + sum(sec_std,exp(WAG)*LAB) ) / exp(PRID)
  ) ;
def validate_OUTPEUR_with_OUTP(self) -> bool:

Overview

OUTPEUR = (sum(regions,OUTP)) ;
def validate_OUTPEUR_with_OUTLEUR(self) -> bool:

Overview

lead(OUTLEUR) = OUTPEUR ;
def validate_EYGREUR_with_OUTPEUR(self) -> bool:

Overview

EYGREUR = ln(lead(OUTPEUR)) - ln(OUTPEUR) ;
def validate_INFLEUR_WITH_INFL(self) -> bool:

Overview

INFLEUR = sum(regions,eurowt*INFL) ;
def validate_ROGYEUR_WITH_ROGY(self) -> bool:

Overview

ROGYEUR = sum(regions,eurowt*ROGY) ;
def validate_PRCTEUR_WITH_PRCT(self) -> bool:

Overview

PRCTEUR = (sum(regions,eurowt*PRCT)) ;
def validate_PRCTEUR_with_PRCEURL(self) -> bool:

Overview

lead(PRCEURL) = PRCTEUR ;
def validate_PRIDEUR_WITH_PRID(self) -> bool:

Overview

PRIDEUR = (sum(regions,eurowt*PRID)) ;
def validate_PRIDEUR_with_PRDEURL(self) -> bool:

Overview

lead(PRDEURL) = PRIDEUR ;
def validate_INFPEUR_WITH_INFP(self) -> bool:

Overview

INFPEUR = sum(regions,eurowt*INFP) ;
def validate_INFCLEUR_WITH_INFCL(self) -> bool:

Overview

INFCLEUR = sum(regions,eurowt*INFCL) ;
def validate_EPRCEUR_with_OUTPEUR(self) -> bool:

Overview

EPRCEUR =  lead(PRCTEUR)-PRCTEUR ;
def validate_NGOEUR_with_OUTP_and_PRID_and_TBAL(self) -> bool:

Overview

NGOEUR = ln( sum(regions, eurowt * ( (OUTP-TBAL)*exp(PRID) ) ) ) ;
def validate_all_relationships(self):

Overview

Validate the G-Cubed model database by checking the consistency of various variables and their relationships.

def validate_european_variables(self):

Overview

Validate the European variables in the G-Cubed model database by checking their relationships and consistency.

def generate_investment_to_capital_ratios_by_sector(self):

Overview

Generate investment to capital ratios by sector for the G-Cubed model database.

The values are to be interpreted as percentages, so they are multiplied by 100. A value of 10 means that investment is 10% of capital.

This function calculates the investment to capital ratios for each sector in the G-Cubed model database. It uses the investment (INV) and capital (CAP) variables to compute the ratios and stores them in a new variable.

def generate_investment_to_capital_ratio_for_raw_capital_sector(self):
def generate_output_to_domestic_output_ratios_by_sector(self):

Overview

Generate output to domestic output ratios by sector for the G-Cubed model database.

The values are to be interpreted as percentages, so they are multiplied by 100. A value of 10 means that output is 10% of domestic output.

This function calculates the output to domestic output ratios for each sector in the G-Cubed model database. It uses the output (OUTP) and domestic output (OUTD) variables to compute the ratios and stores them in a new variable.

Values should be greater than 100 %.

def generate_investment_to_capital_ratio_for_households(self):
def generate_database_metrics(self):

Overview

Generate metrics for the G-Cubed model database to assess the consistency and relationships of various variables.