Wrong Numeric Results with Right Math Implementation.
Hi guys, i would like to ask for help in this thread:
Implemented normal distribution value in a method that take double's as argument and return double. However i've got a bunch of digusting results, a lot of numbers above 1.0, what's obvious wrong result for a gaussian normal form.
Here is the code:
Code:
public void gaussianShape(double data,double point,double bin){
value =(double) Math.exp(-(Math.pow((double) ((double) (data-point))/bin,2.0E0)/2.0E0))/((double) Math.sqrt(2.0E0*Math.PI)*bin);
}
public double getValue(){
return value;
}
And the main calls :
Code:
public static void main(String[] args) {
// args.length is equivalent to argc in C
ArrayList<BaseMath.BasicMath> data = new ArrayList<BaseMath.BasicMath>();
if (args.length == 1)
{
try
{
// Open the file that is the first
// command line parameter
File fstream = new File(args[0]);
// Convert our input stream to a
// DataInputStream
//DataInputStream in = new DataInputStream(fstream);
Scanner reader = new Scanner(fstream);
Writer writer = new BufferedWriter(new FileWriter("/home/penalva/Desktop/Data.csv"));
int i = 0;
// Continue to read lines while
// there are still some left to read
while (reader.hasNext())
{
// Print file line to screen
data.add(new BasicMath());
//System.out.println(Double.parseDouble(reader.nextLine()));
data.get(data.size()-1).gaussianShape(Double.parseDouble(reader.nextLine()),0.02E0,0.002E0);
System.out.println(data.get(data.size()-1).getValue());
//data.add(a);
// double c = Math.log(a)-Math.log(b);
// writer.write(String.valueOf(c)+"\n");
i++;
}
// writer.write(String.valueOf(sum(data,1,1000)));
}
catch (Exception e)
{
System.err.println("File input error");
}
}
else
System.out.println("Invalid parameters");
simplePlot(new File("/home/penalva/Desktop/Data.csv"));
}
a sample of the result:
7.537208259145137E-53
2.3899568967108583E-52
3.3110908849100844E-55
180.17021643451255
1.2574847138544774E-81
7.856584775355024E-11
3.84729931335321E-20
1.588541231772254E-15
5.906721238556497E-15
20.977704189864777
1.2788843013602114E-79
7.932917621330264E-162
2.0502620451222263E-52
9.501495747135711E-52
ps1: I dont think that is a reference problem a-priori...
ps2: I believe that is a problem of type out of bounds operation, but how acess it and resolve ? i dont know ! may be tricky T_T;
ps3: The field value lives in the class BasicMath and is initiated with the constructor call, i.e. value = 0.0 .
You guys are welcome !