GeneticAlgorithmMultiObjective

Library "GeneticAlgorithmMultiObjective"
Fast multi-objective genetic algorithm (NSGA-II) for Pine Script. All objectives are MAXIMIZED. Real-coded genes with SBX crossover and polynomial mutation, true Pareto fronts, per-front crowding distance, and elitist environmental selection.
createConfig(populationSize, geneCount, objectiveCount, minValues, maxValues, mutationRate, crossoverRate, elitismRate, tournamentSize, maxGenerations, etaCrossover, etaMutation, useSBX)
Creates a GA_Config.
Parameters:
populationSize (int)
geneCount (int)
objectiveCount (int)
minValues (array<float>)
maxValues (array<float>)
mutationRate (float)
crossoverRate (float)
elitismRate (float)
tournamentSize (int)
maxGenerations (int)
etaCrossover (float)
etaMutation (float)
useSBX (bool)
Returns: GA_Config
randomFloat(minVal, maxVal)
Random float in [minVal, maxVal).
Parameters:
minVal (float)
maxVal (float)
randomInt(minVal, maxVal)
Random integer in [minVal, maxVal) (upper bound excluded).
Parameters:
minVal (int)
maxVal (int)
createRandomChromosome(config)
Creates one random chromosome inside the gene bounds.
Parameters:
config (GA_Config)
initializePopulation(config)
Creates the initial random population.
Parameters:
config (GA_Config)
cloneChromosome(chrom)
Deep copy of a chromosome.
Parameters:
chrom (GA_Chromosome)
dominates(a, b)
Dominance test between two chromosomes (all objectives maximized).
Parameters:
a (GA_Chromosome)
b (GA_Chromosome)
rankPopulation(population, objectiveCount)
Fast non-dominated sorting (true Pareto fronts) plus crowding distance per front, in one pass. Sets rank and crowding on every chromosome. Call this before selection.
Parameters:
population (array<GA_Chromosome>): The evaluated population (objectives filled).
objectiveCount (int): Number of objectives.
Returns: The same array.
tournamentSelection(population, tournamentSize)
Tournament selection by rank, then crowding. Population must be ranked.
Parameters:
population (array<GA_Chromosome>)
tournamentSize (int)
selectBest(population, targetSize)
Picks the best targetSize individuals by (rank, crowding). Population must be ranked. Returns references (no copies).
Parameters:
population (array<GA_Chromosome>)
targetSize (int)
getParetoFront(population)
Returns the first Pareto front (rank 0). Population must be ranked.
Parameters:
population (array<GA_Chromosome>)
crossoverUniform(parent1, parent2, config)
Uniform crossover. Returns a new child.
Parameters:
parent1 (GA_Chromosome)
parent2 (GA_Chromosome)
config (GA_Config)
crossoverSBX(parent1, parent2, config)
Simulated Binary Crossover (SBX), bounded. Returns a new child.
Parameters:
parent1 (GA_Chromosome)
parent2 (GA_Chromosome)
config (GA_Config)
mutateUniform(chrom, config)
Random-reset mutation (in place).
Parameters:
chrom (GA_Chromosome)
config (GA_Config)
mutatePolynomial(chrom, config)
Polynomial mutation (in place). Small local changes, much more accurate than random reset.
Parameters:
chrom (GA_Chromosome)
config (GA_Config)
mutate(chrom, config)
Mutation chosen by config.useSBX.
Parameters:
chrom (GA_Chromosome)
config (GA_Config)
createOffspring(population, config, count)
Creates `count` unevaluated children from a ranked population (call rankPopulation first, or use the output of environmentalSelection).
Parameters:
population (array<GA_Chromosome>)
config (GA_Config)
count (int)
environmentalSelection(combined, config)
True NSGA-II survivor selection. Pass parents + evaluated offspring merged in one array; returns the best populationSize individuals (ranked, with crowding set).
Parameters:
combined (array<GA_Chromosome>)
config (GA_Config)
createNextGeneration(population, config)
Simple generational step with elitism (compatible with the old API). The returned population has elites evaluated and new children with zero objectives (evaluate them before the next call).
Parameters:
population (array<GA_Chromosome>)
config (GA_Config)
GA_Chromosome
A candidate solution.
Fields:
genes (array<float>): Gene values.
objectives (array<float>): Objective values (all maximized). Filled by the user.
fitness (series float): Free slot for user data.
rank (series int): Pareto front index (0 = best front).
crowding (series float): Crowding distance inside its front (bigger = more isolated = better).
GA_Config
Algorithm settings.
Fields:
populationSize (series int): Number of individuals.
geneCount (series int): Number of genes per individual.
objectiveCount (series int): Number of objectives.
minValues (array<float>): Lower bound of each gene.
maxValues (array<float>): Upper bound of each gene.
mutationRate (series float): Per-gene mutation probability (a good default is 1 / geneCount).
crossoverRate (series float): Probability that two parents are recombined.
elitismRate (series float): Share of the population kept as elites in createNextGeneration.
tournamentSize (series int): Tournament size (2 = binary tournament).
maxGenerations (series int): Free slot for the caller's loop.
etaCrossover (series float): SBX distribution index (10 to 20; larger = children closer to parents).
etaMutation (series float): Polynomial mutation distribution index (15 to 30).
useSBX (series bool): true = SBX + polynomial mutation, false = uniform crossover + random reset.
Fast multi-objective genetic algorithm (NSGA-II) for Pine Script. All objectives are MAXIMIZED. Real-coded genes with SBX crossover and polynomial mutation, true Pareto fronts, per-front crowding distance, and elitist environmental selection.
createConfig(populationSize, geneCount, objectiveCount, minValues, maxValues, mutationRate, crossoverRate, elitismRate, tournamentSize, maxGenerations, etaCrossover, etaMutation, useSBX)
Creates a GA_Config.
Parameters:
populationSize (int)
geneCount (int)
objectiveCount (int)
minValues (array<float>)
maxValues (array<float>)
mutationRate (float)
crossoverRate (float)
elitismRate (float)
tournamentSize (int)
maxGenerations (int)
etaCrossover (float)
etaMutation (float)
useSBX (bool)
Returns: GA_Config
randomFloat(minVal, maxVal)
Random float in [minVal, maxVal).
Parameters:
minVal (float)
maxVal (float)
randomInt(minVal, maxVal)
Random integer in [minVal, maxVal) (upper bound excluded).
Parameters:
minVal (int)
maxVal (int)
createRandomChromosome(config)
Creates one random chromosome inside the gene bounds.
Parameters:
config (GA_Config)
initializePopulation(config)
Creates the initial random population.
Parameters:
config (GA_Config)
cloneChromosome(chrom)
Deep copy of a chromosome.
Parameters:
chrom (GA_Chromosome)
dominates(a, b)
Dominance test between two chromosomes (all objectives maximized).
Parameters:
a (GA_Chromosome)
b (GA_Chromosome)
rankPopulation(population, objectiveCount)
Fast non-dominated sorting (true Pareto fronts) plus crowding distance per front, in one pass. Sets rank and crowding on every chromosome. Call this before selection.
Parameters:
population (array<GA_Chromosome>): The evaluated population (objectives filled).
objectiveCount (int): Number of objectives.
Returns: The same array.
tournamentSelection(population, tournamentSize)
Tournament selection by rank, then crowding. Population must be ranked.
Parameters:
population (array<GA_Chromosome>)
tournamentSize (int)
selectBest(population, targetSize)
Picks the best targetSize individuals by (rank, crowding). Population must be ranked. Returns references (no copies).
Parameters:
population (array<GA_Chromosome>)
targetSize (int)
getParetoFront(population)
Returns the first Pareto front (rank 0). Population must be ranked.
Parameters:
population (array<GA_Chromosome>)
crossoverUniform(parent1, parent2, config)
Uniform crossover. Returns a new child.
Parameters:
parent1 (GA_Chromosome)
parent2 (GA_Chromosome)
config (GA_Config)
crossoverSBX(parent1, parent2, config)
Simulated Binary Crossover (SBX), bounded. Returns a new child.
Parameters:
parent1 (GA_Chromosome)
parent2 (GA_Chromosome)
config (GA_Config)
mutateUniform(chrom, config)
Random-reset mutation (in place).
Parameters:
chrom (GA_Chromosome)
config (GA_Config)
mutatePolynomial(chrom, config)
Polynomial mutation (in place). Small local changes, much more accurate than random reset.
Parameters:
chrom (GA_Chromosome)
config (GA_Config)
mutate(chrom, config)
Mutation chosen by config.useSBX.
Parameters:
chrom (GA_Chromosome)
config (GA_Config)
createOffspring(population, config, count)
Creates `count` unevaluated children from a ranked population (call rankPopulation first, or use the output of environmentalSelection).
Parameters:
population (array<GA_Chromosome>)
config (GA_Config)
count (int)
environmentalSelection(combined, config)
True NSGA-II survivor selection. Pass parents + evaluated offspring merged in one array; returns the best populationSize individuals (ranked, with crowding set).
Parameters:
combined (array<GA_Chromosome>)
config (GA_Config)
createNextGeneration(population, config)
Simple generational step with elitism (compatible with the old API). The returned population has elites evaluated and new children with zero objectives (evaluate them before the next call).
Parameters:
population (array<GA_Chromosome>)
config (GA_Config)
GA_Chromosome
A candidate solution.
Fields:
genes (array<float>): Gene values.
objectives (array<float>): Objective values (all maximized). Filled by the user.
fitness (series float): Free slot for user data.
rank (series int): Pareto front index (0 = best front).
crowding (series float): Crowding distance inside its front (bigger = more isolated = better).
GA_Config
Algorithm settings.
Fields:
populationSize (series int): Number of individuals.
geneCount (series int): Number of genes per individual.
objectiveCount (series int): Number of objectives.
minValues (array<float>): Lower bound of each gene.
maxValues (array<float>): Upper bound of each gene.
mutationRate (series float): Per-gene mutation probability (a good default is 1 / geneCount).
crossoverRate (series float): Probability that two parents are recombined.
elitismRate (series float): Share of the population kept as elites in createNextGeneration.
tournamentSize (series int): Tournament size (2 = binary tournament).
maxGenerations (series int): Free slot for the caller's loop.
etaCrossover (series float): SBX distribution index (10 to 20; larger = children closer to parents).
etaMutation (series float): Polynomial mutation distribution index (15 to 30).
useSBX (series bool): true = SBX + polynomial mutation, false = uniform crossover + random reset.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.