/* SCCS - @(#)NslSigmoid.java 1.9 - 08/06/99 - 04:56:01 */ // 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. //////////////////////////////////////////////////////////// // // Sigmoid threshold routines // // /** Sigmoid threshold routines. There are four basic format for the evaluation method in this routine: 1. eval(a,slope,offset) -> c a is the input parameter to pass the threshold function: c = 1/(1+exp(-slope*(x-offset))) 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 c = ky2 if a>=kx2} c = (1/(1+exp(-slope(a-kx1))))((ky2-ky1)/(kx2-kx1))+ky1 for kx1<=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. */ //////////////////////////////////////////////////////////////////////////////// // sigmoid functions package nslj.src.math; import nslj.src.lang.*; public final class NslSigmoid { // doubles private static double value(double x, double slope, double offset) { return (1.0/(1.0+Math.exp(-slope*(x-offset)))); } private static double value(double x, double kx1, double kx2, double ky1, double ky2) { double offset = ((kx1 + kx2) / 2.0 ); double slope = (1.0/((kx2-kx1)/10.0)); double exp = ( 1.0 / ( 1.0 + Math.exp(-slope*(x - offset)) ) ); double temp = (exp * (ky2 - ky1)) + ky1; return temp; } public static double eval(double a) { return eval(a,1,0); } public static double[] eval(double[] a) { return eval(a,1,0); } public static double[][] eval(double[][] a) { return eval(a,1,0); } public static double[][][] eval(double[][][] a) { return eval(a,1,0); } public static double[][][][] eval(double[][][][] a) { return eval(a,1,0); } public static double[] eval(double[] dest, double[] a) { return eval(dest,a,1,0); } public static double[][] eval(double[][] dest, double[][] a) { return eval(dest,a,1,0); } public static double[][][] eval(double[][][] dest, double[][][] a) { return eval(dest,a,1,0); } public static double[][][][] eval(double[][][][] dest, double[][][][] a) { return eval(dest,a,1,0); } public static double eval(double a, double slope) { return value(a,slope,0); } 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[] dest = new double[a.length]; return eval(dest, a, slope); } public static double[] eval (double[] dest, double[] a, double slope) { int i; if (dest.length!=a.length) { dest = new double[a.length]; } for (i=0; i