OpenMS
Loading...
Searching...
No Matches
Weights Class Reference

Pairs an alphabet of double-valued masses with the scaled integer weights derived from them. More...

#include <OpenMS/CHEMISTRY/MASSDECOMPOSITION/IMS/Weights.h>

Collaboration diagram for Weights:
[legend]

Public Types

typedef long unsigned int weight_type
 Type of integer values to be used.
 
typedef double alphabet_mass_type
 Type of double values to be used.
 
typedef std::vector< weight_typeweights_type
 Type of container to store integer values.
 
typedef std::vector< alphabet_mass_typealphabet_masses_type
 Type of container to store double values.
 
typedef weights_type::size_type size_type
 Type of container's size.
 

Public Member Functions

 Weights ()
 Default constructor.
 
 Weights (const alphabet_masses_type &masses, alphabet_mass_type precision)
 Construct from a set of masses and a precision.
 
 Weights (const Weights &other)
 
Weightsoperator= (const Weights &other)
 
size_type size () const
 
weight_type getWeight (size_type i) const
 
void setPrecision (alphabet_mass_type precision)
 Replace the precision and recompute the integer weights from the stored alphabet masses.
 
alphabet_mass_type getPrecision () const
 
weight_type operator[] (size_type i) const
 
weight_type back () const
 
alphabet_mass_type getAlphabetMass (size_type i) const
 
alphabet_mass_type getParentMass (const std::vector< unsigned int > &decomposition) const
 Reconstruct a parent mass from a decomposition expressed as multiplicities of the alphabet.
 
void swap (size_type index1, size_type index2)
 Exchange the alphabet mass and the integer weight at index1 with those at index2.
 
bool divideByGCD ()
 Divide every integer weight by the greatest common divisor of all weights and scale the precision accordingly.
 
alphabet_mass_type getMinRoundingError () const
 Largest negative relative rounding error introduced by the current precision.
 
alphabet_mass_type getMaxRoundingError () const
 Largest positive relative rounding error introduced by the current precision.
 

Private Attributes

alphabet_masses_type alphabet_masses_
 
alphabet_mass_type precision_
 
weights_type weights_
 

Detailed Description

Pairs an alphabet of double-valued masses with the scaled integer weights derived from them.

Many mass-decomposition algorithms only operate on integer weights; this class provides those integers alongside the original double-valued masses, derived once at construction (or on the next setPrecision call) by computing round(mass / precision) per entry. Subsequent access is plain vector lookup – no recomputation happens on read.

Typical precision values are in (0, 1] (smaller values mean a finer-grained integer grid); the cpp itself does not enforce a range.

Note
The terms "weights" (the scaled integers) and "masses" (the original doubles) are intentionally kept distinct: the masses are invariants of the alphabet, while the weights depend on the chosen precision.

Member Typedef Documentation

◆ alphabet_mass_type

typedef double alphabet_mass_type

Type of double values to be used.

◆ alphabet_masses_type

Type of container to store double values.

◆ size_type

typedef weights_type::size_type size_type

Type of container's size.

◆ weight_type

typedef long unsigned int weight_type

Type of integer values to be used.

◆ weights_type

typedef std::vector<weight_type> weights_type

Type of container to store integer values.

Constructor & Destructor Documentation

◆ Weights() [1/3]

Weights ( )
inline

Default constructor.

Produces an empty instance; size returns 0 until masses and a precision have been supplied.

◆ Weights() [2/3]

Weights ( const alphabet_masses_type masses,
alphabet_mass_type  precision 
)
inline

Construct from a set of masses and a precision.

Stores masses as the alphabet masses and computes the integer weights via round(mass / precision) for each entry (so the size of both the alphabet-mass and the weight container is masses.size() after the call).

Parameters
[in]massesOriginal double-valued alphabet masses.
[in]precisionPrecision used to scale the masses; smaller values yield finer-grained integer weights.

◆ Weights() [3/3]

Weights ( const Weights other)
inline

