Free cookie consent management tool by TermsFeed Policy Generator

source: branches/XmlTextWriterBranch/HeuristicLab.StructureIdentification/Evaluation/FunctionEvaluator.cs @ 165

Last change on this file since 165 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

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 HeuristicLab.Core;
26using HeuristicLab.Data;
27using System.Diagnostics;
28using HeuristicLab.Functions;
29using HeuristicLab.Operators;
30using HeuristicLab.DataAnalysis;
31
32namespace HeuristicLab.StructureIdentification {
33  public class FunctionEvaluator : OperatorBase {
34    public override string Description {
35      get { return @"Evaluates 'FunctionTree' on samples 'FirstSampleIndex' - 'LastSampleIndex' (inclusive) of
36'Dataset' and stores the results in array 'Results'."; }
37    }
38
39    public FunctionEvaluator()
40      : base() {
41      AddVariableInfo(new VariableInfo("FunctionTree", "The combined operator containing a function tree that should be evaluated", typeof(IFunction), VariableKind.In));
42      AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In));
43      AddVariableInfo(new VariableInfo("FirstSampleIndex", "Index of the first row of the dataSet on which the function should be evaluated", typeof(IntData), VariableKind.In));
44      AddVariableInfo(new VariableInfo("LastSampleIndex", "Index of the last row of the dataSet on which the function should be evaluated (inclusive)", typeof(IntData), VariableKind.In));
45      AddVariableInfo(new VariableInfo("Results", "Array of results of the function for each sample", typeof(DoubleArrayData), VariableKind.New));
46    }
47
48    public override IOperation Apply(IScope scope) {
49
50      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
51      double[] results = new double[dataset.Rows];
52
53      IFunction function = GetVariableValue<IFunction>("FunctionTree", scope, true);
54
55      int firstIndex = GetVariableValue<IntData>("FirstSampleIndex", scope, true).Data;
56      int lastIndex = GetVariableValue<IntData>("LastSampleIndex", scope, true).Data;
57
58      for(int sample = firstIndex; sample <= lastIndex; sample++) {
59        results[sample] = function.Evaluate(dataset, sample);
60      }
61
62      scope.AddVariable(new HeuristicLab.Core.Variable("Results", new DoubleArrayData(results)));
63      return null;
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.