QMCPACK
LinearFit.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #ifndef LINEAR_FIT_H
16 #define LINEAR_FIT_H
17 
18 #include <vector>
19 #include <stdexcept>
20 #include "OhmmsPETE/TinyVector.h"
21 #include "OhmmsPETE/OhmmsMatrix.h"
23 
24 
25 namespace qmcplusplus
26 {
27 template<typename T>
28 inline void LinearFit(std::vector<T>& y, Matrix<T>& A, std::vector<T>& coefs)
29 {
30  int N = A.size(0);
31  int M = A.size(1);
32  if (y.size() != N)
33  throw std::runtime_error("Differernt number of rows in basis functions that in data points in LinearFit.");
34  // Construct alpha matrix
35  Matrix<T> alpha(M, M);
36  alpha = 0.0;
37  for (int j = 0; j < M; j++)
38  for (int k = 0; k < M; k++)
39  for (int i = 0; i < N; i++)
40  alpha(k, j) += A(i, j) * A(i, k);
41  // Next, construct beta vector
42  std::vector<T> beta(M, 0.0);
43  for (int k = 0; k < M; k++)
44  for (int i = 0; i < N; i++)
45  beta[k] += y[i] * A(i, k);
46  invert_matrix(alpha, false);
47  coefs.resize(M, 0.0);
48  for (int i = 0; i < M; i++)
49  for (int j = 0; j < M; j++)
50  coefs[i] += alpha(i, j) * beta[j];
51 }
52 } // namespace qmcplusplus
53 
54 #endif
MatrixA::value_type invert_matrix(MatrixA &M, bool getdet=true)
invert a matrix
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Define determinant operators.
void LinearFit(std::vector< T > &y, Matrix< T > &A, std::vector< T > &coefs)
Definition: LinearFit.h:28