diff options
author | Andreas Maunz <andreas@maunz.de> | 2011-07-21 12:48:08 +0200 |
---|---|---|
committer | Andreas Maunz <andreas@maunz.de> | 2011-07-21 12:48:08 +0200 |
commit | ba3e92cb0c64b5051aa5790f125797bb00eab74a (patch) | |
tree | 2950a7c79a4096ec0197ea43fc11029623c490bc | |
parent | aa3cde05ee8467a280dfc648a7b98e736704a770 (diff) |
Added zero-variance test
-rw-r--r-- | lib/algorithm.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb index 199c4d8..22768cc 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -726,7 +726,7 @@ module OpenTox raise "Error! PCA needs at least two dimensions." if data_matrix.size2 < 2 @data_matrix_selected = nil (0..@data_matrix.size2-1).each { |i| - if !Algorithm::isnull_or_singular?(@data_matrix.col(i).to_a) + if !Algorithm::zero_variance?(@data_matrix.col(i).to_a) if @data_matrix_selected.nil? @data_matrix_selected = GSL::Matrix.alloc(@data_matrix.size1, 1) @data_matrix_selected.col(0)[0..@data_matrix.size1-1] = @data_matrix.col(i) @@ -811,6 +811,13 @@ module OpenTox (nr_zeroes == array.size-1) || # remove singular feature (nr_zeroes == 0) # also remove feature present everywhere end + + # For symbolic features + # @param [Array] Array to test, must indicate non-occurrence with 0. + # @return [Boolean] Whether the feature has variance zero. + def self.zero_variance?(array) + return (array.to_scale.variance_sample == 0.0) + end # Median of an array # @param [Array] Array with values |