Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:05

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4SimplexDownhill
0027 //
0028 // Class description:
0029 //
0030 // Class implementing minimization of a function of n variables.
0031 // Reference: "A Simplex method for function minimization"
0032 //            by J. A. Nelder and R. Mead, Computer Journal, 7, 308 (1965)
0033 // and also: "Numerical Recipes in C: the art of scientific computing"
0034 //            by William H., Cambridge University Press ISBN 0521437202 (1992)
0035 
0036 // Author: Tatsumi Koi (SLAC/SCCS), 2007
0037 // --------------------------------------------------------------------
0038 #ifndef G4SimplexDownhill_hh
0039 #define G4SimplexDownhill_hh 1
0040 
0041 #include "globals.hh"
0042 
0043 #include <algorithm>
0044 #include <vector>
0045 
0046 template <class T>
0047 class G4SimplexDownhill
0048 {
0049  public:
0050   G4SimplexDownhill(T* tp, G4int n)
0051     : currentValue(0.)
0052     , target(tp)
0053     , numberOfVariable(n)
0054   {
0055     init();
0056   }
0057 
0058   ~G4SimplexDownhill();
0059 
0060   G4double GetMinimum();
0061 
0062   std::vector<G4double> GetMinimumPoint();
0063 
0064  private:
0065   G4double getValue(std::vector<G4double> x)
0066   {
0067     return target->GetValueOfMinimizingFunction(x);
0068   }
0069 
0070   void initialize();
0071   std::vector<std::vector<G4double>> currentSimplex;
0072 
0073   void calHeights();
0074   std::vector<G4double> currentHeights;
0075   G4double currentValue;
0076 
0077   std::vector<G4double> calCentroid(G4int);
0078 
0079   G4bool isItGoodEnough();
0080 
0081   std::vector<G4double> getReflectionPoint(std::vector<G4double>,
0082                                            std::vector<G4double>);
0083   std::vector<G4double> getExpansionPoint(std::vector<G4double>,
0084                                           std::vector<G4double>);
0085   std::vector<G4double> getContractionPoint(std::vector<G4double>,
0086                                             std::vector<G4double>);
0087 
0088   void doDownhill();
0089 
0090   void init();
0091 
0092  private:
0093   T* target;
0094 
0095   G4int numberOfVariable;
0096 
0097   G4double alpha;
0098   G4double beta;
0099   G4double gamma;
0100   G4double max_se;
0101   G4double max_ratio;
0102   G4int maximum_no_trial;
0103   G4bool minimized;
0104 
0105   std::vector<G4double> minimumPoint;
0106 };
0107 
0108 #include "G4SimplexDownhill.icc"
0109 
0110 #endif