summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2011-04-08 15:39:55 +0200
committermguetlein <martin.guetlein@gmail.com>2011-05-03 11:46:30 +0200
commit78751b778a5dabfac142a017fc1e0d8d1c045acd (patch)
tree6257c90d38d1082637a65e3846944bd313464edd /lib
parentd5fe870fa184ef44390a0311664b7813360a44f5 (diff)
switch from datamapper/mysql to redis (sqlite for qmrf)
Diffstat (limited to 'lib')
-rw-r--r--lib/merge.rb14
-rwxr-xr-xlib/ot_predictions.rb4
-rwxr-xr-xlib/validation_db.rb116
3 files changed, 73 insertions, 61 deletions
diff --git a/lib/merge.rb b/lib/merge.rb
index 527415e..ecbe133 100644
--- a/lib/merge.rb
+++ b/lib/merge.rb
@@ -20,8 +20,7 @@ module Lib
def self.merge_array_objects( array )
return nil if array.size == nil
return array[0] if array.size==1
-
- m = self.merge_objects(array[0], array[1] )
+ m = self.merge_objects(array[0], array[1])
(2..array.size-1).each do |i|
m = self.merge_objects(m, array[i] )
end
@@ -33,8 +32,7 @@ module Lib
end
def self.merge_objects( object1, object2 )
-
- raise "classes not equal" if object1.class != object2.class
+ raise "classes not equal : "+object1.class.to_s+" != "+object2.class.to_s if object1.class != object2.class
object_class = object1.class
raise "register which attributes to merge first, nothing found for class "+object_class.to_s unless merge_attributes_registered?(object_class)
raise "not supported, successivly add unmerged object to a merge object" if merge_count(object2)>1
@@ -71,6 +69,11 @@ module Lib
variance = nil
if (avg=avg_attribute?(object_class, attribute)) || sum_attribute?(object_class, attribute)
+ # we string to numerics if wanted, value1 is no string anymore if weight>1
+ if value2.is_a?(String) and ((weight1==1 and value1.is_a?(String)) or (weight1>1 and value1.is_a?(Numeric)))
+ value1 = value1.to_f
+ value2 = value2.to_f
+ end
if (value1==nil and value2==nil )
#do nothing
elsif value1.is_a?(Numeric) and value2.is_a?(Numeric)
@@ -104,7 +107,8 @@ module Lib
end
end
else
- raise "invalid, cannot avg/sum non-numeric content for attribute: "+attribute.to_s+" contents: '"+value1.to_s+"', '"+value2.to_s+"'"
+ raise "invalid, cannot avg/sum non-numeric content for attribute: "+attribute.to_s+" contents: '"+value1.to_s+"' ("+
+ value1.class.to_s+"), '"+value2.to_s+"' ("+value2.class.to_s+")"
end
elsif non_numeric_attribute?(object_class, attribute)
if (value1.is_a?(Hash) and value2.is_a?(Hash))
diff --git a/lib/ot_predictions.rb b/lib/ot_predictions.rb
index f812854..5033425 100755
--- a/lib/ot_predictions.rb
+++ b/lib/ot_predictions.rb
@@ -184,9 +184,9 @@ module Lib
res = {}
case @feature_type
when "classification"
- (Lib::VAL_CLASS_PROPS).each{ |s| res[s] = send(s)}
+ (Validation::VAL_CLASS_PROPS).each{ |s| res[s] = send(s)}
when "regression"
- (Lib::VAL_REGR_PROPS).each{ |s| res[s] = send(s) }
+ (Validation::VAL_REGR_PROPS).each{ |s| res[s] = send(s) }
end
return res
end
diff --git a/lib/validation_db.rb b/lib/validation_db.rb
index 0d5db21..0beb73d 100755
--- a/lib/validation_db.rb
+++ b/lib/validation_db.rb
@@ -4,7 +4,7 @@
#end
require "lib/merge.rb"
-module Lib
+module Validation
VAL_PROPS_GENERAL = [ :validation_uri, :validation_type, :model_uri, :algorithm_uri, :training_dataset_uri, :prediction_feature,
:test_dataset_uri, :test_target_dataset_uri, :prediction_dataset_uri, :date ]
@@ -48,42 +48,53 @@ module Lib
VAL_MERGE_AVG = VAL_PROPS_AVG + VAL_CLASS_PROPS_SINGLE_AVG + VAL_CLASS_PROPS_PER_CLASS_AVG + VAL_REGR_PROPS
-# class Validation < ActiveRecord::Base
-# serialize :classification_statistics
-# serialize :regression_statistics
-#
-# alias_attribute :date, :created_at
-
- class Validation
- include DataMapper::Resource
+ class Validation < Ohm::Model
- property :id, Serial
- property :validation_type, String, :length => 512
- property :model_uri, String, :length => 512
- property :algorithm_uri, String, :length => 512
- property :training_dataset_uri, String, :length => 512
- property :test_target_dataset_uri, String, :length => 512
- property :test_dataset_uri, String, :length => 512
- property :prediction_dataset_uri, String, :length => 512
- property :prediction_feature, String, :length => 512
- property :created_at, DateTime
- property :num_instances, Integer
- property :num_without_class, Integer
- property :num_unpredicted, Integer
- property :crossvalidation_id, Integer
- property :crossvalidation_fold, Integer
- property :real_runtime, Float
- property :percent_without_class, Float
- property :percent_unpredicted, Float
- property :classification_statistics, Object
- property :regression_statistics, Object
- property :finished, Boolean, :default => false
+ attribute :validation_type
+ attribute :model_uri
+ attribute :algorithm_uri
+ attribute :training_dataset_uri
+ attribute :test_target_dataset_uri
+ attribute :test_dataset_uri
+ attribute :prediction_dataset_uri
+ attribute :prediction_feature
+ attribute :created_at
+ attribute :num_instances
+ attribute :num_without_class
+ attribute :num_unpredicted
+ attribute :crossvalidation_id
+ attribute :crossvalidation_fold
+ attribute :real_runtime
+ attribute :percent_without_class
+ attribute :percent_unpredicted
+ attribute :classification_statistics_yaml
+ attribute :regression_statistics_yaml
+ attribute :finished
+
+ index :model_uri
+ index :validation_type
+ index :crossvalidation_id
attr_accessor :subjectid
- after :save, :check_policy
- private
- def check_policy
+ def classification_statistics
+ YAML.load(self.classification_statistics_yaml) if self.classification_statistics_yaml
+ end
+
+ def classification_statistics=(cs)
+ self.classification_statistics_yaml = cs.to_yaml
+ end
+
+ def regression_statistics
+ YAML.load(self.regression_statistics_yaml) if self.regression_statistics_yaml
+ end
+
+ def regression_statistics=(rs)
+ self.regression_statistics_yaml = rs.to_yaml
+ end
+
+ def save
+ super
OpenTox::Authorization.check_policy(validation_uri, subjectid)
end
@@ -115,25 +126,27 @@ module Lib
end
-# class Crossvalidation < ActiveRecord::Base
-# alias_attribute :date, :created_at
- class Crossvalidation
- include DataMapper::Resource
+ class Crossvalidation < Ohm::Model
- property :id, Serial
- property :algorithm_uri, String, :length => 512
- property :dataset_uri, String, :length => 512
- property :created_at, DateTime
- property :num_folds, Integer, :default => 10
- property :random_seed, Integer, :default => 1
- property :finished, Boolean, :default => false
- property :stratified, Boolean, :default => false
+ attribute :algorithm_uri
+ attribute :dataset_uri
+ attribute :created_at
+ attribute :num_folds
+ attribute :random_seed
+ attribute :finished
+ attribute :stratified
attr_accessor :subjectid
+
+ index :algorithm_uri
+ index :dataset_uri
+ index :num_folds
+ index :random_seed
+ index :stratified
+ index :finished
- after :save, :check_policy
- private
- def check_policy
+ def save
+ super
OpenTox::Authorization.check_policy(crossvalidation_uri, subjectid)
end
@@ -152,7 +165,7 @@ module Lib
# further conditions can be specified in __conditions__
def self.find_all_uniq(conditions={}, subjectid=nil )
#cvs = Lib::Crossvalidation.find(:all, :conditions => conditions)
- cvs = Lib::Crossvalidation.all(:conditions => conditions)
+ cvs = Crossvalidation.find( conditions )
uniq = []
cvs.each do |cv|
next if AA_SERVER and !OpenTox::Authorization.authorized?(cv.crossvalidation_uri,"GET",subjectid)
@@ -171,8 +184,3 @@ module Lib
end
end
-
-Lib::Validation.auto_upgrade!
-Lib::Validation.raise_on_save_failure = true
-Lib::Crossvalidation.auto_upgrade!
-Lib::Crossvalidation.raise_on_save_failure = true