IMP logo
IMP Reference Guide  2.6.1
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-2016 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  */
25 class IMPALGEBRAEXPORT VectorKDMetric : public Object {
26  public:
27  VectorKDMetric(std::string name);
28  virtual double get_distance(const VectorKD &a, const VectorKD &b) const = 0;
29  virtual VectorKD get_centroid(const VectorKDs &vs) const = 0;
30 };
31 
33 
34 /** The l2 norm on the distance vector.
35  */
36 class IMPALGEBRAEXPORT EuclideanVectorKDMetric : public VectorKDMetric {
37  public:
38  EuclideanVectorKDMetric(std::string name = "EuclideanVectorKDMetric%1%");
39  double get_distance(const VectorKD &a, const VectorKD &b) const {
40  return get_l2_norm(a - b);
41  }
42  VectorKD get_centroid(const VectorKDs &vs) const {
43  IMP_USAGE_CHECK(!vs.empty(), "Needs things to have a centroid");
44  VectorKD sum = std::accumulate(vs.begin(), vs.end(),
45  get_zero_vector_kd(vs[0].get_dimension()));
46  return sum / vs.size();
47  }
49 };
50 
51 /** The l-infinity norm on the difference between the two vectors. And the
52  centroid is the center of the bounding box of the vectors.
53  */
54 class IMPALGEBRAEXPORT MaxVectorKDMetric : public VectorKDMetric {
55  public:
56  MaxVectorKDMetric(std::string name = "MaxVectorKDMetric%1%");
57  double get_distance(const VectorKD &a, const VectorKD &b) const {
58  return get_linf_norm(a - b);
59  }
60  VectorKD get_centroid(const VectorKDs &vs) const {
61  IMP_USAGE_CHECK(!vs.empty(), "Needs things to have a centroid");
62  BoundingBoxKD bb = std::accumulate(vs.begin(), vs.end(),
63  BoundingBoxKD(vs[0].get_dimension()));
64  return .5 * (bb.get_corner(0) + bb.get_corner(1));
65  }
67 };
68 
69 IMPALGEBRA_END_NAMESPACE
70 
71 #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
double get_distance(const Plane3D &pln, const Vector3D &p)
Return the distance between a plane and a point in 3D.
Definition: Plane3D.h:63
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)
Returns the centroid of a set of vectors.
Definition: Vector3D.h:56
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
Definition: object_macros.h:42
A nullptr-initialized pointer to an IMP Object.
A shared base class to help in debugging and things.
#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