Giter Club home page Giter Club logo

Comments (4)

yxie20 avatar yxie20 commented on May 16, 2024 1

Fixed, confirmed! Mod seems to be the issue indeed.

from pysr.

MilesCranmer avatar MilesCranmer commented on May 16, 2024

I have no idea why sqrt(Abs(x1) + 2) is appearing as an output of your equation search... PySR should not find integers, only real numbers. But let me try to reproduce this...

By the way; some of the operators you are using are not actually implemented in the torch export, so it won't work anyways. You can add them as with, e.g., extra_torch_mappings={'atanh_clip': ...}. (I should give a better error for this). It also looks like this argument was also not transferring to the torch export; I'll add this now.

Also - that many operators and features will make the search very very slow. As a rule of thumb, the search will take O(factorial(M * N)) slower if you increase the number of operators by N and the number of features by M. There's also some redundant operators among the ones you passed - e.g., pow is redundant with exp. You can do feature pre-selection for all equations via the select_k_features argument (in which case you probably want to split this into multiple PySR runs!). Or use the methods described here to break down your problem: https://arxiv.org/abs/2006.11287.

from pysr.

MilesCranmer avatar MilesCranmer commented on May 16, 2024

I can't reproduce your example; it outputs fine for me. Presumably this is because it discovers a different equation. What was the output equation that it tried to convert to torch format?

from pysr.

MilesCranmer avatar MilesCranmer commented on May 16, 2024

Update: the thing I said about 'atanh_clip' is actually incorrect, sorry. It should have worked without that manual mapping. This is because this is equal to:

"atanh_clip": lambda x: sympy.atanh(sympy.Mod(x + 1, 2) - 1)

and each atanh and Mod are converted to PyTorch separately.

However, it looks like mod was not implemented in the torch mapping. I just added it in 4d5aec3 (0.6.8). I think this should be fixed now, but let me know if it does not work!

Also, here's a way to test if an expression will work, without needing to run the full PySR pipeline:

from pysr import sympy2torch
import torch
from sympy import *
import numpy as np

x, y, z = symbols("x y z")
expression = x ** 2 + atanh(Mod(y + 1, 2) - 1) * 3.2 * z

module = sympy2torch(expression, [x, y, z])

print(module)
# >> _SingleSymPyModule(expression=x**2 + 3.2*z*atanh(Mod(y + 1, 2) - 1))

X = torch.rand(100, 3).float() * 10

torch_out = module(X)
true_out = X[:, 0] ** 2 + torch.atanh(torch.remainder(X[:, 1] + 1, 2) - 1) * 3.2 * X[:, 2]

Test it:

np.testing.assert_array_almost_equal(true_out.detach(), torch_out.detach(), decimal=4)

So we can see it gives the same answer for tanh_clip now.

Cheers,
Miles

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.