Skip to content

Commit

Permalink
Bug fix for floating point data inconsistencies
Browse files Browse the repository at this point in the history
Floating point (non-integer) environmental data was being treated differently for presence and background points, resulting in the "add samples to background" option not working correctly.  This caused some response curves to have abrupt changes, typically at the edge of the predictor range.
  • Loading branch information
mrmaxent authored Nov 9, 2020
1 parent bad787e commit 8fc0619
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions density/CachedFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ a copy of this software and associated documentation files (the
package density;

class CachedFeature extends Feature {
float[] vals=null;
double[] vals=null;
Feature f;

public CachedFeature(Feature f) {
this.f = f;
name = f.name;
n = f.n;
vals = new float[n];
vals = new double[n];
for (int p=0; p<n; p++)
vals[p] = (float) f.eval(p);
vals[p] = f.eval(p);
}

public double eval(int p) { return vals[p]; }
Expand Down
4 changes: 2 additions & 2 deletions density/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -1238,14 +1238,14 @@ Feature[] featuresWithSamples(Feature[] f, Sample[] ss) {
double[] backgroundHash = new double[f[0].n];
for (int i=0; i<f[0].n; i++)
for (int j=0; j<f.length; j++)
backgroundHash[i] += rnd[j] * (float) f[j].eval(i);
backgroundHash[i] += rnd[j] * f[j].eval(i);
Arrays.sort(backgroundHash);
ArrayList samplesToAdda = new ArrayList();
for (int i=0; i<ss.length; i++) {
double r = 0.0;
for (int j=0; j<f.length; j++)
if (f[j].hasData(ss[i]))
r += rnd[j] * (float) f[j].eval(ss[i]);
r += rnd[j] * f[j].eval(ss[i]);
if (is("addAllSamplesToBackground") || Arrays.binarySearch(backgroundHash, r) < 0) // not found
samplesToAdda.add(ss[i]);
}
Expand Down
6 changes: 3 additions & 3 deletions density/SampleSet2.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ public void process() {
Sample s = new Sample(-1, r, c, y, x, spid, null);

int goodvals = 0;
float[] data = new float[n];
double[] data = new double[n];
for (int j=0; j<n; j++) {
int idx = layerToColumn[j];
data[j] = NODATA_value;
if (idx!=-1 && idx<fields.length && !fields[SampleSet.firstEnvVar+idx].trim().equals(""))
data[j] = Float.parseFloat(fields[SampleSet.firstEnvVar+idx]);
data[j] = Double.parseDouble(fields[SampleSet.firstEnvVar+idx]);
if (data[j] == NODATA_value && idx!=-1) {
warnPartialData(x,y,sampleFileName,layers[j].name);
if (!params.allowpartialdata())
Expand Down Expand Up @@ -204,7 +204,7 @@ static void warnPartialData(double x, double y, String sampleFileName, String fi
public void createMaps() {
Sample[] s = getSamples();
for (int i=0; i<s.length; i++) {
float[] data = (float[]) datamap.get(s[i]);
double[] data = (double[]) datamap.get(s[i]);
HashMap map = new HashMap();
for (int j=0; j<n; j++)
map.put(layers[j].getName(), (data[j]==SampleSet.NODATA_value) ? null : new Double(data[j]));
Expand Down
2 changes: 1 addition & 1 deletion density/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ a copy of this software and associated documentation files (the

public class Utils {

static String version = "3.4.2";
static String version = "3.4.3";
static boolean interrupt=false, warnings=true;
public static boolean verbose=false, visible=true;
static JFrame topLevelFrame = null;
Expand Down

0 comments on commit 8fc0619

Please sign in to comment.