jimu-decompiled/sources/com/google/common/math/PairedStats.java
2025-05-13 19:24:51 +02:00

133 lines
4.5 KiB
Java

package com.google.common.math;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/* loaded from: classes.dex */
public final class PairedStats implements Serializable {
private static final int BYTES = 88;
private static final long serialVersionUID = 0;
private final double sumOfProductsOfDeltas;
private final Stats xStats;
private final Stats yStats;
PairedStats(Stats stats, Stats stats2, double d) {
this.xStats = stats;
this.yStats = stats2;
this.sumOfProductsOfDeltas = d;
}
private static double ensureInUnitRange(double d) {
if (d >= 1.0d) {
return 1.0d;
}
if (d <= -1.0d) {
return -1.0d;
}
return d;
}
private static double ensurePositive(double d) {
if (d > 0.0d) {
return d;
}
return Double.MIN_VALUE;
}
public static PairedStats fromByteArray(byte[] bArr) {
Preconditions.a(bArr);
Preconditions.a(bArr.length == 88, "Expected PairedStats.BYTES = %s, got %s", 88, bArr.length);
ByteBuffer order = ByteBuffer.wrap(bArr).order(ByteOrder.LITTLE_ENDIAN);
return new PairedStats(Stats.readFrom(order), Stats.readFrom(order), order.getDouble());
}
public long count() {
return this.xStats.count();
}
public boolean equals(Object obj) {
if (obj == null || PairedStats.class != obj.getClass()) {
return false;
}
PairedStats pairedStats = (PairedStats) obj;
return this.xStats.equals(pairedStats.xStats) && this.yStats.equals(pairedStats.yStats) && Double.doubleToLongBits(this.sumOfProductsOfDeltas) == Double.doubleToLongBits(pairedStats.sumOfProductsOfDeltas);
}
public int hashCode() {
return Objects.a(this.xStats, this.yStats, Double.valueOf(this.sumOfProductsOfDeltas));
}
public LinearTransformation leastSquaresFit() {
Preconditions.b(count() > 1);
if (Double.isNaN(this.sumOfProductsOfDeltas)) {
return LinearTransformation.a();
}
double sumOfSquaresOfDeltas = this.xStats.sumOfSquaresOfDeltas();
if (sumOfSquaresOfDeltas > 0.0d) {
return this.yStats.sumOfSquaresOfDeltas() > 0.0d ? LinearTransformation.a(this.xStats.mean(), this.yStats.mean()).a(this.sumOfProductsOfDeltas / sumOfSquaresOfDeltas) : LinearTransformation.a(this.yStats.mean());
}
Preconditions.b(this.yStats.sumOfSquaresOfDeltas() > 0.0d);
return LinearTransformation.b(this.xStats.mean());
}
public double pearsonsCorrelationCoefficient() {
Preconditions.b(count() > 1);
if (Double.isNaN(this.sumOfProductsOfDeltas)) {
return Double.NaN;
}
double sumOfSquaresOfDeltas = xStats().sumOfSquaresOfDeltas();
double sumOfSquaresOfDeltas2 = yStats().sumOfSquaresOfDeltas();
Preconditions.b(sumOfSquaresOfDeltas > 0.0d);
Preconditions.b(sumOfSquaresOfDeltas2 > 0.0d);
return ensureInUnitRange(this.sumOfProductsOfDeltas / Math.sqrt(ensurePositive(sumOfSquaresOfDeltas * sumOfSquaresOfDeltas2)));
}
public double populationCovariance() {
Preconditions.b(count() != 0);
return this.sumOfProductsOfDeltas / count();
}
public double sampleCovariance() {
Preconditions.b(count() > 1);
return this.sumOfProductsOfDeltas / (count() - 1);
}
double sumOfProductsOfDeltas() {
return this.sumOfProductsOfDeltas;
}
public byte[] toByteArray() {
ByteBuffer order = ByteBuffer.allocate(88).order(ByteOrder.LITTLE_ENDIAN);
this.xStats.writeTo(order);
this.yStats.writeTo(order);
order.putDouble(this.sumOfProductsOfDeltas);
return order.array();
}
public String toString() {
if (count() <= 0) {
MoreObjects.ToStringHelper a = MoreObjects.a(this);
a.a("xStats", this.xStats);
a.a("yStats", this.yStats);
return a.toString();
}
MoreObjects.ToStringHelper a2 = MoreObjects.a(this);
a2.a("xStats", this.xStats);
a2.a("yStats", this.yStats);
a2.a("populationCovariance", populationCovariance());
return a2.toString();
}
public Stats xStats() {
return this.xStats;
}
public Stats yStats() {
return this.yStats;
}
}