package edu.neu.ccs.evergreen.util; /** * Class used to determine the appMean for a set of relation weights. */ public class AppMean { /** * Determine the appMean given the percentage weights of each relation * present in the formula. * * @param weights * Percentage weight of each relation * @return appMean */ public static double appMean(double weights[]) { Polynomial polynomial = null; for (int m = 0; m < weights.length; m++) { if (weights[m] > 0.0) { Polynomial temp = AppSAT.appSAT(m); temp = temp.multiply(weights[m]); if (polynomial == null) { polynomial = temp; } else { polynomial = polynomial.add(temp); } } } if (polynomial == null) { return Double.MIN_VALUE; } return polynomial.eval(maxX0To1(polynomial)); } /** * Find the value of x which maximizes the value of the polynomial given by * the coefficients over the domain 0 to 1 inclusive. * * @param polynomial * Polynomial to maximize * @return best value of x */ public static double maxX0To1(Polynomial polynomial) { // find best between maximum and minimum of domain double result = 0.0; double best = polynomial.eval(0.0); double test = polynomial.eval(1.0); if (test > best) { result = 1.0; best = test; } // if it is more than just a line we need to check // for interesting points between 0 and 1 if (polynomial.degree() > 1) { // when the derivative is 0 we have a stationary point // which could be a local maximum, minimum, or inflection // for each such value check to see if it gives a higher // value for y double results[] = polynomial.differentiate().solve0(); if (results.length > 0) { for (int i = 0; i < results.length; i++) { if ((results[i] > 0.0) && (results[i] < 1.0)) { test = polynomial.eval(results[i]); if (test > best) { result = results[i]; best = test; } } } } } return result; } }