MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / det

Method det

JSAT/src/jsat/linear/LUPDecomposition.java:58–86  ·  view source on GitHub ↗

@return the determinant of the original Matrix A, |A|

()

Source from the content-addressed store, hash-verified

56 * @return the determinant of the original Matrix A, |A|
57 */
58 public double det()
59 {
60 if(!isSquare())
61 throw new ArithmeticException("Rectangual matricies do not have a determinat");
62 double det = 1;
63
64 for(int i = 0; i < Math.min(U.rows(), U.cols()); i++)
65 det *= U.get(i, i);
66
67 //We need to swap back P to get the sign, so we make a clone. This could be cached if we need to
68 int rowSwaps = 0;
69
70 Matrix pCopy = P.clone();
71 //The number of row swaps in P is the sign change
72 for(int i = 0; i < pCopy.cols(); i++)
73 if(pCopy.get(i, i) != 1)
74 {
75 rowSwaps++;
76 //find the row that has our '1'!
77 int j = i+1;
78 while(pCopy.get(j, i) == 0)
79 j++;
80
81 pCopy.swapRows(i, j);//Dont really care who we swap with, it will work out in the end
82 }
83
84
85 return rowSwaps % 2 !=0 ? -det : det;
86 }
87
88 public Vec solve(Vec b)
89 {

Callers 5

testDetMethod · 0.95
trainMethod · 0.95
setCovarianceMethod · 0.95
trainMethod · 0.95
iterationStepMethod · 0.95

Calls 8

isSquareMethod · 0.95
colsMethod · 0.95
getMethod · 0.95
swapRowsMethod · 0.95
cloneMethod · 0.65
minMethod · 0.45
rowsMethod · 0.45
getMethod · 0.45

Tested by 1

testDetMethod · 0.76