HydroCNHS.calibration package¶
Submodules¶
HydroCNHS.calibration.convertor module¶
-
class
HydroCNHS.calibration.convertor.
Convertor
¶ Bases:
object
-
gen_cali_inputs
(wd, df_list, par_bound_df_list, fixed_par_list=None)¶ Generate inputs dictionary required for calibration.
- wdstr
Working directory.
- df_listlist
A list of parameter dataframes. Dataframe index is parameter names.
- par_bound_df_listlist
A list of parameter bound dataframes.
- fixed_par_listlist, optional
A list contains a list of tuples of fixed parameter location like [([“CN2”], [“outlet1”, “outlet2”]), ([“b”], [“outlet1”])], by default None. The number of tuples in the list is corresponding to the number of dataframes.
- dict
Input for calibration.
-
gen_formatter
(df_list, fixed_par_list=None)¶ Generate formatter for given list of dataframe objects. This is already included in gen_cali_inputs().
- df_listlist
A list of parameter dataframes. Dataframe index is parameter names.
- fixed_par_listlist, optional
A list contains a list of tuples of fixed parameter location. For example, we want to fix par1 of outlet1 & 2 and all par2 in dataframe 1 and not to fix df2. We can input the following list, [[([“par1”], [“outlet1”, “outlet2”]), ([“par2”], [“:”])], []]. fixed_par_list is by default None. The number of lists in the list is corresponding to the number of dataframes.
- dict
formatter.
-
static
to_1D_array
(df_list, formatter)¶ Convert a list of dataframes to a 1D array.
- df_listlist
A list of parameter dataframes. Dataframe index is parameter names.
- formatterdict
Formatter, generated by gen_formatter or gen_cali_inputs. It is stored in attributes of the Convertor object.
- array
1D array.
-
static
to_df_list
(var_array, formatter)¶ Convert 1D array back to a list of dataframes.
- var_arrayarray
1D array.
- formatterdict
Formatter, generated by gen_formatter or gen_cali_inputs. It is stored in attributes of the Convertor object.
- list
A list of dataframes.
-
HydroCNHS.calibration.ga_deap module¶
-
class
HydroCNHS.calibration.ga_deap.
GA_DEAP
(evaluation_func, rn_gen=None)¶ Bases:
object
-
auto_save
()¶
-
find_best_and_record
(pop)¶
-
gen_rn_gens
(seed, size)¶
-
load
(GA_auto_save_file, max_gen=None)¶ Load save pickle file (i.e., continue previous run).
- GA_auto_save_filestr
Filename.
- max_genint, optional
This allow user to increase max_gen for continuing calibration for a longer searching, by default None.
-
run
(guess_pop=None)¶ Run calibration.
- guess_pop2darray, optional
Assigned initial guesses, by default None. guess_pop has the size = [number of guesses, number of parameters]
-
run_individual
(individual='best', name='best')¶ Run the evaluation for a given individual.
Warning! run_individual() does not generantee the same rn_gen will be assign to the evaluation, but the same one will be used for run_individual()
- individual1darray, optional
Individual or solution, by default “best”.
- namestr, optional
This will be sent to the evaluation function through info = (cali_wd, name, name, formatter, rn_gen), by default “best”.
-
set
(inputs, config, formatter=None, name='Calibration')¶ Setup the GA calibration.
- inputsdict
Calibration input dictionary generated by Convertor. Or, get the template by calling get_inputs_template().
- configdict
Calibration configuration dictionary. Get the template by calling get_config_template().
- formatterdict, optional
Formatter generated by Convertor, by default None.
- namestr, optional
Name of the calibration, by default “Calibration”.
-
-
HydroCNHS.calibration.ga_deap.
cxUniform
(ind1, ind2, indpb, rn_gen_gen)¶
-
HydroCNHS.calibration.ga_deap.
descale
(individual, bound_scale, lower_bound)¶ individual is 1d ndarray.
-
HydroCNHS.calibration.ga_deap.
gen_init_pop
(creator, size, method='LHC', guess_pop=None, rn_gen_gen=None)¶
-
HydroCNHS.calibration.ga_deap.
logger
= <Logger HydroCNHS.GA (INFO)>¶ - inputs = {“par_name”: [“a”,”b”,”c”],
“par_bound”: [[0,1],[0,1],[0,1]], “wd”: r””}
- config = {“min_or_max”: “min”,
“pop_size”: 100, “num_ellite”: 1, “prob_cross”: 0.5, “prob_mut”: 0.1, “stochastic”: False, “max_gen”: 100, “sampling_method”: “LHC”, “drop_record”: False, “paral_cores”: -1, “paral_verbose”: 1, “auto_save”: True, “print_level”: 10, “plot”: True }
-
HydroCNHS.calibration.ga_deap.
mut_middle
(individual, p1, p2, prob_mut, rn_gen_gen)¶
-
HydroCNHS.calibration.ga_deap.
mut_uniform
(individual, prob_mut, rn_gen_gen)¶
-
HydroCNHS.calibration.ga_deap.
sample_by_LHC
(size, rn_gen_gen)¶
-
HydroCNHS.calibration.ga_deap.
sample_by_MC
(size, rn_gen_gen)¶
-
HydroCNHS.calibration.ga_deap.
scale
(individual, bound_scale, lower_bound)¶ individual is 1d ndarray.
-
HydroCNHS.calibration.ga_deap.
selRoulette
(individuals, k, rn_gen_gen, fit_attr='fitness')¶