| OpenMS 2.5.0

Public Types | Public Member Functions | Private Attributes | List of all members
Weights Class Reference

Represents a set of weights (double values and scaled with a certain precision their integer counterparts) with a quick access. More...

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

## Public Types

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

## Public Member Functions

| Weights ()
| Empty constructor. More...
| Weights (const alphabet_masses_type &masses, alphabet_mass_type precision)
| Weights (const Weights &other)
Weights & | operator= (const Weights &other)
size_type | size () const
weight_type | getWeight (size_type i) const
void | setPrecision (alphabet_mass_type precision)
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
void | swap (size_type index1, size_type index2)
bool | divideByGCD ()
alphabet_mass_type | getMinRoundingError () const
alphabet_mass_type | getMaxRoundingError () const

## Private Attributes

alphabet_masses_type | alphabet_masses_
alphabet_mass_type | precision_
weights_type | weights_

## Detailed Description

Represents a set of weights (double values and scaled with a certain precision their integer counterparts) with a quick access.

Many algorithms can't work with real-valued alphabets and need integer weights. Those are usually obtained by dividing all alphabet masses by a "precision" parameter (0; 1) and rounding the result to integers. Class `Weights` allows access to the scaled masses (the weights) and to the original masses as well. Weights are cached and will not be recalculated on access.

Note
  Words 'weights' and 'masses' were used deliberately for naming corresponding values to help users quickly understand how they can be used. Names were chosen due to similarity in 'weights' and 'masses' interconnection in this class with real life. In reality mass value is always the same, and weight value depends on circumstances. The same as here original double masses stay the same, and scaled integer weights depend on precision applied.

Author
  Anton Pervukhin Anton.nosp@m..Per.nosp@m.vukhi.nosp@m.n@Ce.nosp@m.BiTec.nosp@m..Uni.nosp@m.-Biel.nosp@m.efel.nosp@m.d.DE

## Member Typedef Documentation

## ◆ alphabet_mass_type

typedef double alphabet_mass_type

Type of double values to be used.

## ◆ alphabet_masses_type

typedef std::vector<alphabet_mass_type> 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

Empty constructor.

## ◆ Weights() [2/3]

Weights | ( | const alphabet_masses_type & | masses,
|  | alphabet_mass_type | precision
| ) |  |

inline

Constructor with double values and precision.

Parameters

  masses | Original double values to be scaled.
  precision | Precision to scale double values.

## ◆ Weights() [3/3]

Weights | ( | const Weights & | other | ) |

inline

Copy constructor.

Parameters

  other | Weights to be copied.

## Member Function Documentation

## ◆ back()

weight_type back | ( |  | ) | const

inline

Gets a last weight.

Returns
  a last weight.

## ◆ divideByGCD()

bool divideByGCD | ( |  | ) |

Divides the integer weights by their gcd. The precision is also adjusted.

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 new weights are 3, 5, 8 with precision 1.0 (since the gcd of 30, 50, and 80 is 10).

Returns
  true if anything was changed, that is, if the gcd was > 1. false if the gcd was already 1 or there are less than two weights.

## ◆ getAlphabetMass()

alphabet_mass_type getAlphabetMass | ( | size_type | i | ) | const

inline

Gets an original (double) alphabet mass by index.

Parameters

  i | An index to access alphabet masses.

Returns
  A double alphabet mass.

## ◆ getMaxRoundingError()

alphabet_mass_type getMaxRoundingError | ( |  | ) | const

## ◆ getMinRoundingError()

alphabet_mass_type getMinRoundingError | ( |  | ) | const

## ◆ getParentMass()

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

Returns a parent mass for a given `decomposition`

## ◆ 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

  i | An 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

  other | Weights to be assigned.

Returns
  Reference to this object.

## ◆ operator[]()

weight_type operator[] | ( | size_type | i | ) | const

inline

Operator to access weights by index.

Parameters

  i | An index to access weights.

Returns
  An integer weight.

See also
  getWeight(size_type i)

## ◆ setPrecision()

void setPrecision | ( | alphabet_mass_type | precision | ) |

Sets a new precision to scale double values to integer.

Parameters

  precision | A new precision.

## ◆ size()

size_type size | ( |  | ) | const

inline

Gets size of a set of weights.

Returns
  Size of a set of weights.

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

## ◆ swap()

void swap | ( | size_type | index1,
|  | size_type | index2
| ) |  |

Exchanges weight and mass at index1 with weight and mass at index2.

Parameters

  index1 | Index of weight and mass to be exchanged.
  index2 | Index of weight and mass to be exchanged.

## 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.