IMP logo
IMP Reference Guide  2.7.0
The Integrative Modeling Platform
vector_metrics.h
Go to the documentation of this file.
1 /**
2  * \file IMP/algebra/vector_metrics.h \brief Functions to generate vectors.
3  *
4  * Copyright 2007-2017 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPALGEBRA_VECTOR_METRICS_H
9 #define IMPALGEBRA_VECTOR_METRICS_H
10 
11 #include "VectorD.h"
12 #include "BoundingBoxD.h"
13 #include <IMP/types.h>
14 #include <IMP/Object.h>
15 #include <iostream>
16 #include <IMP/Pointer.h>
17 #include <IMP/WeakPointer.h>
18 #include <algorithm>
19 #include <numeric>
20 
21 IMPALGEBRA_BEGIN_NAMESPACE
22 
23 //! The base class for a metric on VectorKDs.
24 class IMPALGEBRAEXPORT VectorKDMetric : public Object {
25  public:
26  VectorKDMetric(std::string name);
27  virtual double get_distance(const VectorKD &a, const VectorKD &b) const = 0;
28  virtual VectorKD get_centroid(const VectorKDs &vs) const = 0;
29 };
30 
32 
33 //! The l2 norm on the distance vector.
34 class IMPALGEBRAEXPORT EuclideanVectorKDMetric : public VectorKDMetric {
35  public:
36  EuclideanVectorKDMetric(std::string name = "EuclideanVectorKDMetric%1%");
37  double get_distance(const VectorKD &a, const VectorKD &b) const {
38  return get_l2_norm(a - b);
39  }
40  VectorKD get_centroid(const VectorKDs &vs) const {
41  IMP_USAGE_CHECK(!vs.empty(), "Needs things to have a centroid");
42  VectorKD sum = std::accumulate(vs.begin(), vs.end(),
43  get_zero_vector_kd(vs[0].get_dimension()));
44  return sum / vs.size();
45  }
47 };
48 
49 /** The l-infinity norm on the difference between the two vectors. And the
50  centroid is the center of the bounding box of the vectors.
51  */
52 class IMPALGEBRAEXPORT MaxVectorKDMetric : public VectorKDMetric {
53  public:
54  MaxVectorKDMetric(std::string name = "MaxVectorKDMetric%1%");
55  double get_distance(const VectorKD &a, const VectorKD &b) const {
56  return get_linf_norm(a - b);
57  }
58  VectorKD get_centroid(const VectorKDs &vs) const {
59  IMP_USAGE_CHECK(!vs.empty(), "Needs things to have a centroid");
60  BoundingBoxKD bb = std::accumulate(vs.begin(), vs.end(),
61  BoundingBoxKD(vs[0].get_dimension()));
62  return .5 * (bb.get_corner(0) + bb.get_corner(1));
63  }
65 };
66 
67 IMPALGEBRA_END_NAMESPACE
68 
69 #endif /* IMPALGEBRA_VECTOR_METRICS_H */
BoundingBoxD<-1 > BoundingBoxKD
Typedef for Python.
Definition: BoundingBoxD.h:176
Basic types used by IMP.
VectorD< D > get_zero_vector_kd(int Di)
Return a dynamically sized vector of zeros.
Definition: VectorD.h:262
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
The l2 norm on the distance vector.
Common base class for heavy weight IMP objects.
Definition: Object.h:106
A bounding box in D dimensions.
Simple D vector class.
A nullptr-initialized pointer to an Object.
An axis-aligned bounding box.
Definition: BoundingBoxD.h:27
Vector3D get_centroid(const Vector3Ds &ps)
Return the centroid of a set of vectors.
Definition: Vector3D.h:68
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
A nullptr-initialized pointer to an IMP Object.
A shared base class to help in debugging and things.
The base class for a metric on VectorKDs.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
VectorD<-1 > VectorKD
Definition: VectorD.h:411
double get_distance(const Line3D &s, const Vector3D &p)
Get closest distance between a line and a point.