facebookresearch / SymbolicMathematics

Deep Learning for Symbolic Mathematics
Other
523 stars 114 forks source link

coefficients #20

Closed arthurserres closed 3 years ago

arthurserres commented 3 years ago

Hi everyone !

I need to use coefficients such as a_0 but I have some trouble to find out how to do so. Of course I changed n_coefficients from 0 to 1 but also the leaf probability but then I don't know how to declare my coefficient let's say a_0 many thanks by advance for those of you that can help me :)

f-charton commented 3 years ago

Coefficient tokens will be 'a0', 'a1', ... They are defined in line 43 and 283 of file src/envs/char_sp.py

To use them you need to set parameter n_coefficients to the number you want (1 if you are going to use a0, 2 if you want a0 and a1...), and adjust the second number in leaf_probs (e.g. 0.6,0.2,0.2,0 for 20% of terminal symbols to be coefficients). This should work so long you use less than 10 coefficients (or 8 for differential equations, since we use a8 and a9 as placeholders for integration constants in our generation routine)

You will need to generate new training data using these coefficients, since the model has never seen them at training time (you might try without, but I doubt it works). But it is possible that retraining a pre-trained model on a relatively small additional sample of data featuring the coefficents (aka few shots learning) might work.

arthurserres commented 3 years ago

Thanks for answering this is really helpful !

The make sense, The last question is how should I declare them ?

Do I need to use the same syntax I used for x, or f that is for instance "a0 = env.local_dict['a0']" or something else ?

Thanks by advance,

Best,

Arthur

f-charton commented 3 years ago

I would expect so: for Sympy, a0 is a variable, just like x, and so it should be addressed exactly the same.

arthurserres commented 3 years ago

Nice, thanks for answering :)