Loading...
Searching...
No Matches
pappso::CosineSimilarity Class Reference

`#include <cosinesimilarity.h>`

## Public Member Functions

| CosineSimilarity (PrecisionPtr precision)
| CosineSimilarity (const CosineSimilarity &other)
| ~CosineSimilarity ()
double | similarity (pappso::Trace trace_a, pappso::Trace trace_b) const

## Private Attributes

PrecisionPtr | mp_precision
FilterInterfaceSPtr | msp_filterExclusion

## Detailed Description

Todo:
  write docs

Definition at line 43 of file cosinesimilarity.h.

## Constructor & Destructor Documentation

## CosineSimilarity() [1/2]

CosineSimilarity::CosineSimilarity | ( | PrecisionPtr | precision | ) |

Default constructor

Definition at line 36 of file cosinesimilarity.cpp.

{
mp_precision = precision;
msp_filterExclusion = std::make_shared<FilterMzExclusion>(precision);
}
pappso::CosineSimilarity::mp_precision
PrecisionPtr mp_precision
Definition cosinesimilarity.h:66
pappso::CosineSimilarity::msp_filterExclusion
FilterInterfaceSPtr msp_filterExclusion
Definition cosinesimilarity.h:67

References mp_precision, and msp_filterExclusion.

## CosineSimilarity() [2/2]

CosineSimilarity::CosineSimilarity | ( | const CosineSimilarity & | other | ) |

Copy constructor

Parameters

  other | TODO

Definition at line 43 of file cosinesimilarity.cpp.

{
mp_precision = other.mp_precision;
msp_filterExclusion = other.msp_filterExclusion;
}

References mp_precision, and msp_filterExclusion.

## ~CosineSimilarity()

CosineSimilarity::~CosineSimilarity | ( |  | ) |

Destructor

Definition at line 49 of file cosinesimilarity.cpp.

{
}

## Member Function Documentation

## similarity()

double pappso::CosineSimilarity::similarity | ( | pappso::Trace | trace_a,
|  | pappso::Trace | trace_b
| ) |  | const

Definition at line 54 of file cosinesimilarity.cpp.

{
// get inner peaks
// we need a filter to get pairs of common peaks between a & b
// or at least compute quickly intensity square of common pairs
msp_filterExclusion.get()->filter(trace_a);
msp_filterExclusion.get()->filter(trace_b);
auto itb = trace_b.begin();
double inner_intensity_product = 0;
for(const auto &peak_a : trace_a)
{
MzRange range(peak_a.x, mp_precision);
double low = range.lower();
double up = range.upper();
while((itb != trace_b.end()) && (itb->x < low))
{
itb++;
}
if(itb->x < up)
{
inner_intensity_product += peak_a.y * itb->y;
}
}
double tracea_product = 0;
// a intensity sum of intensity square
for(const auto &peak_a : trace_a)
{
tracea_product += peak_a.y * peak_a.y;
}
double traceb_product = 0;
// a intensity sum of intensity square
for(const auto &peak_a : trace_b)
{
traceb_product += peak_a.y * peak_a.y;
}
return (inner_intensity_product /
(sqrt(tracea_product) * sqrt(traceb_product)));
}
pappso::MzRange
Definition mzrange.h:46

References pappso::MzRange::lower(), and pappso::MzRange::upper().

## Member Data Documentation

## mp_precision

PrecisionPtr pappso::CosineSimilarity::mp_precision

private

Definition at line 66 of file cosinesimilarity.h.

Referenced by CosineSimilarity(), and CosineSimilarity().

## msp_filterExclusion

FilterInterfaceSPtr pappso::CosineSimilarity::msp_filterExclusion

private

Definition at line 67 of file cosinesimilarity.h.

Referenced by CosineSimilarity(), and CosineSimilarity().

The documentation for this class was generated from the following files:

- pappsomspp/processing/compartraces/cosinesimilarity.h
- pappsomspp/processing/compartraces/cosinesimilarity.cpp