Skip to content
Snippets Groups Projects

Lib updates

Merged Powers, Peter M. requested to merge ghsc/users/pmpowers/nshmp-lib:lib-work into master
14 files
+ 154
88
Compare changes
  • Side-by-side
  • Inline
Files
14
@@ -11,6 +11,7 @@ import java.util.List;
@@ -11,6 +11,7 @@ import java.util.List;
import gov.usgs.earthquake.nshmp.Maths;
import gov.usgs.earthquake.nshmp.Maths;
import gov.usgs.earthquake.nshmp.data.MutableXySequence;
import gov.usgs.earthquake.nshmp.data.MutableXySequence;
 
import gov.usgs.earthquake.nshmp.data.XyPoint;
import gov.usgs.earthquake.nshmp.data.XySequence;
import gov.usgs.earthquake.nshmp.data.XySequence;
import gov.usgs.earthquake.nshmp.gmm.Imt;
import gov.usgs.earthquake.nshmp.gmm.Imt;
import gov.usgs.earthquake.nshmp.gmm.MultiScalarGroundMotion;
import gov.usgs.earthquake.nshmp.gmm.MultiScalarGroundMotion;
@@ -37,6 +38,10 @@ public enum ExceedanceModel {
@@ -37,6 +38,10 @@ public enum ExceedanceModel {
* TODO We probably want to refactor this to probability model and provide
* TODO We probably want to refactor this to probability model and provide
* 'occurrence' in addition to exceedence. See commented distribution function
* 'occurrence' in addition to exceedence. See commented distribution function
* at eof.
* at eof.
 
*
 
* Developer note: Exceedance methods can be called millions of times in a
 
* hazard calculation; do not be tempted to use streams to update XySequence
 
* values.
*/
*/
/**
/**
@@ -52,8 +57,11 @@ public enum ExceedanceModel {
@@ -52,8 +57,11 @@ public enum ExceedanceModel {
}
}
@Override
@Override
XySequence exceedance(double μ, double σ, double n, Imt imt, XySequence sequence) {
MutableXySequence exceedance(double μ, double σ, double n, Imt imt,
sequence.stream().forEach(p -> p.set(Maths.stepFunction(μ, p.x())));
MutableXySequence sequence) {
 
for (XyPoint p : sequence) {
 
p.set(Maths.stepFunction(μ, p.x()));
 
}
return sequence;
return sequence;
}
}
},
},
@@ -70,7 +78,8 @@ public enum ExceedanceModel {
@@ -70,7 +78,8 @@ public enum ExceedanceModel {
}
}
@Override
@Override
XySequence exceedance(double μ, double σ, double n, Imt imt, XySequence sequence) {
MutableXySequence exceedance(double μ, double σ, double n, Imt imt,
 
MutableXySequence sequence) {
return boundedCcdFn(μ, σ, sequence, 0.0, 1.0);
return boundedCcdFn(μ, σ, sequence, 0.0, 1.0);
}
}
},
},
@@ -87,7 +96,8 @@ public enum ExceedanceModel {
@@ -87,7 +96,8 @@ public enum ExceedanceModel {
}
}
@Override
@Override
XySequence exceedance(double μ, double σ, double n, Imt imt, XySequence sequence) {
MutableXySequence exceedance(double μ, double σ, double n, Imt imt,
 
MutableXySequence sequence) {
return boundedCcdFn(μ, σ, sequence, prob(μ, σ, n), 1.0);
return boundedCcdFn(μ, σ, sequence, prob(μ, σ, n), 1.0);
}
}
},
},
@@ -105,7 +115,8 @@ public enum ExceedanceModel {
@@ -105,7 +115,8 @@ public enum ExceedanceModel {
}
}
@Override
@Override
XySequence exceedance(double μ, double σ, double n, Imt imt, XySequence sequence) {
MutableXySequence exceedance(double μ, double σ, double n, Imt imt,
 
MutableXySequence sequence) {
double pHi = prob(μ, σ, n);
double pHi = prob(μ, σ, n);
return boundedCcdFn(μ, σ, sequence, pHi, 1.0 - pHi);
return boundedCcdFn(μ, σ, sequence, pHi, 1.0 - pHi);
}
}
@@ -123,7 +134,8 @@ public enum ExceedanceModel {
@@ -123,7 +134,8 @@ public enum ExceedanceModel {
}
}
@Override
@Override
XySequence exceedance(double μ, double σ, double n, Imt imt, XySequence sequence) {
MutableXySequence exceedance(double μ, double σ, double n, Imt imt,
 
MutableXySequence sequence) {
return Ccdfs.UPPER_3SIGMA.get(μ, σ, sequence);
return Ccdfs.UPPER_3SIGMA.get(μ, σ, sequence);
}
}
},
},
@@ -141,7 +153,8 @@ public enum ExceedanceModel {
@@ -141,7 +153,8 @@ public enum ExceedanceModel {
}
}
@Override
@Override
XySequence exceedance(double μ, double σ, double n, Imt imt, XySequence sequence) {
MutableXySequence exceedance(double μ, double σ, double n, Imt imt,
 
MutableXySequence sequence) {
return boundedCcdFn(μ, 0.65, sequence, 0.0, 1.0);
return boundedCcdFn(μ, 0.65, sequence, 0.0, 1.0);
}
}
},
},
@@ -164,8 +177,11 @@ public enum ExceedanceModel {
@@ -164,8 +177,11 @@ public enum ExceedanceModel {
}
}
@Override
@Override
XySequence exceedance(double μ, double σ, double n, Imt imt, XySequence sequence) {
MutableXySequence exceedance(double μ, double σ, double n, Imt imt,
sequence.stream().forEach(p -> p.set(exceedance(μ, σ, n, imt, p.x())));
MutableXySequence sequence) {
 
for (XyPoint p : sequence) {
 
p.set(exceedance(μ, σ, n, imt, p.x()));
 
}
return sequence;
return sequence;
}
}
},
},
@@ -185,7 +201,8 @@ public enum ExceedanceModel {
@@ -185,7 +201,8 @@ public enum ExceedanceModel {
}
}
@Override
@Override
XySequence exceedance(double μ, double σ, double n, Imt imt, XySequence sequence) {
MutableXySequence exceedance(double μ, double σ, double n, Imt imt,
 
MutableXySequence sequence) {
double pHi = prob(μ, σ, n, Math.log(ceusMaxValue(imt)));
double pHi = prob(μ, σ, n, Math.log(ceusMaxValue(imt)));
return boundedCcdFn(μ, σ, sequence, pHi, 1.0);
return boundedCcdFn(μ, σ, sequence, pHi, 1.0);
}
}
@@ -209,7 +226,8 @@ public enum ExceedanceModel {
@@ -209,7 +226,8 @@ public enum ExceedanceModel {
}
}
@Override
@Override
XySequence exceedance(double μ, double σ, double n, Imt imt, XySequence sequence) {
MutableXySequence exceedance(double μ, double σ, double n, Imt imt,
 
MutableXySequence sequence) {
double lnMaxGm = Math.log(ceusMaxValue(imt));
double lnMaxGm = Math.log(ceusMaxValue(imt));
double ln3σGm = μ + 3.0 * σ;
double ln3σGm = μ + 3.0 * σ;
if (ln3σGm < lnMaxGm) {
if (ln3σGm < lnMaxGm) {
@@ -249,7 +267,12 @@ public enum ExceedanceModel {
@@ -249,7 +267,12 @@ public enum ExceedanceModel {
* {@link #NSHM_CEUS_MAX_INTENSITY}
* {@link #NSHM_CEUS_MAX_INTENSITY}
* @param value for which to compute the exceedance probability
* @param value for which to compute the exceedance probability
*/
*/
abstract double exceedance(double μ, double σ, double n, Imt imt, double value);
abstract double exceedance(
 
double μ,
 
double σ,
 
double n,
 
Imt imt,
 
double value);
/**
/**
* Compute the probability of exceeding a sequence of x-values.
* Compute the probability of exceeding a sequence of x-values.
@@ -262,7 +285,12 @@ public enum ExceedanceModel {
@@ -262,7 +285,12 @@ public enum ExceedanceModel {
* @param sequence the x-values for which to compute exceedance probabilities
* @param sequence the x-values for which to compute exceedance probabilities
* @return the supplied {@code sequence}
* @return the supplied {@code sequence}
*/
*/
abstract XySequence exceedance(double μ, double σ, double n, Imt imt, XySequence sequence);
abstract MutableXySequence exceedance(
 
double μ,
 
double σ,
 
double n,
 
Imt imt,
 
MutableXySequence sequence);
/*
/*
* Return a list of exceedance curves, one for each tree branch in the
* Return a list of exceedance curves, one for each tree branch in the
@@ -285,8 +313,7 @@ public enum ExceedanceModel {
@@ -285,8 +313,7 @@ public enum ExceedanceModel {
for (int i = 0; i < means.length; i++) {
for (int i = 0; i < means.length; i++) {
double μ = means[i];
double μ = means[i];
for (int j = 0; j < sigmas.length; j++) {
for (int j = 0; j < sigmas.length; j++) {
curves.add(MutableXySequence.copyOf(
curves.add(exceedance(μ, sigmas[j], n, imt, MutableXySequence.emptyCopyOf(sequence)));
exceedance(μ, sigmas[j], n, imt, MutableXySequence.emptyCopyOf(sequence))));
}
}
}
}
return curves;
return curves;
@@ -343,14 +370,16 @@ public enum ExceedanceModel {
@@ -343,14 +370,16 @@ public enum ExceedanceModel {
* lower probability limits. Return the supplied {@code XySequence} populated
* lower probability limits. Return the supplied {@code XySequence} populated
* with probabilities.
* with probabilities.
*/
*/
private static XySequence boundedCcdFn(
private static MutableXySequence boundedCcdFn(
double μ,
double μ,
double σ,
double σ,
XySequence sequence,
MutableXySequence sequence,
double pHi,
double pHi,
double pLo) {
double pLo) {
sequence.stream().forEach(p -> p.set(boundedCcdFn(μ, σ, p.x(), pHi, pLo)));
for (XyPoint p : sequence) {
 
p.set(boundedCcdFn(μ, σ, p.x(), pHi, pLo));
 
}
return sequence;
return sequence;
}
}
@@ -462,8 +491,10 @@ public enum ExceedanceModel {
@@ -462,8 +491,10 @@ public enum ExceedanceModel {
return 0.0;
return 0.0;
}
}
XySequence get(double μ, double σ, XySequence sequence) {
MutableXySequence get(double μ, double σ, MutableXySequence sequence) {
sequence.stream().forEach(p -> p.set(get(μ, σ, p.x())));
for (XyPoint p : sequence) {
 
p.set(get(μ, σ, p.x()));
 
}
return sequence;
return sequence;
}
}
}
}
Loading