00001 #ifndef OPENTISSUE_CORE_MATH_OPTIMIZATION_COMPUTE_NATURAL_MERIT_H 00002 #define OPENTISSUE_CORE_MATH_OPTIMIZATION_COMPUTE_NATURAL_MERIT_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 #include <OpenTissue/core/math/big/big_types.h> 00013 #include <OpenTissue/core/math/math_value_traits.h> 00014 #include <cmath> 00015 00016 namespace OpenTissue 00017 { 00018 namespace math 00019 { 00020 namespace optimization 00021 { 00022 00030 template < typename T > 00031 inline T compute_natural_merit( ublas::vector<T> const & F ) 00032 { 00033 using std::min; 00034 using std::max; 00035 00036 typedef OpenTissue::math::ValueTraits<T> value_traits; 00037 00038 static T const one_half = value_traits::one()/value_traits::two(); 00039 00040 size_t m = F.size(); 00041 00042 if(m==0) 00043 return value_traits::zero(); 00044 00045 T theta = value_traits::zero(); 00046 for (size_t i = 0; i < m; ++ i) 00047 { 00048 T const f_i = F(i); 00049 theta += f_i*f_i; 00050 } 00051 theta *= one_half; 00052 return theta; 00053 } 00054 00055 } // namespace optimization 00056 } // namespace math 00057 } // namespace OpenTissue 00058 00059 // OPENTISSUE_CORE_MATH_OPTIMIZATION_COMPUTE_NATURAL_MERIT_H 00060 #endif