List of usage examples for org.apache.mahout.math DenseVector clone
@SuppressWarnings("CloneDoesntCallSuperClone") @Override public DenseVector clone()
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(); // get positive values into RPositive DenseVector RPositive = R.clone();// w w w .j ava2 s . c o m 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); }
From source file:root.hap.responsibility.ResponsibilityReducer.java
License:Apache License
private void updateResponsibility(Context context, DenseVector A, DenseVector S, DenseVector R, DenseVector T, int reducerLevelNum, int reducerRowNum, int N, String responsibilty) throws IOException, InterruptedException { DenseVector oldR = R.clone(); DenseVector sum = (DenseVector) A.plus(S); double maxValue = sum.maxValue(); int maxValueIndex = sum.maxValueIndex(); maxValue *= -1;//from w w w . java 2 s.c o m sum.set(maxValueIndex, Double.NEGATIVE_INFINITY); double tau = T.get(0); double YH = Math.min(maxValue, tau); double actualMax = sum.maxValue(); actualMax *= -1; double YH2 = Math.min(actualMax, tau); R = (DenseVector) S.plus(YH); R.setQuick(maxValueIndex, S.get(maxValueIndex) + YH2); // Dampen double lambda = context.getConfiguration().getFloat("lambda", 0); R = (DenseVector) R.times(1 - lambda); oldR = (DenseVector) oldR.times(lambda); R = (DenseVector) R.plus(oldR); VectorWritable RWritable = new VectorWritable(R); context.write(new Text(reducerRowNum + "\t" + reducerLevelNum + "\t" + responsibilty), RWritable); }