pinv is the “pseudi-inverse”. It is always defined, even of the matrix is not invertible.
https://numpy.org/doc/stable/reference/generated/numpy.linalg.pinv.html
If the matrix is invertibles, and well conditioned, inv and pinv are identical.
> On 20 Sep 2023, at 17:53, Ziyuan Yang <
0yang....@gmail.com> wrote:
>
> Dear Michel,
>
> When I check the code in results.py, I find the function use pinv() to calculate varCovar.
>
> Here is the code in results.py line 481:
> self.data.varCovar = -linalg.pinv(np.nan_to_num(self.data.H))
>
> Why need to use pinv() here instead of inv()? And I find in some situation these 2 function returns different values, I have no idea why, but I think maybe the inv() provide a more possible right results in my experiment?
>
> These are my codes and the result, as you can see out2 looks more like E:
> import pandas as pd
> import numpy as np
> temp = pd.read_pickle('data/555.pickle')['self'].data.H
> temp2 = np.nan_to_num(temp)
> out1 = np.dot(temp2, np.linalg.pinv(temp2))
> out2 = np.dot(temp2, np.linalg.inv(temp2))<f0848f5fd71a7482120123452e80510.png><6a3b6ea034d6a13b25a45e0c17df72f.png>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Biogeme" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
biogeme+u...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/biogeme/fdabfade-1003-4428-a2db-a223e3799ac9n%40googlegroups.com.
> <f0848f5fd71a7482120123452e80510.png><6a3b6ea034d6a13b25a45e0c17df72f.png>
Michel Bierlaire
Transport and Mobility Laboratory
School of Architecture, Civil and Environmental Engineering
EPFL - Ecole Polytechnique Fédérale de Lausanne
http://transp-or.epfl.ch
http://people.epfl.ch/michel.bierlaire