compute sum(XY), sum(X), sum(Y), sum(XX), sum(YY) from given data sets @param first DataBag containing first data set @param second DataBag containing second data set @return tuple containing sum(XY), sum(X), sum(Y), sum(XX), sum(YY)
(DataBag first, DataBag second)
| 303 | * @return tuple containing sum(XY), sum(X), sum(Y), sum(XX), sum(YY) |
| 304 | */ |
| 305 | protected static Tuple computeAll(DataBag first, DataBag second) throws IOException { |
| 306 | double sum_x_y = 0.0; |
| 307 | double sum_x = 0.0; |
| 308 | double sum_y = 0.0; |
| 309 | double sum_x_square = 0.0; |
| 310 | double sum_y_square = 0.0; |
| 311 | Iterator<Tuple> iterator_x = first.iterator(); |
| 312 | Iterator<Tuple> iterator_y = second.iterator(); |
| 313 | try{ |
| 314 | while(iterator_x.hasNext()){ |
| 315 | double x = (Double)iterator_x.next().get(0); |
| 316 | double y = (Double)iterator_y.next().get(0); |
| 317 | sum_x_y+=x*y; |
| 318 | sum_x+=x; |
| 319 | sum_y+=y; |
| 320 | sum_x_square+=x*x; |
| 321 | sum_y_square+=y*y; |
| 322 | } |
| 323 | }catch(Exception e){ |
| 324 | throw new IOException("Caught exception processing input", e); |
| 325 | } |
| 326 | |
| 327 | Tuple result = TupleFactory.getInstance().newTuple(5); |
| 328 | try{ |
| 329 | result.set(0, sum_x_y); |
| 330 | result.set(1, sum_x); |
| 331 | result.set(2, sum_y); |
| 332 | result.set(3, sum_x_square); |
| 333 | result.set(4, sum_y_square); |
| 334 | }catch(Exception e){ |
| 335 | throw new IOException("Caught exception processing result", e); |
| 336 | } |
| 337 | return result; |
| 338 | |
| 339 | } |
| 340 | |
| 341 | @Override |
| 342 | public Schema outputSchema(Schema input) { |