Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: matrix.adjuadge return a error value when row and col are greater than 2; #47

Open
mmooyyii opened this issue Aug 15, 2021 · 0 comments

Comments

@mmooyyii
Copy link

A matrix dot by it's inverse matrix will be a cell matrix.
There are two example of numpy and trueskill.mathematics

>> from trueskill.trueskill.mathematics import Matrix
>> import numpy as np
>> d = [[1, 2, 3], [6, 5, 10], [7, 8, 9]]
>> m = Matrix(d[:])
>> m.inverse() * m
Matrix([[4.2222222222222205, 3.1666666666666656, 4.777777777777777], [-0.6666666666666659, 4.440892098500626e-16, -1.3333333333333321], [0.11111111111111138, -0.16666666666666652, 0.8888888888888893]])
>> m = np.array(d[:])
>> np.linalg.inv(m) @ m
array([[ 1.00000000e+00,  1.11022302e-15,  1.85962357e-15],
       [-5.27355937e-16,  1.00000000e+00, -3.60822483e-16],
       [-2.22044605e-16, -2.22044605e-16,  1.00000000e+00]])

This reason for this bug is that adjugate matrix is not transposed.

### trueskill\trueskill\mathematics.py

def adjugate(self):
        height, width = self.height, self.width
        if height != width:
            raise ValueError('Only square matrix can be adjugated')
        if height == 2:
            a, b = self[0][0], self[0][1]
            c, d = self[1][0], self[1][1]
            return type(self)([[d, -b], [-c, a]])
        src = {}
        for r in range(height):
            for c in range(width):
                sign = -1 if (r + c) % 2 else 1
                src[r, c] = self.minor(r, c).determinant() * sign
---     return type(self)(src, height, width)
+++     return type(self)(src, height, width).transpose()
@mmooyyii mmooyyii changed the title bug: matrix.adjuadge return a error value when row and col is greater than 2; bug: matrix.adjuadge return a error value when row and col are greater than 2; Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant