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;
|
---|
40 | using HeuristicLab.Modeling;
|
---|
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 |
|
---|
71 | protected void StoreResults(IAlgorithm finishedAlgorithm) {
|
---|
72 | Entity modelEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
|
---|
73 | store.Add(new Statement(modelEntity, Ontology.InstanceOf, Ontology.TypeModel));
|
---|
74 | StoreEntityAttribute(modelEntity, Ontology.TargetVariable, finishedAlgorithm.Model.TargetVariable);
|
---|
75 | StoreEntityAttribute(modelEntity, Ontology.AlgorithmName, finishedAlgorithm.Description);
|
---|
76 |
|
---|
77 | IModel model = finishedAlgorithm.Model;
|
---|
78 | StoreEntityAttribute(modelEntity, Ontology.TrainingMeanSquaredError, model.TrainingMeanSquaredError);
|
---|
79 | StoreEntityAttribute(modelEntity, Ontology.ValidationMeanSquaredError, model.ValidationMeanSquaredError);
|
---|
80 | StoreEntityAttribute(modelEntity, Ontology.TestMeanSquaredError, model.TestMeanSquaredError);
|
---|
81 | StoreEntityAttribute(modelEntity, Ontology.TrainingCoefficientOfDetermination, model.TrainingCoefficientOfDetermination);
|
---|
82 | StoreEntityAttribute(modelEntity, Ontology.ValidationCoefficientOfDetermination, model.ValidationCoefficientOfDetermination);
|
---|
83 | StoreEntityAttribute(modelEntity, Ontology.TestCoefficientOfDetermination, model.TestCoefficientOfDetermination);
|
---|
84 | StoreEntityAttribute(modelEntity, Ontology.TrainingVarianceAccountedFor, model.TrainingVarianceAccountedFor);
|
---|
85 | StoreEntityAttribute(modelEntity, Ontology.ValidationVarianceAccountedFor, model.ValidationVarianceAccountedFor);
|
---|
86 | StoreEntityAttribute(modelEntity, Ontology.TestVarianceAccountedFor, model.TestVarianceAccountedFor);
|
---|
87 | StoreEntityAttribute(modelEntity, Ontology.TrainingMeanAbsolutePercentageError, model.TrainingMeanAbsolutePercentageError);
|
---|
88 | StoreEntityAttribute(modelEntity, Ontology.ValidationMeanAbsolutePercentageError, model.ValidationMeanAbsolutePercentageError);
|
---|
89 | StoreEntityAttribute(modelEntity, Ontology.TestMeanAbsolutePercentageError, model.TestMeanAbsolutePercentageError);
|
---|
90 | StoreEntityAttribute(modelEntity, Ontology.TrainingMeanAbsolutePercentageOfRangeError, model.TrainingMeanAbsolutePercentageOfRangeError);
|
---|
91 | StoreEntityAttribute(modelEntity, Ontology.ValidationMeanAbsolutePercentageOfRangeError, model.ValidationMeanAbsolutePercentageOfRangeError);
|
---|
92 | StoreEntityAttribute(modelEntity, Ontology.TestMeanAbsolutePercentageOfRangeError, model.TestMeanAbsolutePercentageOfRangeError);
|
---|
93 |
|
---|
94 | for (int i = 0; i < finishedAlgorithm.Dataset.Columns; i++) {
|
---|
95 | try {
|
---|
96 | string variableName = finishedAlgorithm.Dataset.GetVariableName(i);
|
---|
97 | double qualImpact = model.GetVariableQualityImpact(variableName);
|
---|
98 | double evalImpact = model.GetVariableEvaluationImpact(variableName);
|
---|
99 |
|
---|
100 | Entity inputVariableEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());
|
---|
101 | store.Add(new Statement(inputVariableEntity, Ontology.InstanceOf, Ontology.TypeVariableImpact));
|
---|
102 | store.Add(new Statement(modelEntity, Ontology.HasInputVariable, inputVariableEntity));
|
---|
103 | StoreEntityAttribute(inputVariableEntity, Ontology.EvaluationImpact, evalImpact);
|
---|
104 | StoreEntityAttribute(inputVariableEntity, Ontology.QualityImpact, qualImpact);
|
---|
105 | StoreEntityAttribute(inputVariableEntity, Ontology.Name, variableName);
|
---|
106 | }
|
---|
107 | catch (ArgumentException) {
|
---|
108 | // ignore
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | byte[] serializedModel = PersistenceManager.SaveToGZip(model.Data);
|
---|
113 | store.Add(new Statement(modelEntity, Ontology.SerializedData, new Literal(Convert.ToBase64String(serializedModel))));
|
---|
114 | }
|
---|
115 |
|
---|
116 | private void StoreEntityAttribute(Entity entity, Entity predicate, object value) {
|
---|
117 | store.Add(new Statement(entity, predicate, new Literal(value)));
|
---|
118 | }
|
---|
119 |
|
---|
120 | public abstract string[] GetJobs();
|
---|
121 | }
|
---|
122 | }
|
---|