G4SimplexDownhill.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // Class description:
00030 //
00031 // Class implementing minimization of a function of n variables.
00032 // Reference: "A Simplex method for function minimization"
00033 //            by J. A. Nelder and R. Mead, Computer Journal, 7, 308 (1965)
00034 // and also: "Numerical Recipes in C: the art of scientific computing"
00035 //            by William H., Cambridge University Press ISBN 0521437202 (1992)
00036 
00037 // Author: Tatsumi Koi (SLAC/SCCS), 2007
00038 // --------------------------------------------------------------------------
00039 
00040 #ifndef G4SimplexDownhill
00041 #define G4SimplexDownhill_h
00042 
00043 #include "globals.hh"
00044 
00045 #include <vector> 
00046 #include <algorithm> 
00047 
00048 template<class T>
00049 class G4SimplexDownhill
00050 {
00051 
00052    public: // with description
00053 
00054       G4SimplexDownhill( T* tp , G4int n )
00055         : currentValue(0.), target(tp), numberOfVariable(n)
00056       { init(); }
00057 
00058       ~G4SimplexDownhill();
00059 
00060       G4double GetMinimum();
00061 
00062       std::vector< G4double > GetMinimumPoint();
00063 
00064 
00065    private:
00066 
00067       G4double getValue( std::vector< G4double > x )
00068       { return target->GetValueOfMinimizingFunction( x ); }
00069 
00070       void initialize();
00071       std::vector< std::vector< G4double > > currentSimplex;
00072 
00073       void calHeights();
00074       std::vector< G4double > currentHeights;
00075       G4double currentValue;
00076 
00077       std::vector< G4double > calCentroid( G4int );
00078 
00079       G4bool isItGoodEnough();
00080 
00081       std::vector< G4double > getReflectionPoint( std::vector< G4double > ,
00082                                                   std::vector< G4double > );
00083       std::vector< G4double > getExpansionPoint( std::vector< G4double > ,
00084                                                  std::vector< G4double > );
00085       std::vector< G4double > getContractionPoint( std::vector< G4double > ,
00086                                                    std::vector< G4double > );
00087 
00088       void doDownhill();
00089 
00090       void init();
00091 
00092    private:
00093 
00094       T* target;
00095 
00096       G4int numberOfVariable; 
00097 
00098       G4double alpha;
00099       G4double beta;
00100       G4double gamma;
00101       G4double max_se;
00102       G4double max_ratio;
00103       G4int maximum_no_trial;
00104       G4bool minimized;
00105 
00106       std::vector< G4double > minimumPoint;
00107 };
00108 
00109 #include "G4SimplexDownhill.icc"
00110 
00111 #endif

Generated on Mon May 27 17:49:50 2013 for Geant4 by  doxygen 1.4.7