Template class for managing multidimensional arrays. This class is based on boost multi_array. This classes is primarily aimed to implement generic 2D and 3D bitmaps. See GridD if you want a more general purpose spatial grid.
The class adds new functionality to the boost class: 1) Operators + - * and / to deal with other multiarrays and scalars 2) Computation of maximum, minimum, and statistical properties of the array. 3) Read/Write both in text and binary modes (taking into account the endianess).
Inheritance diagram for IMP::algebra::MultiArray< T, D >:Public Types | |
| typedef boost::multi_array< T, D > | BMA |
|
typedef boost::multi_array_types::index | index |
|
typedef boost::multi_array_types::size_type | size_type |
| typedef MultiArray< T, D > | This |
Public Member Functions | |
| MultiArray () | |
| Empty constructor. | |
| bool | almost_equal (const double a, const double b, const double epsilon) |
| void | centered_start () |
| double | compute_avg () const |
| Average of the values in the array. | |
| T | compute_max () const |
| Maximum of the values in the array. | |
| template<typename T1 > | |
| T | compute_max (T1 &max_idx) const |
| Maximum of the values in the array. | |
| T | compute_min () const |
| Minimum of the values in the array. | |
| template<typename T1 > | |
| T | compute_min (T1 &min_idx) const |
| Minimum of the values in the array. | |
| void | compute_stats (double &avg, double &stddev, T &minval, T &maxval) const |
| Compute average, standard deviation, minimum and maximum values. | |
| double | compute_stddev () const |
| Standard deviation of the values in the array. | |
| void | copy (This &v) |
| template<typename U > | |
| void | copy_with_casting (MultiArray< U, D > &v) |
| Copy with casting. Use with care! | |
| double | cross_correlation_coefficient (const This &v, bool apply_threshold=false, double threshold=0.0, bool divide_by_stddev=true, bool force_recalc_stats=true, double avg=0.0, double stddev=0.0, double avg_v=0.0, double stddev_v=0.0) |
| Computes the cross correlation coeffcient between two MultiArrays. | |
| void | fill_with_value (T val=0) |
| Fill all the voxels of the array with a given value. | |
| bool | first_element () const |
| Returns the first element. | |
| int | get_finish (const int dim) const |
| int | get_size (const int dim) const |
| int | get_start (const int dim) const |
| void | init_zeros () |
| All the values of the array are set to zero. | |
| template<typename T1 > | |
| bool | is_logical_element (T1 &v) const |
| Returns true if the LOGICAL index belongs to those of the matrix. | |
| template<typename T1 > | |
| bool | is_physical_element (T1 &v) const |
| Returns true if the PHYSICAL index belongs to those of the matrix. | |
| bool | is_void () const |
| Check if the array has some dimensionality or is just empty. | |
| void | normalize () |
| This | operator* (const This &v) const |
| Multiplication operator. | |
| This | operator* (const T &v) const |
| Multiplication operator for an array and a scalar. | |
| void | operator*= (const This &v) const |
| Multiplication operator. | |
| void | operator*= (const T &v) const |
| Multiplication operator for an array and a scalar. | |
| This | operator+ (const This &v) const |
| Sum operator. | |
| This | operator+ (const T &v) const |
| Sum operator for an array and a scalar. | |
| void | operator+= (const This &v) const |
| Addition operator. | |
| void | operator+= (const T &v) const |
| Addition operator for an array and a scalar. | |
| This | operator- (const This &v) const |
| Minus operator. | |
| This | operator- (const T &v) const |
| Minus operator for an array and a scalar. | |
| void | operator-= (const This &v) const |
| Substraction operator. | |
| void | operator-= (const T &v) const |
| Substraction operator for an array and a scalar. | |
| This | operator/ (const This &v) const |
| Division operator. | |
| This | operator/ (const T &v) const |
| Division operator for an array and a scalar. | |
| void | operator/= (const This &v) const |
| Division operator. | |
| void | operator/= (const T &v) const |
| Division operator for an array and a scalar. | |
| void | print_shape (std::ostream &out=std::cout) const |
| Print shape of multidimensional array. | |
| void | read (const std::string &filename) |
| Read from an ASCII file. | |
| void | read_binary (const std::string &filename, bool reversed=false) |
| Read from a binary file. | |
| void | read_binary (std::ifstream &input, bool reversed=false) |
| Read from a input stream in binary mode. | |
| template<typename T1 > | |
| bool | same_shape (const MultiArray< T1, D > &b) const |
| Compares the shape of two multidimensional arrays. | |
| template<typename T1 > | |
| bool | same_size (const MultiArray< T1, D > &b) const |
| Compares the size of two multidimensional arrays. | |
| template<typename T1 > | |
| bool | same_start (const MultiArray< T1, D > &b) const |
| Compares the origin of two multidimensional arrays. | |
| void | set_start (const int dim, const int value) |
| template<typename T1 > | |
| void | set_start (const T1 &v) |
| T | squared_difference (const This &v) const |
| T | sum_elements () const |
| Computes the sum of all the array elements. | |
| T | sum_squared_elements () const |
| void | write (const std::string &filename) const |
| Write to an ASCII file. | |
| void | write_binary (const std::string &filename, bool reversed=false) |
| Write to a binary file. | |
| void | write_binary (std::ofstream &out, bool reversed=false) |
| Write to a output stream in binary mode. | |
Friends | |
| std::istream & | operator>> (std::istream &input, This &v) |
Related Functions | |
(Note that these are not member functions.) | |
| template<class T , int D> | |
| MultiArray< T, D > | operator* (const T &X, const MultiArray< T, D > &a1) |
| Multiplication operator for a scalar and an array. | |
| template<class T , int D> | |
| MultiArray< T, D > | operator+ (const T &X, const MultiArray< T, D > &a1) |
| Sum operator for a scalar and an array. | |
| template<class T , int D> | |
| MultiArray< T, D > | operator- (const T &X, const MultiArray< T, D > &a1) |
| Minus operator for a scalar and an array. | |
| template<class T , int D> | |
| MultiArray< T, D > | operator/ (const T &X, const MultiArray< T, D > &a1) |
| Division operator for a scalar and an array. | |
| IMP::algebra::MultiArray< T, D >::MultiArray | ( | ) |
Empty constructor.
| void IMP::algebra::MultiArray< T, D >::centered_start | ( | ) |
Sets the zero (0,0,0,...) of the logical coordinates at the center of the center of the matrix. Some examples:
| double IMP::algebra::MultiArray< T, D >::compute_avg | ( | ) | const |
Average of the values in the array.
The returned value is always double, independently of the type of the array.
| T IMP::algebra::MultiArray< T, D >::compute_max | ( | ) | const |
Maximum of the values in the array.
| T IMP::algebra::MultiArray< T, D >::compute_max | ( | T1 & | max_idx | ) | const |
Maximum of the values in the array.
| [out] | max_idx | index containing the maximum value |
| T IMP::algebra::MultiArray< T, D >::compute_min | ( | ) | const |
Minimum of the values in the array.
| T IMP::algebra::MultiArray< T, D >::compute_min | ( | T1 & | min_idx | ) | const |
Minimum of the values in the array.
| [out] | min_idx | index containing the minimum value |
| void IMP::algebra::MultiArray< T, D >::compute_stats | ( | double & | avg, |
| double & | stddev, | ||
| T & | minval, | ||
| T & | maxval | ||
| ) | const |
Compute average, standard deviation, minimum and maximum values.
| double IMP::algebra::MultiArray< T, D >::compute_stddev | ( | ) | const |
Standard deviation of the values in the array.
| void IMP::algebra::MultiArray< T, D >::copy | ( | This & | v | ) |
Copies the contents of a MultiArray to this one (no resizing is done). For copying with resizing use operator=
| [in] | v | MultiArray whose contents to copy |
| void IMP::algebra::MultiArray< T, D >::copy_with_casting | ( | MultiArray< U, D > & | v | ) |
Copy with casting. Use with care!
| double IMP::algebra::MultiArray< T, D >::cross_correlation_coefficient | ( | const This & | v, |
| bool | apply_threshold = false, |
||
| double | threshold = 0.0, |
||
| bool | divide_by_stddev = true, |
||
| bool | force_recalc_stats = true, |
||
| double | avg = 0.0, |
||
| double | stddev = 0.0, |
||
| double | avg_v = 0.0, |
||
| double | stddev_v = 0.0 |
||
| ) |
Computes the cross correlation coeffcient between two MultiArrays.
| [in] | v | array to compute the cross_correlation with. |
| [in] | apply_threshold | true if a threshold is applied to the elements of v . |
| [in] | threshold | minimum value for an element v to consider it in the computation . |
| [in] | divide_by_stddev | true if the cross correlation term is divided by the standard deviation to get the cross correlation coefficient (0 <= ccc <= 1). |
| [in] | force_recalc_stats | true if the statistics (mean, stddev) for the Multiarrays must be recalculated (default). If the statistics are known from previous computations, you can speed up the next computations setting this variable to false and directly providing the parameters. |
| [in] | avg | average of this Multiarray. |
| [in] | stddev | standard deviation of this Multiarray. |
| [in] | avg_v | average of Multiarray v. |
| [in] | stddev_v | standard deviation of Multiarray v. |
| void IMP::algebra::MultiArray< T, D >::fill_with_value | ( | T | val = 0 | ) |
Fill all the voxels of the array with a given value.
| bool IMP::algebra::MultiArray< T, D >::first_element | ( | ) | const |
Returns the first element.
| int IMP::algebra::MultiArray< T, D >::get_finish | ( | const int | dim | ) | const |
Another way of asking for the final value (logical) for the index of the dimension
| int IMP::algebra::MultiArray< T, D >::get_size | ( | const int | dim | ) | const |
Another way of asking for the size of a given dimension. You can always use x.shape()[i] too.
| int IMP::algebra::MultiArray< T, D >::get_start | ( | const int | dim | ) | const |
Another way of asking for the initial value (logical) for the index of the dimension. You can always use index_bases()[dim]
| void IMP::algebra::MultiArray< T, D >::init_zeros | ( | ) |
All the values of the array are set to zero.
| bool IMP::algebra::MultiArray< T, D >::is_logical_element | ( | T1 & | v | ) | const |
Returns true if the LOGICAL index belongs to those of the matrix.
| [in] | v | Any class able to be accessed with [] |
| bool IMP::algebra::MultiArray< T, D >::is_physical_element | ( | T1 & | v | ) | const |
Returns true if the PHYSICAL index belongs to those of the matrix.
| [in] | v | Any class able to be accessed with [] |
| bool IMP::algebra::MultiArray< T, D >::is_void | ( | ) | const |
Check if the array has some dimensionality or is just empty.
| void IMP::algebra::MultiArray< T, D >::normalize | ( | ) |
Normalize the values of the MultiArray to mean value 0 and standard deviation 1.
| This IMP::algebra::MultiArray< T, D >::operator* | ( | const This & | v | ) | const |
Multiplication operator.
| This IMP::algebra::MultiArray< T, D >::operator* | ( | const T & | v | ) | const |
Multiplication operator for an array and a scalar.
Reimplemented in IMP::algebra::Matrix2D< T >, and IMP::algebra::Matrix3D< T >.
| void IMP::algebra::MultiArray< T, D >::operator*= | ( | const This & | v | ) | const |
Multiplication operator.
| void IMP::algebra::MultiArray< T, D >::operator*= | ( | const T & | v | ) | const |
Multiplication operator for an array and a scalar.
| This IMP::algebra::MultiArray< T, D >::operator+ | ( | const This & | v | ) | const |
Sum operator.
| This IMP::algebra::MultiArray< T, D >::operator+ | ( | const T & | v | ) | const |
Sum operator for an array and a scalar.
Reimplemented in IMP::algebra::Matrix2D< T >, and IMP::algebra::Matrix3D< T >.
| void IMP::algebra::MultiArray< T, D >::operator+= | ( | const This & | v | ) | const |
Addition operator.
| void IMP::algebra::MultiArray< T, D >::operator+= | ( | const T & | v | ) | const |
Addition operator for an array and a scalar.
| This IMP::algebra::MultiArray< T, D >::operator- | ( | const This & | v | ) | const |
Minus operator.
| This IMP::algebra::MultiArray< T, D >::operator- | ( | const T & | v | ) | const |
Minus operator for an array and a scalar.
Reimplemented in IMP::algebra::Matrix2D< T >, and IMP::algebra::Matrix3D< T >.
| void IMP::algebra::MultiArray< T, D >::operator-= | ( | const This & | v | ) | const |
Substraction operator.
| void IMP::algebra::MultiArray< T, D >::operator-= | ( | const T & | v | ) | const |
Substraction operator for an array and a scalar.
| This IMP::algebra::MultiArray< T, D >::operator/ | ( | const This & | v | ) | const |
Division operator.
| This IMP::algebra::MultiArray< T, D >::operator/ | ( | const T & | v | ) | const |
Division operator for an array and a scalar.
Reimplemented in IMP::algebra::Matrix2D< T >, and IMP::algebra::Matrix3D< T >.
| void IMP::algebra::MultiArray< T, D >::operator/= | ( | const This & | v | ) | const |
Division operator.
| void IMP::algebra::MultiArray< T, D >::operator/= | ( | const T & | v | ) | const |
Division operator for an array and a scalar.
| void IMP::algebra::MultiArray< T, D >::print_shape | ( | std::ostream & | out = std::cout | ) | const |
Print shape of multidimensional array.
This function shows the size, starting and finishing indexes of the given array. No end of line is printed neither at the beginning nor the end.
| void IMP::algebra::MultiArray< T, D >::read | ( | const std::string & | filename | ) |
Read from an ASCII file.
The array must be previously resized to the correct size.
| void IMP::algebra::MultiArray< T, D >::read_binary | ( | const std::string & | filename, |
| bool | reversed = false |
||
| ) |
Read from a binary file.
The array must be previously resized to the correct size.
| void IMP::algebra::MultiArray< T, D >::read_binary | ( | std::ifstream & | input, |
| bool | reversed = false |
||
| ) |
Read from a input stream in binary mode.
The array must be previously resized to the correct size.
| bool IMP::algebra::MultiArray< T, D >::same_shape | ( | const MultiArray< T1, D > & | b | ) | const |
Compares the shape of two multidimensional arrays.
| bool IMP::algebra::MultiArray< T, D >::same_size | ( | const MultiArray< T1, D > & | b | ) | const |
Compares the size of two multidimensional arrays.
| bool IMP::algebra::MultiArray< T, D >::same_start | ( | const MultiArray< T1, D > & | b | ) | const |
Compares the origin of two multidimensional arrays.
| void IMP::algebra::MultiArray< T, D >::set_start | ( | const int | dim, |
| const int | value | ||
| ) |
Another way setting the initial value (logical) for the index of the dimension. You can always use reindex()
| void IMP::algebra::MultiArray< T, D >::set_start | ( | const T1 & | v | ) |
Another way setting the initial value (logical) for the index of the dimension.
| [in] | v | Any class able to be accessed with [] |
| T IMP::algebra::MultiArray< T, D >::squared_difference | ( | const This & | v | ) | const |
Computes the sum of the squared elements of the difference MultiArray obtained from substracting v.
| T IMP::algebra::MultiArray< T, D >::sum_elements | ( | ) | const |
Computes the sum of all the array elements.
| T IMP::algebra::MultiArray< T, D >::sum_squared_elements | ( | ) | const |
Computes the sum of all the squared elements of the array. (Frobenius norm)
| void IMP::algebra::MultiArray< T, D >::write | ( | const std::string & | filename | ) | const |
Write to an ASCII file.
| void IMP::algebra::MultiArray< T, D >::write_binary | ( | const std::string & | filename, |
| bool | reversed = false |
||
| ) |
Write to a binary file.
| void IMP::algebra::MultiArray< T, D >::write_binary | ( | std::ofstream & | out, |
| bool | reversed = false |
||
| ) |
Write to a output stream in binary mode.
|
related |
Multiplication operator for a scalar and an array.
|
related |
Sum operator for a scalar and an array.
|
related |
Minus operator for a scalar and an array.
|
related |
Division operator for a scalar and an array.