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>
23 IMPALGEBRA_BEGIN_NAMESPACE
31 virtual int get_dimension()
const = 0;
36 double ci = 1.0 /
static_cast<double>(get_dimension());
37 return get_ones_vector_kd<D>(get_dimension(), ci);
48 double atol = std::numeric_limits<double>::epsilon())
const {
49 int d = p.get_dimension();
50 if (d != get_dimension())
return false;
52 for (
int i = 0; i < d; ++i) {
53 if (p[i] < 0)
return false;
56 if (std::abs(nrm - 1) > d * atol)
return false;
96 { out <<
"UnitSimplexKD(" << d_ <<
")"; });
102 typedef UnitSimplexD<1> UnitSimplex1D;
122 for (
int i = 0; i < d; ++i)
123 ret.push_back(get_basis_vector_kd<D>(d, i));
129 return Triangle3D(ps[0], ps[1], ps[2]);
141 "Dimension of point must match dimension of simplex.");
144 std::partial_sum(p.begin(), p.end(), q.begin());
155 "Dimension of point must match dimension of simplex.");
157 std::adjacent_difference(p.begin(), p.end(), q.begin());
173 "Dimension of point must match dimension of simplex.");
178 std::sort(u.begin(), u.end(), std::greater<double>());
181 std::partial_sum(u.begin(), u.end(), u_cumsum.begin());
185 if (u[rho] + (1 - u_cumsum[rho]) / (rho + 1) < 0)
break;
188 double lam = (1 - u_cumsum[rho - 1]) / rho;
190 for (
int i = 0; i < d; ++i) {
191 double ui = p[i] + lam;
192 u[i] = ui > 0 ? ui : 0.0;
198 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.