package model.compute; /** *

Title:NormalEQ.java

*

Description: Computes outputs using the normal distribution. * the primary distribution is 2D with one standard deviation so * it is circular.

*

Copyright: Copyright (c) 2009

*

Company: Hanover College

* @author John H. Krantz, Ph.D. * @version 0.1 */ public class NormalEq { // parameters private double meanX = 0; private double meanY = 0; private double sd = 1; // values private double x = 0; private double y = 0; // computational constants private final static double SQRT_2_PI = Math.sqrt(2*Math.PI); // empty constrcutor public NormalEq(){} /** * getNomral2D: get the height of a 2d normal distribution * at a given location while setting all the parameters * @param double mean_X mean of distribution in x dimension * @param double mean_Y mean of distribution in y dimension * @param double stdDev standard deviation of distribution * @param double xPos x position of value to get * @param double yPos y position of value to get * @return double the height of the distribution at location */ public double getNormal2D(double mean_X,double mean_Y, double stdDev, double xPos, double yPos){ setCtr(mean_X,mean_Y); setStdDev(stdDev); return getNormal2D(xPos,yPos); } /** * getNormal2D: return the height of the 2d normal distribution * with mean and standard deviation previously set. * @param double xPos x position of value to get * @param double yPos y position of value to get * @return double height of the distribution at this location. */ public double getNormal2D(double xPos, double yPos){ x = xPos; y = yPos; double val = 0; val = (1/(sd*SQRT_2_PI))* Math.exp(-(sqr(x-meanX)+sqr(y-meanY)) /(2*sqr(sd))); return val; } /** * squares a number * @param double val the number to square * @return double */ private double sqr(double val){ return val*val; } // set methods /** * setCtr: set the center location of the 2d normal * distribution * @param double mean_X x position of the center. * @param double mean_Y y position of the center. */ public void setCtr(double mean_X, double mean_Y){ meanX = mean_X; meanY = mean_Y; } /** * setStdDev: set the standard deviation of the normal * distribution * @param stdDev */ public void setStdDev(double stdDev){ sd = stdDev > 0 ? stdDev : sd; } }