Efficiency Vector¶
-
class EfficiencyVector¶
The Efficiency Vector is the central object for the Theia code. It encodes a proposed operating efficiency history for Gaia, and allows for the appropriate transforms between Property Spaces .
Public Types
-
enum VectorMode¶
The first component of any Access/Assign/Increment call: determines which side of the Property Space is accessed.
Values:
-
enumerator Raw¶
-
enumerator Transformed¶
-
enumerator Raw¶
Public Functions
-
EfficiencyVector(std::string load_location, std::string save_location)¶
Constructor function for the master version of the EfficiencyVector
- Parameters
load_location – The location of a Raw position vector to load in (via a LoadVector() call). If set to a null value, GenerateVector() is called instead.
save_location – The directory into which the vector is saved
-
EfficiencyVector(std::vector<double> newTransformed)¶
Constructor for the basic version of the EfficiencyVector - when initialised in this way it has only the ability to index appropriately into the TransformedVector everything else is uninitiliased memory.
-
EfficiencyVector()¶
Default constructor (does nothing except sit there like a lemon)
-
double Access(VectorMode rawOrTransformed, VectorComponent component, VectorType positionOrGradient, int index) const¶
Access the specified component without needing to worry about the internal structure of the vector
- Parameters
rawOrTransformed – a VectorMode enum determining which side of Property Space is accessed
component – a VectorComponent enum determining which of temporal/spatial/hyper you are accessing
positionOrGradient – a VectorType enum determining if access is requested for position or gradient
index – The single-element index of the requested element
- Returns
The requested member of the Raw/Transformed Position/Gradient
-
void Assign(VectorMode rawOrTransformed, VectorComponent component, VectorType positionOrGradient, int index, double newValue)¶
Assign a value to the specified component without needing to worry about the internal structure of the vector
- Parameters
rawOrTransformed – a VectorMode enum determining which side of Property Space is accessed
component – a VectorComponent enum determining which of temporal/spatial/hyper you are accessing
positionOrGradient – a VectorType enum determining if access is requested for position or gradient
index – The single-element index of the requested element
newValue – The value to be assigned to the chosen element
-
void Increment(VectorMode rawOrTransformed, VectorComponent component, VectorType positionOrGradient, int index, double value)¶
Increments the value of a specified component without needing to worry about the internal structure of the vector
- Parameters
rawOrTransformed – a VectorMode enum determining which side of Property Space is accessed
component – a VectorComponent enum determining which of temporal/spatial/hyper you are accessing
positionOrGradient – a VectorType enum determining if access is requested for position or gradient
index – The single-element index of the requested element
value – The value to be added to the chosen element
-
double Access(VectorMode rawOrTransformed, VectorComponent component, VectorType positionOrGradient, int index1, int index2) const¶
An overload for Access(), but for vector access which requires two indices for easy access.
-
void Assign(VectorMode rawOrTransformed, VectorComponent component, VectorType positionOrGradient, int index1, int index2, double value)¶
An overload for Assign(), but for vector access which requires two indices for easy access.
-
void Increment(VectorMode rawOrTransformed, VectorComponent component, VectorType positionOrGradient, int index1, int index2, double newValue)¶
An overload for Increment(), but for vector access which requires two indices for easy access.
-
void ForwardTransform(const std::vector<double> &z)¶
An implementation of Forward Transform , assigns
zto the RawPosition and then transforms it into TransformedPosition- Parameters
z – The new value of RawPosition
-
void BackwardTransform()¶
An implementation of Backward Transform , transforms TransformedGradient into RawGradient
-
void Save(bool finalSave, int saveStep, bool uniqueSave)¶
Saves the current value of RawPosition and TransformedPosition to file
- Parameters
finalSave – If true, saves the files as “FinalPosition_<>.dat” in a parent directory, else saves them as “TempPosition_<>.dat” in a labelled directory.
saveStep – The current epoch-id, if unique-saving is active, saves the Transformed vectors as TempPosition
saveStep_<>.datuniqueSave – If true, allows multiple copies of the TransformedVector to be saved, instead of only the most recent one
Public Members
-
std::vector<double> RawPosition¶
The internal representation of the \(\vec{z}\) vector . Elements can be accessed manually, but internal structure is only guaranteed through the Access(), Assign() and Increment() commands.
-
std::vector<double> TransformedPosition¶
The internal representation of the \(\vec{x}\) vector . Elements can be accessed manually, but internal structure is only guaranteed through the Access(), Assign() and Increment() commands.
-
std::vector<double> RawGradient¶
The internal representation of the \(\nabla_z \mathcal{L}\) vector . Elements can be accessed manually, but internal structure is only guaranteed through the Access(), Assign() and Increment() commands.
-
std::vector<double> TransformedGradient¶
The internal representation of the \(\nabla_x \mathcal{L}\) vector . Elements can be accessed manually, but internal structure is only guaranteed through the Access(), Assign() and Increment() commands.
Private Functions
-
void ForwardTransform_Temporal()¶
Executes the Temporal part of the ForwardTransform(). See Temporal Forward Transform for implementation details.
-
void ForwardTransform_Spatial()¶
Executes the Spatial part of the ForwardTransform(). See Spatial Forward Transform for implementation details.
-
void ForwardTransform_Hyper()¶
Executes the Hyperparameter part of the ForwardTransform(). See Hyperparameter Forward Transform for implementation details.
-
void BackwardTransform_Hyper()¶
Executes the Temporal part of the BackwardTransform(). See Temporal Backward Transform for implementation details.
-
void BackwardTransform_Spatial()¶
Executes the Spatial part of the BackwardTransform(). See Spatial Backward Transform for implementation details.
-
void BackwardTransform_Temporal()¶
Executes the Hyperparameter part of the BackwardTransform(). See Hyperparameter Backward Transform for implementation details.
-
void GenerateVector()¶
Generates a random Raw vector. All elements are initialised to +/- initialisationBounds. The zeroth-order spatial modes have an additional offset equal to xmInitialised.
-
void LoadVector(std::string load_location)¶
Searches for a valid savefile given by the input. If it is of the correct length, loads it in as the RawPosition, otherwise throws an error
- Parameters
load_location – The name of the savefile to attempt to load`
-
void LoadNeedlets()¶
Searches for a valid needlet file and loads the contents into needlet_u, needlet_v and needlet_w. See Needlet Files for the required file properties. Run only at object initialisation.
-
void LoadCholesky()¶
Generates a matrix CholeskyKg used for magnitude-correlations, then decomposes it into choleskyN non-zero elements encodes by cholesky_w. Run only at object initialisation.
-
void Reset()¶
Sets the RawPosition, RawGradient, TransformedPosition and TransformedGradient to empty vectors required because the transforms are additive so need a zero-base to work from (rather than simply overlaying the old values with the new ones)
Private Members
-
int needletN¶
The number of needlet elements - unknown at run time as it depends on the spatial resolution chosen, and the chosen zero-rounding cutoff.
-
std::vector<int> needlet_u¶
Non-zero i-indices in the needlet matrix.
-
std::vector<int> needlet_v¶
Non-zero j-indices in the needlet matrix.
-
std::vector<double> bVector¶
A temporary holder (to prevent needless memory initialisations) for the spatial transform.
-
int choleskyN¶
The BackwardTransform() requires the use of a cholesky-decomposed matrix for the magnitude-coupling (encoded by lm). This required many cycles over elements which were near-zero. We have decomposed this into a list of choleskyN elements which are significant, to cut the runtime of this expensive operation.
-
std::vector<int> cholesky_u¶
Non-zero i-indices of the cholesky-matrix Kg.
-
std::vector<int> cholesky_v¶
Non-zero j-indices of the cholesky-matrix Kg.
-
std::vector<double> cholesky_w¶
The value of CholeskyKg_ij, with ij determined from cholesky_u and cholesky_v.
-
enum VectorMode¶
Examples¶
#include "EfficiencyVector.h"
int main()
{
//null loading location --> initialises a random number between initialisationBounds (+/- 0.3)
std::string loadLocation = "__null_location__";
std::string saveLocation = "Output";
EfficiencyVector V(loadLocation, saveLocation);
//Temporal access
std::cout << "Examine first 5 temporal elements: " << std::endl;
for (int i = 0; i < 5; ++i)
{
std::cout << "z_t[" << i << "] = " << V.Access(V.Raw, V.Temporal, V.Position, i) << std::endl;
}
std::cout << "\n\n";
//Spatial access
std::cout << "Spatial/Magnitude elements have two indices:" << std::endl;
for (int j = 0; j < 3;++j)
{
for (int m = 0; m < 2;++m)
{
std::cout << "z_lm[" << j << ", " << m << "] = " << V.Access(V.Raw, V.Spatial, V.Position, j,m) << std::endl;
}
}
std::cout << "\n\n";
//Assignation
std::cout << "Assignation uses similar syntax: " << std::endl;
for (int j = 0; j < 3;++j)
{
for (int m = 0; m < 2;++m)
{
V.Assign(V.Raw, V.Spatial, V.Position, j,m,j + m);
std::cout << "z_lm[" << j << ", " << m << "] = " << V.Access(V.Raw, V.Spatial, V.Position, j,m) << std::endl;
}
}
}
Gives the following output:
Examine first 5 temporal elements:
z_t[0] = 0.204113
z_t[1] = -0.0633702
z_t[2] = 0.16986
z_t[3] = 0.179064
z_t[4] = 0.246988
Spatial/Magnitude elements have two indices:
z_lm[0, 0] = -0.192967
z_lm[0, 1] = 0.103349
z_lm[1, 0] = 0.102755
z_lm[1, 1] = 0.0303147
z_lm[2, 0] = 0.0325592
z_lm[2, 1] = -0.0851858
Assignation uses similar syntax:
z_lm[0, 0] = 0
z_lm[0, 1] = 1
z_lm[1, 0] = 1
z_lm[1, 1] = 2
z_lm[2, 0] = 2
z_lm[2, 1] = 3