Registered Member
|
hi,
I wrote a algorithm of minimization (UZAWA) thanks to Eigen. Using Eigen::VectorXd, and Eigen::MatrixXd. My problem is actually realy simple : Sometimes, checking the convergence, my variable "double test" exceeds the max double value. test = vector_1.dot(vector_2); // test = nan or inf Is there any method witch can convert a VectorXd or MatrixXd into <long double, Dynamic, Dynamic > ? Because all my prog is written with double, and I really don't want to redefine all my VectorXd and MatrixXd... I tried a loop : v(i)= (long double) V(i); that's efficient but some kind of dirty Thanks a lot ! |
Registered Member
|
I'm not sure, but you could try
or
(untested code) |
Moderator
|
The second version manuels proposed is correct. But you won't get much higher precision, 80 bits instead of 64... Cannot you write your condition as a vector norm instead of a inner product of two different vectors? In this case you can use a stable norm, e.g., vec.stableNorm() which avoids under/overflows.
|
Registered Member
|
thks for the advices both manuels and ggael,
Actually, my test checks the karush kuhn tucker condition, test = (lagrange multipliers).dot(constraint) < tolerance so, I don't see how to use the stable norm instead :/ |
Moderator
|
I see, I'm also using the same test in my iterative solvers. There exists other solution than extending the precision. For instance, if you need the value of the dot product only for this test, then overflow is not a big deal since in this case you know that it is greater than tolerance. Another solution is to apply appropriate scaling, e.g:
double maxL = lm.cwiseAbs().max(); double maxR = res.cwiseAbs().max(); (lm/maxL).dot(res/maxR) < tolerance |
Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar