Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Operator Architecture Refactoring/HeuristicLab.CEDMA.Server/3.3/ExecuterBase.cs @ 2614

Last change on this file since 2614 was 1922, checked in by gkronber, 16 years ago

#650 (IAlgorithm and derived interfaces should provide properties to retrieve results):

  • Implemented properties to retrieve model quality
  • Changed CEDMA executor to retrieve results via properties
  • Removed obsolete class Execution in CEDMA (replaced by the interface IAlgorithm)
File size: 4.9 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Text;
25using System.Windows.Forms;
26using HeuristicLab.PluginInfrastructure;
27using System.Net;
28using System.ServiceModel;
29using HeuristicLab.CEDMA.DB.Interfaces;
30using HeuristicLab.CEDMA.DB;
31using System.ServiceModel.Description;
32using System.Linq;
33using HeuristicLab.CEDMA.Core;
34using HeuristicLab.GP.StructureIdentification;
35using HeuristicLab.Data;
36using HeuristicLab.Grid;
37using System.Diagnostics;
38using HeuristicLab.Core;
39using System.Threading;
40using HeuristicLab.Modeling;
41
42namespace 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      // TODO (gkronber 27052009)
74      // store.Add(new Statement(finishedAlgorithm.DataSetEntity, Ontology.PredicateHasModel, modelEntity));
75      StoreModelAttribute(modelEntity, Ontology.TargetVariable, finishedAlgorithm.Model.TargetVariable);
76      StoreModelAttribute(modelEntity, Ontology.AlgorithmName, finishedAlgorithm.Description);
77     
78      IModel model = finishedAlgorithm.Model;
79      StoreModelAttribute(modelEntity, Ontology.TrainingMeanSquaredError, model.TrainingMeanSquaredError);
80      StoreModelAttribute(modelEntity, Ontology.ValidationMeanSquaredError, model.ValidationMeanSquaredError);
81      StoreModelAttribute(modelEntity, Ontology.TestMeanSquaredError, model.TestMeanSquaredError);
82      StoreModelAttribute(modelEntity, Ontology.TrainingCoefficientOfDetermination, model.TrainingCoefficientOfDetermination);
83      StoreModelAttribute(modelEntity, Ontology.ValidationCoefficientOfDetermination, model.ValidationCoefficientOfDetermination);
84      StoreModelAttribute(modelEntity, Ontology.TestCoefficientOfDetermination, model.TestCoefficientOfDetermination);
85      StoreModelAttribute(modelEntity, Ontology.TrainingVarianceAccountedFor, model.TrainingVarianceAccountedFor);
86      StoreModelAttribute(modelEntity, Ontology.ValidationVarianceAccountedFor, model.ValidationVarianceAccountedFor);
87      StoreModelAttribute(modelEntity, Ontology.TestVarianceAccountedFor, model.TestVarianceAccountedFor);
88      StoreModelAttribute(modelEntity, Ontology.TrainingMeanAbsolutePercentageError, model.TrainingMeanAbsolutePercentageError);
89      StoreModelAttribute(modelEntity, Ontology.ValidationMeanAbsolutePercentageError, model.ValidationMeanAbsolutePercentageError);
90      StoreModelAttribute(modelEntity, Ontology.TestMeanAbsolutePercentageError, model.TestMeanAbsolutePercentageError);
91      StoreModelAttribute(modelEntity, Ontology.TrainingMeanAbsolutePercentageOfRangeError, model.TrainingMeanAbsolutePercentageOfRangeError);
92      StoreModelAttribute(modelEntity, Ontology.ValidationMeanAbsolutePercentageOfRangeError, model.ValidationMeanAbsolutePercentageOfRangeError);
93      StoreModelAttribute(modelEntity, Ontology.TestMeanAbsolutePercentageOfRangeError, model.TestMeanAbsolutePercentageOfRangeError);
94
95      byte[] serializedModel = PersistenceManager.SaveToGZip(model.Data);
96      store.Add(new Statement(modelEntity, Ontology.PredicateSerializedData, new Literal(Convert.ToBase64String(serializedModel))));
97    }
98
99    private void StoreModelAttribute(Entity model, Entity predicate, object value) {
100      store.Add(new Statement(model, predicate, new Literal(value)));
101    }
102
103    public abstract string[] GetJobs();
104  }
105}
Note: See TracBrowser for help on using the repository browser.