Skip to content
Snippets Groups Projects
Commit ae936979 authored by Peter Alexander's avatar Peter Alexander
Browse files

Allow NaN yields to be clustered. Needed for GGCMI

parent f57bb1b5
No related branches found
No related tags found
No related merge requests found
......@@ -55,7 +55,9 @@ public class Cluster<K, P extends ClusteringPoint<K>> {
protected double distanceFromCentroid(ClusteringPoint<K> p) {
double squaredTotal=0;
for (K key : centroid.getAllClusteringKeys()) {
squaredTotal += Math.pow(centroid.getClusteringValue(key)-p.getClusteringValue(key), 2);
double a = centroid.getClusteringValue(key);
double b = p.getClusteringValue(key);
squaredTotal += Math.pow(a-b, 2);
}
return Math.sqrt(squaredTotal);
......
......@@ -51,7 +51,11 @@ public class YieldClusterPoint implements ClusteringPoint<String> {
@Override
public double getClusteringValue(String key) {
double v = getClusteringValueNaN(key);
return Double.isNaN(v) ? 0.0 : v; // LPJ with emulator provides NaN yields. How to cluster these is tricky, but assuming they are 0
}
private double getClusteringValueNaN(String key) {
switch (key) {
case PASTURE: return pasture;
case WHEAT_MIN: return wheatMin;
......@@ -61,9 +65,9 @@ public class YieldClusterPoint implements ClusteringPoint<String> {
case MAIZE_MAX: return maizeMax;
case IRRIG_WATER_AVAL: return irrigWaterAval;
case PROTECTED_AREA: return protectedArea;
default:
throw new RuntimeException("YieldClusterPoint.getClusteringValue: got unknown value " + key);
}
LogWriter.printlnError("YieldClusterPoint.getClusteringValue: got unknown value " + key);
return Double.NaN;
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment