Comments (3)
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.
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.
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:
- Use
*
instead of^
. - Give the model
abs
as a unary operator, so you makeabs(x)^1.9999
a valid outcome, making it easier to find x^2. - Define a custom operator
abs_pow(x, y) = abs(x) ^ y
(if in Python: inbinary_operators
as a string, and also withextra_sympy_mappings={"abs_pow": lambda x, y: abs(x) ** y}
. - 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
. - 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)
- [Feature]: Composite regressors
- [Feature]: Warn if better linear model available HOT 4
- [BUG]: Using dimensional constraints result in "UndefVarError: `k` not defined" error HOT 4
- Update Head Worker Occupation Warning HOT 3
- Command '['julia', '-e', '...']' returned non-zero exit status 1 HOT 2
- [BUG]: Encounter segmentation faults in running the toy example on RHEL machines HOT 14
- Windows Julia Install - could not load library "libpcre2-8" The specified module could not be found. HOT 19
- [BUG]: PyTorch module does not preserve dimensions of input tensor
- [Feature]: Recover up-to-date expression from exported PyTorch model (SingleSymPyModule)
- [Feature]: Select Julia version at first import.
- [Feature]: TensorBoard support
- Search-replace old code snippets with new syntax
- Error Running PySR with Julia in Windows 10 (Anaconda Environment)
- [BUG]: Can't pickle greater: attribute lookup greater on __main__ failed HOT 3
- [Feature] Should warn if populations < procs
- [BUG]: Compatibility Issue with Julia Version When Using PySR HOT 6
- [DOCS] Import sections of JuliaCall docs
- [Feature]: Warn user about low `niterations`
- [Feature]: Supplying initial guess to Symbolic Regression
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pysr.