-
Notifications
You must be signed in to change notification settings - Fork 0
/
MinMaxNorm.java
75 lines (73 loc) · 1.8 KB
/
MinMaxNorm.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.lang.*;
import java.util.*;
import java.io.*;
class MinMaxNorm
{
public static void main(String[] args) throws Exception
{
BufferedReader in = new BufferedReader(new FileReader("C://Users/it/Desktop/data.txt"));
String inputLine = in.readLine();
String [] fields = inputLine.split(" "); // Splits at the space
int i=0;
int [] arr=new int[fields.length];
for(String str:fields){
int x=Integer.parseInt(str); //prints out name
arr[i++]=x;
}
for(int a:arr)
{
System.out.println(a);
}
int max1=Integer.MIN_VALUE;
int min1=Integer.MAX_VALUE;
for( i=0;i<arr.length;i++)
{
if(arr[i]>max1)
max1=arr[i];
}
System.out.println(max1);
for( i=0;i<arr.length;i++)
{
if(arr[i]<min1)
min1=arr[i];
}
System.out.println(min1);
int max2=1;
int min2=0;
double normArray[]=new double[arr.length];
for( i=0;i<arr.length;i++)
{
normArray[i]=(double)((double)(arr[i]-min1)/(double)(max1-min1));
}
for( i=0;i<arr.length;i++)
{
System.out.println(arr[i]+"---Normalized value-->"+normArray[i]);
}
double mean=0.0;
double sum=0.0;
for(i=0;i<arr.length;i++)
{
sum+=arr[i];
}
mean=sum/arr.length;
int n=arr.length;
double sd=0.0;
double sqrsum=0.0;
for( i=0;i<n;i++)
{
sqrsum=sqrsum+(arr[i]-mean)*(arr[i]-mean);
}
sqrsum=sqrsum/n;
sd=Math.sqrt(sqrsum);
double zscore[]=new double[n];
for( i=0;i<n;i++)
{
zscore[i]=(arr[i]-mean)/sd;
}
System.out.println("Data item ------------->zscore");
for( i=0;i<n;i++)
{
System.out.println(arr[i]+" ------------->"+zscore[i]);
}
}
}