| 1 | /* SlopeSelector_def.h |
| 2 | * |
| 3 | * Copyright (C) 2025 David Weenink |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | /* |
| 20 | We would have liked to inherit from the ExtendedReal struct and only overload the operator< |
| 21 | but that is not possible in a _def file?? |
| 22 | */ |
| 23 | #define ooSTRUCTcxx . . $ `dwsys/SlopeSelector_def.h:23:9`! ExtendedCrossing |
| 24 | oo_DEFINE_STRUCTcxx . . $ `sys/oo_WRITE_BINARY.h:132:9`! (ExtendedCrossing) |
| 25 | oo_DOUBLEcxx . . $ `sys/oo.h:58:9`! (real) |
| 26 | oo_INTEGERcxx . . $ `sys/oo.h:45:9`! (low) |
| 27 | oo_INTEGERcxx . . $ `sys/oo.h:45:9`! (high) |
| 28 | #if oo_DECLARINGcxx . . $ `sys/oo_WRITE_BINARY.h:149:9`! |
| 29 | |
| 30 | friend bool operator< (const structExtendedCrossing& lhs, const structExtendedCrossing& rhs) { |
| 31 | auto approximatelyEqual = [&] (double numericalEqualityPrecision) { |
| 32 | if (std::fabs (lhs.real) < numericalEqualityPrecision || std::fabs (rhs.real) < numericalEqualityPrecision) { |
| 33 | return std::fabs (lhs.real - rhs.real) < numericalEqualityPrecision; |
| 34 | } |
| 35 | // Use relative difference otherwise |
| 36 | return std::fabs (lhs.real - rhs.real) <= numericalEqualityPrecision * std::fmax (std::fabs (lhs.real), std::fabs (rhs.real)); |
| 37 | }; |
| 38 | const bool r = ( !approximatelyEqual (1e-12) ? (lhs.real < rhs.real) : |
| 39 | (lhs.high != rhs.high ? (lhs.high > rhs.high) : (lhs.low < rhs.low)) ); |
| 40 | return r; |
| 41 | } |
| 42 | /* |
| 43 | All derived from above comparison |
| 44 | */ |
| 45 | friend inline bool operator> (const structExtendedCrossing& lhs, const structExtendedCrossing& rhs) { |
| 46 | return rhs < lhs; |
| 47 | } |
| 48 | friend inline bool operator<= (const structExtendedCrossing& lhs, const structExtendedCrossing& rhs) { |
| 49 | return ! (lhs > rhs); |
| 50 | } |
| 51 | friend inline bool operator>= (const structExtendedCrossing& lhs, const structExtendedCrossing& rhs) { |
| 52 | return ! (lhs < rhs); |
| 53 | } |
| 54 | friend inline bool operator== (const structExtendedCrossing& lhs, const structExtendedCrossing& rhs) { |
| 55 | return std::tie (lhs.real, lhs.low, lhs.high) == std::tie (rhs.real, rhs.low, rhs.high); |
| 56 | } |
| 57 | friend inline bool operator!= (const structExtendedCrossing& lhs, const structExtendedCrossing& rhs) { |
| 58 | return ! (lhs == rhs); |
| 59 | } |
| 60 | |
| 61 | #endif |
| 62 | oo_END_STRUCTcxx . . $ `sys/oo_WRITE_BINARY.h:135:9`! (ExtendedCrossing) |
| 63 | #undef ooSTRUCTcxx . . $ `dwsys/SlopeSelector_def.h:23:9`! |
| 64 | |
| 65 | #define ooSTRUCTcxx . . $ `dwsys/SlopeSelector_def.h:65:9`! SlopeSelector |
| 66 | oo_DEFINE_CLASScxx . . $ `sys/oo_WRITE_BINARY.h:138:9`! (SlopeSelector, Daata) |
| 67 | oo_INTEGERcxx . . $ `sys/oo.h:45:9`! (numberOfPoints) |
| 68 | oo_INTEGERcxx . . $ `sys/oo.h:45:9`! (sampleSize) |
| 69 | |
| 70 | oo_INTEGERcxx . . $ `sys/oo.h:45:9`! (numberOfTries) |
| 71 | oo_INTEGERcxx . . $ `sys/oo.h:45:9`! (maximumNumberOfTries) |
| 72 | oo_INTEGERcxx . . $ `sys/oo.h:45:9`! (maximumContractionSize) // > sampleSize + numberOfPoints |
| 73 | oo_OBJECTcxx . . $ `sys/oo_WRITE_BINARY.h:102:9`! (Permutation, 0, lineRankingAtLowX) |
| 74 | oo_OBJECTcxx . . $ `sys/oo_WRITE_BINARY.h:102:9`! (Permutation, 0, lineRankingAtLowXPrevious) |
| 75 | oo_OBJECTcxx . . $ `sys/oo_WRITE_BINARY.h:102:9`! (Permutation, 0, inverseOfLineRankingAtLowX) |
| 76 | oo_OBJECTcxx . . $ `sys/oo_WRITE_BINARY.h:102:9`! (Permutation, 0, lineRankingAtHighX) |
| 77 | oo_OBJECTcxx . . $ `sys/oo_WRITE_BINARY.h:102:9`! (Permutation, 0, lineRankingAtHighXPrevious) |
| 78 | oo_INTVECcxx . . $ `sys/oo.h:76:9`! (sortedRandomCrossingCodes, sampleSize) |
| 79 | oo_INTEGERcxx . . $ `sys/oo.h:45:9`! (inversionsSize) |
| 80 | oo_INTVECcxx . . $ `sys/oo.h:76:9`! (currentInversions, inversionsSize) |
| 81 | oo_STRUCTVECcxx . . $ `sys/oo_WRITE_BINARY.h:82:9`! (ExtendedCrossing, xslopes, maximumContractionSize) |
| 82 | oo_VECcxx . . $ `sys/oo.h:74:9`! (buffer, maximumContractionSize) // for buffering and final quantile calculations |
| 83 | oo_STRUCTVECcxx . . $ `sys/oo_WRITE_BINARY.h:82:9`! (ExtendedCrossing, xcrossings, numberOfPoints) |
| 84 | oo_OBJECTcxx . . $ `sys/oo_WRITE_BINARY.h:102:9`! (PermutationInversionCounter, 0, inversionCounter) |
| 85 | |
| 86 | #if oo_DECLARINGcxx . . $ `sys/oo_WRITE_BINARY.h:149:9`! |
| 87 | constVEC xp; // links to the outside world data points (by newDataPoints(x,y)) |
| 88 | constVEC yp; // |
| 89 | |
| 90 | void newDataPoints (constVEC const& x, constVEC const& y); |
| 91 | |
| 92 | double getSlope_Siegel (); |
| 93 | |
| 94 | double getSlope_TheilSen (); |
| 95 | |
| 96 | double getIntercept (double slope); |
| 97 | |
| 98 | void getSlopeAndIntercept_leastSquares (double &slope, double& intercept); |
| 99 | |
| 100 | void getKth_TheilSen (integer k, double& kth, double& kp1th); |
| 101 | |
| 102 | double slopeQuantile_TheilSen (double factor); |
| 103 | |
| 104 | double slopeQuantile_orderNSquared (double factor); |
| 105 | |
| 106 | double slopeQuantile_orderNSquaredWithBuffer (double factor, VEC const& buffer); |
| 107 | |
| 108 | double slopeQuantile (double factor) { |
| 109 | return slopeQuantile_TheilSen (factor); |
| 110 | } |
| 111 | #endif |
| 112 | #if oo_COPYINGcxx . . $ `sys/oo_WRITE_BINARY.h:151:9`! |
| 113 | thy xp = xp; // superfluous: xp and yp need to be linked explicitely to the external data (by newDataPoints) |
| 114 | thy yp = yp; // |
| 115 | #endif |
| 116 | oo_END_CLASScxx . . $ `sys/oo_WRITE_BINARY.h:142:9`! (SlopeSelector) |
| 117 | #undef ooSTRUCTcxx . . $ `dwsys/SlopeSelector_def.h:65:9`! |
| 118 | |
| 119 | /* End of file SlopeSelector_def */ |