Giter Club home page Giter Club logo

Comments (3)

foxtran avatar foxtran commented on May 29, 2024

Looks like it is not a proper place where this bug is. With the following Julia script, the same problem is:

using SymbolicRegression
using MLJ
X = 8randn(1000, 1)
y = @. X[:, 1]^2 - 2

model = SRRegressor(
    binary_operators=[+, ^],
    unary_operators=[exp, cos],
    niterations=40
)
mach = machine(model, X, y)
fit!(mach)

r = report(mach)
r.equations[r.best_idx]

output:

((0.7841441981843509 ^ (x₁ + -3.7374866510975324)) + (exp(x₁ + 27.319351179464586) ^ 0.12208411287569956))

from pysr.

foxtran avatar foxtran commented on May 29, 2024

The problem arises because in X negative numbers may occur and, in such case, pow(negate, Real) gives complex number, but the SR is running in Real mode.

from pysr.

MilesCranmer avatar MilesCranmer commented on May 29, 2024

Ah yeah that looks like the issue. It simply can't find exactly 2.0000, because even 1.9999 would produce imaginary output, thus creating NaN output and infinite loss – so it would have to randomly guess 2.0000 by pure luck. There are a bunch of solutions:

  1. Use * instead of ^.
  2. Give the model abs as a unary operator, so you make abs(x)^1.9999 a valid outcome, making it easier to find x^2.
  3. Define a custom operator abs_pow(x, y) = abs(x) ^ y (if in Python: in binary_operators as a string, and also with extra_sympy_mappings={"abs_pow": lambda x, y: abs(x) ** y}.
  4. Cast the input to imaginary numbers (e.g., + 0j in python or + 0im in Julia), so that -1 ^ 1.5 is a valid result, and so the model can descend smoothly towards -1 ^ 2.
  5. I'm assuming this isn't what you want but you could just use square which is one of the unary operators

from pysr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.