9 #ifndef IMPALGEBRA_UNIT_SIMPLEX_D_H
10 #define IMPALGEBRA_UNIT_SIMPLEX_D_H
12 #include <IMP/algebra/algebra_config.h>
17 #include <boost/math/special_functions/gamma.hpp>
18 #include <boost/serialization/access.hpp>
24 IMPALGEBRA_BEGIN_NAMESPACE
32 virtual int get_dimension()
const = 0;
37 double ci = 1.0 /
static_cast<double>(get_dimension());
38 return get_ones_vector_kd<D>(get_dimension(), ci);
49 double atol = std::numeric_limits<double>::epsilon())
const {
50 int d = p.get_dimension();
51 if (d != get_dimension())
return false;
53 for (
int i = 0; i < d; ++i) {
54 if (p[i] < 0)
return false;
57 if (std::abs(nrm - 1) > d * atol)
return false;
71 friend class boost::serialization::access;
73 template<
class Archive>
void serialize(Archive &ar,
const unsigned int) {}
90 friend class boost::serialization::access;
92 template<
class Archive>
void serialize(Archive &ar,
const unsigned int) {
107 { out <<
"UnitSimplexKD(" << d_ <<
")"; });
113 typedef UnitSimplexD<1> UnitSimplex1D;
133 for (
int i = 0; i < d; ++i)
134 ret.push_back(get_basis_vector_kd<D>(d, i));
140 return Triangle3D(ps[0], ps[1], ps[2]);
152 "Dimension of point must match dimension of simplex.");
155 std::partial_sum(p.begin(), p.end(), q.begin());
166 "Dimension of point must match dimension of simplex.");
168 std::adjacent_difference(p.begin(), p.end(), q.begin());
184 "Dimension of point must match dimension of simplex.");
189 std::sort(u.begin(), u.end(), std::greater<double>());
192 std::partial_sum(u.begin(), u.end(), u_cumsum.begin());
196 if (u[rho] + (1 - u_cumsum[rho]) / (rho + 1) < 0)
break;
199 double lam = (1 - u_cumsum[rho - 1]) / rho;
201 for (
int i = 0; i < d; ++i) {
202 double ui = p[i] + lam;
203 u[i] = ui > 0 ? ui : 0.0;
209 IMPALGEBRA_END_NAMESPACE
int get_dimension() const override
Get dimension D of embedded real space.
Base class for geometric types.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
VectorD< D > get_zero_vector_kd(int Di)
Return a dynamically sized vector of zeros.
Vector< VectorD< 3 > > Vector3Ds
VectorD< D > get_barycenter() const
Get center of mass on simplex in embedded coordinates.
Represent a unit simplex embedded in D-dimensional real space.
Represent a triangle in 3D.
A more IMP-like version of the std::vector.
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Base class for geometric types.
bool get_contains(const VectorD< D > &p, double atol=std::numeric_limits< double >::epsilon()) const
Get whether the point is on the unit simplex.
VectorD< D > get_increasing_from_embedded(const UnitSimplexD< D > &s, const VectorD< D > &p)
Convert point on simplex from embedded to increasing coordinates.
A Cartesian vector in D-dimensions.
VectorD< D > get_embedded_from_increasing(const UnitSimplexD< D > &s, const VectorD< D > &p)
Convert point on simplex from increasing to embedded coordinates.
int get_dimension() const override
Get dimension of embedded real space.
Represent a triangle in 3D.
UnitSimplexD(int d=1)
Construct from dimension d of embedded real space.
Base class for a unit simplex embedded in D-dimensional real space.
Represent a unit simplex embedded in d-dimensional real space.
Vector< VectorD< D > > get_vertices(const UnitSimplexD< D > &s)
Return a list of the vertices (bases) of the unit simplex.
VectorD< D > get_projected(const UnitSimplexD< D > &s, const VectorD< D > &p)
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Macros to help with objects that can be printed to a stream.