Sha256: 5df84cf07a314ed58d4a9d87663082ced48316f5a910c2f1c04747560668da39

Contents?: true

Size: 1.01 KB

Versions: 13

Compression:

Stored size: 1.01 KB

Contents

module Libsvm
  class Node
    class << self
      def features(*vargs)
        array_of_nodes = []
        if vargs.size == 1
          if vargs.first.class == Array
            vargs.first.each_with_index do |value, index|
              array_of_nodes << Node.new(index.to_i, value.to_f)
            end
          elsif vargs.first.class == Hash
            vargs.first.each do |index, value|
              array_of_nodes << Node.new(index.to_i, value.to_f)
            end
          else
            raise(ArgumentError.new("Node features need to be a Hash, Array or Floats"))
          end
        else
          vargs.each_with_index do |value, index|
            array_of_nodes << Node.new(index.to_i, value.to_f)
          end
        end
        array_of_nodes
      end

      def [](index, value)
        new(index, value)
      end
    end

    def initialize(index=0, value=0.0)
      self.index = index
      self.value = value
    end

    def ==(other)
      index == other.index && value == other.value
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rb-libsvm-1.2.0 lib/libsvm/node.rb
rb-libsvm-1.1.5 lib/libsvm/node.rb
rb-libsvm-1.1.4 lib/libsvm/node.rb
rb-libsvm-1.1.3 lib/libsvm/node.rb
rb-libsvm-1.1.2 lib/libsvm/node.rb
rb-libsvm-1.1.1 lib/libsvm/node.rb
rb-libsvm-1.1.0 lib/libsvm/node.rb
rb-libsvm-1.0.11 lib/libsvm/node.rb
rb-libsvm-1.0.10 lib/libsvm/node.rb
rb-libsvm-1.0.9 lib/libsvm/node.rb
rb-libsvm-1.0.8 lib/libsvm/node.rb
rb-libsvm-1.0.7 lib/libsvm/node.rb
rb-libsvm-1.0.6 lib/libsvm/node.rb