Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
Public Member Functions | Protected Attributes | List of all members
LinearInterpolation< Key, Value > Class Template Reference

Provides access to linearly interpolated values (and derivatives) from discrete data points. Values beyond the given range of data points are implicitly taken as zero. More...

#include <OpenMS/MATH/MISC/LinearInterpolation.h>

Public Types

Typedefs
typedef Value value_type
 
typedef Key key_type
 
typedef std::vector< value_typecontainer_type
 
typedef value_type ValueType
 
typedef key_type KeyType
 
typedef container_type ContainerType
 

Public Member Functions

 LinearInterpolation (KeyType scale=1., KeyType offset=0.)
 Constructors and destructor. More...
 
 LinearInterpolation (LinearInterpolation const &arg)
 Copy constructor. More...
 
LinearInterpolationoperator= (LinearInterpolation const &arg)
 Assignment operator. More...
 
 ~LinearInterpolation ()
 Destructor. More...
 
Interpolated data
ValueType value (KeyType arg_pos) const
 Returns the interpolated value. More...
 
void addValue (KeyType arg_pos, ValueType arg_value)
 Performs linear resampling. The arg_value is split up and added to the data points around arg_pos. More...
 
ValueType derivative (KeyType arg_pos) const
 Returns the interpolated derivative. More...
 
Discrete (non-interpolated) data
ContainerTypegetData ()
 Returns the internal random access container from which interpolated values are being sampled. More...
 
ContainerType const & getData () const
 Returns the internal random access container from which interpolated values are being sampled. More...
 
template<typename SourceContainer >
void setData (SourceContainer const &data)
 Assigns data to the internal random access container from which interpolated values are being sampled. More...
 
bool empty () const
 Returns true if getData() is empty. More...
 
Transformation
KeyType key2index (KeyType pos) const
 The transformation from "outside" to "inside" coordinates. More...
 
KeyType index2key (KeyType pos) const
 The transformation from "inside" to "outside" coordinates. More...
 
KeyType const & getScale () const
 Accessor. "Scale" is the difference (in "outside" units) between consecutive entries in "Data". More...
 
void setScale (KeyType const &scale)
 Accessor. "Scale" is the difference (in "outside" units) between consecutive entries in "Data". More...
 
KeyType const & getOffset () const
 Accessor. "Offset" is the point (in "outside" units) which corresponds to "Data[0]". More...
 
void setOffset (KeyType const &offset)
 Accessor. "Offset" is the point (in "outside" units) which corresponds to "Data[0]". More...
 
void setMapping (KeyType const &scale, KeyType const &inside, KeyType const &outside)
 Specifies the mapping from "outside" to "inside" coordinates by the following data: More...
 
void setMapping (KeyType const &inside_low, KeyType const &outside_low, KeyType const &inside_high, KeyType const &outside_high)
 Specifies the mapping from "outside" to "inside" coordinates by the following data: More...
 
KeyType const & getInsideReferencePoint () const
 Accessor. See setMapping(). More...
 
KeyType const & getOutsideReferencePoint () const
 Accessor. See setMapping(). More...
 
KeyType supportMin () const
 Lower boundary of the support, in "outside" coordinates. More...
 
KeyType supportMax () const
 Upper boundary of the support, in "outside" coordinates. More...
 

Protected Attributes

KeyType scale_
 
KeyType offset_
 
KeyType inside_
 
KeyType outside_
 
ContainerType data_
 

Detailed Description

template<typename Key = double, typename Value = Key>
class OpenMS::Math::LinearInterpolation< Key, Value >

Provides access to linearly interpolated values (and derivatives) from discrete data points. Values beyond the given range of data points are implicitly taken as zero.

The input is just a vector of values ("Data"). These are interpreted as the y-coordinates at the x-coordinate positions 0,...,data_.size-1.

The interpolated data can also be scaled and shifted in the x-dimension by an affine mapping. That is, we have "inside" and "outside" x-coordinates. The affine mapping can be specified in two ways:

By default the identity mapping (scale=1, offset=0) is used.

Using the value() and derivative() methods you can sample linearly interpolated values for a given x-coordinate position of the data and the derivative of the data.

See also
BilinearInterpolation

Member Typedef Documentation

◆ container_type

typedef std::vector<value_type> container_type

◆ ContainerType

◆ key_type

typedef Key key_type

◆ KeyType

typedef key_type KeyType

◆ value_type

typedef Value value_type

◆ ValueType

Constructor & Destructor Documentation

◆ LinearInterpolation() [1/2]

LinearInterpolation ( KeyType  scale = 1.,
KeyType  offset = 0. 
)
inline

Constructors and destructor.

The first argument is the scale which is applied to the arguments of value() and derivative() before looking up the interpolated values in the container. The second argument is the offset, which is subtracted before everything else.

