SSAGES  0.8.3
Software Suite for Advanced General Ensemble Simulations
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SSAGES::GridBase< T > Class Template Referenceabstract

Base class for Grids. More...

#include <GridBase.h>

Inheritance diagram for SSAGES::GridBase< T >:
Inheritance graph
[legend]

Public Member Functions

void syncGrid ()
 Sync the grid.
 
size_t GetDimension () const
 Get the dimension. More...
 
const std::vector< int > GetNumPoints () const
 Get the number of points for all dimensions. More...
 
int GetNumPoints (size_t dim) const
 Get the number of points for a specific dimension. More...
 
const std::vector< double > GetLower () const
 Return the lower edges of the Grid. More...
 
double GetLower (size_t dim) const
 Get the lower edge for a specific dimension. More...
 
const std::vector< double > GetUpper () const
 Return the upper edges of the Grid. More...
 
double GetUpper (size_t dim) const
 Get the upper edge for a specific dimension. More...
 
const std::vector< bool > & GetPeriodic () const
 Return the periodicity of the Grid. More...
 
bool GetPeriodic (size_t dim) const
 Get the periodicity in a specific dimension. More...
 
size_t size () const
 Get the size of the internal storage vector. More...
 
T * data ()
 Get pointer to the internal data storage vector. More...
 
T const * data () const
 Get pointer to const of the internal data storage vector. More...
 
std::vector< int > GetIndices (const std::vector< double > &x) const
 Return the Grid indices for a given point. More...
 
int GetIndex (double x) const
 Return linear interpolation on a coordinate. More...
 
std::vector< double > GetCoordinates (const std::vector< int > &indices)
 ! Return the distance to adjacent grid center points from given coordinates More...
 
double GetCoordinate (int index)
 Return center point of 1d-grid. More...
 
const T & at (const std::vector< int > &indices) const
 Access Grid element read-only. More...
 
T & at (const std::vector< int > &indices)
 Access Grid element read/write. More...
 
template<typename R >
const T & at (std::initializer_list< R > &&x) const
 Const access of Grid element via initializer list. More...
 
template<typename R >
T & at (std::initializer_list< R > &&x)
 Access Grid element via initializer list. More...
 
const T & at (int index) const
 Access 1d Grid by index, read-only. More...
 
T & at (int index)
 Access 1d Grid by index, read-write. More...
 
const T & at (const std::vector< double > &x) const
 Access Grid element pertaining to a specific point – read-only. More...
 
T & at (const std::vector< double > &x)
 Access Grid element pertaining to a specific point – read/write. More...
 
const T & at (double x) const
 Access 1d-Grid by point - read-only. More...
 
T & at (double x)
 Access 1d-Grid by point - read-write. More...
 
const T & operator[] (const std::vector< int > &indices) const
 Access Grid element per [] read-only. More...
 
T & operator[] (const std::vector< int > &indices)
 Access Grid element per [] read-write. More...
 
template<typename R >
const T & operator[] (std::initializer_list< R > &&x) const
 Const access of Grid element via initializer list. More...
 
template<typename R >
T & operator[] (std::initializer_list< R > &&x)
 Access Grid element via initializer list. More...
 
const T & operator[] (int index) const
 Access 1d-Grid per [] operator, read-only. More...
 
T & operator[] (int index)
 Access 1d-Grid per [] operator, read-write. More...
 
const T & operator[] (const std::vector< double > &x) const
 Access Grid element pertaining to a specific point per [] read-only. More...
 
T & operator[] (const std::vector< double > &x)
 Access Grid element pertaining to a specific point per [] read-write. More...
 
const T & operator[] (double x) const
 Access 1d-Grid via specific point, read-only. More...
 
T & operator[] (double x)
 Access 1d-Grid via specific point, read-write. More...
 
virtual ~GridBase ()
 Destructor.
 

Protected Member Functions

std::vector< int > wrapIndices (const std::vector< int > &indices) const
 Wrap the index around periodic boundaries.
 
virtual size_t mapTo1d (const std::vector< int > &indices) const =0
 This function needs to be implemented by child classes. More...
 
 GridBase (std::vector< int > numPoints, std::vector< double > lower, std::vector< double > upper, std::vector< bool > isPeriodic)
 Constructor. More...
 

Protected Attributes

std::vector< T > data_
 Internal storage of the data.
 
size_t dimension_
 Dimension of the grid.
 
std::vector< int > numPoints_
 Number of points in each dimension.
 
std::pair< std::vector< double >, std::vector< double > > edges_
 Edges of the Grid in each dimension.
 
