Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Server/3.3/RandomDispatcher.cs @ 1857

Last change on this file since 1857 was 1857, checked in by gkronber, 15 years ago

Worked on lose coupling of CEDMA and GP/SVR with plugin HeuristicLab.Modeling as common bridge. #635

File size: 3.0 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.Core;
37using HeuristicLab.Modeling;
38
39namespace HeuristicLab.CEDMA.Server {
40  public class RandomDispatcher : DispatcherBase {
41    private Random random;
42    public RandomDispatcher(IStore store)
43      : base(store) {
44      random = new Random();
45    }
46
47    public override IAlgorithm SelectAlgorithm(DataSet dataSet, int targetVariable, LearningTask learningTask) {
48      DiscoveryService ds = new DiscoveryService();
49      IAlgorithm[] algos = ds.GetInstances<IAlgorithm>();
50      switch (learningTask) {
51        case LearningTask.Regression: {
52            var regressionAlgos = algos.Where(a => (a as IClassificationAlgorithm) == null && (a as ITimeSeriesAlgorithm) == null);
53            if (regressionAlgos.Count() == 0) return null;
54            return regressionAlgos.ElementAt(random.Next(regressionAlgos.Count()));
55          }
56        case LearningTask.Classification: {
57            var classificationAlgos = algos.Where(a => (a as IClassificationAlgorithm) != null);
58            if (classificationAlgos.Count() == 0) return null;
59            return classificationAlgos.ElementAt(random.Next(classificationAlgos.Count()));
60          }
61        case LearningTask.TimeSeries: {
62            var timeSeriesAlgos = algos.Where(a => (a as ITimeSeriesAlgorithm) != null);
63            if (timeSeriesAlgos.Count() == 0) return null;
64            return timeSeriesAlgos.ElementAt(random.Next(timeSeriesAlgos.Count()));
65          }
66      }
67      return null;
68    }
69
70    public override Entity SelectDataSet(Entity[] datasets) {
71      return datasets[random.Next(datasets.Length)];
72    }
73
74    public override int SelectTargetVariable(DataSet dataSet, int[] targetVariables) {
75      return targetVariables[random.Next(targetVariables.Length)];
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.