Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_MATH_OPTIMIZATION_PERTURBATION_H
00002 #define OPENTISSUE_CORE_MATH_OPTIMIZATION_PERTURBATION_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/big/big_types.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace math
00017 {
00018 namespace optimization
00019 {
00020
00060 template<typename T>
00061 inline void perturbation(
00062 boost::numeric::ublas::vector<T> & y
00063 , T const & lambda
00064 , ublas::compressed_matrix<T> const & A
00065 , ublas::vector<T> const & b
00066 , ublas::compressed_matrix<T> & A_prime
00067 , ublas::vector<T> & b_prime
00068 )
00069 {
00070 size_t const m = A.size1();
00071 size_t const n = A.size2();
00072
00073 assert(m>0 || !"perturbation(): A was empty");
00074 assert(n>0 || !"perturbation(): A was empty");
00075 assert(m==n || !"perturbation(): A was not square");
00076 assert(b.size() == m || !"perturbation(): Incompatible dimension between A and b");
00077 assert(y.size() == m || !"perturbation(): Incompatible dimension between b and y");
00078
00079 A_prime.resize(m,n,false);
00080 b_prime.resize(n);
00081 A_prime.assign( A );
00082 b_prime.assign( b );
00083
00084 for(size_t i=0;i<m;++i)
00085 {
00086 A_prime(i,i) += lambda;
00087 b_prime(i) -= lambda*y(i);
00088 }
00089 }
00090
00091 }
00092 }
00093 }
00094
00095
00096 #endif