MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / pointToBytes

Method pointToBytes

JSAT/src/jsat/io/JSATData.java:424–476  ·  view source on GitHub ↗
(DataPoint dp, double label, ByteArrayOutputStream byteOut)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

isSparseMethod · 0.95
nnzMethod · 0.95
lengthMethod · 0.95
getMethod · 0.95
writeFPMethod · 0.80
getCategoricalValuesMethod · 0.80
getNumericalValuesMethod · 0.80
logMethod · 0.80
getNameMethod · 0.65
getWeightMethod · 0.45
getIndexMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected