ootk 3.0.0 → 4.0.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +235 -10
- package/README.md +27 -40
- package/dist/coordinate/Hill.d.ts +49 -0
- package/dist/coordinate/Hill.js +222 -0
- package/dist/coordinate/Hill.js.map +1 -0
- package/dist/coordinate/index.d.ts +1 -0
- package/dist/coordinate/index.js +2 -0
- package/dist/coordinate/index.js.map +1 -0
- package/dist/covariance/CovarianceSample.d.ts +43 -0
- package/dist/covariance/CovarianceSample.js +147 -0
- package/dist/covariance/CovarianceSample.js.map +1 -0
- package/dist/covariance/StateCovariance.d.ts +42 -0
- package/dist/covariance/StateCovariance.js +65 -0
- package/dist/covariance/StateCovariance.js.map +1 -0
- package/dist/force/AtmosphericDrag.d.ts +31 -0
- package/dist/force/AtmosphericDrag.js +73 -0
- package/dist/force/AtmosphericDrag.js.map +1 -0
- package/dist/force/EarthGravity.d.ts +27 -0
- package/dist/force/EarthGravity.js +117 -0
- package/dist/force/EarthGravity.js.map +1 -0
- package/{lib/ootk.d.ts → dist/force/Force.d.ts} +12 -11
- package/dist/force/Force.js +31 -0
- package/dist/force/Force.js.map +1 -0
- package/dist/force/ForceModel.d.ts +37 -0
- package/dist/force/ForceModel.js +75 -0
- package/dist/force/ForceModel.js.map +1 -0
- package/dist/force/Gravity.d.ts +38 -0
- package/dist/force/Gravity.js +47 -0
- package/dist/force/Gravity.js.map +1 -0
- package/dist/{ootk.d.ts → force/SolarRadiationPressure.d.ts} +12 -11
- package/dist/force/SolarRadiationPressure.js +44 -0
- package/dist/force/SolarRadiationPressure.js.map +1 -0
- package/dist/force/ThirdBodyGravity.d.ts +26 -0
- package/dist/force/ThirdBodyGravity.js +57 -0
- package/dist/force/ThirdBodyGravity.js.map +1 -0
- package/dist/force/Thrust.d.ts +34 -0
- package/dist/force/Thrust.js +58 -0
- package/dist/force/Thrust.js.map +1 -0
- package/dist/interfaces/RfSensorParams.d.ts +28 -0
- package/dist/interfaces/RfSensorParams.js +24 -0
- package/dist/interfaces/RfSensorParams.js.map +1 -0
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/interfaces/index.js +2 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interpolator/ChebyshevCoefficients.d.ts +50 -0
- package/dist/interpolator/ChebyshevCoefficients.js +94 -0
- package/dist/interpolator/ChebyshevCoefficients.js.map +1 -0
- package/dist/interpolator/ChebyshevInterpolator.d.ts +38 -0
- package/dist/interpolator/ChebyshevInterpolator.js +71 -0
- package/dist/interpolator/ChebyshevInterpolator.js.map +1 -0
- package/dist/interpolator/CubicSpline.d.ts +35 -0
- package/dist/interpolator/CubicSpline.js +69 -0
- package/dist/interpolator/CubicSpline.js.map +1 -0
- package/dist/interpolator/CubicSplineInterpolator.d.ts +36 -0
- package/dist/interpolator/CubicSplineInterpolator.js +80 -0
- package/dist/interpolator/CubicSplineInterpolator.js.map +1 -0
- package/dist/interpolator/FieldInterpolator.d.ts +28 -0
- package/dist/interpolator/FieldInterpolator.js +34 -0
- package/dist/interpolator/FieldInterpolator.js.map +1 -0
- package/dist/interpolator/Interpolator.d.ts +22 -0
- package/dist/interpolator/Interpolator.js +47 -0
- package/dist/interpolator/Interpolator.js.map +1 -0
- package/dist/interpolator/LagrangeInterpolator.d.ts +40 -0
- package/dist/interpolator/LagrangeInterpolator.js +159 -0
- package/dist/interpolator/LagrangeInterpolator.js.map +1 -0
- package/dist/interpolator/StateInterpolator.d.ts +27 -0
- package/dist/interpolator/StateInterpolator.js +35 -0
- package/dist/interpolator/StateInterpolator.js.map +1 -0
- package/dist/interpolator/VerletBlendInterpolator.d.ts +43 -0
- package/dist/interpolator/VerletBlendInterpolator.js +118 -0
- package/dist/interpolator/VerletBlendInterpolator.js.map +1 -0
- package/{lib/ootk.js → dist/main.d.ts} +13 -10
- package/dist/{objects/space-object.d.ts → main.js} +17 -23
- package/dist/main.js.map +1 -0
- package/dist/maneuver/TwoBurnOrbitTransfer.d.ts +41 -0
- package/dist/maneuver/TwoBurnOrbitTransfer.js +65 -0
- package/dist/maneuver/TwoBurnOrbitTransfer.js.map +1 -0
- package/dist/maneuver/Waypoint.d.ts +91 -0
- package/dist/maneuver/Waypoint.js +179 -0
- package/dist/maneuver/Waypoint.js.map +1 -0
- package/{lib/objects/detailed-sat.d.ts → dist/objects/DetailedSatellite.d.ts} +40 -36
- package/dist/objects/DetailedSatellite.js +136 -0
- package/dist/objects/DetailedSatellite.js.map +1 -0
- package/dist/objects/DetailedSensor.d.ts +42 -0
- package/dist/objects/DetailedSensor.js +65 -0
- package/dist/objects/DetailedSensor.js.map +1 -0
- package/dist/objects/LandObject.d.ts +33 -0
- package/dist/objects/LandObject.js +34 -0
- package/dist/objects/LandObject.js.map +1 -0
- package/dist/objects/Marker.d.ts +20 -0
- package/dist/objects/Marker.js +24 -0
- package/dist/objects/Marker.js.map +1 -0
- package/dist/objects/RfSensor.d.ts +41 -0
- package/dist/objects/RfSensor.js +67 -0
- package/dist/objects/RfSensor.js.map +1 -0
- package/dist/objects/index.d.ts +5 -4
- package/dist/objects/index.js +6 -0
- package/dist/objects/index.js.map +1 -0
- package/dist/observation/Observation.d.ts +89 -0
- package/dist/observation/Observation.js +102 -0
- package/dist/observation/Observation.js.map +1 -0
- package/dist/observation/ObservationOptical.d.ts +48 -0
- package/dist/observation/ObservationOptical.js +105 -0
- package/dist/observation/ObservationOptical.js.map +1 -0
- package/dist/observation/ObservationRadar.d.ts +46 -0
- package/dist/observation/ObservationRadar.js +96 -0
- package/dist/observation/ObservationRadar.js.map +1 -0
- package/dist/observation/ObservationUtils.d.ts +20 -0
- package/dist/observation/ObservationUtils.js +32 -0
- package/dist/observation/ObservationUtils.js.map +1 -0
- package/dist/observation/PropagatorPairs.d.ts +32 -0
- package/dist/observation/PropagatorPairs.js +43 -0
- package/dist/observation/PropagatorPairs.js.map +1 -0
- package/dist/operations/BoxMuller.d.ts +46 -0
- package/dist/operations/BoxMuller.js +77 -0
- package/dist/operations/BoxMuller.js.map +1 -0
- package/dist/operations/EulerAngles.d.ts +105 -0
- package/dist/operations/EulerAngles.js +161 -0
- package/dist/operations/EulerAngles.js.map +1 -0
- package/dist/operations/Quaternion.d.ts +56 -0
- package/dist/operations/Quaternion.js +167 -0
- package/dist/operations/Quaternion.js.map +1 -0
- package/dist/operations/RandomGaussianSource.d.ts +24 -0
- package/dist/operations/RandomGaussianSource.js +43 -0
- package/dist/operations/RandomGaussianSource.js.map +1 -0
- package/dist/operations/index.d.ts +4 -0
- package/dist/operations/index.js +5 -0
- package/dist/operations/index.js.map +1 -0
- package/dist/optimize/ChebyshevCompressor.d.ts +32 -0
- package/dist/optimize/ChebyshevCompressor.js +83 -0
- package/dist/optimize/ChebyshevCompressor.js.map +1 -0
- package/dist/optimize/DownhillSimplex.d.ts +64 -0
- package/dist/optimize/DownhillSimplex.js +182 -0
- package/dist/optimize/DownhillSimplex.js.map +1 -0
- package/dist/optimize/GoldenSection.d.ts +39 -0
- package/dist/optimize/GoldenSection.js +55 -0
- package/dist/optimize/GoldenSection.js.map +1 -0
- package/dist/optimize/PolynomialRegression.d.ts +49 -0
- package/dist/optimize/PolynomialRegression.js +83 -0
- package/dist/optimize/PolynomialRegression.js.map +1 -0
- package/dist/optimize/PolynomicalRegressionResult.d.ts +31 -0
- package/dist/optimize/PolynomicalRegressionResult.js +38 -0
- package/dist/optimize/PolynomicalRegressionResult.js.map +1 -0
- package/dist/optimize/SimpleLinearRegression.d.ts +44 -0
- package/dist/optimize/SimpleLinearRegression.js +112 -0
- package/dist/optimize/SimpleLinearRegression.js.map +1 -0
- package/dist/optimize/SimplexEntry.d.ts +32 -0
- package/dist/optimize/SimplexEntry.js +42 -0
- package/dist/optimize/SimplexEntry.js.map +1 -0
- package/dist/orbit_determination/BatchLeastSquaresOD.d.ts +65 -0
- package/dist/orbit_determination/BatchLeastSquaresOD.js +143 -0
- package/dist/orbit_determination/BatchLeastSquaresOD.js.map +1 -0
- package/dist/orbit_determination/BatchLeastSquaresResult.d.ts +31 -0
- package/{lib/objects/space-object.d.ts → dist/orbit_determination/BatchLeastSquaresResult.js} +21 -23
- package/dist/orbit_determination/BatchLeastSquaresResult.js.map +1 -0
- package/dist/orbit_determination/GibbsIOD.d.ts +38 -0
- package/dist/orbit_determination/GibbsIOD.js +76 -0
- package/dist/orbit_determination/GibbsIOD.js.map +1 -0
- package/dist/orbit_determination/GoodingIOD.d.ts +51 -0
- package/dist/orbit_determination/GoodingIOD.js +247 -0
- package/dist/orbit_determination/GoodingIOD.js.map +1 -0
- package/dist/orbit_determination/HerrickGibbsIOD.d.ts +33 -0
- package/dist/orbit_determination/HerrickGibbsIOD.js +50 -0
- package/dist/orbit_determination/HerrickGibbsIOD.js.map +1 -0
- package/dist/orbit_determination/LambertIOD.d.ts +59 -0
- package/dist/orbit_determination/LambertIOD.js +213 -0
- package/dist/orbit_determination/LambertIOD.js.map +1 -0
- package/dist/orbit_determination/ModifiedGoodingIOD.d.ts +40 -0
- package/dist/orbit_determination/ModifiedGoodingIOD.js +83 -0
- package/dist/orbit_determination/ModifiedGoodingIOD.js.map +1 -0
- package/dist/propagator/DormandPrince54Propagator.d.ts +28 -0
- package/dist/propagator/DormandPrince54Propagator.js +64 -0
- package/dist/propagator/DormandPrince54Propagator.js.map +1 -0
- package/dist/propagator/KeplerPropagator.d.ts +35 -0
- package/dist/propagator/KeplerPropagator.js +84 -0
- package/dist/propagator/KeplerPropagator.js.map +1 -0
- package/dist/propagator/Propagator.d.ts +34 -0
- package/dist/propagator/Propagator.js +162 -0
- package/dist/propagator/Propagator.js.map +1 -0
- package/dist/propagator/RkCheckpoint.d.ts +22 -0
- package/dist/propagator/RkCheckpoint.js +27 -0
- package/dist/propagator/RkCheckpoint.js.map +1 -0
- package/dist/propagator/RkResult.d.ts +23 -0
- package/dist/propagator/RkResult.js +30 -0
- package/dist/propagator/RkResult.js.map +1 -0
- package/dist/propagator/RungeKutta4Propagator.d.ts +50 -0
- package/dist/propagator/RungeKutta4Propagator.js +141 -0
- package/dist/propagator/RungeKutta4Propagator.js.map +1 -0
- package/dist/propagator/RungeKutta89Propagator.d.ts +28 -0
- package/dist/propagator/RungeKutta89Propagator.js +126 -0
- package/dist/propagator/RungeKutta89Propagator.js.map +1 -0
- package/dist/propagator/RungeKuttaAdaptive.d.ts +54 -0
- package/dist/propagator/RungeKuttaAdaptive.js +159 -0
- package/dist/propagator/RungeKuttaAdaptive.js.map +1 -0
- package/dist/propagator/Sgp4Propagator.d.ts +34 -0
- package/dist/propagator/Sgp4Propagator.js +56 -0
- package/dist/propagator/Sgp4Propagator.js.map +1 -0
- package/dist/smoothing/ExponentialSmoothing.d.ts +23 -0
- package/dist/smoothing/ExponentialSmoothing.js +81 -0
- package/dist/smoothing/ExponentialSmoothing.js.map +1 -0
- package/dist/transforms/index.d.ts +1 -0
- package/dist/transforms/index.js +2 -0
- package/dist/transforms/index.js.map +1 -0
- package/dist/transforms/transforms.d.ts +56 -92
- package/dist/transforms/transforms.js +94 -0
- package/dist/transforms/transforms.js.map +1 -0
- package/dist/types/types.d.ts +105 -584
- package/dist/types/types.js +23 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/jacobian.d.ts +11 -0
- package/dist/utils/jacobian.js +29 -0
- package/dist/utils/jacobian.js.map +1 -0
- package/package.json +34 -42
- package/src/coordinate/Hill.ts +326 -0
- package/src/coordinate/index.ts +1 -0
- package/src/covariance/CovarianceSample.ts +194 -0
- package/src/covariance/StateCovariance.ts +69 -0
- package/src/force/AtmosphericDrag.ts +101 -0
- package/src/force/EarthGravity.ts +157 -0
- package/src/force/Force.ts +33 -0
- package/src/force/ForceModel.ts +91 -0
- package/src/force/Gravity.ts +53 -0
- package/src/force/SolarRadiationPressure.ts +42 -0
- package/src/force/ThirdBodyGravity.ts +62 -0
- package/src/force/Thrust.ts +83 -0
- package/src/interfaces/RfSensorParams.ts +30 -0
- package/src/interfaces/index.ts +1 -0
- package/src/interpolator/ChebyshevCoefficients.ts +109 -0
- package/src/interpolator/ChebyshevInterpolator.ts +87 -0
- package/src/interpolator/CubicSpline.ts +72 -0
- package/src/interpolator/CubicSplineInterpolator.ts +90 -0
- package/src/interpolator/FieldInterpolator.ts +37 -0
- package/src/interpolator/Interpolator.ts +56 -0
- package/src/interpolator/LagrangeInterpolator.ts +192 -0
- package/src/interpolator/StateInterpolator.ts +39 -0
- package/src/interpolator/VerletBlendInterpolator.ts +146 -0
- package/src/main.ts +32 -0
- package/src/maneuver/TwoBurnOrbitTransfer.ts +79 -0
- package/src/maneuver/Waypoint.ts +267 -0
- package/src/objects/DetailedSatellite.ts +159 -0
- package/src/objects/DetailedSensor.ts +68 -0
- package/src/objects/LandObject.ts +46 -0
- package/src/objects/Marker.ts +25 -0
- package/src/objects/RfSensor.ts +78 -0
- package/src/objects/index.ts +5 -0
- package/src/observation/Observation.ts +125 -0
- package/src/observation/ObservationOptical.ts +146 -0
- package/src/observation/ObservationRadar.ts +131 -0
- package/src/observation/ObservationUtils.ts +40 -0
- package/src/observation/PropagatorPairs.ts +45 -0
- package/src/operations/BoxMuller.ts +87 -0
- package/src/operations/EulerAngles.ts +183 -0
- package/src/operations/Quaternion.ts +222 -0
- package/src/operations/RandomGaussianSource.ts +51 -0
- package/src/operations/index.ts +4 -0
- package/src/optimize/ChebyshevCompressor.ts +96 -0
- package/src/optimize/DownhillSimplex.ts +212 -0
- package/src/optimize/GoldenSection.ts +71 -0
- package/src/optimize/PolynomialRegression.ts +109 -0
- package/src/optimize/PolynomicalRegressionResult.ts +32 -0
- package/src/optimize/SimpleLinearRegression.ts +127 -0
- package/src/optimize/SimplexEntry.ts +50 -0
- package/src/orbit_determination/BatchLeastSquaresOD.ts +174 -0
- package/src/orbit_determination/BatchLeastSquaresResult.ts +33 -0
- package/src/orbit_determination/GibbsIOD.ts +95 -0
- package/src/orbit_determination/GoodingIOD.ts +380 -0
- package/src/orbit_determination/HerrickGibbsIOD.ts +51 -0
- package/src/orbit_determination/LambertIOD.ts +260 -0
- package/src/orbit_determination/ModifiedGoodingIOD.ts +133 -0
- package/src/propagator/DormandPrince54Propagator.ts +73 -0
- package/src/propagator/KeplerPropagator.ts +102 -0
- package/src/propagator/Propagator.ts +253 -0
- package/src/propagator/RkCheckpoint.ts +25 -0
- package/src/propagator/RkResult.ts +26 -0
- package/src/propagator/RungeKutta4Propagator.ts +179 -0
- package/src/propagator/RungeKutta89Propagator.ts +132 -0
- package/src/propagator/RungeKuttaAdaptive.ts +232 -0
- package/src/propagator/Sgp4Propagator.ts +71 -0
- package/src/smoothing/ExponentialSmoothing.ts +90 -0
- package/src/transforms/index.ts +1 -0
- package/src/transforms/transforms.ts +117 -0
- package/src/types/types.ts +135 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/jacobian.ts +38 -0
- package/.eslintrc.json +0 -244
- package/.prettierrc +0 -17
- package/babel.config.js +0 -16
- package/codecov.yml +0 -21
- package/dist/objects/base-object.d.ts +0 -40
- package/dist/objects/detailed-sat.d.ts +0 -66
- package/dist/objects/sat.d.ts +0 -92
- package/dist/objects/sensor.d.ts +0 -93
- package/dist/objects/star.d.ts +0 -46
- package/dist/ootk.js +0 -2
- package/dist/ootk.js.LICENSE.txt +0 -77
- package/dist/sgp4/sgp4.d.ts +0 -82
- package/dist/tle/tle-format-data.d.ts +0 -6
- package/dist/tle/tle.d.ts +0 -375
- package/dist/utils/constants.d.ts +0 -34
- package/dist/utils/moon-math.d.ts +0 -113
- package/dist/utils/sun-math.d.ts +0 -230
- package/dist/utils/utils.d.ts +0 -39
- package/jest.config.ts +0 -30
- package/lib/objects/base-object.d.ts +0 -40
- package/lib/objects/base-object.js +0 -79
- package/lib/objects/base-object.js.map +0 -1
- package/lib/objects/detailed-sat.js +0 -149
- package/lib/objects/detailed-sat.js.map +0 -1
- package/lib/objects/index.d.ts +0 -4
- package/lib/objects/index.js +0 -5
- package/lib/objects/index.js.map +0 -1
- package/lib/objects/sat.d.ts +0 -92
- package/lib/objects/sat.js +0 -188
- package/lib/objects/sat.js.map +0 -1
- package/lib/objects/sensor.d.ts +0 -93
- package/lib/objects/sensor.js +0 -273
- package/lib/objects/sensor.js.map +0 -1
- package/lib/objects/space-object.js +0 -60
- package/lib/objects/space-object.js.map +0 -1
- package/lib/objects/star.d.ts +0 -46
- package/lib/objects/star.js +0 -91
- package/lib/objects/star.js.map +0 -1
- package/lib/ootk.js.map +0 -1
- package/lib/sgp4/sgp4.d.ts +0 -82
- package/lib/sgp4/sgp4.js +0 -3262
- package/lib/sgp4/sgp4.js.map +0 -1
- package/lib/tle/tle-format-data.d.ts +0 -6
- package/lib/tle/tle-format-data.js +0 -10
- package/lib/tle/tle-format-data.js.map +0 -1
- package/lib/tle/tle.d.ts +0 -375
- package/lib/tle/tle.js +0 -611
- package/lib/tle/tle.js.map +0 -1
- package/lib/transforms/transforms.d.ts +0 -94
- package/lib/transforms/transforms.js +0 -308
- package/lib/transforms/transforms.js.map +0 -1
- package/lib/types/types.d.ts +0 -605
- package/lib/types/types.js +0 -36
- package/lib/types/types.js.map +0 -1
- package/lib/utils/constants.d.ts +0 -34
- package/lib/utils/constants.js +0 -35
- package/lib/utils/constants.js.map +0 -1
- package/lib/utils/moon-math.d.ts +0 -113
- package/lib/utils/moon-math.js +0 -387
- package/lib/utils/moon-math.js.map +0 -1
- package/lib/utils/sun-math.d.ts +0 -230
- package/lib/utils/sun-math.js +0 -422
- package/lib/utils/sun-math.js.map +0 -1
- package/lib/utils/utils.d.ts +0 -39
- package/lib/utils/utils.js +0 -102
- package/lib/utils/utils.js.map +0 -1
- package/sandbox.html +0 -8
- package/tsconfig.base.json +0 -31
- package/tsconfig.build.json +0 -14
- /package/{LICENSE.MD → LICENSE.md} +0 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author @thkruz Theodore Kruczek
|
|
3
|
+
* @license AGPL-3.0-or-later
|
|
4
|
+
* @copyright (c) 2020-2024 Theodore Kruczek
|
|
5
|
+
*
|
|
6
|
+
* Orbital Object ToolKit is free software: you can redistribute it and/or modify it under the
|
|
7
|
+
* terms of the GNU Affero General Public License as published by the Free Software
|
|
8
|
+
* Foundation, either version 3 of the License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Orbital Object ToolKit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
11
|
+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
* See the GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License along with
|
|
15
|
+
* Orbital Object ToolKit. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { CostFunction, SimplexEntry } from './SimplexEntry';
|
|
19
|
+
|
|
20
|
+
// / Derivative-free Nelder-Mead simplex optimizer.
|
|
21
|
+
export class DownhillSimplex {
|
|
22
|
+
private constructor() {
|
|
23
|
+
// disable constructor
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Compute the centroid from a list of [SimplexEntry] objects, using cost
|
|
28
|
+
* function [f].
|
|
29
|
+
* @param f Cost function
|
|
30
|
+
* @param xss Simplex entries
|
|
31
|
+
* @returns The centroid.
|
|
32
|
+
*/
|
|
33
|
+
private static _centroid(f: CostFunction, xss: SimplexEntry[]): SimplexEntry {
|
|
34
|
+
const n = xss[0].points.length;
|
|
35
|
+
const m = xss.length - 1;
|
|
36
|
+
const output = new Float64Array(n);
|
|
37
|
+
|
|
38
|
+
for (let i = 0; i < m; i++) {
|
|
39
|
+
for (let j = 0; j < n; j++) {
|
|
40
|
+
output[j] += xss[i].points[j];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
for (let i = 0; i < n; i++) {
|
|
44
|
+
output[i] /= m;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return new SimplexEntry(f, output);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private static _shrink(s: number, xss: SimplexEntry[]): void {
|
|
51
|
+
const x1 = xss[0];
|
|
52
|
+
|
|
53
|
+
for (let i = 1; i < xss.length; i++) {
|
|
54
|
+
const xi = xss[i];
|
|
55
|
+
|
|
56
|
+
xss[i] = x1.modify(s, xi, x1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Generate a new simplex from initial guess [x0], and an optional
|
|
62
|
+
* simplex [step] value.
|
|
63
|
+
* @param x0 Initial guess
|
|
64
|
+
* @param step Simplex step
|
|
65
|
+
* @returns The simplex.
|
|
66
|
+
*/
|
|
67
|
+
static generateSimplex(x0: Float64Array, step = 0.01): Float64Array[] {
|
|
68
|
+
const output: Float64Array[] = [x0.slice(0)];
|
|
69
|
+
|
|
70
|
+
for (let i = 0; i < x0.length; i++) {
|
|
71
|
+
const tmp = x0.slice(0);
|
|
72
|
+
|
|
73
|
+
tmp[i] += tmp[i] * step;
|
|
74
|
+
output.push(tmp);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return output;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Perform derivative-free Nelder-Mead simplex optimization to minimize the
|
|
82
|
+
* cost function [f] for the initial simplex [xs].
|
|
83
|
+
*
|
|
84
|
+
* Optional arguments:
|
|
85
|
+
* - `xTolerance`: centroid delta termination criteria
|
|
86
|
+
* - `fTolerance`: cost function delta termination criteria
|
|
87
|
+
* - `maxIter`: maximum number of optimization iterations
|
|
88
|
+
* - `adaptive`: use adaptive coefficients if possible
|
|
89
|
+
* - `printIter`: print a debug statement after each iteration
|
|
90
|
+
* @param f Cost function
|
|
91
|
+
* @param xs Initial simplex
|
|
92
|
+
* @param root0 Root0
|
|
93
|
+
* @param root0.xTolerance Root0.xTolerance
|
|
94
|
+
* @param root0.fTolerance Root0.fTolerance
|
|
95
|
+
* @param root0.maxIter Root0.maxIter
|
|
96
|
+
* @param root0.adaptive Root0.adaptive
|
|
97
|
+
* @param root0.printIter Root0.printIter
|
|
98
|
+
* @returns The optimal input value.
|
|
99
|
+
*/
|
|
100
|
+
static solveSimplex(
|
|
101
|
+
f: CostFunction,
|
|
102
|
+
xs: Float64Array[],
|
|
103
|
+
{
|
|
104
|
+
xTolerance = 1e-12,
|
|
105
|
+
fTolerance = 1e-12,
|
|
106
|
+
maxIter = 10000,
|
|
107
|
+
adaptive = false,
|
|
108
|
+
printIter = false,
|
|
109
|
+
}: {
|
|
110
|
+
xTolerance?: number;
|
|
111
|
+
fTolerance?: number;
|
|
112
|
+
maxIter?: number;
|
|
113
|
+
adaptive?: boolean;
|
|
114
|
+
printIter?: boolean;
|
|
115
|
+
},
|
|
116
|
+
): Float64Array {
|
|
117
|
+
let a: number;
|
|
118
|
+
let g: number;
|
|
119
|
+
let p: number;
|
|
120
|
+
let s: number;
|
|
121
|
+
const n = xs.length - 1;
|
|
122
|
+
|
|
123
|
+
if (adaptive && n >= 2) {
|
|
124
|
+
a = 1.0;
|
|
125
|
+
g = 1.0 + 2.0 / n;
|
|
126
|
+
p = 0.75 - 1.0 / (2.0 * n);
|
|
127
|
+
s = 1.0 - 1.0 / n;
|
|
128
|
+
} else {
|
|
129
|
+
a = 1.0;
|
|
130
|
+
g = 2.0;
|
|
131
|
+
p = 0.5;
|
|
132
|
+
s = 0.5;
|
|
133
|
+
}
|
|
134
|
+
let iter = 0;
|
|
135
|
+
let action = 'init';
|
|
136
|
+
const ordered: SimplexEntry[] = [];
|
|
137
|
+
|
|
138
|
+
for (const x of xs) {
|
|
139
|
+
ordered.push(new SimplexEntry(f, x));
|
|
140
|
+
}
|
|
141
|
+
// eslint-disable-next-line no-constant-condition
|
|
142
|
+
while (true) {
|
|
143
|
+
ordered.sort((x, y) => x.score - y.score);
|
|
144
|
+
const x0 = DownhillSimplex._centroid(f, ordered);
|
|
145
|
+
// update exit criterea
|
|
146
|
+
let xd = 0.0;
|
|
147
|
+
let fd = 0.0;
|
|
148
|
+
|
|
149
|
+
for (let i = 1; i < ordered.length; i++) {
|
|
150
|
+
xd = Math.max(xd, x0.distance(ordered[i]));
|
|
151
|
+
fd = Math.max(fd, Math.abs(x0.score - ordered[i].score));
|
|
152
|
+
}
|
|
153
|
+
if (printIter) {
|
|
154
|
+
// eslint-disable-next-line no-console
|
|
155
|
+
console.log(`${iter}: score=${x0.score} xd=${xd} fd=${fd} [${action}]`);
|
|
156
|
+
}
|
|
157
|
+
if (iter !== 0 && (xd < xTolerance || fd < fTolerance)) {
|
|
158
|
+
return ordered[0].points;
|
|
159
|
+
}
|
|
160
|
+
if (iter >= maxIter) {
|
|
161
|
+
return ordered[0].points;
|
|
162
|
+
}
|
|
163
|
+
iter++;
|
|
164
|
+
// reflection
|
|
165
|
+
const xr = x0.modify(a, x0, ordered[ordered.length - 1]);
|
|
166
|
+
|
|
167
|
+
if (ordered[0].score <= xr.score && xr.score < ordered[ordered.length - 2].score) {
|
|
168
|
+
ordered[ordered.length - 1] = xr;
|
|
169
|
+
action = 'reflect';
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
// expansion
|
|
173
|
+
if (xr.score < ordered[0].score) {
|
|
174
|
+
const xe = x0.modify(g, xr, x0);
|
|
175
|
+
|
|
176
|
+
if (xe.score < xr.score) {
|
|
177
|
+
ordered[ordered.length - 1] = xe;
|
|
178
|
+
} else {
|
|
179
|
+
ordered[ordered.length - 1] = xr;
|
|
180
|
+
}
|
|
181
|
+
action = 'expand';
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
// contraction
|
|
185
|
+
if (xr.score < ordered[ordered.length - 1].score) {
|
|
186
|
+
const xc = x0.modify(p, xr, x0);
|
|
187
|
+
|
|
188
|
+
if (xc.score < xr.score) {
|
|
189
|
+
ordered[ordered.length - 1] = xc;
|
|
190
|
+
action = 'contract';
|
|
191
|
+
continue;
|
|
192
|
+
} else {
|
|
193
|
+
DownhillSimplex._shrink(s, ordered);
|
|
194
|
+
action = 'shrink';
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
} else if (xr.score >= ordered[ordered.length - 1].score) {
|
|
198
|
+
const xc = x0.modify(p, ordered[ordered.length - 1], x0);
|
|
199
|
+
|
|
200
|
+
if (xc.score < ordered[ordered.length - 1].score) {
|
|
201
|
+
ordered[ordered.length - 1] = xc;
|
|
202
|
+
action = 'contract';
|
|
203
|
+
continue;
|
|
204
|
+
} else {
|
|
205
|
+
DownhillSimplex._shrink(s, ordered);
|
|
206
|
+
action = 'shrink';
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author @thkruz Theodore Kruczek
|
|
3
|
+
* @license AGPL-3.0-or-later
|
|
4
|
+
* @copyright (c) 2020-2024 Theodore Kruczek
|
|
5
|
+
*
|
|
6
|
+
* Orbital Object ToolKit is free software: you can redistribute it and/or modify it under the
|
|
7
|
+
* terms of the GNU Affero General Public License as published by the Free Software
|
|
8
|
+
* Foundation, either version 3 of the License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Orbital Object ToolKit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
11
|
+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
* See the GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License along with
|
|
15
|
+
* Orbital Object ToolKit. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { DifferentiableFunction } from '../main';
|
|
19
|
+
|
|
20
|
+
// / Golden Section bounded single value optimizer.
|
|
21
|
+
export class GoldenSection {
|
|
22
|
+
private static readonly _grInv: number = 1.0 / (0.5 * (Math.sqrt(5) + 1));
|
|
23
|
+
|
|
24
|
+
private static _check(fc: number, fd: number, solveMax: boolean): boolean {
|
|
25
|
+
return solveMax ? fc > fd : fc < fd;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Search for an optimal input value for function [f] that minimizes the
|
|
30
|
+
* output value.
|
|
31
|
+
*
|
|
32
|
+
* Takes [lower] and [upper] input search bounds, and an optional
|
|
33
|
+
* search [tolerance].
|
|
34
|
+
* @param f Function to optimize
|
|
35
|
+
* @param lower Lower bound
|
|
36
|
+
* @param upper Upper bound
|
|
37
|
+
* @param root0 Root0
|
|
38
|
+
* @param root0.tolerance Root0.tolerance
|
|
39
|
+
* @param root0.solveMax Root0.solveMax
|
|
40
|
+
* @returns The optimal input value.
|
|
41
|
+
*/
|
|
42
|
+
static search(
|
|
43
|
+
f: DifferentiableFunction,
|
|
44
|
+
lower: number,
|
|
45
|
+
upper: number,
|
|
46
|
+
{
|
|
47
|
+
tolerance = 1e-5,
|
|
48
|
+
solveMax = false,
|
|
49
|
+
}: {
|
|
50
|
+
tolerance?: number;
|
|
51
|
+
solveMax?: boolean;
|
|
52
|
+
},
|
|
53
|
+
): number {
|
|
54
|
+
let a = lower;
|
|
55
|
+
let b = upper;
|
|
56
|
+
let c = b - (b - a) * GoldenSection._grInv;
|
|
57
|
+
let d = a + (b - a) * GoldenSection._grInv;
|
|
58
|
+
|
|
59
|
+
while (Math.abs(b - a) > tolerance) {
|
|
60
|
+
if (GoldenSection._check(f(c), f(d), solveMax)) {
|
|
61
|
+
b = d;
|
|
62
|
+
} else {
|
|
63
|
+
a = c;
|
|
64
|
+
}
|
|
65
|
+
c = b - (b - a) * GoldenSection._grInv;
|
|
66
|
+
d = a + (b - a) * GoldenSection._grInv;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return 0.5 * (b + a);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author @thkruz Theodore Kruczek
|
|
3
|
+
* @license AGPL-3.0-or-later
|
|
4
|
+
* @copyright (c) 2020-2024 Theodore Kruczek
|
|
5
|
+
*
|
|
6
|
+
* Orbital Object ToolKit is free software: you can redistribute it and/or modify it under the
|
|
7
|
+
* terms of the GNU Affero General Public License as published by the Free Software
|
|
8
|
+
* Foundation, either version 3 of the License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Orbital Object ToolKit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
11
|
+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
* See the GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License along with
|
|
15
|
+
* Orbital Object ToolKit. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/* eslint-disable require-jsdoc */
|
|
19
|
+
/* eslint-disable func-style */
|
|
20
|
+
import { evalPoly } from 'ootk-core';
|
|
21
|
+
import { DownhillSimplex } from './DownhillSimplex';
|
|
22
|
+
import { PolynomicalRegressionResult } from './PolynomicalRegressionResult';
|
|
23
|
+
// / Polynomial regression optimizer.
|
|
24
|
+
export class PolynomialRegression {
|
|
25
|
+
private constructor() {
|
|
26
|
+
// disable constructor
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private static _bayesInformationCriterea(n: number, k: number, sse: number): number {
|
|
30
|
+
return n * Math.log(sse) + k * Math.log(n);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Optimize polynomial coefficients to fit data series [xs] and [ys] for the
|
|
35
|
+
* provided polynomial [order].
|
|
36
|
+
* @param xs x values
|
|
37
|
+
* @param ys y values
|
|
38
|
+
* @param order Polynomial order
|
|
39
|
+
* @param root0 Root0
|
|
40
|
+
* @param root0.printIter Root0.printIter
|
|
41
|
+
* @returns The optimal input value.
|
|
42
|
+
*/
|
|
43
|
+
static solve(
|
|
44
|
+
xs: Float64Array,
|
|
45
|
+
ys: Float64Array,
|
|
46
|
+
order: number,
|
|
47
|
+
{ printIter = false }: { printIter?: boolean } = {},
|
|
48
|
+
): PolynomicalRegressionResult {
|
|
49
|
+
const simplex = DownhillSimplex.generateSimplex(Float64Array.from(Array(order + 1).fill(1.0)));
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Sum of squared errors.
|
|
53
|
+
* @param coeffs Polynomial coefficients
|
|
54
|
+
* @returns Sum of squared errors
|
|
55
|
+
*/
|
|
56
|
+
function f(coeffs: Float64Array): number {
|
|
57
|
+
let sse = 0.0;
|
|
58
|
+
|
|
59
|
+
for (let i = 0; i < xs.length; i++) {
|
|
60
|
+
const diff = ys[i] - evalPoly(xs[i], coeffs);
|
|
61
|
+
|
|
62
|
+
sse += diff * diff;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return sse;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const result = DownhillSimplex.solveSimplex(f, simplex, {
|
|
69
|
+
adaptive: true,
|
|
70
|
+
printIter,
|
|
71
|
+
});
|
|
72
|
+
const sse = f(result);
|
|
73
|
+
|
|
74
|
+
return new PolynomicalRegressionResult(
|
|
75
|
+
result,
|
|
76
|
+
Math.sqrt(sse),
|
|
77
|
+
PolynomialRegression._bayesInformationCriterea(xs.length, order, sse),
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Optimize polynomial coefficients to fit data series [xs] and [ys], and
|
|
83
|
+
* attempt to find an optimal order within the [minOrder] and
|
|
84
|
+
* [maxOrder] bounds.
|
|
85
|
+
* @param xs x values
|
|
86
|
+
* @param ys y values
|
|
87
|
+
* @param minOrder Minimum polynomial order
|
|
88
|
+
* @param maxOrder Maximum polynomial order
|
|
89
|
+
* @param root0 Root0
|
|
90
|
+
* @param root0.printIter Root0.printIter
|
|
91
|
+
* @returns The optimal input value.
|
|
92
|
+
*/
|
|
93
|
+
static solveOrder(
|
|
94
|
+
xs: Float64Array,
|
|
95
|
+
ys: Float64Array,
|
|
96
|
+
minOrder: number,
|
|
97
|
+
maxOrder: number,
|
|
98
|
+
{ printIter = false }: { printIter?: boolean } = {},
|
|
99
|
+
): PolynomicalRegressionResult {
|
|
100
|
+
const cache: PolynomicalRegressionResult[] = [];
|
|
101
|
+
|
|
102
|
+
for (let order = minOrder; order <= maxOrder; order++) {
|
|
103
|
+
cache.push(PolynomialRegression.solve(xs, ys, order, { printIter }));
|
|
104
|
+
}
|
|
105
|
+
cache.sort((a, b) => a.bic - b.bic);
|
|
106
|
+
|
|
107
|
+
return cache[0];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author @thkruz Theodore Kruczek
|
|
3
|
+
* @license AGPL-3.0-or-later
|
|
4
|
+
* @copyright (c) 2020-2024 Theodore Kruczek
|
|
5
|
+
*
|
|
6
|
+
* Orbital Object ToolKit is free software: you can redistribute it and/or modify it under the
|
|
7
|
+
* terms of the GNU Affero General Public License as published by the Free Software
|
|
8
|
+
* Foundation, either version 3 of the License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Orbital Object ToolKit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
11
|
+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
* See the GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License along with
|
|
15
|
+
* Orbital Object ToolKit. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// / Polynomial regression optimization result.
|
|
19
|
+
export class PolynomicalRegressionResult {
|
|
20
|
+
/**
|
|
21
|
+
* Create a new [PolynomicalRegressionResult] object, containing the
|
|
22
|
+
* polynomial [coefficients], root-sum-squared error [rss], and Bayes
|
|
23
|
+
* information criterea [bic].
|
|
24
|
+
* @param coefficients The polynomial coefficients.
|
|
25
|
+
* @param rss The root-sum-squared error.
|
|
26
|
+
* @param bic The Bayes information criterea.
|
|
27
|
+
* @returns The optimal input value.
|
|
28
|
+
*/
|
|
29
|
+
constructor(public coefficients: Float64Array, public rss: number, public bic: number) {
|
|
30
|
+
// Nothing to do here.
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author @thkruz Theodore Kruczek
|
|
3
|
+
* @license AGPL-3.0-or-later
|
|
4
|
+
* @copyright (c) 2020-2024 Theodore Kruczek
|
|
5
|
+
*
|
|
6
|
+
* Orbital Object ToolKit is free software: you can redistribute it and/or modify it under the
|
|
7
|
+
* terms of the GNU Affero General Public License as published by the Free Software
|
|
8
|
+
* Foundation, either version 3 of the License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Orbital Object ToolKit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
11
|
+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
* See the GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License along with
|
|
15
|
+
* Orbital Object ToolKit. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// / Simple linear regression _(y = mx + b)_.
|
|
19
|
+
export class SimpleLinearRegression {
|
|
20
|
+
/**
|
|
21
|
+
* Create a new [SimpleLinearRegression] object from lists of x and y
|
|
22
|
+
* values.
|
|
23
|
+
* @param xs x values
|
|
24
|
+
* @param ys y values
|
|
25
|
+
*/
|
|
26
|
+
constructor(public xs: number[], public ys: number[]) {
|
|
27
|
+
this.update();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// / Line slope
|
|
31
|
+
private _slope = 0.0;
|
|
32
|
+
|
|
33
|
+
// / Y-axis intercept
|
|
34
|
+
private _intercept = 0.0;
|
|
35
|
+
|
|
36
|
+
private _error = 0.0;
|
|
37
|
+
|
|
38
|
+
// / Line slope
|
|
39
|
+
get slope(): number {
|
|
40
|
+
return this._slope;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// / Y-axis intercept
|
|
44
|
+
get intercept(): number {
|
|
45
|
+
return this._intercept;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// / Linear regression standard deviation
|
|
49
|
+
get error(): number {
|
|
50
|
+
return this._error;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// / Data length
|
|
54
|
+
get length(): number {
|
|
55
|
+
return Math.min(this.xs.length, this.ys.length);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private _calcError(): void {
|
|
59
|
+
let total = 0.0;
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < this.length; i++) {
|
|
62
|
+
const delta = this.ys[i] - this.evaluate(this.xs[i]);
|
|
63
|
+
|
|
64
|
+
total += delta * delta;
|
|
65
|
+
}
|
|
66
|
+
this._error = Math.sqrt(total / (this.length - 1));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// / Update the linear fit with this object's current [xs] and [ys] values.
|
|
70
|
+
update(): void {
|
|
71
|
+
const n = Math.min(this.xs.length, this.ys.length);
|
|
72
|
+
let xMu = 0.0;
|
|
73
|
+
let yMu = 0.0;
|
|
74
|
+
|
|
75
|
+
for (let i = 0; i < n; i++) {
|
|
76
|
+
xMu += this.xs[i];
|
|
77
|
+
yMu += this.ys[i];
|
|
78
|
+
}
|
|
79
|
+
xMu /= n;
|
|
80
|
+
yMu /= n;
|
|
81
|
+
let pa = 0.0;
|
|
82
|
+
let xSig = 0.0;
|
|
83
|
+
let ySig = 0.0;
|
|
84
|
+
|
|
85
|
+
for (let i = 0; i < n; i++) {
|
|
86
|
+
const xd = this.xs[i] - xMu;
|
|
87
|
+
const yd = this.ys[i] - yMu;
|
|
88
|
+
|
|
89
|
+
pa += xd * yd;
|
|
90
|
+
xSig += xd * xd;
|
|
91
|
+
ySig += yd * yd;
|
|
92
|
+
}
|
|
93
|
+
const p = pa / (Math.sqrt(xSig) * Math.sqrt(ySig));
|
|
94
|
+
|
|
95
|
+
xSig = Math.sqrt(xSig / (n - 1));
|
|
96
|
+
ySig = Math.sqrt(ySig / (n - 1));
|
|
97
|
+
this._slope = p * (ySig / xSig);
|
|
98
|
+
this._intercept = yMu - this._slope * xMu;
|
|
99
|
+
this._calcError();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// / Evaluate this linear fit for y, given an [x] value.
|
|
103
|
+
evaluate(x: number): number {
|
|
104
|
+
return this._slope * x + this._intercept;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Create a new [SimpleLinearRegression] object with outliers above the
|
|
109
|
+
* provided standard deviation [sigma] value removed.
|
|
110
|
+
* @param sigma standard deviation
|
|
111
|
+
* @returns new [SimpleLinearRegression] object
|
|
112
|
+
*/
|
|
113
|
+
filterOutliers(sigma = 1.0): SimpleLinearRegression {
|
|
114
|
+
const limit = this.error * sigma;
|
|
115
|
+
const xsOut: number[] = [];
|
|
116
|
+
const ysOut: number[] = [];
|
|
117
|
+
|
|
118
|
+
for (let i = 0; i < this.length; i++) {
|
|
119
|
+
if (Math.abs(this.ys[i] - this.evaluate(this.xs[i])) < limit) {
|
|
120
|
+
xsOut.push(this.xs[i]);
|
|
121
|
+
ysOut.push(this.ys[i]);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return new SimpleLinearRegression(xsOut, ysOut);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author @thkruz Theodore Kruczek
|
|
3
|
+
* @license AGPL-3.0-or-later
|
|
4
|
+
* @copyright (c) 2020-2024 Theodore Kruczek
|
|
5
|
+
*
|
|
6
|
+
* Orbital Object ToolKit is free software: you can redistribute it and/or modify it under the
|
|
7
|
+
* terms of the GNU Affero General Public License as published by the Free Software
|
|
8
|
+
* Foundation, either version 3 of the License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Orbital Object ToolKit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
11
|
+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
* See the GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License along with
|
|
15
|
+
* Orbital Object ToolKit. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { Vector } from 'ootk-core';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Optimization cost function that takes in parameter array [xs] and returns
|
|
22
|
+
* a score.
|
|
23
|
+
*/
|
|
24
|
+
export type CostFunction = (points: Float64Array) => number;
|
|
25
|
+
|
|
26
|
+
export class SimplexEntry {
|
|
27
|
+
score: number;
|
|
28
|
+
private _x: Vector;
|
|
29
|
+
|
|
30
|
+
constructor(private _f: CostFunction, public points: Float64Array) {
|
|
31
|
+
this._x = new Vector(points);
|
|
32
|
+
this.score = this._f(points);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getPoints(): Float64Array {
|
|
36
|
+
return this._x.toArray();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getScore(): number {
|
|
40
|
+
return this.score;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
modify(n: number, xa: SimplexEntry, xb: SimplexEntry): SimplexEntry {
|
|
44
|
+
return new SimplexEntry(this._f, this._x.add(xa._x.subtract(xb._x).scale(n)).toArray());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
distance(se: SimplexEntry): number {
|
|
48
|
+
return this._x.distance(se._x);
|
|
49
|
+
}
|
|
50
|
+
}
|