std::vector< bool > isPeriodic_
 Periodicity of the Grid.
 

Detailed Description

template<typename T>
class SSAGES::GridBase< T >

Base class for Grids.

Template Parameters
Typeof data stored on the grid

Base class for all grids. Currently, these are 'Grid' and 'Histogram'.

Definition at line 38 of file GridBase.h.

Constructor & Destructor Documentation

◆ GridBase()

template<typename T>
SSAGES::GridBase< T >::GridBase ( std::vector< int >  numPoints,
std::vector< double >  lower,
std::vector< double >  upper,
std::vector< bool >  isPeriodic 
)
inlineprotected

Constructor.

Parameters
numPointsNumber of grid points in each dimension.
lowerLower edges of the grid.
upperUpper edges of the grid.
isPeriodicBools specifying the periodicity in the respective dimension.

The constructor is protected by design. This makes sure that only child classes of GridBase are constructed.

Definition at line 99 of file GridBase.h.

103  : dimension_(numPoints.size()),
104  numPoints_(numPoints),
105  edges_(std::pair< std::vector<double>, std::vector<double> >(lower, upper)),
106  isPeriodic_(isPeriodic)
107  {
108  // Check that vector sizes are correct
109  if (edges_.first.size() != dimension_ ||
110  edges_.second.size() != dimension_) {
111  throw std::invalid_argument("Size of vector containing upper or "
112  "lower edges, does not match size of vector containing "
113  "number of grid points.");
114  }
115  if (isPeriodic_.size() == 0) {
116  // Default: Non-periodic in all dimensions
117  isPeriodic.resize(dimension_, false);
118  } else if (isPeriodic_.size() != dimension_) {
119  throw std::invalid_argument("Size of vector isPeriodic does not "
120  "match size of vector containing number of grid points.");
121  }
122  for(size_t i=0 ; i < isPeriodic_.size() ; i++)
123  {
124  if(isPeriodic_[i])
125  {
126  if(numPoints_[i] <= 1)
127  {
128  throw std::invalid_argument("A periodic grid is incompatible with a grid size of 1.");
129  }
130  double spacing = (edges_.second[i] - edges_.first[i]) / (numPoints_[i]-1);
131  edges_.first[i] -= spacing/2;
132  edges_.second[i] += spacing/2;
133  }
134  }
135 
136  }
std::pair< std::vector< double >, std::vector< double > > edges_
Edges of the Grid in each dimension.
Definition: GridBase.h:51
std::vector< int > numPoints_
Number of points in each dimension.
Definition: GridBase.h:48
size_t dimension_
Dimension of the grid.
Definition: GridBase.h:45
std::vector< bool > isPeriodic_
Periodicity of the Grid.
Definition: GridBase.h:54

Member Function Documentation

◆ at() [1/10]

template<typename T>
const T& SSAGES::GridBase< T >::at ( const std::vector< int > &  indices) const
inline

Access Grid element read-only.

Parameters
indicesVector of integers specifying the grid point.
Returns
const reference of the value stored at the given grid point.

In non-periodic dimensions, the index needs to be in the interval [-1, numPoints]. Grid::at(-1) accessed the underflow bin, Grid::at(numPoints) accesses the overflow bin.

In periodic dimensions, the index may take any integer value and will be mapped back to the interval [0, numPoints-1]. Thus, Grid::at(-1) will access the same value as Grid::at(numPoints-1).

Definition at line 541 of file GridBase.h.

Referenced by SSAGES::GridBase< Eigen::VectorXd >::at(), SSAGES::GridBase< Eigen::VectorXd >::GetCoordinate(), SSAGES::GridBase< Eigen::VectorXd >::operator[](), SSAGES::ANN::PostIntegration(), and SSAGES::GridBase< Eigen::VectorXd >::syncGrid().

542  {
543  // Check that indices are in bound.
544  if (indices.size() != GetDimension()) {
545  throw std::invalid_argument("Dimension of indices does not match "
546  "dimension of the grid.");
547  }
548 
549  return data_.at(mapTo1d(indices));
550  }
size_t GetDimension() const
Get the dimension.
Definition: GridBase.h:190
std::vector< T > data_
Internal storage of the data.
Definition: GridBase.h:42
virtual size_t mapTo1d(const std::vector< int > &indices) const =0
This function needs to be implemented by child classes.
Here is the caller graph for this function:

◆ at() [2/10]

template<typename T>
T& SSAGES::GridBase< T >::at ( const std::vector< int > &  indices)
inline

Access Grid element read/write.

Parameters
indicesVector of integers specifying the grid point.
Returns
Reference to value at the specified grid point.

