()
| 255 | } |
| 256 | |
| 257 | @Test |
| 258 | public void testReadWriteRegression() throws Exception |
| 259 | { |
| 260 | System.out.println("ReadWriteRegression"); |
| 261 | |
| 262 | |
| 263 | //use the last categorical feature as the read target so that forcing as a standard dataset produces the same expected result as the original simple dataset |
| 264 | RegressionDataSet rds = new RegressionDataSet(simpleData.getBackingList(), simpleData.getNumNumericalVars()-1); |
| 265 | |
| 266 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 267 | JSATData.writeData(rds, baos); |
| 268 | |
| 269 | ByteArrayInputStream bin = new ByteArrayInputStream(baos.toByteArray()); |
| 270 | |
| 271 | //check classificaiton is right |
| 272 | DataSet readBack = JSATData.load(bin); |
| 273 | checkDataSet(rds, readBack); |
| 274 | bin.reset(); |
| 275 | readBack = JSATData.loadRegression(bin); |
| 276 | checkDataSet(rds, readBack); |
| 277 | //check forcing as simple |
| 278 | bin = new ByteArrayInputStream(baos.toByteArray()); |
| 279 | readBack = JSATData.load(bin, true); |
| 280 | checkDataSet(simpleData, readBack); |
| 281 | |
| 282 | rds.applyTransform(new DenseSparceTransform(0.5));//sparcify our numeric values and try again |
| 283 | simpleData.applyTransform(new DenseSparceTransform(0.5)); |
| 284 | |
| 285 | baos = new ByteArrayOutputStream(); |
| 286 | JSATData.writeData(rds, baos); |
| 287 | |
| 288 | bin = new ByteArrayInputStream(baos.toByteArray()); |
| 289 | |
| 290 | //check classificaiton is right |
| 291 | readBack = JSATData.load(bin); |
| 292 | checkDataSet(rds, readBack); |
| 293 | bin.reset(); |
| 294 | readBack = JSATData.loadRegression(bin); |
| 295 | checkDataSet(rds, readBack); |
| 296 | //check forcing as simple |
| 297 | byte[] raw_read_back = baos.toByteArray(); |
| 298 | bin = new ByteArrayInputStream(raw_read_back); |
| 299 | readBack = JSATData.load(bin, true); |
| 300 | checkDataSet(simpleData, readBack); |
| 301 | |
| 302 | //what if we muck the number of data points to be a negative value? indicates streaming write scenario |
| 303 | raw_read_back[17] = -1; |
| 304 | raw_read_back[18] = -1; |
| 305 | raw_read_back[19] = -1; |
| 306 | raw_read_back[20] = -1; |
| 307 | bin = new ByteArrayInputStream(raw_read_back); |
| 308 | |
| 309 | readBack = JSATData.load(bin, true); |
| 310 | |
| 311 | checkDataSet(simpleData, readBack); |
| 312 | |
| 313 | //Check data-writer appraoch looks like mucked version of binary |
| 314 |
nothing calls this directly
no test coverage detected