Replies: 1 comment
-
The issue looks to be with the sympy version of the expression. What is I would recommend just doing something like class HTC(sympy.Function):
pass
extra_sympy_mappings={"HTC": HTC} It won’t be able to numerically evaluate the expression in Python though. But if you just want the string form of the equation, this will help. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
def h_ref34(T,Vs,T1):
#Vs is the jet debit in kg/(m²*s)
a=np.tanh(Vs/8)
b=140*Vs*(1-Vs*(T-T1)/72000)
c=3.26*(1-np.tanh((T-T1)/128))*(T-T1)**2
return 190+a*(b+c)
I would like to implement this function to use it in a more complex regression but it doesn't seem to work.
I have looked on the API and I though I understood but it seems that I didn't
model = PySRRegressor( niterations=30, binary_operators=["+", "*","-"], unary_operators=["HTC(x) = 190+tanh(10/8)*(140*10*(1-10*(x-294)/72000+3.26*(1-tanh((x-294)/128))*(x-294)^2))"] , extra_sympy_mappings={ "HTC": lambda x: 190+m.tanh(10/8)*(140*10*(1-10*(x-294)/72000+3.26*(1-m.tanh((x-294)/128))*(x-294)**2))}, **default_pysr_params,)
When I tried to fit the data, which are just X=[i for i in range(294,1100)] and Y=[h_ref34(T,Vs=10,T_wat=294) for T in X ], I get this error message :
/ValueError Traceback (most recent call last)
ValueError: Error from parse_expr with transformed code: <code object at 0x00000244BA2EE6A0, file "", line 1>
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
File ~\AppData\Roaming\Python\Python312\site-packages\pysr\export_sympy.py:91, in pysr2sympy(equation, feature_names_in, extra_sympy_mappings)
90 try:
---> 91 return sympify(equation, locals=local_sympy_mappings, evaluate=False)
92 except TypeError as e:
File ~\AppData\Roaming\Python\Python312\site-packages\sympy\core\sympify.py:481, in sympify(a, locals, convert_xor, strict, rational, evaluate)
480 a = a.replace('\n', '')
--> 481 expr = parse_expr(a, local_dict=locals, transformations=transformations, evaluate=evaluate)
482 except (TokenError, SyntaxError) as exc:
File ~\AppData\Roaming\Python\Python312\site-packages\sympy\parsing\sympy_parser.py:1090, in parse_expr(s, local_dict, transformations, global_dict, evaluate)
1089 local_dict[i] = null
-> 1090 raise e from ValueError(f"Error from parse_expr with transformed code: {code!r}")
File ~\AppData\Roaming\Python\Python312\site-packages\sympy\parsing\sympy_parser.py:1081, in parse_expr(s, local_dict, transformations, global_dict, evaluate)
1080 try:
-> 1081 rv = eval_expr(code, local_dict, global_dict)
1082 # restore neutral definitions for names
File ~\AppData\Roaming\Python\Python312\site-packages\sympy\parsing\sympy_parser.py:909, in eval_expr(code, local_dict, global_dict)
904 """
905 Evaluate Python code generated by
stringify_expr
.906
907 Generally,
parse_expr
should be used.908 """
--> 909 expr = eval(
910 code, global_dict, local_dict) # take local objects in preference
911 return expr
File :1
Cell In[288], line 6, in (x)
1 model = PySRRegressor(
2 niterations=30,
3 binary_operators=["+", "","-"],
4 unary_operators=["HTC"] ,
5 extra_sympy_mappings={
----> 6 "HTC": lambda x: 190+m.tanh(10/8)(14010(1-10*(x-294)/72000+3.26*(1-m.tanh((x-294)/128))*(x-294)**2))},
7 **default_pysr_params,)
File ~\AppData\Roaming\Python\Python312\site-packages\sympy\core\expr.py:340, in Expr.float(self)
339 raise TypeError("Cannot convert complex to float")
--> 340 raise TypeError("Cannot convert expression to float")
TypeError: Cannot convert expression to float
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
Cell In[289], line 1
----> 1 model.fit(X, y)
File ~\AppData\Roaming\Python\Python312\site-packages\pysr\sr.py:2087, in PySRRegressor.fit(self, X, y, Xresampled, weights, variable_names, complexity_of_variables, X_units, y_units)
2084 self._checkpoint()
2086 # Perform the search:
-> 2087 self._run(X, y, runtime_params, weights=weights, seed=seed)
2089 # Then, after fit, we save again, so the pickle file contains
2090 # the equations:
2091 if not self.temp_equation_file:
File ~\AppData\Roaming\Python\Python312\site-packages\pysr\sr.py:1921, in PySRRegressor.run(self, X, y, runtime_params, weights, seed)
1918 self.julia_state_stream = jl_serialize(out)
1920 # Set attributes
-> 1921 self.equations_ = self.get_hof()
1923 if self.delete_tempfiles:
1924 shutil.rmtree(self.tempdir_)
File ~\AppData\Roaming\Python\Python312\site-packages\pysr\sr.py:2412, in PySRRegressor.get_hof(self)
2409 torch_format = []
2411 for , eqn_row in output.iterrows():
-> 2412 eqn = pysr2sympy(
2413 eqn_row["equation"],
2414 feature_names_in=self.feature_names_in,
2415 extra_sympy_mappings=self.extra_sympy_mappings,
2416 )
2417 sympy_format.append(eqn)
2419 # NumPy:
File ~\AppData\Roaming\Python\Python312\site-packages\pysr\export_sympy.py:95, in pysr2sympy(equation, feature_names_in, extra_sympy_mappings)
93 if "got an unexpected keyword argument 'evaluate'" in str(e):
94 return sympify(equation, locals=local_sympy_mappings)
---> 95 raise TypeError(f"Error processing equation '{equation}'") from e
TypeError: Error processing equation 'HTC(x0) * 0.0007979723263663934'
Beta Was this translation helpful? Give feedback.
All reactions