MilesCranmer / PySR

High-Performance Symbolic Regression in Python and Julia
https://astroautomata.com/PySR
Apache License 2.0
2.35k stars 211 forks source link

Update the method run_on_problem() in FeynmanProblems.py to use the new PySRRegressor Interface #261

Open dbl001 opened 1 year ago

dbl001 commented 1 year ago

Currently, run_on_problem() uses the deprectated pysr() interface and pysr.best() does not work. Upgrade run_on_problem() to use the PySRRegressor Interface, model.fit() and get_best() function.

MilesCranmer commented 1 year ago

Hey @dbl001, I was actually thinking about deleting the feynman problems as I didn't think anybody was using it (including myself). Has it been useful for you? If so you happen to have some time to upgrade it to the new PySRRegressor interface? Best, Miles

dbl001 commented 1 year ago

I just started using it. I got this working...

 def run_on_problem(problem, verbosity=0, multiprocessing=True):
    """
    Takes in a problem and returns a tuple: (equations, best predicted equation, actual equation)
    """
    from time import time

    starting = time()
    model = PySRRegressor()
    model.fit(problem.X, problem.y)
    timing = time() - starting
    others = {"time": timing, "problem": problem}
    if not multiprocessing: 
        others["equations"] = model.equations_
    return str(PySRRegressor.get_best(model)), problem.form, others