MilesCranmer / PySR

High-Performance Symbolic Regression in Python and Julia
https://ai.damtp.cam.ac.uk/pysr
Apache License 2.0
2.46k stars 217 forks source link

Сorrelation as a loss function #182

Closed zachanton closed 1 year ago

zachanton commented 2 years ago

Is there any way to use Pearson or Spearman correlation as a loss function?

MilesCranmer commented 2 years ago

Not by default - these are the available losses: https://astroautomata.com/SymbolicRegression.jl/dev/losses/. As well as any loss function that can be written as a sum over per-element losses, like loss="myloss(x, y) = abs(x - y)" - so long as it is non-negative.

To add a more complex loss like a correlation-based loss, you can tweak this function (in Julia - but it's quite similar to Python): https://github.com/MilesCranmer/SymbolicRegression.jl/blob/7b4fecf9e136eb7b3acf29d0669e00e772efff56/src/LossFunctions.jl#L45-L49 to compare prediction with dataset.y. Both of these are Julia vectors.

Then, give your path to the local copy of SymbolicRegression.jl to the julia_project parameter in PySRRegressor.

Cheers, Miles

MilesCranmer commented 1 year ago

276 fixes this and allows you to do this.