[1044] | 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;
|
---|
[1053] | 34 | using HeuristicLab.GP.StructureIdentification;
|
---|
| 35 | using HeuristicLab.Data;
|
---|
[1060] | 36 | using HeuristicLab.Core;
|
---|
[1857] | 37 | using HeuristicLab.Modeling;
|
---|
[1044] | 38 |
|
---|
| 39 | namespace HeuristicLab.CEDMA.Server {
|
---|
[1287] | 40 | public abstract class DispatcherBase : IDispatcher {
|
---|
[1044] | 41 | private IStore store;
|
---|
[2012] | 42 | private DataSet dataset;
|
---|
| 43 |
|
---|
[1217] | 44 | public DispatcherBase(IStore store) {
|
---|
[1044] | 45 | this.store = store;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[1922] | 48 | public IAlgorithm GetNextJob() {
|
---|
[2012] | 49 | if (dataset == null) {
|
---|
| 50 | var datasetEntities = store.Query("?DataSet <" + Ontology.PredicateInstanceOf.Uri + "> <" + Ontology.TypeDataSet.Uri + "> .", 0, 1)
|
---|
| 51 | .Select(x => (Entity)x.Get("DataSet"));
|
---|
| 52 | if (datasetEntities.Count() == 0) return null;
|
---|
| 53 | dataset = new DataSet(store, datasetEntities.ElementAt(0));
|
---|
| 54 | }
|
---|
| 55 | int targetVariable = SelectTargetVariable(dataset.Problem.AllowedTargetVariables.ToArray());
|
---|
| 56 | IAlgorithm selectedAlgorithm = SelectAlgorithm(targetVariable, dataset.Problem.LearningTask);
|
---|
| 57 | string targetVariableName = dataset.Problem.GetVariableName(targetVariable);
|
---|
[1130] | 58 |
|
---|
[1857] | 59 | if (selectedAlgorithm != null) {
|
---|
[2012] | 60 | SetProblemParameters(selectedAlgorithm, dataset.Problem, targetVariable);
|
---|
[1922] | 61 | }
|
---|
| 62 | return selectedAlgorithm;
|
---|
[1044] | 63 | }
|
---|
| 64 |
|
---|
[2012] | 65 | public abstract int SelectTargetVariable(int[] targetVariables);
|
---|
| 66 | public abstract IAlgorithm SelectAlgorithm(int targetVariable, LearningTask learningTask);
|
---|
[1060] | 67 |
|
---|
[1857] | 68 | private void SetProblemParameters(IAlgorithm algo, Problem problem, int targetVariable) {
|
---|
[2000] | 69 | algo.Dataset = problem.Dataset;
|
---|
[1922] | 70 | algo.TargetVariable = targetVariable;
|
---|
[1287] | 71 | algo.ProblemInjector.GetVariable("TrainingSamplesStart").GetValue<IntData>().Data = problem.TrainingSamplesStart;
|
---|
| 72 | algo.ProblemInjector.GetVariable("TrainingSamplesEnd").GetValue<IntData>().Data = problem.TrainingSamplesEnd;
|
---|
| 73 | algo.ProblemInjector.GetVariable("ValidationSamplesStart").GetValue<IntData>().Data = problem.ValidationSamplesStart;
|
---|
| 74 | algo.ProblemInjector.GetVariable("ValidationSamplesEnd").GetValue<IntData>().Data = problem.ValidationSamplesEnd;
|
---|
| 75 | algo.ProblemInjector.GetVariable("TestSamplesStart").GetValue<IntData>().Data = problem.TestSamplesStart;
|
---|
| 76 | algo.ProblemInjector.GetVariable("TestSamplesEnd").GetValue<IntData>().Data = problem.TestSamplesEnd;
|
---|
| 77 | ItemList<IntData> allowedFeatures = algo.ProblemInjector.GetVariable("AllowedFeatures").GetValue<ItemList<IntData>>();
|
---|
| 78 | foreach (int allowedFeature in problem.AllowedInputVariables) allowedFeatures.Add(new IntData(allowedFeature));
|
---|
| 79 |
|
---|
| 80 | if (problem.LearningTask == LearningTask.TimeSeries) {
|
---|
| 81 | algo.ProblemInjector.GetVariable("Autoregressive").GetValue<BoolData>().Data = problem.AutoRegressive;
|
---|
| 82 | algo.ProblemInjector.GetVariable("MinTimeOffset").GetValue<IntData>().Data = problem.MinTimeOffset;
|
---|
| 83 | algo.ProblemInjector.GetVariable("MaxTimeOffset").GetValue<IntData>().Data = problem.MaxTimeOffset;
|
---|
| 84 | } else if (problem.LearningTask == LearningTask.Classification) {
|
---|
| 85 | ItemList<DoubleData> classValues = algo.ProblemInjector.GetVariable("TargetClassValues").GetValue<ItemList<DoubleData>>();
|
---|
[2000] | 86 | foreach (double classValue in GetDifferentClassValues(problem.Dataset, targetVariable)) classValues.Add(new DoubleData(classValue));
|
---|
[1287] | 87 | }
|
---|
[1053] | 88 | }
|
---|
[1287] | 89 |
|
---|
| 90 | private IEnumerable<double> GetDifferentClassValues(HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable) {
|
---|
| 91 | return Enumerable.Range(0, dataset.Rows).Select(x => dataset.GetValue(x, targetVariable)).Distinct();
|
---|
| 92 | }
|
---|
[1044] | 93 | }
|
---|
| 94 | }
|
---|