SSAGES  0.8.3
Software Suite for Advanced General Ensemble Simulations
Public Member Functions | Private Attributes | List of all members
SSAGES::BasisEvaluator Class Reference

Calculates the inner product of all the basis functions and the histogram. More...

#include <Basis.h>

Public Member Functions

 BasisEvaluator (const std::vector< BasisFunction *> &functions)
 Constructor. More...
 
void CoeffInit ()
 Initializes coefficient lookup vector. More...
 
void BasisInit ()
 Creates lookup table for basis functions.
 
void UpdateBias (Grid< double > *bias, Grid< std::vector< double >> *grad)
 Outputs the basis projection at a specific coordinate.
 
double UpdateCoeff (const std::vector< double > &array, Grid< unsigned int > *hist)
 
std::vector< double > GetCoeff (void)
 Gets the coefficient array.
 
void SetCoeff (const std::vector< double > &coeff)
 Set the coefficient array in the event of a restart run.
 

Private Attributes

std::vector< Mapcoeff_
 Vector of basis function coefficients.
 
std::vector< BasisFunction * > functions_
 Vector of basis functions.
 
std::vector< BasisLUTlookup_
 Lookup table for basis functions.
 

Detailed Description

Calculates the inner product of all the basis functions and the histogram.

Definition at line 332 of file Basis.h.

Constructor & Destructor Documentation

◆ BasisEvaluator()

SSAGES::BasisEvaluator::BasisEvaluator ( const std::vector< BasisFunction *> &  functions)
inline

Constructor.

Parameters
functionsVector of BasisFunction members.

Initialize the evaluator.

Definition at line 346 of file Basis.h.

346  :
347  functions_(functions)
348  {
349  CoeffInit();
350  BasisInit();
351  }
std::vector< BasisFunction * > functions_
Vector of basis functions.
Definition: Basis.h:336
void CoeffInit()
Initializes coefficient lookup vector.
Definition: Basis.cpp:100
void BasisInit()
Creates lookup table for basis functions.
Definition: Basis.cpp:132

Member Function Documentation

◆ CoeffInit()

void SSAGES::BasisEvaluator::CoeffInit ( void  )

Initializes coefficient lookup vector.

For now, when the basis evaluator is called it will store all the values of the basis functions into a lookup table. [Subject to change]

Definition at line 100 of file Basis.cpp.

References SSAGES::BasisFunction::GetOrder().

101  {
102  double coeff_size = 1;
103  //Get the size of the number of coefficients + 1
104  for(size_t i = 0; i < functions_.size(); ++i)
105  {
106  coeff_size *= functions_[i]->GetOrder()+1;
107  }
108 
109  std::vector<int> jdx(functions_.size(), 0);
110  Map temp_map(jdx,0.0);
111  //Initialize the mapping for the coeff function
112  for(size_t i = 0; i < coeff_size; ++i)
113  {
114  for(size_t j = 0; j < jdx.size(); ++j)
115  {
116  if(jdx[j] > 0 && jdx[j] % (functions_[j]->GetOrder()+1) == 0)
117  {
118  if(j != functions_.size() - 1)
119  {
120  jdx[j+1]++;
121  jdx[j] = 0;
122  }
123  }
124  temp_map.map[j] = jdx[j];
125  temp_map.value = 0;
126  }
127  coeff_.push_back(temp_map);
128  jdx[0]++;
129  }
130  }
std::vector< BasisFunction * > functions_
Vector of basis functions.
Definition: Basis.h:336
std::vector< Map > coeff_
Vector of basis function coefficients.
Definition: Basis.h:335
Here is the call graph for this function:

◆ UpdateCoeff()

double SSAGES::BasisEvaluator::UpdateCoeff ( const std::vector< double > &  array,
Grid< unsigned int > *  hist 
)

Calculates the inner product of the basis set and the biased histogram This function then returns the coefficients from this calculation

Parameters
arrayBasis set.
histBiased histrogram.
Returns
Inner product of the basis set and the biased histogram.

Definition at line 194 of file Basis.cpp.

References SSAGES::Grid< T >::begin(), SSAGES::Grid< T >::end(), and SSAGES::GridBase< T >::GetNumPoints().

195  {
196  double coeffTemp = 0;
197  double sum = 0;
198 
199  for(auto& coeff : coeff_)
200  {
201  // The method uses a standard integration
202  size_t j = 0;
203  coeffTemp = coeff.value;
204  coeff.value = 0.0;
205  for(Grid<unsigned int>::iterator it2 = hist->begin(); it2 != hist->end(); ++it2, ++j)
206  {
207 
208  double weight = std::pow(2.0,functions_.size());
209 
210  // This adds in a trap-rule type weighting which lowers error significantly at the boundaries
211  for(size_t k = 0; k < functions_.size(); ++k)
212  {
213  if( it2.index(k) == 0 ||
214  it2.index(k) == hist->GetNumPoints(k)-1)
215  weight /= 2.0;
216  }
217  /*The numerical integration of the biased histogram across the entirety of CV space
218  *All calculations include the normalization as well
219  */
220  double basis = 1.0;
221 
222  for(size_t l = 0; l < functions_.size(); l++)
223  {
224  int nbins = hist->GetNumPoints(l);
225  basis *= lookup_[l].values[it2.index(l) + coeff.map[l]*nbins]*functions_[l]->GetRange()/nbins;
226  //Normalize the values by the associated value
227  basis *= functions_[l]->GetNorm(coeff.map[l])*functions_[l]->Weight(it2.coordinate(l));
228  }
229  coeff.value += basis * array[j] * weight/std::pow(2.0,functions_.size());
230  }
231  coeffTemp -= coeff.value;
232  //std::cout<<coeffTemp<<std::endl;
233  sum += fabs(coeffTemp);
234  }
235  return sum;
236  }
std::vector< BasisFunction * > functions_
Vector of basis functions.
Definition: Basis.h:336
GridIterator< unsigned int > iterator
Custom iterator over a grid.
Definition: Grid.h:515
iterator begin()
Return iterator at first grid point.
Definition: Grid.h:527
std::vector< Map > coeff_
Vector of basis function coefficients.
Definition: Basis.h:335
const std::vector< int > GetNumPoints() const
Get the number of points for all dimensions.
Definition: GridBase.h:200
std::vector< BasisLUT > lookup_
Lookup table for basis functions.
Definition: Basis.h:337
iterator end()
Return iterator after last valid grid point.
Definition: Grid.h:540
Here is the call graph for this function:

The documentation for this class was generated from the following files: