This slight modification of the original answer’s code will leave you à
symliste variable which can be displayed as formatted LaTeX in the Jupyter
notebook. I do not know (yet) how to display a list of such expressions.
from sympy import * X = MatrixSymbol('X',2,2) W = MatrixSymbol('W',2,2) Y =
MatrixSymbol('Y',1,2) W_X = MatMul(W,X.T) n = list(symbols('n:8')) reps =
{} xreps = {} liste = [] k=-1 for i in range(W_X.shape[0]): row = [] for j
in range(W_X.shape[1]): k += 1 row.append(n[k]) y = exp(-W_X[i,j])
reps[n[k]]=1/(1+y) xreps[exp(-W_X[i,j])] = solve(n[k] - reps[n[k]],
y)[0].simplify()
liste.append(row) sigmoid = Matrix(liste) k=-1 liste = [] for i in
range(Y.shape[0]): row = [] for j in range(Y.shape[1]): k+=1 reps[Symbol(
'l%s'%k)]=log(Y[i,j]/(1-Y[i,j])) row.append(Symbol('l%s'%k))
liste.append(row) log_Y = Matrix(liste) test = sigmoid.inv() W2 =
MatMul(log_Y,test).as_explicit() ireps = {v:k for k,v in reps.items()}
symliste = [] for index in range(W2.shape[1]): for i in range(W.shape[0]):
for j in range(W.shape[1]): #
liste.append(W2[index].subs(reps).diff(W[i,j]).subs(ireps).subs(xreps)) #
Defer symbolification symliste.append(W2[index].subs(reps).diff(W[i,j])) #
Symboilification liste=[u.subs(ireps).subs(xreps) for u in symliste] # List
of list of symbolic factors xx = dict(list(zip(list(X), symbols('x:4'))))
liste = [factor(i.as_numer_denom()[0].subs(xx)).args for i in liste] # (*)
liste = [[i for i in j if i not in n and i not in (-1,)+symbols('l:2')] for
j in liste] print(liste)
HTH,
Le mardi 21 mars 2023 à 16:07:51 UTC+1, brombo a écrit :
> Do you have the equations written out in LaTeX so I could understand the
> system better?
> On 3/21/23 10:25 AM, [email protected] wrote:
>
> I have a couple problems with this “answer”, which roughly replace the
> transcendental function calls (which are indeed bijections) with symbols
> and solving for these symbols.
>
> The most serious is that the transformed expressions are rational
> functions, and he proposed solution solves for their numerators. The author
> failed to note that for each proposed solution, the denominators are zero,
> meaning that the expressions are undefined at these points. Using those
> propôsed solutions require serious justifications (e. g. computing the
> limits of the (transformed) expressions at these points).
>
> See my answer
> <https://github.com/sympy/sympy/issues/24824#issuecomment-1474975520>.
>
> Le mardi 7 mars 2023 à 04:18:07 UTC+1, [email protected] a écrit :
>
>> An answer is given in https://github.com/sympy/sympy/issues/24824
>>
>> On Sunday, March 5, 2023 at 1:26:50 PM UTC-6 [email protected] wrote:
>>
>>> I think you should simplifythe equation and reduce the computational
>>> complexity as much as possible. It may also be helpful to check the
>>> implementation for errors or potential issues with the input parameters.
>>>
>>> On Tuesday, 28 February 2023 at 21:35:24 UTC+5:30 [email protected]
>>> wrote:
>>>
>>>> Hi all,
>>>> I try to solve a non linear equation but it conitnue runiing since 48
>>>> hours now.
>>>> ``
>>>> import sympy as sp
>>>>
>>>> X = sp.MatrixSymbol('X',2,2)
>>>> W = sp.MatrixSymbol('W',2,2)
>>>> Y = sp.MatrixSymbol('Y',1,2)
>>>> W_X = sp.MatMul(W,X.T)
>>>>
>>>> liste = []
>>>> for i in range(W_X.shape[0]):
>>>> row = []
>>>> for j in range(W_X.shape[1]):
>>>> row.append(1/(1+sp.exp(-W_X[i,j])))
>>>>
>>>> liste.append(row)
>>>> sigmoid = sp.Matrix(liste)
>>>>
>>>> liste = []
>>>> for i in range(Y.shape[0]):
>>>> row = []
>>>> for j in range(Y.shape[1]):
>>>> row.append(sp.log(Y[i,j]/(1-Y[i,j])))
>>>> liste.append(row)
>>>> log_Y = sp.Matrix(liste)
>>>>
>>>> test = sigmoid.inv()
>>>>
>>>> W2 = sp.MatMul(log_Y,test).as_explicit()
>>>>
>>>> liste = []
>>>> for index in range(W2.shape[1]):
>>>> for i in range(W.shape[0]):
>>>> for j in range(W.shape[1]):
>>>> liste.append(W2[index].diff(W[i,j]))
>>>>
>>>>
>>>> p = sp.solve(liste,list(W),check=False,manual=True)
>>>> ```
>>>>
>>>>
>>>> Do someone have an idea where i am wrong or if it is from sympy ?
>>>>
>>>> Thanks a lot
>>>>
>>> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/f35f8cf2-37af-4930-a544-0e2c04ec56e6n%40googlegroups.com
>
> <https://groups.google.com/d/msgid/sympy/f35f8cf2-37af-4930-a544-0e2c04ec56e6n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/3a3cdd31-5212-44fc-8fd2-59a1dc280d46n%40googlegroups.com.