boost::ublasで逆行列を求めるのにエラーが難しくて悲しい

boost::ublasで逆行列をLU分解によって求めようとすると、

Check failed in file d:\lib\boost_1_34_1\boost\numeric\ublas\lu.hpp at line 272:
detail::expression_type_check (prod (triangular_adaptor<const_matrix_type, upper (m), e), cv2)

とか言われちゃう時の対処法。

This error is usually triggered when the matrix is ill conditioned

(nearly singular). Then the internal checks fail because the result

depends on the order of the floating point operations.



There are several solutions possible:



* disable debugging (define NDEBUG)

* disable type checks (see [1], keyword: BOOST_UBLAS_TYPE_CHECK)

* use a better solver (see http://www.guwi17.de/ublas/examples/)

Re: lu_substitute’s “internal logic” error – msg#00034 – lib.boost.ublas

解が浮動小数点演算の桁に依存するためにinternal checkに失敗するのがエラーの原因だらしい。

つまりややこしい数字を突っ込むと高確率で出現する。

解決法

その1

#define NDEBUG

その2

#undef BOOST_UBLAS_TYPE_CHECK
#define BOOST_UBLAS_TYPE_CHECK 0

BOOST_UBLAS_TYPE_CHECK Enable additional checks for the results of expressions using non dense types. Picks up runtime error such as the assignment of a numerically non-symmetric matrix to symmertic_matrix. Use #define BOOST_UBLAS_TYPE_CHECK 0 to disable expensive numeric type checks. (Note: “structure check” would be a much better name.)
BOOST_USER: Effective UBLAS

その3

uBLAS examplesのExample2とかExample6とか

解答

#undef BOOST_UBLAS_TYPE_CHECK
#define BOOST_UBLAS_TYPE_CHECK 0
template <typename T>
matrix<T> inv(const matrix<T>& m)
throw (std::invalid_argument) {
	typedef matrix<T> m_t;
	m_t a(m);
	m_t b(identity_matrix<T>(m.size1()));
	permutation_matrix<std::size_t> pm(m.size1());

	if (lu_factorize(a,pm) != 0)
	    throw std::invalid_argument(std::string("No inverse exists."));

	lu_substitute(a,pm,b);

	return b;
    }

BOOST_USER: LU Matrix Inversionのパクリ。

lu_factorizeの返り値をちゃんとチェックしないとlu_substituteでまたもや難しいエラーに出会うことになる。


throw std::invalid_argumentの使い方がこれであっているのか自信ない。

17 Comments

  1. Posted 2017年4月11日 at 12:53 AM | Permalink

    Hello there, I found your sjte via Googe at the same time as searching for a similar subject, ylur web site got here up, it appears great.
    I’ve bookmarked it in my google bookmarks.
    Hello there, simply become aware of yor weblog through Google, and found
    that it’s truly informative. I’m going to be careful for brussels.

    I’ll appreciate in the event youu continue this in future.

    Many other folks ight be benefited from your writing. Cheers!

  2. Posted 2017年4月11日 at 12:18 PM | Permalink

    Nice answer back in return of this matter with solid arguments and describing
    everything on the topic of that.

  3. Posted 2017年4月25日 at 3:45 PM | Permalink

    Quality posts is the important to be a focus for the people to
    visit the site, that’s what this site is providing.

  4. Posted 2017年4月30日 at 10:40 AM | Permalink

    Now I am going away to do my breakfast, after having my breakfast coming over
    again to read further news.

  5. Posted 2017年4月30日 at 11:58 PM | Permalink

    No matter if some one searches for his essential thing, thus he/she
    desires to be available that in detail, so that thing is
    maintained over here.

  6. Posted 2017年5月1日 at 3:41 AM | Permalink

    It’s awesome to pay a quick visit this site and reading
    the views of all colleagues concerning this piece of writing, whille I am also eager of getting familiarity.

  7. Posted 2017年5月4日 at 4:14 PM | Permalink

    Have you ever thought about adding a litttle bit more than just your articles?

    I mean, what you say is valuable and everything.
    Butt just imagine iif you added some great images or video clips to give
    your posts more,”pop”! Your content iis excellent but with pics and videos, this
    blog could definitely be one of the very best in its
    field. Terrific blog!

  8. Posted 2017年5月6日 at 6:19 AM | Permalink

    I аll the time used too sгudy article inn news papers but now аs I am a user of web so from now ӏ am
    using neet fߋor articles or reviews, thanks tо web.

  9. Posted 2017年5月6日 at 7:50 PM | Permalink

    It’s awesome designed foor me to have a site, which is helpful in favor of my experience.
    thanks admin

  10. Posted 2017年5月6日 at 9:11 PM | Permalink

    If you desire to improve your knowledge just
    keep visiting this web site and be updated with the hottest information posted here.

  11. Posted 2017年5月16日 at 8:49 PM | Permalink

    I’ve Ьeen surfing on-lіne greatеr than 3 hours lаtely, yyet I by nno means found any attention-grabbing article like yours.
    It’s beautifᥙl worth sufficient for me. In my view, if all website owners and bloggers made good content material as you probably did, the net can be a lot more usefuⅼ
    than ever before.

  12. Posted 2017年5月18日 at 1:09 AM | Permalink

    I do not know whether it’s just me or if everybody else encountering issues
    with your site. It appears as though some of the text in your content are running
    off the screen. Can somebody else please comment and let me know if this is happening
    to them as well? This could be a problem with my internet browser because I’ve
    had this happen before. Thanks

  13. Posted 2017年5月19日 at 8:11 PM | Permalink

    Hi, I do believe this iss an excellent blog.
    I stumbledupon it ;)I will return once again sincde I book-marked it.
    Money and freedim is the greatest way to change, may you be rich and continue to guiide other people.

  14. Posted 2017年5月20日 at 9:38 AM | Permalink

    It’s going to be end of min day, exchept before finish I amm reading thiss great piece of writing to increase my know-how.

  15. Posted 2017年5月20日 at 12:01 PM | Permalink

    It’s going to be finish of mine day, except before finish
    I am reading this fantastic piece of writing to improve my know-how.

  16. Posted 2017年5月20日 at 12:09 PM | Permalink

    Excellent article! We are linking to this great post on our website.
    Keep up the good writing.

  17. Posted 2017年5月29日 at 3:09 PM | Permalink

    Very good article. Іcertainly appreciate this site.
    Stick with it!

4 Trackbacks

  1. By P70cm paper on 2017年3月2日 at 8:18 PM

    P70cm paper

    boost::ublasで逆行列を求めるのにエラーが難しくて悲しい – 放置演算子

  2. By Celebrity Social Media Management on 2017年4月9日 at 3:27 PM

    Celebrity Social Media Management

    boost::ublasで逆行列を求めるのにエラーが難しくて悲しい – 放置演算子

  3. By get fit on 2017年4月17日 at 2:35 PM

    get fit

    boost::ublasで逆行列を求めるのにエラーが難しくて悲しい – 放置演算子

  4. By Garment Conveyor Systems on 2017年5月18日 at 1:52 AM

    Garment Conveyor Systems

    boost::ublasで逆行列を求めるのにエラーが難しくて悲しい – 放置演算子

Post a Comment

Your email is never shared.

引く

PageTop