Sha256: 8d2e69afea1c635d585fdfa5020ddd7e9a294f5dd175d8024070576e07383e99

Contents?: true

Size: 987 Bytes

Versions: 1

Compression:

Stored size: 987 Bytes

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
    end

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jrb-libsvm-0.1.2-java lib/jrb-libsvm/node.rb