|
| | CGA () |
| | Default constructor.
|
| |
| virtual | ~CGA () |
| | Destructor.
|
| |
| | CGA (const CGA &C) |
| | Copy constructor.
|
| |
| CGA | operator= (CGA &C) |
| | Assignment operator.
|
| |
| | CGA (std::string filename, const T &model) |
| | Constructor from configuration file and model.
|
| |
| | CGA (T *model) |
| | Constructor from model pointer.
|
| |
| void | initialize () |
| | Initialize GA structures and allocate memory.
|
| |
| double | getfromoutput (std::string filename) |
| | Read best solution from previous output file.
|
| |
| void | getinifromoutput (std::string filename) |
| | Initialize population from previous output file.
|
| |
| void | getinitialpop (std::string filename) |
| | Read initial population from file.
|
| |
| int | optimize () |
| | Main optimization loop.
|
| |
| bool | SetProperty (const std::string &varname, const std::string &value) |
| | Set GA property from string key-value pair.
|
| |
| bool | SetProperties (const std::map< std::string, std::string > &arguments) |
| | Set multiple GA properties from map.
|
| |
| void | InitiatePopulation () |
| | Create initial population.
|
| |
| void | SetRunTimeWindow (ProgressWindow *_rtw) |
| | Set progress window for GUI updates.
|
| |
|
| double | sumfitness |
| | Sum of all fitness values in current population.
|
| |
| double | MaxFitness |
| | Maximum fitness value in current population.
|
| |
| GA_Tweaking_parameters | GA_params |
| | GA algorithm configuration parameters.
|
| |
| _filenames | filenames |
| | File paths for GA input/output.
|
| |
| std::vector< double > | calc_output_percentiles |
| | Percentiles to calculate for output distributions.
|
| |
| std::vector< std::vector< double > > | initial_pop |
| | Initial population loaded from file.
|
| |
| std::vector< double > | final_params |
| | Final optimized parameter values.
|
| |
| std::vector< int > | params |
| | Parameter indices being optimized.
|
| |
| std::vector< int > | loged |
| | Flags indicating if parameters are log-transformed.
|
| |
| std::vector< int > | to_ts |
| | Time series index for each parameter (if applicable)
|
| |
| std::vector< double > | fixedinputvale |
| | Fixed values for non-optimized parameters.
|
| |
| std::vector< double > | minval |
| | Lower bounds for each parameter.
|
| |
| std::vector< double > | maxval |
| | Upper bounds for each parameter.
|
| |
| std::vector< bool > | apply_to_all |
| | Flags indicating if parameter applies to all entities.
|
| |
| std::vector< std::vector< int > > | outcompare |
| | Output comparison indices (legacy, may be unused)
|
| |
| std::vector< CIndividual > | Ind |
| | Current population of individuals.
|
| |
| std::vector< CIndividual > | Ind_old |
| | Previous generation's population.
|
| |
| std::vector< std::string > | paramname |
| | Names of parameters being optimized.
|
| |
| std::vector< T > | Models |
| | Copies of model for parallel fitness evaluation.
|
| |
| T | Model_out |
| | Output model configured with best parameters.
|
| |
| T * | Model |
| | Pointer to the model being optimized.
|
| |
| std::string | last_error |
| | Last error message from GA execution.
|
| |
|
| void | Setminmax (int a, double minrange, double maxrange, int prec) |
| | Set parameter bounds and precision.
|
| |
| void | fitnessdistini () |
| | Initialize fitness distribution for selection.
|
| |
| void | crossover () |
| | Perform crossover operation on population.
|
| |
| double | avgfitness () |
| | Calculate average fitness of population.
|
| |
| void | mutate (double mu) |
| | Apply mutation to population.
|
| |
| void | assignfitnesses () |
| | Evaluate fitness for all individuals in population.
|
| |
| int | maxfitness () |
| | Find index of individual with maximum fitness.
|
| |
| double | variancefitness () |
| | Calculate variance of population fitness.
|
| |
| double | stdfitness () |
| | Calculate standard deviation of population fitness.
|
| |
| double | avg_actual_fitness () |
| | Calculate average of actual (untransformed) fitness values.
|
| |
| void | write_to_detailed_GA (std::string s) |
| | Write detailed GA information to file.
|
| |
| void | setnumpop (int n) |
| | Set population size.
|
| |
| double | avg_inv_actual_fitness () |
| | Calculate average of inverse actual fitness.
|
| |
| int | optimize (int nGens, char DefOutPutFileName[]) |
| | Optimize for specified number of generations.
|
| |
| void | setnparams (int n) |
| | Set number of parameters.
|
| |
| void | assignfixedvalues () |
| | Assign fixed values to non-optimized parameters.
|
| |
| void | assignrank () |
| | Assign ranks to individuals based on fitness.
|
| |
| void | assignfitness_rank (double N) |
| | Assign fitness using rank-based scheme.
|
| |
| void | shake () |
| | Apply shake/perturbation to population.
|
| |
| void | crossoverRC () |
| | Real-coded crossover operation.
|
| |
| void | getfromfile (char filename[]) |
| | Read population from file.
|
| |
| void | fillfitdist () |
| | Fill fitness distribution for roulette wheel selection.
|
| |
| double | assignfitnesses (std::vector< double > inp) |
| | Evaluate fitness for specific parameter vector.
|
| |
| double | Gradient_Descent (std::vector< double > inp) |
| | Perform gradient descent local search.
|
| |
| int | getparamno (int i, int ts) |
| | Get parameter index for variable and time series.
|
| |
| int | get_act_paramno (int i) |
| | Get active parameter number.
|
| |
| int | get_time_series (int i) |
| | Get time series index for parameter.
|
| |
| double | evaluateforward () |
| | Evaluate model forward (compute predictions)
|
| |
| double | evaluateforward_mixed (std::vector< double > v) |
| | Evaluate model with mixed parameters.
|
| |
template<class T>
class CGA< T >
Genetic Algorithm optimizer for global parameter estimation.
The CGA class implements a sophisticated genetic algorithm with both binary and real-coded representations for solving complex optimization problems in sediment source fingerprinting.
Algorithm Overview
Genetic Algorithms are population-based metaheuristic optimization methods inspired by natural evolution:
- Initialize: Create random population of candidate solutions
- Evaluate: Calculate fitness (objective function) for each individual
- Select: Choose parents based on fitness (better individuals more likely)
- Crossover: Combine parent solutions to create offspring
- Mutate: Randomly perturb offspring to maintain diversity
- Replace: Form next generation from offspring (and/or parents)
- Repeat: Continue until convergence or generation limit reached
Key Features
- Multiple encoding schemes: Binary and real-coded representations
- Flexible selection methods: Fitness proportionate, rank-based, tournament
- Various crossover operators: Single-point, two-point, uniform, arithmetic
- Adaptive mutation: Self-adjusting based on convergence state
- Hybrid optimization: Optional gradient-based local search
- Parallel evaluation: Thread-safe fitness evaluation
- Progress tracking: GUI integration for real-time monitoring
Usage in SedSat3
GA provides global optimization for source apportionment when:
- Posterior is multimodal (multiple local optima)
- Gradient information unavailable or unreliable
- Robust global search needed
- Derivative-free optimization preferred
GA finds parameter values that minimize error between predicted and observed tracer concentrations, subject to constraints (e.g., contributions sum to 100%).
Mathematical Details
Fitness function (for minimization):
fitness = -Σ((y_observed - y_predicted)² / σ²)
Selection probability (fitness proportionate):
P(select individual i) = fitness_i / Σ(fitness_j)
Rank-based fitness:
fitness_rank(i) = N - 2(N-1)(rank(i)-1)/(population_size-1)
where N is selection pressure parameter (typically 1.5-2.0)
- Template Parameters
-
| T | Model class type (e.g., SourceSinkData) that provides:
- Parameter setting interface
- Objective function evaluation
- Model predictions
|
- Note
- Thread-safe for parallel fitness evaluation
- Warning
- May converge to local optimum; multiple runs recommended
- See also
- CIndividual
-
GADistribution
-
SourceSinkData
Example usage:
ga.GA_params.maxpop = 100;
ga.GA_params.nGen = 500;
ga.GA_params.pcross = 0.8;
ga.GA_params.pmute = 0.02;
ga.GA_params.RCGA = true;
ga.minval = {0.0, 0.0, 0.0};
ga.maxval = {1.0, 1.0, 1.0};
ga.InitiatePopulation();
ga.optimize();
std::vector<double> bestParams = ga.final_params;
Genetic Algorithm optimizer for global parameter estimation.
Definition at line 349 of file GA.h.