Skip to content

Commit

Permalink
Improving file size of write output when integer values are encounter…
Browse files Browse the repository at this point in the history
…ed by dropping the ".0" that is normally written from a double
  • Loading branch information
EdwardRaff committed Dec 27, 2015
1 parent 84685b5 commit 3c0d235
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 5 additions & 1 deletion JSAT/src/jsat/ARFFLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ public static void writeArffFile(DataSet data, OutputStream os, String relation)
if(!firstFeature)
writer.write(",");
firstFeature = false;
writer.write(Double.toString(v.get(i)));
double val = v.get(i);
if(Math.rint(val) == val)//cast to long before writting to save space
writer.write(Long.toString((long) val));
else
writer.write(Double.toString(val));
}
if (data instanceof ClassificationDataSet)//also write out class variable
{
Expand Down
7 changes: 6 additions & 1 deletion JSAT/src/jsat/io/CSV.java
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,12 @@ else if(data instanceof RegressionDataSet)
{
if(!nothingWrittenYet)
writer.write(delimiter);
writer.write(Double.toString(v.get(j)));

double val = v.get(j);
if(Math.rint(val) == val)//cast to long before writting to save space
writer.write(Long.toString((long) val));
else
writer.write(Double.toString(val));
nothingWrittenYet = false;
}
//then categorical features, useing the safe names we constructed earlier
Expand Down
16 changes: 14 additions & 2 deletions JSAT/src/jsat/io/LIBSVMLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,13 @@ public static void write(ClassificationDataSet data, OutputStream os)
Vec vals = data.getDataPoint(i).getNumericalValues();
writer.write(pred + " ");
for(IndexValue iv : vals)
writer.write((iv.getIndex()+1) + ":" + iv.getValue() + " ");//+1 b/c 1 based indexing
{
double val = iv.getValue();
if(Math.rint(val) == val)//cast to long before writting to save space
writer.write((iv.getIndex()+1) + ":" + (long)val + " ");//+1 b/c 1 based indexing
else
writer.write((iv.getIndex()+1) + ":" + val + " ");//+1 b/c 1 based indexing
}
writer.write("\n");
}
writer.flush();
Expand All @@ -501,7 +507,13 @@ public static void write(RegressionDataSet data, OutputStream os)
Vec vals = data.getDataPoint(i).getNumericalValues();
writer.write(pred + " ");
for(IndexValue iv : vals)
writer.write((iv.getIndex()+1) + ":" + iv.getValue() + " ");//+1 b/c 1 based indexing
{
double val = iv.getValue();
if(Math.rint(val) == val)//cast to long before writting to save space
writer.write((iv.getIndex()+1) + ":" + (long)val + " ");//+1 b/c 1 based indexing
else
writer.write((iv.getIndex()+1) + ":" + val + " ");//+1 b/c 1 based indexing
}
writer.write("\n");
}
writer.flush();
Expand Down

0 comments on commit 3c0d235

Please sign in to comment.