[1898] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Text;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.PluginInfrastructure;
|
---|
| 27 | using System.Net;
|
---|
| 28 | using System.ServiceModel;
|
---|
| 29 | using HeuristicLab.CEDMA.DB.Interfaces;
|
---|
| 30 | using HeuristicLab.CEDMA.DB;
|
---|
| 31 | using System.ServiceModel.Description;
|
---|
| 32 | using System.Linq;
|
---|
| 33 | using HeuristicLab.CEDMA.Core;
|
---|
| 34 | using HeuristicLab.GP.StructureIdentification;
|
---|
| 35 | using HeuristicLab.Data;
|
---|
| 36 | using HeuristicLab.Grid;
|
---|
| 37 | using System.Diagnostics;
|
---|
| 38 | using HeuristicLab.Core;
|
---|
| 39 | using System.Threading;
|
---|
[1922] | 40 | using HeuristicLab.Modeling;
|
---|
[1898] | 41 |
|
---|
| 42 | namespace HeuristicLab.CEDMA.Server {
|
---|
| 43 | public abstract class ExecuterBase : IExecuter {
|
---|
| 44 | private IDispatcher dispatcher;
|
---|
| 45 | protected IDispatcher Dispatcher {
|
---|
| 46 | get { return dispatcher; }
|
---|
| 47 | }
|
---|
| 48 | private IStore store;
|
---|
| 49 |
|
---|
| 50 | private int maxActiveJobs;
|
---|
| 51 | public int MaxActiveJobs {
|
---|
| 52 | get { return maxActiveJobs; }
|
---|
| 53 | set {
|
---|
| 54 | if (value < 0) throw new ArgumentException("Only positive values are allowed for MaxActiveJobs");
|
---|
| 55 | maxActiveJobs = value;
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | public ExecuterBase(IDispatcher dispatcher, IStore store) {
|
---|
| 60 | maxActiveJobs = 10;
|
---|
| 61 | this.dispatcher = dispatcher;
|
---|
| 62 | this.store = store;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | public void Start() {
|
---|
| 66 | new Thread(StartJobs).Start();
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | protected abstract void StartJobs();
|
---|
| 70 |
|
---|
[1922] | 71 | protected void StoreResults(IAlgorithm finishedAlgorithm) {
|
---|
| 72 | Entity modelEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
|
---|
[2053] | 73 | List<Statement> statements = new List<Statement>();
|
---|
| 74 | statements.Add(new Statement(modelEntity, Ontology.InstanceOf, Ontology.TypeModel));
|
---|
| 75 | statements.Add(new Statement(modelEntity, Ontology.TargetVariable, new Literal(finishedAlgorithm.Model.TargetVariable)));
|
---|
| 76 | statements.Add(new Statement(modelEntity, Ontology.Name, new Literal(finishedAlgorithm.Description)));
|
---|
[1922] | 77 |
|
---|
| 78 | IModel model = finishedAlgorithm.Model;
|
---|
[2053] | 79 | statements.Add(new Statement(modelEntity, Ontology.TrainingMeanSquaredError, new Literal(model.TrainingMeanSquaredError)));
|
---|
| 80 | statements.Add(new Statement(modelEntity, Ontology.ValidationMeanSquaredError, new Literal(model.ValidationMeanSquaredError)));
|
---|
| 81 | statements.Add(new Statement(modelEntity, Ontology.TestMeanSquaredError, new Literal(model.TestMeanSquaredError)));
|
---|
| 82 | statements.Add(new Statement(modelEntity, Ontology.TrainingCoefficientOfDetermination, new Literal(model.TrainingCoefficientOfDetermination)));
|
---|
| 83 | statements.Add(new Statement(modelEntity, Ontology.ValidationCoefficientOfDetermination, new Literal(model.ValidationCoefficientOfDetermination)));
|
---|
| 84 | statements.Add(new Statement(modelEntity, Ontology.TestCoefficientOfDetermination, new Literal(model.TestCoefficientOfDetermination)));
|
---|
| 85 | statements.Add(new Statement(modelEntity, Ontology.TrainingVarianceAccountedFor, new Literal(model.TrainingVarianceAccountedFor)));
|
---|
| 86 | statements.Add(new Statement(modelEntity, Ontology.ValidationVarianceAccountedFor, new Literal(model.ValidationVarianceAccountedFor)));
|
---|
| 87 | statements.Add(new Statement(modelEntity, Ontology.TestVarianceAccountedFor, new Literal(model.TestVarianceAccountedFor)));
|
---|
| 88 | statements.Add(new Statement(modelEntity, Ontology.TrainingMeanAbsolutePercentageError, new Literal(model.TrainingMeanAbsolutePercentageError)));
|
---|
| 89 | statements.Add(new Statement(modelEntity, Ontology.ValidationMeanAbsolutePercentageError, new Literal(model.ValidationMeanAbsolutePercentageError)));
|
---|
| 90 | statements.Add(new Statement(modelEntity, Ontology.TestMeanAbsolutePercentageError, new Literal(model.TestMeanAbsolutePercentageError)));
|
---|
| 91 | statements.Add(new Statement(modelEntity, Ontology.TrainingMeanAbsolutePercentageOfRangeError, new Literal(model.TrainingMeanAbsolutePercentageOfRangeError)));
|
---|
| 92 | statements.Add(new Statement(modelEntity, Ontology.ValidationMeanAbsolutePercentageOfRangeError, new Literal(model.ValidationMeanAbsolutePercentageOfRangeError)));
|
---|
| 93 | statements.Add(new Statement(modelEntity, Ontology.TestMeanAbsolutePercentageOfRangeError, new Literal(model.TestMeanAbsolutePercentageOfRangeError)));
|
---|
[1898] | 94 |
|
---|
[2045] | 95 | for (int i = 0; i < finishedAlgorithm.Dataset.Columns; i++) {
|
---|
| 96 | try {
|
---|
[2047] | 97 | string variableName = finishedAlgorithm.Dataset.GetVariableName(i);
|
---|
| 98 | double qualImpact = model.GetVariableQualityImpact(variableName);
|
---|
| 99 | double evalImpact = model.GetVariableEvaluationImpact(variableName);
|
---|
| 100 |
|
---|
| 101 | Entity inputVariableEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
|
---|
[2053] | 102 | statements.Add(new Statement(inputVariableEntity, Ontology.InstanceOf, Ontology.TypeVariableImpact));
|
---|
| 103 | statements.Add(new Statement(modelEntity, Ontology.HasInputVariable, inputVariableEntity));
|
---|
| 104 | statements.Add(new Statement(inputVariableEntity, Ontology.EvaluationImpact, new Literal(evalImpact)));
|
---|
| 105 | statements.Add(new Statement(inputVariableEntity, Ontology.QualityImpact, new Literal(qualImpact)));
|
---|
| 106 | statements.Add(new Statement(inputVariableEntity, Ontology.Name, new Literal(variableName)));
|
---|
[2045] | 107 | }
|
---|
| 108 | catch (ArgumentException) {
|
---|
| 109 | // ignore
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[1922] | 113 | byte[] serializedModel = PersistenceManager.SaveToGZip(model.Data);
|
---|
[2053] | 114 | statements.Add(new Statement(modelEntity, Ontology.SerializedData, new Literal(Convert.ToBase64String(serializedModel))));
|
---|
| 115 | store.AddRange(statements);
|
---|
[1898] | 116 | }
|
---|
| 117 |
|
---|
| 118 | public abstract string[] GetJobs();
|
---|
| 119 | }
|
---|
| 120 | }
|
---|