List of usage examples for org.apache.mahout.math DenseVector zSum
@Override public double zSum()
From source file:root.hap.availability.AvailabilityReducer.java
License:Apache License
private void updateAvailability(Context context, DenseVector A, DenseVector R, DenseVector S, DenseVector P, DenseVector C, int reducerColNum, int reducerLevelNum, int N, String availability) throws IOException, InterruptedException { DenseVector oldA = A.clone();/*from w w w . ja va 2 s . c o m*/ // get positive values into RPositive DenseVector RPositive = R.clone(); for (int rowNum = 0; rowNum < N; rowNum++) { double RValue = RPositive.get(rowNum); if (RValue < 0) { RPositive.setQuick(rowNum, 0); } } // reset diagonal value from R RPositive.setQuick(reducerColNum, R.get(reducerColNum)); // sum R Positive values double RPSum = RPositive.zSum(); double CVal = C.get(0); double PVal = P.get(0); double CHat = CVal + PVal; // sum together CHat and RPSum into a vector A.assign(CHat + RPSum); A = (DenseVector) A.minus(RPositive); for (int rowNum = 0; rowNum < N; rowNum++) { if (rowNum == reducerColNum) { continue; } double value = A.get(rowNum) < 0 ? A.get(rowNum) : 0; A.setQuick(rowNum, value); } double lambda = context.getConfiguration().getFloat("lambda", 0); A = (DenseVector) A.times(1 - lambda); oldA = (DenseVector) oldA.times(lambda); A = (DenseVector) A.plus(oldA); VectorWritable AWritable = new VectorWritable(A); context.write(new Text(reducerColNum + "\t" + reducerLevelNum + "\t" + availability), AWritable); }