Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_MATH_BIG_BIG_GENERATE_PSD_H
00002 #define OPENTISSUE_CORE_MATH_BIG_BIG_GENERATE_PSD_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_random.h>
00013 #include <OpenTissue/core/math/big/big_types.h>
00014 #include <OpenTissue/core/math/big/big_generate_random.h>
00015 #include <OpenTissue/core/math/big/big_gram_schmidt.h>
00016 #include <OpenTissue/core/math/big/big_diag.h>
00017 #include <OpenTissue/core/math/math_value_traits.h>
00018
00019 namespace OpenTissue
00020 {
00021 namespace math
00022 {
00023 namespace big
00024 {
00025
00041 template<typename matrix_type>
00042 inline void generate_PSD( size_t const & n, matrix_type & A, typename matrix_type::value_type const & fraction )
00043 {
00044 typedef typename matrix_type::value_type value_type;
00045 typedef OpenTissue::math::ValueTraits<value_type> value_traits;
00046 typedef ublas::vector<value_type> vector_type;
00047
00048 assert( fraction >= value_traits::zero() || !"generate_PSD(): invalid fraction specified");
00049 assert( fraction <= value_traits::one() || !"generate_PSD(): invalid fraction specified");
00050 assert( n > 0 || !"generate_PSD(): invalid problem size specified");
00051
00052 Random<value_type> value(value_traits::zero(),value_traits::one());
00053
00054 matrix_type Q;
00055 matrix_type D;
00056 matrix_type M;
00057 vector_type d;
00058 OpenTissue::math::big::generate_random( n, d );
00059 if(fraction>value_traits::zero())
00060 {
00061 for(size_t i = 0;i< n;++i)
00062 {
00063 if(value()<fraction)
00064 d(i) = value_traits::zero();
00065 }
00066 }
00067 OpenTissue::math::big::diag( d, D );
00068 OpenTissue::math::big::generate_random(n, n, Q);
00069 OpenTissue::math::big::gram_schmidt(Q);
00070 A.resize(n,n,false);
00071 M.resize(n,n,false);
00072 M = ublas::prod(D, ublas::trans(Q) );
00073 A = ublas::prod( Q, M );
00074 }
00075
00076 }
00077 }
00078 }
00079
00080
00081 #endif