Registered Member
|
Hi,
The following is a matrix that I get after accumulating some data points. 12259.3 127.299 12233.8 124.392 41.709 12146.1 25.6935 12129.9 12193.4 25.6935 12168.8 0.852933 1.38459 12129.9 0.852933 12129.3 When I calculate the deteminant of the matrix I get 0.0331911 as the answer, which is incorrect. In order to be sure, I defined a fresh matrix and gave it the above values where I get 9.62156e+07 as the answer which is correct. This is the code snippet where I obtain the first answer.
This is the code snippet where the values are hardcoded.
And the results obtained are: Although I am using a vector to store number of MatrixXd instances, I don't think that it should matter as the values of the matrixs are correct, hence the deteminant should also be correct. Am I wrong to have thought like that? I am a bit perplexed how this could happen. Any input would be much appreciated. Thank you, Prasad |
Registered Member
|
Small precision that I forgot to add. I am also using the Eigen/StdVector in my implementation. Sadly, having it or not didn't change the results I got.
|
Registered Member
|
If it helps; their norms are the same but Eigen values differ. Here is the output.
|
Moderator
|
Sorry but I don't understand your issue. The first matrix you shown is not the same than the one of the code. Please, output with full precision the matrix for which you think the determinant is not correct. Also, an alternative to compute the determinant of a matrix is:
|
Registered Member
|
Hi Gaël,
Thank you very much for your quick response. I am sorry that my explanation of the problem wasn’t clear. And I am extremely sorry to have incuded incorrect values for the matrix in the first comment, which I had got from another test case. I will try to do better this time. covarVec is a vector of MatrixXd. The number of elements in the vector and the size of the matrix depend on the user input. For one of the test cases, I print the value of the first element in the vector (covarVec[0]) which is 4x4 matrix. Then I calculate its determinant. Here is the output. And here is the code snippet.
The value 0.0331911 is incorrect. As you can see, I am not performing any other operation between the two lines and the application is single threaded as well. Hence, I think it is fair to assume that as soon as the value is displayed, the deteminant is calculated. In order to do a simple test, I created another 4x4 matrix giving the values obtained from the covarVec[0] and calculated its determinant which gave me the correct answer of 9.62156e+07. This is the code snippet.
And here is the output. Since the values of both the matrices are equivalent, they should give the same determinant. Yet, it doesn’t happen. Using the alternative code snippet you have given, I obtain the same results as the previous case. This is not a test case specific behavior as I get erratic behavior irrespective of the test inputs. Finally, here are the outputs with higher precision. For the covarVec For the hardcoded matrix. Thank you, Prasad |
Moderator
|
The last digits might be of high importance, I recommend you to try the "hardcoded" version with full precision. If you still get the "correct" result, then you probably have some memory problems with your code and I recommend you to try it with walgrind.
|
Registered Member
|
Hi Gaël,
Thank you very much for the insight. You are spot on with the precision playing a part in the output. It is exactly what that had happened. Once I make the hardcoded values to be as same as that of the highest possible precision values, the deteminant appears to be the same. I wouldn't have imagined that it would play such a part, now I know better, thanks to your guidance. For the completion of the thread, I am attaching the obtained outputs using the highest available precision. Obtained output Expected output I really appreciate your advices, thank you very much again, Prasad. |
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]