annotate tools/stats/generate_matrix_for_pca_lda.pl @ 2:c2a356708570

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:45:42 -0500
parents 9071e359b9a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #!/usr/bin/perl -w
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 use strict;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 use warnings;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 my $Input_Matrix = $ARGV[0];
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 my $Input_Label = $ARGV[1];
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 my %Hash_X = ();
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 my %Hash_Y = ();
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 my $My_Num_X = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 my $My_Num_Y = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 open (OUT, "> $ARGV[2]");
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 open (LABEL, "< $Input_Label") ||
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 die "Sorry, I couldn't open the escape.txt for clone: $!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 my $Label_Index = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 my $X_Label;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 my $input_Label;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 while (defined($input_Label = <LABEL>)){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 chomp($input_Label);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 my @cArray_Label = $input_Label =~ /(\S+)\s*/g;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 if ($input_Label =~ /\w/){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 if ($Label_Index == 0){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 $Hash_X{$cArray_Label[0]} = $cArray_Label[1];
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 $X_Label = $cArray_Label[1];
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 $Label_Index = 1;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 }else{
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 if ($cArray_Label[1] eq $X_Label){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 $Hash_X{$cArray_Label[0]} = $cArray_Label[1];
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 }else{
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 $Hash_Y{$cArray_Label[0]} = $cArray_Label[1];
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39 close(LABEL);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 open (MATRIX, "< $Input_Matrix") ||
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 die "Sorry, I couldn't open the escape.txt for clone: $!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44 my %Hash_Matrix = ();
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 my %Hash_Features = ();
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 my @cArray_Features = ();
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48 my %Hash_Sum = ();
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49 my $Matrix_Index = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
50 my $input_Matrix;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
51 while (defined($input_Matrix = <MATRIX>)){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
52 chomp($input_Matrix);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
53 my @cArray_Matrix = $input_Matrix =~ /(\S+)\s*/g;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
54 if ($input_Matrix =~ /\w/){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
55 if ($Matrix_Index == 0){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
56 @cArray_Features = @cArray_Matrix;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
57 my $Temp_Num_Array = scalar(@cArray_Matrix);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
58 my $Temp_Index = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
59 for(;$Temp_Index < $Temp_Num_Array; $Temp_Index++){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
60 $Hash_Features{$cArray_Matrix[$Temp_Index]} = "BOL";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
61 $Hash_Sum{$cArray_Matrix[$Temp_Index]} = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
62 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
63 $Matrix_Index = 1;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
64 }else{
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
65 $Hash_Matrix{$cArray_Matrix[0]} = $input_Matrix;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
66 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
67 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
68 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
69 close(MATRIX);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
70
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
71 my $Trace_Key;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
72
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
73 foreach $Trace_Key (sort {$a cmp $b} keys %Hash_X){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
74 my @cArray_Trace_X = $Hash_Matrix{$Trace_Key} =~ /(\S+)\s*/g;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
75 my $Num_Array_Feature_X = scalar(@cArray_Features);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
76 my $Index_Feature_X = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
77 for(;$Index_Feature_X < $Num_Array_Feature_X; $Index_Feature_X++){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
78 if ($Hash_Features{$cArray_Features[$Index_Feature_X]} eq "BOL"){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
79 $Hash_Features{$cArray_Features[$Index_Feature_X]} = $cArray_Trace_X[$Index_Feature_X + 1];
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
80 }else{
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
81 $Hash_Features{$cArray_Features[$Index_Feature_X]} = $Hash_Features{$cArray_Features[$Index_Feature_X]} . "\t" . $cArray_Trace_X[$Index_Feature_X + 1];
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
82 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
83
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
84 $Hash_Sum{$cArray_Features[$Index_Feature_X]} += $cArray_Trace_X[$Index_Feature_X + 1];
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
85 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
86 $My_Num_X ++;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
87 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
88
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
89 my $Append_Key;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
90 foreach $Append_Key (keys %Hash_Features){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
91 $Hash_Features{$Append_Key} = $Hash_Features{$Append_Key} . "\t" . $Hash_Sum{$Append_Key};
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
92 $Hash_Sum{$Append_Key} = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
93 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
94
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
95 foreach $Trace_Key (sort {$a cmp $b} keys %Hash_Y){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
96 my @cArray_Trace_Y = $Hash_Matrix{$Trace_Key} =~ /(\S+)\s*/g;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
97 my $Num_Array_Feature_Y = scalar(@cArray_Features);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
98 my $Index_Feature_Y = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
99 for(;$Index_Feature_Y < $Num_Array_Feature_Y; $Index_Feature_Y++){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
100 if ($Hash_Features{$cArray_Features[$Index_Feature_Y]} eq "BOL"){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
101 $Hash_Features{$cArray_Features[$Index_Feature_Y]} = $cArray_Trace_Y[$Index_Feature_Y + 1];
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
102 }else{
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
103 $Hash_Features{$cArray_Features[$Index_Feature_Y]} = $Hash_Features{$cArray_Features[$Index_Feature_Y]} . "\t" . $cArray_Trace_Y[$Index_Feature_Y + 1];
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
104 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
105
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
106 $Hash_Sum{$cArray_Features[$Index_Feature_Y]} += $cArray_Trace_Y[$Index_Feature_Y + 1];
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
107 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
108 $My_Num_Y ++;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
109 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
110
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
111 foreach $Append_Key (keys %Hash_Features){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
112 $Hash_Features{$Append_Key} = $Hash_Features{$Append_Key} . "\t" . $Hash_Sum{$Append_Key} . "\t" . "EOL";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
113 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
114
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
115 my $Prt_Key;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
116 print OUT " \t";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
117 foreach $Prt_Key (sort {$a cmp $b} keys %Hash_X){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
118 print OUT "$Prt_Key \t";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
119 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
120 print OUT "X(SUM) \t";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
121
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
122 foreach $Prt_Key (sort {$a cmp $b} keys %Hash_Y){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
123 print OUT "$Prt_Key \t";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
124 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
125 print OUT "Y(SUM) \t";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
126 print OUT "\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
127
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
128 my $Prt_Index = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
129 my $Prt_Array_Num = scalar (@cArray_Features);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
130 for(;$Prt_Index < $Prt_Array_Num; $Prt_Index++){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
131 print OUT "$cArray_Features[$Prt_Index] \t$Hash_Features{$cArray_Features[$Prt_Index]}\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
132 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
133
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
134 print OUT " \t";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
135 my $My_Label_Index = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
136 for(;$My_Label_Index < $My_Num_X; $My_Label_Index++){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
137 print OUT "X \t";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
138 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
139 print OUT " \t";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
140
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
141 $My_Label_Index = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
142 for(;$My_Label_Index < $My_Num_Y; $My_Label_Index++){
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
143 print OUT "Y \t";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
144 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
145 print OUT " \t\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
146
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
147 close(OUT);