I am in highschool and have not taken any courses on this. Rather I am working on an outside project. I don't quite understand how Genetic Programming could be used effectively to generate a set of equations to evaluate. My understanding is an operator will be added to a parent equation (the operator being a primitive?) and then that equation will be optimized and if the fit is better than some of the other added operators new generations will use an equation with that operator as the parent equation.
What I find strange is this:
If my equation is f(x) = -sin(x) and I currently have f(x) = x as my parent equation. When I attempt to add sin() to create f(x) = sin(x) the fit would be even worse and that operator would get thrown out even though I need it.
I understand that this is not the best example because it does not have a coefficient to be optimized.
Would someone please explain how genetic programming is used to make an equation set for optimization. You don't have to use my example either
Symbolic regression via genetic programming generally works by applying genetic operators to a population of models (in this case math equations). Generally, the genetic operators are mutation and crossover.
Mutation works by modifying a single model from the population and is similar to what you suggested in your example. Adding the sin function to another function or changing a function in a model to another function (f(x)=x*2->f(x)=x+2).
Crossover generally works by taking two models from the population and swapping pieces of them. For example $f(x)=2+sin(x)$ and $g(x)=5+2*x$ after crossover is applied could be $f(x)=2+2*x$ and $g(x) = 5+sin(x)$.
Your observation about a new model that is intuitively closer to the correct solution, but makes the fitness of the model worse is an interesting problem in genetic programming since it highlights the choice of the fitness function used. In your example, it is unclear what fitness function you are using, but if you were using correlation squared ($R^2$) Pearson correlation coefficient $sin(x)$ would actually have a perfect correlation, then the negative sign would just need to be applied to make it fit perfectly.
The choice of the fitness function is key. Choosing a poor fitness function could mislead the search. The best choice of fitness function can greatly vary between problems.