convergence.test | R Documentation |
This function checks for convergence in a vector of scores, identifying if there has been a stable sequence of scores over a specified number of steps. Convergence is defined as no change in score for 'steps' consecutive generations.
convergence.test(x, steps = 10)
x |
A numeric vector representing scores from successive generations in an evolutionary algorithm. |
steps |
An integer specifying the number of consecutive steps required with no change in score to consider the sequence as converged. |
The function iterates through the scores in 'x' and counts consecutive instances where there is no change in score. If the count reaches 'steps', the function returns 'TRUE', indicating convergence. If there are fewer scores in 'x' than 'steps', the function stops with an error.
**Usage in Evolutionary Algorithms**: This convergence test is useful in evolutionary algorithms to detect when further evolution is unlikely to yield improved scores, allowing the algorithm to terminate early.
A logical value: 'TRUE' if convergence is detected, 'FALSE' otherwise.
## Not run:
scores <- c(0.8, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85)
has_converged <- convergence.test(scores, steps = 5)
print(has_converged) # Returns TRUE, as the score did not change for 5 steps
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.