Function to compute correlation between data sets. @param input input tuple which contains data sets. @return output output dataBag which contain correlation between each pair of data sets.
(Tuple input)
| 64 | * @return output output dataBag which contain correlation between each pair of data sets. |
| 65 | */ |
| 66 | @Override |
| 67 | public DataBag exec(Tuple input) throws IOException { |
| 68 | if (input == null || input.size() == 0) |
| 69 | return null; |
| 70 | |
| 71 | DataBag output = DefaultBagFactory.getInstance().newDefaultBag(); |
| 72 | for(int i=0;i<input.size();i++){ |
| 73 | for(int j=i+1;j<input.size();j++){ |
| 74 | Tuple temp = TupleFactory.getInstance().newTuple(3); |
| 75 | try{ |
| 76 | if(flag){ |
| 77 | temp.set(0, schemaName.elementAt(i)); |
| 78 | temp.set(1, schemaName.elementAt(j)); |
| 79 | } |
| 80 | else{ |
| 81 | temp.set(0, "var"+i); |
| 82 | temp.set(1, "var"+j); |
| 83 | } |
| 84 | |
| 85 | Tuple tempResult = computeAll((DataBag)input.get(i),(DataBag)input.get(j)); |
| 86 | double size = ((DataBag)input.get(i)).size(); |
| 87 | double sum_x_y = (Double)tempResult.get(0); |
| 88 | double sum_x = (Double)tempResult.get(1); |
| 89 | double sum_y = (Double)tempResult.get(2); |
| 90 | double sum_x_square = (Double)tempResult.get(3); |
| 91 | double sum_y_square = (Double)tempResult.get(4); |
| 92 | double result = (size*sum_x_y - sum_x*sum_y)/Math.sqrt((size*sum_x_square-sum_x*sum_x)*(size*sum_y_square-sum_y*sum_y)); |
| 93 | temp.set(2, result); |
| 94 | }catch (Exception e){ |
| 95 | System.err.println("Failed to process input record; error - " + e.getMessage()); |
| 96 | return null; |
| 97 | } |
| 98 | output.add(temp); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | return output; |
| 103 | } |
| 104 | |
| 105 | //used to pass schema name to Final class constructor |
| 106 | /** |