31#ifndef __TASMANIAN_SPARSE_GRID_DYNAMIC_CONST_GLOBAL_HPP
32#define __TASMANIAN_SPARSE_GRID_DYNAMIC_CONST_GLOBAL_HPP
34#include <forward_list>
118 size_t num_entries = (size_t) std::distance(list.begin(), list.end());
119 std::vector<const T*> refs(num_entries);
120 auto p = list.begin();
121 auto r = refs.rbegin();
122 while(p != list.end()) *r++ = &*p++;
132template<
bool use_ascii>
134 if (use_ascii ==
mode_ascii){ os << std::scientific; os.precision(17); }
139 for(
auto d : data_refs){
151template<
typename iomode>
152std::forward_list<NodeData>
readNodeDataList(std::istream &is,
size_t num_dimensions,
size_t num_outputs){
153 std::forward_list<NodeData> data;
156 for(
int i=0; i<num_nodes; i++){
172template<
typename iomode>
174 std::forward_list<TensorData> tensors;
177 for(
int i=0; i<num_entries; i++){
196template<
class RuleLike>
197std::vector<double>
listToNodes(std::forward_list<NodeData>
const &node_list,
size_t num_dimensions, RuleLike
const &rule){
198 std::vector<double> result(
Utils::size_mult(std::distance(node_list.begin(), node_list.end()), num_dimensions));
199 auto ix = result.begin();
200 for(
auto const &t : node_list)
211template<
typename callable_method>
212std::vector<double>
listToLocalNodes(std::forward_list<NodeData>
const &node_list,
size_t num_dimensions, callable_method rule){
213 std::vector<double> result(
Utils::size_mult(std::distance(node_list.begin(), node_list.end()), num_dimensions));
214 auto ix = result.begin();
215 for(
auto const &t : node_list)
216 ix = std::transform(t.point.begin(), t.point.end(), ix, rule);
246 template<
typename iomode>
248 num_dimensions(cnum_dimensions),
249 num_outputs(cnum_outputs),
257 template<
bool use_ascii>
void write(std::ostream &os)
const;
260 void restrictData(
int ibegin,
int iend){
for(
auto &d : data) d.value = std::vector<double>(d.value.begin() + ibegin, d.value.begin() + iend); }
267 for(
auto it = tensors.begin(); it != tensors.end(); it++){
268 if (it->weight > maxw) maxw = it->weight;
283 void addTensor(
const int *tensor, std::function<
int(
int)> getNumPoints,
double weight);
295 size_t num_dimensions, num_outputs;
296 std::forward_list<TensorData> tensors;
297 std::forward_list<NodeData> data;
316 template<
typename iomode>
324 std::forward_list<NodeData>
data;
326 template<
bool use_ascii>
329 writeNodeDataList<use_ascii>(
data, os);
332 void restrictData(
int ibegin,
int iend){
for(
auto &d :
data) d.value = std::vector<double>(d.value.begin() + ibegin, d.value.begin() + iend); }
335 size_t num_outputs =
data.front().value.size();
338 auto p =
data.before_begin();
339 auto d =
data.begin();
340 while(d !=
data.end()){
341 int slot = points.
getSlot(d->point);
343 std::copy_n(d->value.begin(), num_outputs, result.
getStrip(slot));
Generic 2D data structure divided into contiguous strips of fixed length (similar to a matrix).
Definition tsgIndexSets.hpp:104
T * getStrip(int i)
Returns a reference to the i-th strip.
Definition tsgIndexSets.hpp:141
std::vector< T > release()
Moves the data vector out of the class, this method invalidates the object.
Definition tsgIndexSets.hpp:164
Helper class that stores data from dynamic construction of a Global grid.
Definition tsgDConstructGridGlobal.hpp:231
void clearTesnors()
Delete the tensors with non-negative weights, i.e., clear all but the tensors selected by the initial...
void write(std::ostream &os) const
Write the data to a stream using ascii or binary format.
void reloadPoints(std::function< int(int)> getNumPoints)
Called after read, reinitializes the points and loaded structures for the tensors.
~DynamicConstructorDataGlobal()=default
Default destructor, release all used memory and erase all stored data.
AddPointResult addNewNode(const std::vector< int > &point, const std::vector< double > &value)
Add a new data point with the index and the value, returns information about the tensor.
void ejectCompleteTensor(MultiIndexSet const ¤t_tensors, MultiIndexSet &new_tensors, MultiIndexSet &new_points, StorageSet &vals)
Returns a new set of tensors, points and values that can be added to the current tensors.
int getMaxTensor() const
Returns the maximum index of any of the stored tensors.
DynamicConstructorDataGlobal(std::istream &is, size_t cnum_dimensions, size_t cnum_outputs, iomode)
Read constructor.
Definition tsgDConstructGridGlobal.hpp:247
AddPointResult
Defines the result of adding a point to the list of know points with values.
Definition tsgDConstructGridGlobal.hpp:234
@ tensor_missing
Indicates the point is associated with an unknown tensor.
@ tensor_incomplete
Indicates the point was added to an existing tensor but more points are needed before processing the ...
@ tensor_complete
Indicates the point was added to an existing tensor and the tensor is ready for processing.
DynamicConstructorDataGlobal(size_t cnum_dimensions, size_t cnum_outputs)
Constructor, requires that the dimension and the number of model outputs is specified.
Definition tsgDConstructGridGlobal.hpp:244
void addTensor(const int *tensor, std::function< int(int)> getNumPoints, double weight)
Add a new tensor to the candidates, with the given weight and using getNumPoints() to define the asso...
MultiIndexSet getInitialTensors() const
Get a set of all tensors with negative weight, i.e., the tensors selected for the initial run.
MultiIndexSet getNodesIndexes()
Get the node indexes of the points associated with the candidate tensors, the order is the same as th...
double getMaxTensorWeight() const
Returns the maximum tensor weight.
Definition tsgDConstructGridGlobal.hpp:265
void restrictData(int ibegin, int iend)
Restrict data between ibegin and iend entries.
Definition tsgDConstructGridGlobal.hpp:260
Class that stores multi-indexes in sorted (lexicographical) order.
Definition tsgIndexSets.hpp:234
int getSlot(const int *p) const
Returns the slot containing index p, returns -1 if not found.
int getNumIndexes() const
Returns the number of indexes.
Definition tsgIndexSets.hpp:265
void write(std::ostream &os) const
Write the set to ASCII or binary stream, use with std::ofstream and std::ifstream.
Class that stores values, i.e., model outputs, the order of the values is in sync with the order of s...
Definition tsgIndexSets.hpp:334
void writeNumbers(std::ostream &os, Vals... vals)
Write a bunch of numbers with the same type.
Definition tsgIOHelpers.hpp:383
OutputIteratorLike indexesToNodes(IndexList const &list, RuleLike const &rule, OutputIteratorLike nodes)
Converts int-indexes to double-valued abscissas using the provided rule.
Definition tsgIndexManipulator.hpp:569
std::vector< const T * > makeReverseReferenceVector(const std::forward_list< T > &list)
Takes a list and creates a vector of references in reversed order, needed for I/O so that read can be...
Definition tsgDConstructGridGlobal.hpp:117
std::forward_list< NodeData > readNodeDataList(std::istream &is, size_t num_dimensions, size_t num_outputs)
Reads a NodeData std::forward_list from a file using either binary or ascii format....
Definition tsgDConstructGridGlobal.hpp:152
std::vector< double > listToNodes(std::forward_list< NodeData > const &node_list, size_t num_dimensions, RuleLike const &rule)
Using MultiIndexManipulations::indexesToNodes() convert the node_list to actual points according to t...
Definition tsgDConstructGridGlobal.hpp:197
void writeNodeDataList(const std::forward_list< NodeData > &data, std::ostream &os)
Writes a NodeData std::forward_list to a file using either binary or ascii format....
Definition tsgDConstructGridGlobal.hpp:133
std::vector< double > listToLocalNodes(std::forward_list< NodeData > const &node_list, size_t num_dimensions, callable_method rule)
Using MultiIndexManipulations::indexesToNodes() convert the node_list to actual points according to t...
Definition tsgDConstructGridGlobal.hpp:212
std::forward_list< TensorData > readTensorDataList(std::istream &is, size_t num_dimensions)
Reads a TensorData std::forward_list from a file using either binary or ascii format.
Definition tsgDConstructGridGlobal.hpp:173
constexpr bool mode_ascii
Constant allowing for more expressive selection of ascii and binary mode in IO methods.
Definition tsgIOHelpers.hpp:62
size_t size_mult(IntA a, IntB b)
Converts two integer-like variables to size_t and returns the product..
Definition tsgUtils.hpp:82
Encapsulates the Tasmanian Sparse Grid module.
Definition TasmanianSparseGrid.hpp:68
Holds the pair of point index and model value, the struct is used in a std::forward_list.
Definition tsgDConstructGridGlobal.hpp:82
std::vector< double > value
The values of the model outputs at the point.
Definition tsgDConstructGridGlobal.hpp:86
std::vector< int > point
The multi-index of the point.
Definition tsgDConstructGridGlobal.hpp:84
Holds a std::forward_list of pairs of points indexes and values, and a MultiIndexSet of initial nodes...
Definition tsgDConstructGridGlobal.hpp:312
std::forward_list< NodeData > data
A list of pair indicating point and model output values.
Definition tsgDConstructGridGlobal.hpp:324
void restrictData(int ibegin, int iend)
Restrict data between ibegin and iend entries.
Definition tsgDConstructGridGlobal.hpp:332
void write(std::ostream &os) const
Save to a file in either ascii or binary format.
Definition tsgDConstructGridGlobal.hpp:327
std::vector< double > extractValues(MultiIndexSet const &points)
Remove points from the data and return a vector of the values in the points order.
Definition tsgDConstructGridGlobal.hpp:334
MultiIndexSet initial_points
Keeps track of the initial point set, so those can be computed first.
Definition tsgDConstructGridGlobal.hpp:322
SimpleConstructData(std::istream &is, int num_dimensions, int num_outputs, iomode)
Read constructor, requires the number of dimensions and outputs.
Definition tsgDConstructGridGlobal.hpp:317
SimpleConstructData()=default
Default empty constructor.
Holds the description of a single tensor candidate for inclusion into the grid.
Definition tsgDConstructGridGlobal.hpp:99
MultiIndexSet points
The points associated with the surplus operator, the tensor can be included only when all points are ...
Definition tsgDConstructGridGlobal.hpp:105
std::vector< bool > loaded
For each point false if the model data is not yet available for the point, true otherwise.
Definition tsgDConstructGridGlobal.hpp:107
double weight
The weight indicates the relative importance of the tensor.
Definition tsgDConstructGridGlobal.hpp:101
std::vector< int > tensor
Multi-index of the tensor.
Definition tsgDConstructGridGlobal.hpp:103
Algorithms for manipulating sets of multi-indexes.