/* SCCS - @(#)NslSaturation.java 1.6 - 09/01/99 - 00:18:08 */ // Copyright: Copyright (c) 1997 University of Southern California Brain Project. // Copyright: This software may be freely copied provided the toplevel // Copyright: COPYRIGHT file is included with each such copy. // Copyright: Email nsl@java.usc.edu. //////////////////////////////////////////////////////////// // // Saturation threshold routines // // /** Saturation threshold routines. There are four basic format for the evaluation method in this routine: 1, eval(a) -> c a is the input parameter to pass the threshold function: if a < 0, c = 0, else if 0 <= a < 1, c = a; else c = 1. 2. eval(dest, a) -> c a is the parameter of the threshold function and dest is the temporary space to hold the result. The method returns the reference to dest. 3. eval(a, kx1, kx2, ky1, ky2) -> c if a < kx1, c = ky1, else if kx1 <= a < kx2, c=(ky2-ky1)(a-kx1)/(kx2-kx1)+ky1, else, c = ky2. 2. eval(dest, a, kx1, kx2, ky1, ky2) -> c a is the parameter of the threshold function and dest is the temporary space to hold the result. The method returns the reference to dest. */ //////////////////////////////////////////////////////////////////////////////// // saturation functions package nslj.src.math; import nslj.src.lang.*; public final class NslSaturation { // doubles private static double value(double x, double slope, double offset) { return slope*(x-offset); } public static double value(double x, double kx1, double kx2, double ky1, double ky2) { if (x=kx2) return ky2; return (((ky2-ky1)*(x-kx1))/(kx2-kx1))+ky1; } public static double eval(double a) { return eval(a,0,1,0,1); } public static double[] eval(double[] a) { return eval(a,0,1,0,1); } public static double[][] eval(double[][] a) { return eval(a,0,1,0,1); } public static double[][][] eval(double[][][] a) { return eval(a,0,1,0,1); } public static double[][][][] eval(double[][][][] a) { return eval(a,0,1,0,1); } public static double[] eval(double[] dest, double[] a) { return eval(dest,a,0,1,0,1); } public static double[][] eval(double[][] dest, double[][] a) { return eval(dest,a,0,1,0,1); } public static double[][][] eval(double[][][] dest, double[][][] a) { return eval(dest,a,0,1,0,1); } public static double[][][][] eval(double[][][][] dest, double[][][][] a) { return eval(dest,a,0,1,0,1); } public static double eval(double a, double slope, double offset) { return value(a,slope,offset); } public static double eval(double a, double kx1, double kx2, double ky1, double ky2) { return value(a, kx1, kx2, ky1, ky2); } public static double[] eval (double[] a, double slope, double offset) { double[] dest = new double[a.length]; return eval(dest, a, slope, offset); } public static double[] eval (double[] dest, double[] a, double slope, double offset) { int i; if (dest.length!=a.length) { dest = new double[a.length]; } for (i=0; i=kx2) return ky2; return (((ky2-ky1)*(x-kx1))/(kx2-kx1))+ky1; } public static float eval(float a) { return eval(a,0,1,0,1); } public static float[] eval(float[] a) { return eval(a,0,1,0,1); } public static float[][] eval(float[][] a) { return eval(a,0,1,0,1); } public static float[][][] eval(float[][][] a) { return eval(a,0,1,0,1); } public static float[][][][] eval(float[][][][] a) { return eval(a,0,1,0,1); } public static float[] eval(float[] dest, float[] a) { return eval(dest,a,0,1,0,1); } public static float[][] eval(float[][] dest, float[][] a) { return eval(dest,a,0,1,0,1); } public static float[][][] eval(float[][][] dest, float[][][] a) { return eval(dest,a,0,1,0,1); } public static float[][][][] eval(float[][][][] dest, float[][][][] a) { return eval(dest,a,0,1,0,1); } public static float eval(float a, float slope, float offset) { return value(a,slope,offset); } public static float eval(float a, float kx1, float kx2, float ky1, float ky2) { return value(a, kx1, kx2, ky1, ky2); } public static float[] eval (float[] a, float slope, float offset) { float[] dest = new float[a.length]; return eval(dest, a, slope, offset); } public static float[] eval (float[] dest, float[] a, float slope, float offset) { int i; if (dest.length!=a.length) { dest = new float[a.length]; } for (i=0; i