ConstrainedOptPack_vector_change_stats.cpp

00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include <limits>
00030 
00031 #include "ConstrainedOptPack_vector_change_stats.hpp"
00032 #include "DenseLinAlgPack_DVectorClass.hpp"
00033 #include "DenseLinAlgPack_AssertOp.hpp"
00034 #include "Teuchos_ScalarTraits.hpp"
00035 
00036 void ConstrainedOptPack::vector_change_stats(
00037     const DVectorSlice& x, const DVectorSlice& d
00038   , value_type* max_term, size_type* max_k
00039   , value_type* min_term, size_type* min_k
00040   , value_type* av_term )
00041 {
00042   typedef Teuchos::ScalarTraits<value_type> ST;
00043   DenseLinAlgPack::VopV_assert_sizes( x.dim(), d.dim() );
00044   const value_type
00045     min_num   = std::numeric_limits<value_type>::min(),
00046     inf     = std::numeric_limits<value_type>::max();
00047   // Initialize statistics
00048   *max_term = 0.0;
00049   *max_k    = 0;
00050   *min_term = inf;
00051   *min_k    = 0;
00052   *av_term  = 0.0;
00053   // Compute statistics
00054   DVectorSlice::const_iterator
00055     x_itr = x.begin(),
00056     d_itr = d.begin();
00057   for( size_type i = 1; x_itr != x.end(); ++i, ++d_itr, ++x_itr ) {
00058     // Compute this ratio and make sure we are not dividing by zero.
00059     // We only care about ratios less than 1.0 and also deal
00060     // with the case that both x(i) and d(i) are zero (in which
00061     // case the ratio should be zero since x(i) == x(i) + d(i)).
00062     const value_type
00063       term = ST::magnitude(*d_itr) / ( 1 + ST::magnitude(*x_itr) );
00064     if( term > *max_term ) {
00065       *max_term = term;
00066       *max_k    = i;
00067     }
00068     if( term < *min_term ) {
00069       *min_term = term;
00070       *min_k    = i;
00071     }
00072     *av_term += term;
00073   }
00074   *av_term = *av_term / x.dim();
00075 }

Generated on Wed May 12 21:51:09 2010 for ConstrainedOptPack: C++ Tools for Constrained (and Unconstrained) Optimization by  doxygen 1.4.7