mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-26 09:02:34 -06:00
101 lines
3.9 KiB
Java
101 lines
3.9 KiB
Java
package com.google.common.math;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
import com.google.common.primitives.Doubles;
|
|
import tech.rabbit.r1launcher.BuildConfig;
|
|
|
|
@ElementTypesAreNonnullByDefault
|
|
/* loaded from: classes3.dex */
|
|
public final class PairedStatsAccumulator {
|
|
private final StatsAccumulator xStats = new StatsAccumulator();
|
|
private final StatsAccumulator yStats = new StatsAccumulator();
|
|
private double sumOfProductsOfDeltas = BuildConfig.SENTRY_SAMPLE_RATE;
|
|
|
|
private double ensurePositive(double d) {
|
|
if (d > BuildConfig.SENTRY_SAMPLE_RATE) {
|
|
return d;
|
|
}
|
|
return Double.MIN_VALUE;
|
|
}
|
|
|
|
public void add(double d, double d2) {
|
|
this.xStats.add(d);
|
|
if (!Doubles.isFinite(d) || !Doubles.isFinite(d2)) {
|
|
this.sumOfProductsOfDeltas = Double.NaN;
|
|
} else if (this.xStats.count() > 1) {
|
|
this.sumOfProductsOfDeltas += (d - this.xStats.mean()) * (d2 - this.yStats.mean());
|
|
}
|
|
this.yStats.add(d2);
|
|
}
|
|
|
|
public void addAll(PairedStats pairedStats) {
|
|
if (pairedStats.count() == 0) {
|
|
return;
|
|
}
|
|
this.xStats.addAll(pairedStats.xStats());
|
|
if (this.yStats.count() == 0) {
|
|
this.sumOfProductsOfDeltas = pairedStats.sumOfProductsOfDeltas();
|
|
} else {
|
|
this.sumOfProductsOfDeltas += pairedStats.sumOfProductsOfDeltas() + ((pairedStats.xStats().mean() - this.xStats.mean()) * (pairedStats.yStats().mean() - this.yStats.mean()) * pairedStats.count());
|
|
}
|
|
this.yStats.addAll(pairedStats.yStats());
|
|
}
|
|
|
|
public PairedStats snapshot() {
|
|
return new PairedStats(this.xStats.snapshot(), this.yStats.snapshot(), this.sumOfProductsOfDeltas);
|
|
}
|
|
|
|
public long count() {
|
|
return this.xStats.count();
|
|
}
|
|
|
|
public Stats xStats() {
|
|
return this.xStats.snapshot();
|
|
}
|
|
|
|
public Stats yStats() {
|
|
return this.yStats.snapshot();
|
|
}
|
|
|
|
public double populationCovariance() {
|
|
Preconditions.checkState(count() != 0);
|
|
return this.sumOfProductsOfDeltas / count();
|
|
}
|
|
|
|
public final double sampleCovariance() {
|
|
Preconditions.checkState(count() > 1);
|
|
return this.sumOfProductsOfDeltas / (count() - 1);
|
|
}
|
|
|
|
public final double pearsonsCorrelationCoefficient() {
|
|
Preconditions.checkState(count() > 1);
|
|
if (Double.isNaN(this.sumOfProductsOfDeltas)) {
|
|
return Double.NaN;
|
|
}
|
|
double sumOfSquaresOfDeltas = this.xStats.sumOfSquaresOfDeltas();
|
|
double sumOfSquaresOfDeltas2 = this.yStats.sumOfSquaresOfDeltas();
|
|
Preconditions.checkState(sumOfSquaresOfDeltas > BuildConfig.SENTRY_SAMPLE_RATE);
|
|
Preconditions.checkState(sumOfSquaresOfDeltas2 > BuildConfig.SENTRY_SAMPLE_RATE);
|
|
return ensureInUnitRange(this.sumOfProductsOfDeltas / Math.sqrt(ensurePositive(sumOfSquaresOfDeltas * sumOfSquaresOfDeltas2)));
|
|
}
|
|
|
|
public final LinearTransformation leastSquaresFit() {
|
|
Preconditions.checkState(count() > 1);
|
|
if (Double.isNaN(this.sumOfProductsOfDeltas)) {
|
|
return LinearTransformation.forNaN();
|
|
}
|
|
double sumOfSquaresOfDeltas = this.xStats.sumOfSquaresOfDeltas();
|
|
if (sumOfSquaresOfDeltas <= BuildConfig.SENTRY_SAMPLE_RATE) {
|
|
Preconditions.checkState(this.yStats.sumOfSquaresOfDeltas() > BuildConfig.SENTRY_SAMPLE_RATE);
|
|
return LinearTransformation.vertical(this.xStats.mean());
|
|
}
|
|
if (this.yStats.sumOfSquaresOfDeltas() > BuildConfig.SENTRY_SAMPLE_RATE) {
|
|
return LinearTransformation.mapping(this.xStats.mean(), this.yStats.mean()).withSlope(this.sumOfProductsOfDeltas / sumOfSquaresOfDeltas);
|
|
}
|
|
return LinearTransformation.horizontal(this.yStats.mean());
|
|
}
|
|
|
|
private static double ensureInUnitRange(double d) {
|
|
return Doubles.constrainToRange(d, -1.0d, 1.0d);
|
|
}
|
|
}
|