public static void updateCovarianceState(CovarianceState state, double x, double y) { long n = state.getCount() + 1; state.setCount(n); double oldMeanX = state.getMeanX(); state.setMeanX(oldMeanX + (x - oldMeanX) / n); double oldMeanY = state.getMeanY(); double newMeanY = oldMeanY + (y - oldMeanY) / n; state.setMeanY(newMeanY); state.setC2(state.getC2() + (x - oldMeanX) * (y - newMeanY)); }
private static void updateCovarianceState(CovarianceState state, CovarianceState otherState) { state.setSumX(state.getSumX() + otherState.getSumX()); state.setSumY(state.getSumY() + otherState.getSumY()); state.setSumXY(state.getSumXY() + otherState.getSumXY()); state.setCount(state.getCount() + otherState.getCount()); }
@AggregationFunction("covar_samp") @OutputFunction(StandardTypes.DOUBLE) public static void covarSamp(CovarianceState state, BlockBuilder out) { if (state.getCount() <= 1) { out.appendNull(); } else { double result = (state.getSumXY() - state.getSumX() * state.getSumY() / state.getCount()) / (state.getCount() - 1); DOUBLE.writeDouble(out, result); } }
public static void mergeCovarianceState(CovarianceState state, CovarianceState otherState) { if (otherState.getCount() == 0) { return; } updateCovarianceState(state, otherState); }
@AggregationFunction("covar_pop") @OutputFunction(StandardTypes.DOUBLE) public static void covarPop(CovarianceState state, BlockBuilder out) { if (state.getCount() == 0) { out.appendNull(); } else { double result = (state.getSumXY() - state.getSumX() * state.getSumY() / state.getCount()) / state.getCount(); DOUBLE.writeDouble(out, result); } } }
@AggregationFunction("covar_samp") @OutputFunction(StandardTypes.REAL) public static void covarSamp(@AggregationState CovarianceState state, BlockBuilder out) { if (state.getCount() <= 1) { out.appendNull(); } else { double result = getCovarianceSample(state); REAL.writeLong(out, Float.floatToRawIntBits((float) result)); } }
private static void updateCovarianceState(CovarianceState state, CovarianceState otherState) { long na = state.getCount(); long nb = otherState.getCount(); long n = na + nb; state.setCount(n); double meanX = state.getMeanX(); double meanY = state.getMeanY(); double deltaX = otherState.getMeanX() - meanX; double deltaY = otherState.getMeanY() - meanY; state.setC2(state.getC2() + otherState.getC2() + deltaX * deltaY * na * nb / (double) n); state.setMeanX(meanX + deltaX * nb / (double) n); state.setMeanY(meanY + deltaY * nb / (double) n); }
@AggregationFunction("covar_pop") @OutputFunction(StandardTypes.REAL) public static void covarPop(@AggregationState CovarianceState state, BlockBuilder out) { if (state.getCount() == 0) { out.appendNull(); } else { double result = getCovariancePopulation(state); REAL.writeLong(out, Float.floatToRawIntBits((float) result)); } } }
@AggregationFunction("covar_pop") @OutputFunction(StandardTypes.DOUBLE) public static void covarPop(@AggregationState CovarianceState state, BlockBuilder out) { if (state.getCount() == 0) { out.appendNull(); } else { double result = getCovariancePopulation(state); DOUBLE.writeDouble(out, result); } } }
@AggregationFunction("covar_samp") @OutputFunction(StandardTypes.DOUBLE) public static void covarSamp(@AggregationState CovarianceState state, BlockBuilder out) { if (state.getCount() <= 1) { out.appendNull(); } else { double result = getCovarianceSample(state); DOUBLE.writeDouble(out, result); } }
public static void mergeCovarianceState(CovarianceState state, CovarianceState otherState) { if (otherState.getCount() == 0) { return; } updateCovarianceState(state, otherState); }