Definition at line 557 of file GridBase.h.

558  {
559  return const_cast<T&>(static_cast<const GridBase<T>* >(this)->at(indices));
560  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ at() [3/10]

template<typename T>
template<typename R >
const T& SSAGES::GridBase< T >::at ( std::initializer_list< R > &&  x) const
inline

Const access of Grid element via initializer list.

Template Parameters
RDatatype in the initializer list
Parameters
xinitializer list
Returns
Const reference to value at the specified point.

This function avoids abiguity if at() is called with a brace-enclosed initializer list. The template parameter makes sure that this function can be called with either ints, specifying a grid point, or doubles, specifying coordinates in space, inside the initializer list.

Definition at line 574 of file GridBase.h.

575  {
576  return at(static_cast<std::vector<R> >(x));
577  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ at() [4/10]

template<typename T>
template<typename R >
T& SSAGES::GridBase< T >::at ( std::initializer_list< R > &&  x)
inline

Access Grid element via initializer list.

Template Parameters
RDatatype in the initializer list
Parameters
xinitializer list
Returns
Reference to value at the specified point.

This function avoids abiguity if at() is called with a brace-enclosed initializer list. The template parameter makes sure that this function can be called with either ints, specifying a grid point, or doubles, specifying coordinates in space, inside the initializer list.

Definition at line 591 of file GridBase.h.

592  {
593  return at(static_cast<std::vector<R> >(x));
594  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ at() [5/10]

template<typename T>
const T& SSAGES::GridBase< T >::at ( int  index) const
inline

Access 1d Grid by index, read-only.

Parameters
indexIndex specifying the grid point.
Returns
Const reference of value at the given index.
Note
This function can only be used for 1d-Grids.

Definition at line 603 of file GridBase.h.

604  {
605  if (dimension_ != 1) {
606  throw std::invalid_argument("Only 1d-Grids can be accessed with a "
607  "single integer as the index.");
608  }
609  return at({index});
610  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541
size_t dimension_
Dimension of the grid.
Definition: GridBase.h:45

◆ at() [6/10]

template<typename T>
T& SSAGES::GridBase< T >::at ( int  index)
inline

Access 1d Grid by index, read-write.

Parameters
indexIndex specifying the grid point.
Returns
Reference of value at the given grid point.
Note
This function can only be used for 1d-Grids.

Definition at line 619 of file GridBase.h.

620  {
621  return const_cast<T&>(static_cast<const GridBase<T>* >(this)->at(index));
622  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ at() [7/10]

template<typename T>
const T& SSAGES::GridBase< T >::at ( const std::vector< double > &  x) const
inline

Access Grid element pertaining to a specific point – read-only.

Parameters
xVector of doubles specifying a point.
Returns
Const reference of the value at the given coordinates.

This function is provided for convenience. It is identical to GridBase::at(GridBase::GetIndices(x)).

Definition at line 632 of file GridBase.h.

633  {
634  return at(GetIndices(x));
635  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541
std::vector< int > GetIndices(const std::vector< double > &x) const
Return the Grid indices for a given point.
Definition: GridBase.h:367

◆ at() [8/10]

template<typename T>
T& SSAGES::GridBase< T >::at ( const std::vector< double > &  x)
inline

Access Grid element pertaining to a specific point – read/write.

Parameters
xVector of doubles specifying a point.
Returns
Reference to the value at the given coordinates.

This function is provided for convenience. It is identical to GridBase::at(GridBase::GetIndices(x)).

Definition at line 645 of file GridBase.h.

646  {
647  return at(GetIndices(x));
648  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541
std::vector< int > GetIndices(const std::vector< double > &x) const
Return the Grid indices for a given point.
Definition: GridBase.h:367

◆ at() [9/10]

template<typename T>
const T& SSAGES::GridBase< T >::at ( double  x) const
inline

Access 1d-Grid by point - read-only.

Parameters
xAccess grid point pertaining to this value.
Returns
Const reference to the value pertaining to the specified coordinate.
Note
This function can only be used for 1d-Grids.

Definition at line 658 of file GridBase.h.

659  {
660  if (dimension_ != 1) {
661  throw std::invalid_argument("Only 1d-Grids can be accessed with a "
662  "single float as the specified point.");
663  }
664  return at({x});
665  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541
size_t dimension_
Dimension of the grid.
Definition: GridBase.h:45

◆ at() [10/10]

template<typename T>
T& SSAGES::GridBase< T >::at ( double  x)
inline

Access 1d-Grid by point - read-write.

Parameters
xAccess grid point pertaining to this value.
Returns
Reference to the value pertaining to the specified coordinate.
Note
This function can only be used for 1d Grids.

Definition at line 674 of file GridBase.h.

675  {
676  return const_cast<T&>(static_cast<const GridBase<T>* >(this)->at(x));
677  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ data() [1/2]

template<typename T>
T* SSAGES::GridBase< T >::data ( )
inline

Get pointer to the internal data storage vector.

Returns
Pointer to data in the internal storage vector.

It is discouraged to directly access the internal data storage. It might, however be necessary. For example when communicating the data over MPI.

Definition at line 333 of file GridBase.h.

Referenced by SSAGES::BFS::ProjectBias(), and SSAGES::ANN::TrainNetwork().

334  {
335  return data_.data();
336  }
std::vector< T > data_
Internal storage of the data.
Definition: GridBase.h:42
Here is the caller graph for this function:

◆ data() [2/2]

template<typename T>
T const* SSAGES::GridBase< T >::data ( ) const
inline

Get pointer to const of the internal data storage vector.

Returns
Const pointer to data in the internal storage vector.

It is discouraged to directly access the internal data storage. It might, however be necessary. For example when communicating data over MPI.

Definition at line 345 of file GridBase.h.

346  {
347  return data_.data();
348  }
std::vector< T > data_
Internal storage of the data.
Definition: GridBase.h:42

◆ GetCoordinate()

template<typename T>
double SSAGES::GridBase< T >::GetCoordinate ( int  index)
inline

Return center point of 1d-grid.

Parameters
indexIndex of the 1d grid.
Returns
Coordinate in real/CV space.
Note
This function is only available for 1d grids.

Definition at line 523 of file GridBase.h.

524  {
525  return GetCoordinates({index}).at(0);
526  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541
std::vector< double > GetCoordinates(const std::vector< int > &indices)
! Return the distance to adjacent grid center points from given coordinates
Definition: GridBase.h:498

◆ GetCoordinates()

template<typename T>
std::vector<double> SSAGES::GridBase< T >::GetCoordinates ( const std::vector< int > &  indices)
inline

! Return the distance to adjacent grid center points from given coordinates

Return coordinates of the grid center points

Parameters
indicesGrid indices specifying a grid point.
Returns
Vector of double specifying the position of the grid point.

The grid is a discretization of real or cv space. Thus, each grid point is associated with an interval of the underlying space. This function returns the center point of this interval.

Definition at line 498 of file GridBase.h.

Referenced by SSAGES::GridBase< Eigen::VectorXd >::GetCoordinate().

499  {
500  if (indices.size() != dimension_) {
501  throw std::invalid_argument(
502  "Grid indices specified for GetCoordinates() do not have "
503  "the same dimensionality as the grid.");
504  }
505 
506  std::vector<double> v(dimension_);
507 
508  for (size_t i = 0; i < dimension_; ++i) {
509  double spacing = (edges_.second[i] - edges_.first[i]) / (numPoints_[i]);
510  v.at(i) = edges_.first[i] + (indices[i] + 0.5)*spacing;
511  }
512 
513  return v;
514  }
std::pair< std::vector< double >, std::vector< double > > edges_
Edges of the Grid in each dimension.
Definition: GridBase.h:51
std::vector< int > numPoints_
Number of points in each dimension.
Definition: GridBase.h:48
size_t dimension_
Dimension of the grid.
Definition: GridBase.h:45
Here is the caller graph for this function:

◆ GetDimension()

template<typename T>
size_t SSAGES::GridBase< T >::GetDimension ( ) const
inline

◆ GetIndex()

template<typename T>
int SSAGES::GridBase< T >::GetIndex ( double  x) const
inline

Return linear interpolation on a coordinate.

Parameters
xPoint in space.
Returns
Linearly interpolated value of grid at that point. This function performs a n-linear interpolation on the grid. The formula is bilinear/trilinear interpolation generalized to N-dimensional space. double GetInterpolated(const std::vector<double> &x) { double interpvalue = 0; int tempindex; for (size_t i = 0 ; i < pow(2,dimension_) ; ++i) {
std::vector<double> shiftedvector = x;
tempindex = i;

double accumulatedweight = 1;
for(size_t j = 0; j < dimension_ ; ++j)
{
    double spacing = (edges_.second[j] - edges_.first[j]) / numPoints_[j];
    shiftedvector[j] += ((tempindex%2)-0.5)*spacing;
    tempindex = tempindex/2;
}

std::vector<int> shiftedindices = GetIndices(shiftedvector);
std::vector<double> shiftedcenters = GetCoordinates(shiftedindices);

for(size_t j = 0; j < dimension_ ; ++j)
{   
    double spacing = (edges_.second[j] - edges_.first[j]) / numPoints_[j];
Handle Edges if(shiftedindices[j] == -1) { accumulatedweight *= ((std::abs(x[j]-GetCoordinates(GetIndices(x))[j])/spacing)); shiftedvector[j] += spacing/2; } else if (shiftedindices[j] == numPoints_[j]) { accumulatedweight *= ((std::abs(x[j]-GetCoordinates(GetIndices(x))[j])/spacing)); shiftedvector[j] -= spacing/2; } else { Handle Periodicity if(std::abs(x[j]-shiftedcenters[j]) > spacing) accumulatedweight *= (1-(std::abs(std::abs(x[j]-shiftedcenters[j]) - (edges_.second[j] - edges_.first[j]))/spacing)); else accumulatedweight *= (1-(std::abs(x[j]-shiftedcenters[j])/spacing)); } } interpvalue += accumulatedweight*at(shiftedvector); } return interpvalue; } Return the Grid index for a one-dimensional grid.
Parameters
xPoint in space.
Returns
Grid index to which the point pertains.

Return the Grid index pertaining to the given point in space. This function is for convenience when accessing 1d-Grids. For higher-dimensional grids, x needs to be a vector of doubles.

Definition at line 467 of file GridBase.h.

468  {
469  if (dimension_ != 1) {
470  throw std::invalid_argument("1d Grid index can only be accessed for "
471  "1d-Grids can be accessed with a.");
472  }
473  return GetIndices({x}).at(0);
474  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541
std::vector< int > GetIndices(const std::vector< double > &x) const
Return the Grid indices for a given point.
Definition: GridBase.h:367
size_t dimension_
Dimension of the grid.
Definition: GridBase.h:45

◆ GetIndices()

template<typename T>
std::vector<int> SSAGES::GridBase< T >::GetIndices ( const std::vector< double > &  x) const
inline

Return the Grid indices for a given point.

Parameters
xPoint in space.
Returns
Indices of the grid point to which the point in space pertains.

The grid discretizes the continuous space. For a given point in this continuous space, this function will return the indices of the grid point covering the point in space.

If the grid is non-periodic in a given dimension and x is lower than the lower edge in this dimension, the function will return -1, the index of the underflow bin. Similarly, it will return numPoints, the index of the overflow bin, if x is larger than the upper edge.

In periodic dimensions, the index can take any integer value and will be wrapped to the interval [0, numPoints).

Definition at line 367 of file GridBase.h.

368  {
369  // Check that input vector has the correct dimensionality
370  if (x.size() != dimension_) {
371  throw std::invalid_argument("Specified point has a larger "
372  "dimensionality than the grid.");
373  }
374 
375  std::vector<int> indices(dimension_);
376  for (size_t i = 0; i < dimension_; ++i)
377  {
378  double xpos = x.at(i);
379  if (!GetPeriodic(i))
380  {
381  if (xpos < edges_.first[i])
382  {
383  indices.at(i) = -1;
384  continue;
385  }
386  else if (xpos > edges_.second[i])
387  {
388  indices.at(i) = numPoints_[i];
389  continue;
390  }
391 
392  }
393 
394  // To make sure, the value is rounded in the correct direction.
395  double spacing = (edges_.second[i] - edges_.first[i]) / (numPoints_[i]);
396  indices.at(i) = std::floor( (xpos - edges_.first[i]) / spacing);
397  }
398 
399  return wrapIndices(indices);
400  }
const std::vector< bool > & GetPeriodic() const
Return the periodicity of the Grid.
Definition: GridBase.h:290
std::pair< std::vector< double >, std::vector< double > > edges_
Edges of the Grid in each dimension.
Definition: GridBase.h:51
std::vector< int > numPoints_
Number of points in each dimension.
Definition: GridBase.h:48
std::vector< int > wrapIndices(const std::vector< int > &indices) const
Wrap the index around periodic boundaries.
Definition: GridBase.h:57
size_t dimension_
Dimension of the grid.
Definition: GridBase.h:45

◆ GetLower() [1/2]

template<typename T>
const std::vector<double> SSAGES::GridBase< T >::GetLower ( ) const
inline

Return the lower edges of the Grid.

Returns
Vector containing the lower edges of the grid.

Definition at line 226 of file GridBase.h.

Referenced by SSAGES::ANN::PostIntegration(), SSAGES::BasisEvaluator::UpdateBias(), and SSAGES::Grid< Eigen::VectorXd >::WriteToFile().

227  {
228  std::vector<double> lower(dimension_);
229  for(size_t i = 0; i<dimension_;++i)
230  if(GetPeriodic(i)) {lower[i] = edges_.first[i] - ((edges_.first[i] - edges_.second[i]) / (numPoints_[i]))/2;}
231  else {lower[i] = edges_.first[i];}
232  return lower;
233  }
const std::vector< bool > & GetPeriodic() const
Return the periodicity of the Grid.
Definition: GridBase.h:290
std::pair< std::vector< double >, std::vector< double > > edges_
Edges of the Grid in each dimension.
Definition: GridBase.h:51
std::vector< int > numPoints_
Number of points in each dimension.
Definition: GridBase.h:48
size_t dimension_
Dimension of the grid.
Definition: GridBase.h:45
Here is the caller graph for this function:

◆ GetLower() [2/2]

template<typename T>
double SSAGES::GridBase< T >::GetLower ( size_t  dim) const
inline

Get the lower edge for a specific dimension.

Parameters
dimIndex of the dimension.
Returns
Value of the lower edge in the requested dimension.
Note
The first dimension has the index 0.

Definition at line 242 of file GridBase.h.

243  {
244  if (dim >= GetDimension()) {
245  std::cerr << "Warning! Lower edge requested for a dimension larger "
246  "than the grid dimensionality!\n";
247  return 0.0;
248  }
249  if(GetPeriodic(dim)){return edges_.first[dim] - ((edges_.first[dim] - edges_.second[dim]) / (numPoints_[dim]))/2;}
250  else{return edges_.first[dim];}
251  }
const std::vector< bool > & GetPeriodic() const
Return the periodicity of the Grid.
Definition: GridBase.h:290
size_t GetDimension() const
Get the dimension.
Definition: GridBase.h:190
std::pair< std::vector< double >, std::vector< double > > edges_
Edges of the Grid in each dimension.
Definition: GridBase.h:51
std::vector< int > numPoints_
Number of points in each dimension.
Definition: GridBase.h:48

◆ GetNumPoints() [1/2]

template<typename T>
const std::vector<int> SSAGES::GridBase< T >::GetNumPoints ( ) const
inline

Get the number of points for all dimensions.

Returns
Vector of ints containing the number of grid points for each dimension.

Definition at line 200 of file GridBase.h.

Referenced by SSAGES::BFS::Build(), SSAGES::BasisEvaluator::UpdateBias(), SSAGES::BasisEvaluator::UpdateCoeff(), and SSAGES::Grid< Eigen::VectorXd >::WriteToFile().

201  {
202  return numPoints_;
203  }
std::vector< int > numPoints_
Number of points in each dimension.
Definition: GridBase.h:48
Here is the caller graph for this function:

◆ GetNumPoints() [2/2]

template<typename T>
int SSAGES::GridBase< T >::GetNumPoints ( size_t  dim) const
inline

Get the number of points for a specific dimension.

Parameters
dimIndex of the dimension.
Returns
Number of grid points in the requested dimension.
Note
The first dimension uses the index 0.

Definition at line 212 of file GridBase.h.

213  {
214  if (dim >= GetDimension()) {
215  std::cerr << "Warning! Grid size requested for a dimension larger "
216  "than the grid dimensionality!\n";
217  return 0;
218  }
219  return numPoints_.at(dim);
220  }
size_t GetDimension() const
Get the dimension.
Definition: GridBase.h:190
std::vector< int > numPoints_
Number of points in each dimension.
Definition: GridBase.h:48

◆ GetPeriodic() [1/2]

template<typename T>
const std::vector<bool>& SSAGES::GridBase< T >::GetPeriodic ( ) const
inline

Return the periodicity of the Grid.

Returns
Vector of bools. The values are True (False ) if the grid is periodic (non-periodic) in the given dimension.

Definition at line 290 of file GridBase.h.

Referenced by SSAGES::GridBase< Eigen::VectorXd >::GetLower(), SSAGES::GridBase< Eigen::VectorXd >::GetPeriodic(), SSAGES::GridBase< Eigen::VectorXd >::GetUpper(), and SSAGES::GridBase< Eigen::VectorXd >::wrapIndices().

291  {
292  return isPeriodic_;
293  }
std::vector< bool > isPeriodic_
Periodicity of the Grid.
Definition: GridBase.h:54
Here is the caller graph for this function:

◆ GetPeriodic() [2/2]

template<typename T>
bool SSAGES::GridBase< T >::GetPeriodic ( size_t  dim) const
inline

Get the periodicity in a specific dimension.

Parameters
dimIndex of the dimension.
Returns
True (False ) if the grid is periodic (non-periodic) in the specified dimension.
Note
The dimensions are indexed starting with 0.

Definition at line 303 of file GridBase.h.

304  {
305  if (dim >= GetDimension()) {
306  std::cerr << "Warning! Periodicity requested for a dimension larger "
307  "than the grid dimensionality!\n";
308  return false;
309  }
310  return GetPeriodic().at(dim);
311  }
const std::vector< bool > & GetPeriodic() const
Return the periodicity of the Grid.
Definition: GridBase.h:290
size_t GetDimension() const
Get the dimension.
Definition: GridBase.h:190

◆ GetUpper() [1/2]

template<typename T>
const std::vector<double> SSAGES::GridBase< T >::GetUpper ( ) const
inline

Return the upper edges of the Grid.

Returns
Vector containing the upper edges of the grid.

Definition at line 257 of file GridBase.h.

Referenced by SSAGES::ANN::PostIntegration(), SSAGES::BasisEvaluator::UpdateBias(), and SSAGES::Grid< Eigen::VectorXd >::WriteToFile().

258  {
259  std::vector<double> upper(dimension_);
260  for(size_t i = 0; i<dimension_;++i)
261  if(GetPeriodic(i)) {upper[i] = edges_.second[i] + ((edges_.first[i] - edges_.second[i]) / (numPoints_[i]))/2;}
262  else {upper[i] = edges_.second[i];}
263  return upper;
264  }
const std::vector< bool > & GetPeriodic() const
Return the periodicity of the Grid.
Definition: GridBase.h:290
std::pair< std::vector< double >, std::vector< double > > edges_
Edges of the Grid in each dimension.
Definition: GridBase.h:51
std::vector< int > numPoints_
Number of points in each dimension.
Definition: GridBase.h:48
size_t dimension_
Dimension of the grid.
Definition: GridBase.h:45
Here is the caller graph for this function:

◆ GetUpper() [2/2]

template<typename T>
double SSAGES::GridBase< T >::GetUpper ( size_t  dim) const
inline

Get the upper edge for a specific dimension.

Parameters
dimIndex of the dimension.
Returns
Value of the upper edge in the given dimension.
Note
The dimensions are indexed starting with 0.

Definition at line 274 of file GridBase.h.

275  {
276  if (dim >= GetDimension()) {
277  std::cerr << "Warning! Upper edge requested for a dimension larger "
278  "than the grid dimensionality!\n";
279  return 0.0;
280  }
281  if(GetPeriodic(dim)){return edges_.second[dim] + ((edges_.first[dim] - edges_.second[dim]) / (numPoints_[dim]))/2;}
282  else{return edges_.second[dim];}
283  }
const std::vector< bool > & GetPeriodic() const
Return the periodicity of the Grid.
Definition: GridBase.h:290
size_t GetDimension() const
Get the dimension.
Definition: GridBase.h:190
std::pair< std::vector< double >, std::vector< double > > edges_
Edges of the Grid in each dimension.
Definition: GridBase.h:51
std::vector< int > numPoints_
Number of points in each dimension.
Definition: GridBase.h:48

◆ mapTo1d()

template<typename T>
virtual size_t SSAGES::GridBase< T >::mapTo1d ( const std::vector< int > &  indices) const
protectedpure virtual

This function needs to be implemented by child classes.

Parameters
indicesThe indices specifying the grid point.
Returns
Index of the grid point in the 1d storage vector.

mapTo1d maps the indices onto a single index to access the data stored in the data_ vector. This mapping will be different for different grid implementations.

Implemented in SSAGES::Grid< T >, SSAGES::Grid< double >, SSAGES::Grid< Vector >, SSAGES::Grid< int >, SSAGES::Grid< unsigned int >, SSAGES::Grid< std::vector< double > >, and SSAGES::Grid< Eigen::VectorXd >.

Referenced by SSAGES::GridBase< Eigen::VectorXd >::at(), and SSAGES::GridBase< Eigen::VectorXd >::wrapIndices().

Here is the caller graph for this function:

◆ operator[]() [1/10]

template<typename T>
const T& SSAGES::GridBase< T >::operator[] ( const std::vector< int > &  indices) const
inline

Access Grid element per [] read-only.

Parameters
indicesVector of integers specifying the grid point.
Returns
Const reference to value to the given grid point.

Definition at line 684 of file GridBase.h.

685  {
686  return at(indices);
687  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ operator[]() [2/10]

template<typename T>
T& SSAGES::GridBase< T >::operator[] ( const std::vector< int > &  indices)
inline

Access Grid element per [] read-write.

Parameters
indicesVector of integers specifying the grid point.
Returns
Reference to value at the specified grid point.

Definition at line 694 of file GridBase.h.

695  {
696  return at(indices);
697  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ operator[]() [3/10]

template<typename T>
template<typename R >
const T& SSAGES::GridBase< T >::operator[] ( std::initializer_list< R > &&  x) const
inline

Const access of Grid element via initializer list.

Template Parameters
RDatatype in the initializer list
Parameters
xinitializer list
Returns
Const reference to the value at the specified point.

This function avoids abiguity if operator[] is called with a brace-enclosed initializer list.

Example: grid[{0,1}] or grid[{-1.23, 4.2, 0.0}]

Definition at line 711 of file GridBase.h.

712  {
713  return at(static_cast<std::vector<R> >(x));
714  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ operator[]() [4/10]

template<typename T>
template<typename R >
T& SSAGES::GridBase< T >::operator[] ( std::initializer_list< R > &&  x)
inline

Access Grid element via initializer list.

Template Parameters
RDatatype in the initializer list
Parameters
xinitializer list
Returns
Reference to the value at the specified point.

This function avoids abiguity if operator[] is called with a brace-enclosed initializer list.

Example: grid[{0,1}]

Definition at line 728 of file GridBase.h.

729  {
730  return at(static_cast<std::vector<R> >(x));
731  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ operator[]() [5/10]

template<typename T>
const T& SSAGES::GridBase< T >::operator[] ( int  index) const
inline

Access 1d-Grid per [] operator, read-only.

Parameters
indexIndex of the grid point.
Returns
Const reference to the value at the given grid point.
Note
This function can only be used for 1d grids.

Definition at line 740 of file GridBase.h.

741  {
742  return at(index);
743  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ operator[]() [6/10]

template<typename T>
T& SSAGES::GridBase< T >::operator[] ( int  index)
inline

Access 1d-Grid per [] operator, read-write.

Parameters
indexIndex of the grid point.
Returns
Reference to the value at the given grid point.
Note
This function can only be used for 1d grids.

Definition at line 752 of file GridBase.h.

753  {
754  return at(index);
755  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ operator[]() [7/10]

template<typename T>
const T& SSAGES::GridBase< T >::operator[] ( const std::vector< double > &  x) const
inline

Access Grid element pertaining to a specific point per [] read-only.

Parameters
xVector of doubles specifying the point in space.
Returns
Const reference to the value pertaining to the given coordinates.

Definition at line 762 of file GridBase.h.

763  {
764  return at(x);
765  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ operator[]() [8/10]

template<typename T>
T& SSAGES::GridBase< T >::operator[] ( const std::vector< double > &  x)
inline

Access Grid element pertaining to a specific point per [] read-write.

Parameters
xVector of doubles specifying the point in space.
Returns
Reference to the value pertaining to the given coordinates.

Definition at line 772 of file GridBase.h.

773  {
774  return at(x);
775  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ operator[]() [9/10]

template<typename T>
const T& SSAGES::GridBase< T >::operator[] ( double  x) const
inline

Access 1d-Grid via specific point, read-only.

Parameters
xPoint specifying the desired Grid point.
Returns
Const reference to the value at the specified coordinate.
Note
This function can only be used for 1d grids.

Definition at line 784 of file GridBase.h.

785  {
786  return at(x);
787  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ operator[]() [10/10]

template<typename T>
T& SSAGES::GridBase< T >::operator[] ( double  x)
inline

Access 1d-Grid via specific point, read-write.

Parameters
xPoint specifying the desired Grid point.
Returns
Reference to value at the specified coordinate.
Note
This function can only be used for 1d grids.

Definition at line 796 of file GridBase.h.

797  {
798  return at(x);
799  }
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
Definition: GridBase.h:541

◆ size()

template<typename T>
size_t SSAGES::GridBase< T >::size ( ) const
inline

Get the size of the internal storage vector.

Returns
Size of the internal storage vector.

This function returns the size of the internal storage vector. This is also the total number of grid points including the over/underflow bins in case of a histogram.

Definition at line 321 of file GridBase.h.

Referenced by SSAGES::ANN::ANN(), SSAGES::Grid< Eigen::VectorXd >::BuildGrid(), and SSAGES::ANN::TrainNetwork().

322  {
323  return data_.size();
324  }
std::vector< T > data_
Internal storage of the data.
Definition: GridBase.h:42
Here is the caller graph for this function:

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