(DataPoint dp, double label, ByteArrayOutputStream byteOut)
| 422 | } |
| 423 | |
| 424 | @Override |
| 425 | protected void pointToBytes(DataPoint dp, double label, ByteArrayOutputStream byteOut) |
| 426 | { |
| 427 | try |
| 428 | { |
| 429 | DataOutputStream data_out = new DataOutputStream(byteOut); |
| 430 | fpStore.writeFP(dp.getWeight(), data_out); |
| 431 | for(int val : dp.getCategoricalValues()) |
| 432 | data_out.writeInt(val); |
| 433 | if(type == DataWriter.DataSetType.CLASSIFICATION) |
| 434 | data_out.writeInt((int) label); |
| 435 | |
| 436 | Vec numericVals = dp.getNumericalValues(); |
| 437 | |
| 438 | data_out.writeBoolean(numericVals.isSparse()); |
| 439 | if(numericVals.isSparse()) |
| 440 | { |
| 441 | if(type == DataWriter.DataSetType.REGRESSION) |
| 442 | data_out.writeInt(numericVals.nnz()+1);//+1 for the target value, which may actually be zero... |
| 443 | else |
| 444 | data_out.writeInt(numericVals.nnz()); |
| 445 | |
| 446 | for(IndexValue iv : numericVals) |
| 447 | { |
| 448 | data_out.writeInt(iv.getIndex()); |
| 449 | fpStore.writeFP(iv.getValue(), data_out); |
| 450 | } |
| 451 | } |
| 452 | else |
| 453 | { |
| 454 | for(int j = 0; j < numericVals.length(); j++) |
| 455 | fpStore.writeFP(numericVals.get(j), data_out); |
| 456 | } |
| 457 | |
| 458 | //append the target value |
| 459 | if(type == DataWriter.DataSetType.REGRESSION) |
| 460 | { |
| 461 | /* |
| 462 | * if dense, we only need to just add the extra double. If |
| 463 | * sparse, we do the index and then the double. |
| 464 | */ |
| 465 | if (numericVals.isSparse()) |
| 466 | data_out.writeInt(numericVals.length()); |
| 467 | |
| 468 | fpStore.writeFP(label, data_out); |
| 469 | } |
| 470 | data_out.flush(); |
| 471 | } |
| 472 | catch (IOException ex) |
| 473 | { |
| 474 | Logger.getLogger(JSATData.class.getName()).log(Level.SEVERE, null, ex); |
| 475 | } |
| 476 | } |
| 477 | }; |
| 478 | } |
| 479 |
nothing calls this directly
no test coverage detected