Class: SVMFeaturesConfig

Inherits:
Hash
  • Object
show all
Defined in:
lib/svmlab-config.rb

Overview

—SVMFeature configuration—

SVMFeature is initiated by a configuration file in YAML format. Required fields in configuration are: (all paths can be given either absolute or relative to BaseDir)


Features:

  • <targetfeature>

  • <feature1>

  • <feature2>

… BaseDir: <base directory> DataSet: <path of file giving the dataset>

 OR
<prefix of a set of files giving the dataset>

Example: If Dataset is not given, this gives name(s) of examples

to use.

Groups: <range (n1..n2) or (n1…n2) in example name to use for grouping>

 OR
<file prefix relative to BaseDir for files giving groups>

Methods: <path of .rb file holding all feature calculation methods>


targetfeature:

HomeDir: <home directory>
    If HomeDir is not given, it will be set to BaseDir/featurename
Method: <the method calculating this feature>
    If Method is not given, an attempts is made to acquire
    the feature from the database. If it fails, ERROR is reported.
Dimensions: <the number of dimensions in this feature>
    If Dimensions is not given, it will be assumed to be 1
    and only the first value for each example will be used
<Further specific configuration of this feature>

feature1:

HomeDir: <home directory>
Method: <the method calculating this feature>
Dimensions: <the number of dimensions in this feature>
<Further specific configuration of this feature>

feature2: … featureN:

If featureN configuration is not given, then all default settings
will apply to this feature.

Defined Under Namespace

Classes: SVMFeatureConfig

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#cc, #to_xy

Constructor Details

#initialize(arg) ⇒ SVMFeaturesConfig




103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/svmlab-config.rb', line 103

def initialize(arg)
  begin
    cfg = YAML.load(arg)
    cfg.each do |k,v|
      self[k] = v
    end
    # Set up dataset file
    if self['DataSet']
      self['DataSet'] = setupDirInfo(self['DataSet'])
      if !File.exists? self['DataSet']
        raise ArgumentError, "Cannot find dataset file #{self['DataSet']}."
      end
    end
    # Get feature methods
    if methods = self['Methods'] 
      if methods.is_a? Array
        methods.each { |method| require setupDirInfo(method) }
      elsif methods.is_a? String
        require setupDirInfo(methods)
      end
    end
    # Set up each feature's configuration
    raise ArgumentError, "Features not given." if !self['Features']
    @dim = 0
    self['Features'].each do |feature|
      self[feature] = SVMFeatureConfig.new(self,feature)
      @dim += self[feature]['Dimensions']
    end
  rescue ArgumentError, LoadError
    raise $!,$!,nil
  end
end

Instance Attribute Details

#cfgObject (readonly)

Returns the value of attribute cfg.



63
64
65
# File 'lib/svmlab-config.rb', line 63

def cfg
  @cfg
end

#dimObject (readonly)

Returns the value of attribute dim.



63
64
65
# File 'lib/svmlab-config.rb', line 63

def dim
  @dim
end

Instance Method Details

#setupDirInfo(path) ⇒ Object



136
137
138
139
140
141
142
143
144
# File 'lib/svmlab-config.rb', line 136

def setupDirInfo(path)
  if path !~ /^\// 
    base = self['BaseDir']
    raise ArgumentError, "BaseDir not given." if !base
    path.sub!(/#{path}/, base + '/' + path)
    path.sub!(/\/\//,'/')
  end
  path 
end