MPQC  3.0.0-alpha
gaussianfit.h
1 //
2 // gaussianfit.h
3 //
4 // Copyright (C) 2007 Edward Valeev
5 //
6 // Author: Edward Valeev <evaleev@vt.edu>
7 // Maintainer: EV
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _math_optimize_gaussianfit_h
29 #define _math_optimize_gaussianfit_h
30 
31 #include <stdexcept>
32 #include <vector>
33 #include <cmath>
34 
35 namespace sc {
36 
40  template<typename Function, typename Weight>
41  class GaussianFit {
42  public:
43  // If 1, "weigh" the function, else weigh the square of the error
44  static const bool weigh_F = 0;
45 
46  typedef double Exp;
47  typedef double Coef;
48  typedef std::pair<Exp, Coef> Gaussian;
49  typedef std::vector<Gaussian> Gaussians;
51  GaussianFit(unsigned int N, const Weight& W, double left, double right,
52  unsigned int NP);
53  ~GaussianFit();
54 
56  const Gaussians& operator()(const Function& F) const;
57 
58  private:
60  static const int k_ = 0;
61 
63  Weight weight_;
65  mutable std::vector<std::pair<Exp, Coef> > gaussians_;
66  double left_;
67  double right_;
68  unsigned int npts_;
69 
71  mutable double* p_;
73  double* scratch_;
74 
76  static const int classdebug_ = 0;
77 
79  void extract_params() const;
81  void assign_params() const;
82  };
83 
84  namespace math {
86  class Slater1D {
87  public:
88  Slater1D(double a, int k = 0, double c = 1.0) :
89  k_(k), a_(a), c_(c) {
90  }
91  double operator()(double x) const {
92  return c_ * std::pow(x, k_) * std::exp(-a_ * x);
93  }
94  private:
95  int k_;
96  double a_;
97  double c_;
98  };
100  class Gaussian1D {
101  public:
102  Gaussian1D(double a, int k = 0, double c = 1.0) :
103  k_(k), a_(a), c_(c) {
104  }
105  double operator()(double x) const {
106  return c_ * std::pow(x, k_) * std::exp(-a_ * x * x);
107  }
108  private:
109  int k_;
110  double a_;
111  double c_;
112  };
115  public:
116  PowerExponential1D(double a, int l = 2, int k = 0, double c = 1.0) :
117  k_(k), l_(l), a_(a), c_(c) {
118  }
119  double operator()(double x) const {
120  return c_ * std::pow(x, k_) * std::exp(-a_ * std::pow(x, l_));
121  }
122  private:
123  int k_;
124  int l_;
125  double a_;
126  double c_;
127  };
128  }
129 
130 }
131 
132 #endif
133 
134 // Local Variables:
135 // mode: c++
136 // c-file-style: "ETS"
137 // End:
sc::GaussianFit::GaussianFit
GaussianFit(unsigned int N, const Weight &W, double left, double right, unsigned int NP)
Will fit a function F with weight W evenly sampled on NP points in an interval [left,...
Definition: gaussianfit.timpl.h:61
sc::GaussianFit::operator()
const Gaussians & operator()(const Function &F) const
fit F and return the parameters of the fit.
Definition: gaussianfit.timpl.h:195
sc::Function
The Function class is an abstract base class that, given a set of coordinates, will compute a value a...
Definition: function.h:44
sc::math::Gaussian1D
Gaussian1D(k,x) = c x^k exp(-a*x^2)
Definition: gaussianfit.h:100
sc::math::PowerExponential1D
PowerExponential1D(k,l,x) = c x^k exp(-a*x^l)
Definition: gaussianfit.h:114
sc::math::Slater1D
Slater1D(k,x) = .
Definition: gaussianfit.h:86
sc::GaussianFit
GaussianFit<Function> is a fit of Function(x)*Weight(x) to N Gaussians on range [left,...
Definition: gaussianfit.h:41
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14

Generated at Sun Jan 26 2020 23:24:00 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.