-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patharff_naninfzero_checker.pl
48 lines (44 loc) · 1.04 KB
/
arff_naninfzero_checker.pl
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
#!/usr/bin/perl
# locate nan in arff files (and inf) and display affected attribute
$arff=$ARGV[0];
unless ($arff) {
print " -- locate nan in arff files (and inf) and display affected attribute --\n";
print " -- this is useful for debugging new feature extractor components --\n";
print "USAGE: $0 <arff_file_to_check.arff>\n";
exit;
}
open(FILE,"<$arff");
$data=0; my @attr;
@nonzero; $N=0;
while(<FILE>) {
my $line=$_;
$line=~ s/\n$//; $line=~s/\r$//;
if ($data) {
@el = split(/,/,$line);
$N=$#el+1;
for ($i=0; $i<=$#el; $i++) {
if ($el[$i] != 0.0) {
$nonzero[$i] = 1;
}
#if ($el[$i] !~ /^0\.000000e\+00/) {
# $nonzero[$i] = 1;
#}
if (($el[$i] =~ /nan/i)||($el[$i] =~ /inf/i)) {
print "nan/inf @ # $i = $attr[$i]\n";
}
}
} else {
if($line=~/^\@data/) { $data = 1; }
else {
if($line=~/^\@attribute ([^ ]+) /) {
push(@attr,$1);
}
}
}
}
close(FILE);
for ($i=0; $i<$N; $i++) {
unless ($nonzero[$i]) {
print "all-zero: ".$attr[$i]."\n";
}
}