Java Abs absApproximation(double x, double M)

Here you can find the source of absApproximation(double x, double M)

Description

abs Approximation

License

Open Source License

Declaration

public static double absApproximation(double x, double M) 

Method Source Code

//package com.java2s;

public class Main {
    public static double absApproximation(double x, double M) {
        return huberPenaltyFunction(x, M) / (2 * M);
    }/*from  w w  w  .j  av  a2 s.  c  o  m*/

    /**
     * This function computes the Huber penalty function of an 
     * input. The Huber penalty function is equal to x^2 for |x| <= M, 
     * and linear for |x| > M.
     * @param x the value at which to compute the Huber penalty function
     * @param M the parameter which determines the linear/quadratic region
     * @return The Huber penalty function at x
     */
    public static double huberPenaltyFunction(double x, double M) {
        if (Math.abs(x) <= M) {
            return x * x;
        } else {
            return M * (2 * Math.abs(x) - M);
        }
    }
}

Related

  1. abs2(double[][] IN)
  2. abs2(float[] f)
  3. abs_fractional(double number)
  4. abs_min(double a, double b)
  5. absAngleDifference(double angle1Radians, double angle2Radians)
  6. absCap(double value, double bounds)
  7. absClamp(double value, double bounds)
  8. absDegrees(double degrees)
  9. absDelta(double a, double b)