◆ LinearInterpolation() [2/2]

LinearInterpolation ( LinearInterpolation< Key, Value > const &  arg)
inline

Copy constructor.

◆ ~LinearInterpolation()

~LinearInterpolation ( )
inline

Destructor.

Member Function Documentation

◆ addValue()

void addValue ( KeyType  arg_pos,
ValueType  arg_value 
)
inline

Performs linear resampling. The arg_value is split up and added to the data points around arg_pos.

◆ derivative()

ValueType derivative ( KeyType  arg_pos) const
inline

Returns the interpolated derivative.

Please drop me (= the maintainer) a message if you are using this.

◆ empty()

bool empty ( ) const
inline

Returns true if getData() is empty.

Referenced by LinearInterpolation< double >::supportMin().

◆ getData() [1/2]

ContainerType& getData ( )
inline

Returns the internal random access container from which interpolated values are being sampled.

◆ getData() [2/2]

ContainerType const& getData ( ) const
inline

Returns the internal random access container from which interpolated values are being sampled.

◆ getInsideReferencePoint()

KeyType const& getInsideReferencePoint ( ) const
inline

Accessor. See setMapping().

◆ getOffset()

KeyType const& getOffset ( ) const
inline

Accessor. "Offset" is the point (in "outside" units) which corresponds to "Data[0]".

Referenced by MaxLikeliFitter1D::fitOffset_().

◆ getOutsideReferencePoint()

KeyType const& getOutsideReferencePoint ( ) const
inline

Accessor. See setMapping().

◆ getScale()

KeyType const& getScale ( ) const
inline

Accessor. "Scale" is the difference (in "outside" units) between consecutive entries in "Data".

◆ index2key()

KeyType index2key ( KeyType  pos) const
inline

The transformation from "inside" to "outside" coordinates.

Referenced by LinearInterpolation< double >::supportMax(), and LinearInterpolation< double >::supportMin().

◆ key2index()

KeyType key2index ( KeyType  pos) const
inline

The transformation from "outside" to "inside" coordinates.

Referenced by LinearInterpolation< double >::addValue(), LinearInterpolation< double >::derivative(), and LinearInterpolation< double >::value().

◆ operator=()

LinearInterpolation& operator= ( LinearInterpolation< Key, Value > const &  arg)
inline

Assignment operator.

◆ setData()

void setData ( SourceContainer const &  data)
inline

Assigns data to the internal random access container from which interpolated values are being sampled.

SourceContainer must be assignable to ContainerType.

◆ setMapping() [1/2]

void setMapping ( KeyType const &  scale,
KeyType const &  inside,
KeyType const &  outside 
)
inline

Specifies the mapping from "outside" to "inside" coordinates by the following data:

  • scale: the difference in outside coordinates between consecutive values in the data vector.
  • inside and outside: these x-axis positions are mapped onto each other.

For example, when you have a complicated probability distribution which is in fact centered around zero (but you cannot have negative indices in the data vector), then you can arrange things such that inside is the mean of the pre-computed, shifted density values of that distribution and outside is the centroid position of, say, a peak in the real world which you want to model by a scaled and shifted version of the probability distribution.

Referenced by LinearInterpolation< double >::setMapping().

◆ setMapping() [2/2]

void setMapping ( KeyType const &  inside_low,
KeyType const &  outside_low,
KeyType const &  inside_high,
KeyType const &  outside_high 
)
inline

Specifies the mapping from "outside" to "inside" coordinates by the following data:

  • inside_low and outside_low: these axis positions are mapped onto each other.
  • inside_high and outside_high: these axis positions are mapped onto each other.

This four argument version is just a convenience overload for the three argument version, which see.

◆ setOffset()

void setOffset ( KeyType const &  offset)
inline

Accessor. "Offset" is the point (in "outside" units) which corresponds to "Data[0]".

Note: Using this invalidates the inside and outside reference points.

◆ setScale()

void setScale ( KeyType const &  scale)
inline

Accessor. "Scale" is the difference (in "outside" units) between consecutive entries in "Data".

Note: Using this invalidates the inside and outside reference points.

◆ supportMax()

KeyType supportMax ( ) const
inline

Upper boundary of the support, in "outside" coordinates.

◆ supportMin()

KeyType supportMin ( ) const
inline

Lower boundary of the support, in "outside" coordinates.

Referenced by MaxLikeliFitter1D::fitOffset_().

◆ value()

ValueType value ( KeyType  arg_pos) const
inline

Returns the interpolated value.

Member Data Documentation

◆ data_

ContainerType data_
protected

◆ inside_

KeyType inside_
protected

◆ offset_

KeyType offset_
protected

◆ outside_

KeyType outside_
protected

◆ scale_

KeyType scale_
protected

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:15 using doxygen 1.8.13