Copy constructor.

Parameters
[in]otherWeights to be copied.

Member Function Documentation

◆ back()

weight_type back ( ) const
inline

Gets a last weight.

Returns
a last weight.

◆ divideByGCD()

bool divideByGCD ( )

Divide every integer weight by the greatest common divisor of all weights and scale the precision accordingly.

For example, given alphabet weights 3.0, 5.0, 8.0 with precision 0.1, the integer weights would be 30, 50, 80. After calling this method the integer weights become 3, 5, 8 and the precision becomes 1.0 (since the gcd of 30, 50, 80 is 10).

Returns
true when the integer weights and the precision were changed (gcd > 1); false when the gcd was already 1 or fewer than two weights are stored.

◆ getAlphabetMass()

alphabet_mass_type getAlphabetMass ( size_type  i) const
inline

Gets an original (double) alphabet mass by index.

Parameters
[in]iAn index to access alphabet masses.
Returns
A double alphabet mass.

◆ getMaxRoundingError()

alphabet_mass_type getMaxRoundingError ( ) const

Largest positive relative rounding error introduced by the current precision.

Returns
The maximum of (precision * weight[i] - mass[i]) / mass[i] over all entries with a positive value, or 0 if no entry's scaled weight over-estimates its mass.

◆ getMinRoundingError()

alphabet_mass_type getMinRoundingError ( ) const

Largest negative relative rounding error introduced by the current precision.

Returns
The minimum of (precision * weight[i] - mass[i]) / mass[i] over all entries with a negative value, or 0 if no entry's scaled weight under-estimates its mass.

◆ getParentMass()

alphabet_mass_type getParentMass ( const std::vector< unsigned int > &  decomposition) const

Reconstruct a parent mass from a decomposition expressed as multiplicities of the alphabet.

Parameters
[in]decompositionPer-alphabet-entry multiplicities; must have the same length as the alphabet.
Returns
sum(alphabet_mass[i] * decomposition[i]) using the stored original (double) masses.
Exceptions
Exception::InvalidParameterwhen decomposition.size() does not equal size.

◆ getPrecision()

alphabet_mass_type getPrecision ( ) const
inline

Gets precision.

Returns
Precision to scale double values to integer.

◆ getWeight()

weight_type getWeight ( size_type  i) const
inline

Gets a scaled integer weight by index.

Parameters
[in]iAn index to access weights.
Returns
An integer weight.

Referenced by IntegerMassDecomposer< ValueType, DecompositionValueType >::fillExtendedResidueTable_(), and IntegerMassDecomposer< ValueType, DecompositionValueType >::IntegerMassDecomposer().

◆ operator=()

Weights & operator= ( const Weights other)

Assignment operator.

Parameters
[in]otherWeights to be assigned.
Returns
Reference to this object.

◆ operator[]()

weight_type operator[] ( size_type  i) const
inline

Operator to access weights by index.

Parameters
[in]iAn index to access weights.
Returns
An integer weight.
See also
getWeight(size_type i)

◆ setPrecision()

void setPrecision ( alphabet_mass_type  precision)

Replace the precision and recompute the integer weights from the stored alphabet masses.

Parameters
[in]precisionNew precision; the integer weights are refreshed as round(mass / precision) for every stored alphabet mass.

◆ size()

◆ swap()

void swap ( size_type  index1,
size_type  index2 
)

Exchange the alphabet mass and the integer weight at index1 with those at index2.

Both the alphabet_mass entry and its corresponding integer weight at the two indices are swapped, so the mass / weight pairing is preserved.

Parameters
[in]index1First index to swap.
[in]index2Second index to swap.

Member Data Documentation

◆ alphabet_masses_

alphabet_masses_type alphabet_masses_
private

Container to store original (double) alphabet masses.

◆ precision_

alphabet_mass_type precision_
private

Precision which is used to scale double values to integer.

◆ weights_

weights_type weights_
private

Container to store scaled integer weights.