SSAGES
0.9.3
Software Suite for Advanced General Ensemble Simulations
|
Base class for Grids. More...
#include <GridBase.h>
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. More... | |
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. | |
Base class for Grids.
Type | of data stored on the grid |
Base class for all grids. Currently, these are 'Grid' and 'Histogram'.
Definition at line 38 of file GridBase.h.
|
inlineprotected |
Constructor.
numPoints | Number of grid points in each dimension. |
lower | Lower edges of the grid. |
upper | Upper edges of the grid. |
isPeriodic | Bools 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 104 of file GridBase.h.
References SSAGES::GridBase< T >::dimension_, SSAGES::GridBase< T >::edges_, SSAGES::GridBase< T >::isPeriodic_, and SSAGES::GridBase< T >::numPoints_.
|
inline |
Access Grid element pertaining to a specific point – read/write.
x | Vector of doubles specifying a point. |
This function is provided for convenience. It is identical to GridBase::at(GridBase::GetIndices(x)).
Definition at line 650 of file GridBase.h.
References SSAGES::GridBase< T >::at(), and SSAGES::GridBase< T >::GetIndices().
|
inline |
Access Grid element pertaining to a specific point – read-only.
x | Vector of doubles specifying a point. |
This function is provided for convenience. It is identical to GridBase::at(GridBase::GetIndices(x)).
Definition at line 637 of file GridBase.h.
References SSAGES::GridBase< T >::at(), and SSAGES::GridBase< T >::GetIndices().
|
inline |
Access Grid element read/write.
indices | Vector of integers specifying the grid point. |
Definition at line 562 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Access Grid element read-only.
indices | Vector of integers specifying the 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 546 of file GridBase.h.
References SSAGES::GridBase< T >::data_, SSAGES::GridBase< T >::GetDimension(), and SSAGES::GridBase< T >::mapTo1d().
Referenced by SSAGES::GridBase< T >::at(), SSAGES::GridBase< T >::GetCoordinate(), SSAGES::GridBase< T >::GetIndex(), SSAGES::GridBase< T >::operator[](), SSAGES::ANN::PostIntegration(), and SSAGES::GridBase< T >::syncGrid().
|
inline |
Access 1d-Grid by point - read-write.
x | Access grid point pertaining to this value. |
Definition at line 679 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Access 1d-Grid by point - read-only.
x | Access grid point pertaining to this value. |
Definition at line 663 of file GridBase.h.
References SSAGES::GridBase< T >::at(), and SSAGES::GridBase< T >::dimension_.
|
inline |
Access 1d Grid by index, read-write.
index | Index specifying the grid point. |
Definition at line 624 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Access 1d Grid by index, read-only.
index | Index specifying the grid point. |
Definition at line 608 of file GridBase.h.
References SSAGES::GridBase< T >::at(), and SSAGES::GridBase< T >::dimension_.
|
inline |
Access Grid element via initializer list.
R | Datatype in the initializer list |
x | initializer list |
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 596 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Const access of Grid element via initializer list.
R | Datatype in the initializer list |
x | initializer list |
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 579 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Get pointer to the internal data 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 338 of file GridBase.h.
References SSAGES::GridBase< T >::data_.
Referenced by SSAGES::BFS::ProjectBias(), SSAGES::ANN::ReadBias(), SSAGES::ANN::TrainNetwork(), and SSAGES::ANN::WriteBias().
|
inline |
Get pointer to const of the internal data 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 350 of file GridBase.h.
References SSAGES::GridBase< T >::data_.
|
inline |
Return center point of 1d-grid.
index | Index of the 1d grid. |
Definition at line 528 of file GridBase.h.
References SSAGES::GridBase< T >::at(), and SSAGES::GridBase< T >::GetCoordinates().
|
inline |
! Return the distance to adjacent grid center points from given coordinates
Return coordinates of the grid center points
indices | Grid indices specifying a 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 503 of file GridBase.h.
References SSAGES::GridBase< T >::dimension_, SSAGES::GridBase< T >::edges_, and SSAGES::GridBase< T >::numPoints_.
Referenced by SSAGES::GridBase< T >::GetCoordinate().
|
inline |
Get the dimension.
Definition at line 195 of file GridBase.h.
References SSAGES::GridBase< T >::dimension_.
Referenced by SSAGES::ANN::ANN(), SSAGES::GridBase< T >::at(), SSAGES::CFF::CFF(), SSAGES::GridBase< T >::GetLower(), SSAGES::GridBase< T >::GetNumPoints(), SSAGES::GridBase< T >::GetPeriodic(), SSAGES::GridBase< T >::GetUpper(), SSAGES::ANN::PreSimulation(), and SSAGES::GridBase< T >::syncGrid().
|
inline |
Return linear interpolation on a coordinate.
\param x Point in space. \return 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.
x | Point in space. |
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 472 of file GridBase.h.
References SSAGES::GridBase< T >::at(), SSAGES::GridBase< T >::dimension_, and SSAGES::GridBase< T >::GetIndices().
|
inline |
Return the Grid indices for a given point.
x | Point in space. |
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 372 of file GridBase.h.
References SSAGES::GridBase< T >::dimension_, SSAGES::GridBase< T >::edges_, SSAGES::GridBase< T >::GetPeriodic(), SSAGES::GridBase< T >::numPoints_, and SSAGES::GridBase< T >::wrapIndices().
Referenced by SSAGES::GridBase< T >::at(), and SSAGES::GridBase< T >::GetIndex().
|
inline |
Return the lower edges of the Grid.
Definition at line 231 of file GridBase.h.
References SSAGES::GridBase< T >::dimension_, SSAGES::GridBase< T >::edges_, SSAGES::GridBase< T >::GetPeriodic(), and SSAGES::GridBase< T >::numPoints_.
Referenced by SSAGES::ANN::PostIntegration(), SSAGES::BasisEvaluator::UpdateBias(), and SSAGES::Grid< T >::WriteToFile().
|
inline |
Get the lower edge for a specific dimension.
dim | Index of the dimension. |
Definition at line 247 of file GridBase.h.
References SSAGES::GridBase< T >::edges_, SSAGES::GridBase< T >::GetDimension(), SSAGES::GridBase< T >::GetPeriodic(), and SSAGES::GridBase< T >::numPoints_.
|
inline |
Get the number of points for all dimensions.
Definition at line 205 of file GridBase.h.
References SSAGES::GridBase< T >::numPoints_.
Referenced by SSAGES::BFS::Build(), SSAGES::BasisEvaluator::UpdateBias(), SSAGES::BasisEvaluator::UpdateCoeff(), and SSAGES::Grid< T >::WriteToFile().
|
inline |
Get the number of points for a specific dimension.
dim | Index of the dimension. |
Definition at line 217 of file GridBase.h.
References SSAGES::GridBase< T >::GetDimension(), and SSAGES::GridBase< T >::numPoints_.
|
inline |
Return the periodicity of the Grid.
True
(False
) if the grid is periodic (non-periodic) in the given dimension. Definition at line 295 of file GridBase.h.
References SSAGES::GridBase< T >::isPeriodic_.
Referenced by SSAGES::GridBase< T >::GetIndices(), SSAGES::GridBase< T >::GetLower(), SSAGES::GridBase< T >::GetPeriodic(), SSAGES::GridBase< T >::GetUpper(), and SSAGES::GridBase< T >::wrapIndices().
|
inline |
Get the periodicity in a specific dimension.
dim | Index of the dimension. |
True
(False
) if the grid is periodic (non-periodic) in the specified dimension.Definition at line 308 of file GridBase.h.
References SSAGES::GridBase< T >::GetDimension(), and SSAGES::GridBase< T >::GetPeriodic().
|
inline |
Return the upper edges of the Grid.
Definition at line 262 of file GridBase.h.
References SSAGES::GridBase< T >::dimension_, SSAGES::GridBase< T >::edges_, SSAGES::GridBase< T >::GetPeriodic(), and SSAGES::GridBase< T >::numPoints_.
Referenced by SSAGES::ANN::PostIntegration(), SSAGES::BasisEvaluator::UpdateBias(), and SSAGES::Grid< T >::WriteToFile().
|
inline |
Get the upper edge for a specific dimension.
dim | Index of the dimension. |
Definition at line 279 of file GridBase.h.
References SSAGES::GridBase< T >::edges_, SSAGES::GridBase< T >::GetDimension(), SSAGES::GridBase< T >::GetPeriodic(), and SSAGES::GridBase< T >::numPoints_.
|
protectedpure virtual |
This function needs to be implemented by child classes.
indices | The indices specifying the grid point. |
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< T >::at().
|
inline |
Access Grid element pertaining to a specific point per [] read-write.
x | Vector of doubles specifying the point in space. |
Definition at line 777 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Access Grid element pertaining to a specific point per [] read-only.
x | Vector of doubles specifying the point in space. |
Definition at line 767 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Access Grid element per [] read-write.
indices | Vector of integers specifying the grid point. |
Definition at line 699 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Access Grid element per [] read-only.
indices | Vector of integers specifying the grid point. |
Definition at line 689 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Access 1d-Grid via specific point, read-write.
x | Point specifying the desired Grid point. |
Definition at line 801 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Access 1d-Grid via specific point, read-only.
x | Point specifying the desired Grid point. |
Definition at line 789 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Access 1d-Grid per [] operator, read-write.
index | Index of the grid point. |
Definition at line 757 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Access 1d-Grid per [] operator, read-only.
index | Index of the grid point. |
Definition at line 745 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Access Grid element via initializer list.
R | Datatype in the initializer list |
x | initializer list |
This function avoids abiguity if operator[] is called with a brace-enclosed initializer list.
Example: grid[{0,1}]
Definition at line 733 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Const access of Grid element via initializer list.
R | Datatype in the initializer list |
x | initializer list |
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 716 of file GridBase.h.
References SSAGES::GridBase< T >::at().
|
inline |
Get the 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 326 of file GridBase.h.
References SSAGES::GridBase< T >::data_.
Referenced by SSAGES::ANN::ANN(), SSAGES::Grid< T >::BuildGrid(), SSAGES::CFF::CFF(), and SSAGES::ANN::TrainNetwork().
|
inlineprotected |
Wrap the index around periodic boundaries.
indices | Current indices of grid to wrap |
Definition at line 62 of file GridBase.h.
References SSAGES::GridBase< T >::dimension_, SSAGES::GridBase< T >::GetPeriodic(), and SSAGES::GridBase< T >::numPoints_.
Referenced by SSAGES::GridBase< T >::GetIndices().