summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2016-11-10 15:27:26 +0100
committerChristoph Helma <helma@in-silico.ch>2016-11-10 15:27:26 +0100
commit9a06f2ff5ae6bdbe7dc90555599e186f1585e0d2 (patch)
treec9cbb63f398c2937f3cba78a9976c7356a3f79a4 /test
parent85ef2c4982f72c811d5e9fa4ce22e238c512fe6e (diff)
Model::NanoPrediction parameters
Diffstat (limited to 'test')
-rw-r--r--test/model-nanoparticle.rb30
-rw-r--r--test/nanomaterial-prediction-models.rb60
-rw-r--r--test/validation-nanoparticle.rb19
3 files changed, 109 insertions, 0 deletions
diff --git a/test/model-nanoparticle.rb b/test/model-nanoparticle.rb
index 88032bc..c5f3223 100644
--- a/test/model-nanoparticle.rb
+++ b/test/model-nanoparticle.rb
@@ -61,6 +61,36 @@ class NanoparticleModelTest < MiniTest::Test
model.delete
end
+ def test_nanoparticle_fingerprint_model_with_feature_selection
+ assert true, @prediction_feature.measured
+ algorithms = {
+ :descriptors => {
+ :method => "fingerprint",
+ :type => "MP2D",
+ },
+ :similarity => {
+ :method => "Algorithm::Similarity.tanimoto",
+ :min => 0.1
+ },
+ }
+ model = Model::Lazar.create training_dataset: @training_dataset, prediction_feature: @prediction_feature, algorithms: algorithms
+ refute_empty model.algorithms[:feature_selection]
+ refute_empty model.dependent_variables
+ refute_empty model.descriptor_ids
+ refute_empty model.independent_variables
+ assert_equal "Algorithm::Caret.rf", model.algorithms[:prediction][:method]
+ assert_equal "Algorithm::Similarity.tanimoto", model.algorithms[:similarity][:method]
+ nanoparticle = @training_dataset.nanoparticles[-34]
+ assert_includes nanoparticle.dataset_ids, @training_dataset.id
+ prediction = model.predict nanoparticle
+ refute_nil prediction[:value]
+ assert_includes prediction[:prediction_interval][0]..prediction[:prediction_interval][1], prediction[:measurements].median, "This assertion assures that measured values are within the prediction interval. It may fail in 5% of the predictions."
+ prediction = model.predict @training_dataset.substances[14]
+ refute_nil prediction[:value]
+ assert_includes prediction[:prediction_interval][0]..prediction[:prediction_interval][1], prediction[:measurements].median, "This assertion assures that measured values are within the prediction interval. It may fail in 5% of the predictions."
+ model.delete
+ end
+
def test_nanoparticle_calculated_properties_model
skip "Nanoparticle calculate_properties similarity not yet implemented"
assert true, @prediction_feature.measured
diff --git a/test/nanomaterial-prediction-models.rb b/test/nanomaterial-prediction-models.rb
new file mode 100644
index 0000000..b0c05f3
--- /dev/null
+++ b/test/nanomaterial-prediction-models.rb
@@ -0,0 +1,60 @@
+require_relative "setup.rb"
+
+class NanomaterialPredictionModelTest < MiniTest::Test
+
+ def setup
+ @training_dataset = Dataset.where(:name => "Protein Corona Fingerprinting Predicts the Cellular Interaction of Gold and Silver Nanoparticles").first
+ unless @training_dataset
+ Import::Enanomapper.import File.join(File.dirname(__FILE__),"data","enm")
+ @training_dataset = Dataset.where(name: "Protein Corona Fingerprinting Predicts the Cellular Interaction of Gold and Silver Nanoparticles").first
+ end
+ @prediction_feature = @training_dataset.features.select{|f| f["name"] == 'log2(Net cell association)'}.first
+ end
+
+ def test_default_nanomaterial_prediction_model
+ prediction_model = Model::NanoPrediction.create
+ p prediction_model
+ [:endpoint,:species,:source].each do |p|
+ refute_empty prediction_model[p]
+ end
+ assert prediction_model.regression?
+ refute prediction_model.classification?
+ prediction_model.crossvalidations.each do |cv|
+ refute_nil cv.r_squared
+ refute_nil cv.rmse
+ end
+ nanoparticle = @training_dataset.nanoparticles[-34]
+ assert_includes nanoparticle.dataset_ids, @training_dataset.id
+ prediction = prediction_model.predict nanoparticle
+ refute_nil prediction[:value]
+ assert_includes prediction[:prediction_interval][0]..prediction[:prediction_interval][1], prediction[:measurements].median, "This assertion assures that measured values are within the prediction interval. It may fail in 5% of the predictions."
+ prediction_model.delete
+ end
+
+ def test_nanomaterial_prediction_model_parameters
+ algorithms = {
+ :descriptors => {
+ :method => "fingerprint",
+ :type => "MP2D",
+ },
+ :similarity => {
+ :method => "Algorithm::Similarity.tanimoto",
+ :min => 0.1
+ },
+ :prediction => { :method => "OpenTox::Algorithm::Regression.weighted_average" },
+ :feature_selection => nil
+ }
+ prediction_model = Model::NanoPrediction.create algorithms: algorithms
+ assert prediction_model.regression?
+ refute prediction_model.classification?
+ prediction_model.crossvalidations.each do |cv|
+ refute_nil cv.r_squared
+ refute_nil cv.rmse
+ end
+ nanoparticle = @training_dataset.nanoparticles[-34]
+ assert_includes nanoparticle.dataset_ids, @training_dataset.id
+ prediction = prediction_model.predict nanoparticle
+ refute_nil prediction[:value]
+ assert_includes prediction[:prediction_interval][0]..prediction[:prediction_interval][1], prediction[:measurements].median, "This assertion assures that measured values are within the prediction interval. It may fail in 5% of the predictions."
+ end
+end
diff --git a/test/validation-nanoparticle.rb b/test/validation-nanoparticle.rb
index 7391f21..5ed70f2 100644
--- a/test/validation-nanoparticle.rb
+++ b/test/validation-nanoparticle.rb
@@ -113,4 +113,23 @@ class NanoparticleValidationTest < MiniTest::Test
refute_nil cv.rmse
end
+ def test_nanoparticle_fingerprint_model_with_feature_selection
+ algorithms = {
+ :descriptors => {
+ :method => "fingerprint",
+ :type => "MP2D",
+ },
+ :similarity => {
+ :method => "Algorithm::Similarity.tanimoto",
+ :min => 0.1
+ },
+ }
+ model = Model::Lazar.create prediction_feature: @prediction_feature, training_dataset: @training_dataset, algorithms: algorithms
+ cv = CrossValidation.create model
+ p cv.rmse
+ p cv.r_squared
+ refute_nil cv.r_squared
+ refute_nil cv.rmse
+ end
+
end