distribution/log_polynomial.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /// @file | ||
| 2 | /// @brief Size-frequency distributions given by a polynomial in log diameter. | ||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include "terraingen/distribution/size_frequency.h" | ||
| 6 | |||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | namespace terraingen { | ||
| 10 | |||
| 11 | /// N(>=D) = 10^P(x) / `areaUnit` with P(x) = sum_i a_i x^i and x = log10(D / | ||
| 12 | /// `diameterUnit`), the form of the Neukum et al. (2001) production function. | ||
| 13 | class LogPolynomialSfd final : public SizeFrequencyDistribution { | ||
| 14 | public: | ||
| 15 | /// The distribution with the given coefficients and units. | ||
| 16 | /// @param coefficients a_0, a_1, ... in increasing degree; at least one, all finite. | ||
| 17 | /// @param range Diameters in metres with 0 < `min` and finite `max`; polynomials diverge | ||
| 18 | /// outside the interval they were fitted on. | ||
| 19 | /// @param diameterUnit Metres per unit of D in the fit; 1000 for coefficients in km. | ||
| 20 | /// @param areaUnit m^2 per unit of area in the fit; 1e6 for counts per km^2. | ||
| 21 | /// @throws std::invalid_argument for no or non-finite coefficients, a unit that is not positive | ||
| 22 | /// and finite, a range without a positive minimum and finite maximum, or if N(>=D) increases | ||
| 23 | /// anywhere in the range. | ||
| 24 | LogPolynomialSfd(std::vector<double> coefficients, DiameterRange range, | ||
| 25 | SfdKind kind = SfdKind::Density, double diameterUnit = 1.0, | ||
| 26 | double areaUnit = 1.0); | ||
| 27 | |||
| 28 | /// The coefficients a_0, a_1, ... in increasing degree. | ||
| 29 | 2 | const std::vector<double>& Coefficients() const { | |
| 30 | 2 | return coefficients_; | |
| 31 | } | ||
| 32 | |||
| 33 | protected: | ||
| 34 | double CumulativeAt(double diameter) const override; | ||
| 35 | double IncrementalAt(double diameter) const override; | ||
| 36 | |||
| 37 | private: | ||
| 38 | double Polynomial(double x) const; | ||
| 39 | double Derivative(double x) const; | ||
| 40 | |||
| 41 | std::vector<double> coefficients_; | ||
| 42 | double diameterUnit_; | ||
| 43 | double areaUnit_; | ||
| 44 | }; | ||
| 45 | |||
| 46 | } // namespace terraingen | ||
| 47 |