[553] | 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.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using System.Collections;
|
---|
| 28 | using HeuristicLab.CEDMA.DB.Interfaces;
|
---|
| 29 | using System.Xml;
|
---|
| 30 | using System.Runtime.Serialization;
|
---|
| 31 | using System.IO;
|
---|
| 32 | using HeuristicLab.Operators;
|
---|
| 33 |
|
---|
| 34 | namespace HeuristicLab.CEDMA.Core {
|
---|
| 35 | public class ResultList : ItemBase {
|
---|
| 36 | private const string cedmaNS = "http://www.heuristiclab.com/cedma/";
|
---|
| 37 |
|
---|
| 38 | private const string MAPE_TRAINING = "MAPE (training)";
|
---|
| 39 | private const string MAPE_VALIDATION = "MAPE (validation)";
|
---|
| 40 | private const string MAPE_TEST = "MAPE (test)";
|
---|
| 41 | private const string R2_TRAINING = "R2 (training)";
|
---|
| 42 | private const string R2_VALIDATION = "R2 (validation)";
|
---|
| 43 | private const string R2_TEST = "R2 (test)";
|
---|
| 44 | private const string TARGET_VARIABLE = "Target variable";
|
---|
| 45 | private const string TREE_SIZE = "Tree size";
|
---|
| 46 | private const string TREE_HEIGHT = "Tree height";
|
---|
| 47 |
|
---|
| 48 | private readonly Entity targetVariablePredicate = new Entity(cedmaNS + "TargetVariable");
|
---|
| 49 | private readonly Entity trainingMAPEPredicate = new Entity(cedmaNS + "MeanAbsolutePercentageErrorTraining");
|
---|
| 50 | private readonly Entity validationMAPEPredicate = new Entity(cedmaNS + "MeanAbsolutePercentageErrorValidation");
|
---|
| 51 | private readonly Entity testMAPEPredicate = new Entity(cedmaNS + "MeanAbsolutePercentageErrorTest");
|
---|
| 52 | private readonly Entity trainingR2Predicate = new Entity(cedmaNS + "CoefficientOfDeterminationTraining");
|
---|
| 53 | private readonly Entity validationR2Predicate = new Entity(cedmaNS + "CoefficientOfDeterminationValidation");
|
---|
| 54 | private readonly Entity testR2Predicate = new Entity(cedmaNS + "CoefficientOfDeterminationTest");
|
---|
| 55 | private readonly Entity treeSizePredicate = new Entity(cedmaNS + "TreeSize");
|
---|
| 56 | private readonly Entity treeHeightPredicate = new Entity(cedmaNS + "TreeHeight");
|
---|
| 57 | private readonly Entity anyEntity = new Entity(null);
|
---|
| 58 |
|
---|
| 59 | private IStore store;
|
---|
| 60 | public IStore Store {
|
---|
| 61 | get { return store; }
|
---|
| 62 | set {
|
---|
| 63 | store = value;
|
---|
| 64 | ReloadList();
|
---|
| 65 | FireChanged();
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | private List<string> variableNames = new List<string>() { TARGET_VARIABLE, TREE_SIZE, TREE_HEIGHT,
|
---|
| 69 | MAPE_TRAINING, MAPE_VALIDATION, MAPE_TEST,
|
---|
| 70 | R2_TRAINING, R2_VALIDATION, R2_TEST};
|
---|
| 71 | public string[] VariableNames {
|
---|
| 72 | get {
|
---|
| 73 | return variableNames.ToArray();
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | private Dictionary<string, List<double>> allVariables;
|
---|
| 77 |
|
---|
| 78 | private void ReloadList() {
|
---|
| 79 | allVariables.Clear();
|
---|
| 80 | List<double> trainingMAPE = new List<double>();
|
---|
| 81 | List<double> validationMAPE = new List<double>();
|
---|
| 82 | List<double> testMAPE = new List<double>();
|
---|
| 83 | List<double> trainingR2 = new List<double>();
|
---|
| 84 | List<double> validationR2 = new List<double>();
|
---|
| 85 | List<double> testR2 = new List<double>();
|
---|
| 86 | List<double> size = new List<double>();
|
---|
| 87 | List<double> height = new List<double>();
|
---|
| 88 | List<double> targetVariable = new List<double>();
|
---|
| 89 | allVariables[MAPE_TRAINING] = trainingMAPE;
|
---|
| 90 | allVariables[MAPE_VALIDATION] = validationMAPE;
|
---|
| 91 | allVariables[MAPE_TEST] = testMAPE;
|
---|
| 92 | allVariables[R2_TRAINING] = trainingR2;
|
---|
| 93 | allVariables[R2_VALIDATION] = validationR2;
|
---|
| 94 | allVariables[R2_TEST] = testR2;
|
---|
| 95 | allVariables[TREE_SIZE] = size;
|
---|
| 96 | allVariables[TREE_HEIGHT] = height;
|
---|
| 97 | allVariables[TARGET_VARIABLE] = targetVariable;
|
---|
| 98 |
|
---|
| 99 | var results = store.Select(new Statement(anyEntity, new Entity(cedmaNS + "instanceOf"), new Literal("class:GpFunctionTree")))
|
---|
| 100 | .Select(x => store.Select(new SelectFilter(
|
---|
| 101 | new Entity[] { new Entity(x.Subject.Uri) },
|
---|
| 102 | new Entity[] { targetVariablePredicate, treeSizePredicate, treeHeightPredicate,
|
---|
| 103 | trainingMAPEPredicate, validationMAPEPredicate, testMAPEPredicate,
|
---|
| 104 | trainingR2Predicate, validationR2Predicate, testR2Predicate },
|
---|
| 105 | new Resource[] { anyEntity })));
|
---|
| 106 |
|
---|
| 107 | Random random = new Random(); // for adding random noise to int values
|
---|
| 108 | foreach(Statement[] ss in results) {
|
---|
| 109 | targetVariable.Add(double.NaN);
|
---|
| 110 | size.Add(double.NaN);
|
---|
| 111 | height.Add(double.NaN);
|
---|
| 112 | trainingMAPE.Add(double.NaN);
|
---|
| 113 | validationMAPE.Add(double.NaN);
|
---|
| 114 | testMAPE.Add(double.NaN);
|
---|
| 115 | trainingR2.Add(double.NaN);
|
---|
| 116 | validationR2.Add(double.NaN);
|
---|
| 117 | testR2.Add(double.NaN);
|
---|
| 118 | foreach(Statement s in ss) {
|
---|
| 119 | if(s.Predicate.Equals(targetVariablePredicate)) {
|
---|
| 120 | ReplaceLastItem(targetVariable, (double)(int)((Literal)s.Property).Value);
|
---|
| 121 | } else if(s.Predicate.Equals(treeSizePredicate)) {
|
---|
| 122 | ReplaceLastItem(size, (double)(int)((Literal)s.Property).Value);
|
---|
| 123 | } else if(s.Predicate.Equals(treeHeightPredicate)) {
|
---|
| 124 | ReplaceLastItem(height, (double)(int)((Literal)s.Property).Value);
|
---|
| 125 | } else if(s.Predicate.Equals(trainingMAPEPredicate)) {
|
---|
| 126 | ReplaceLastItem(trainingMAPE, (double)((Literal)s.Property).Value);
|
---|
| 127 | } else if(s.Predicate.Equals(validationMAPEPredicate)) {
|
---|
| 128 | ReplaceLastItem(validationMAPE, (double)((Literal)s.Property).Value);
|
---|
| 129 | } else if(s.Predicate.Equals(testMAPEPredicate)) {
|
---|
| 130 | ReplaceLastItem(testMAPE, (double)((Literal)s.Property).Value);
|
---|
| 131 | } else if(s.Predicate.Equals(trainingR2Predicate)) {
|
---|
| 132 | ReplaceLastItem(trainingR2, (double)((Literal)s.Property).Value);
|
---|
| 133 | } else if(s.Predicate.Equals(validationR2Predicate)) {
|
---|
| 134 | ReplaceLastItem(validationR2, (double)((Literal)s.Property).Value);
|
---|
| 135 | } else if(s.Predicate.Equals(testR2Predicate)) {
|
---|
| 136 | ReplaceLastItem(testR2, (double)((Literal)s.Property).Value);
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | private void ReplaceLastItem(List<double> xs, double x) {
|
---|
| 143 | xs.RemoveAt(xs.Count - 1); xs.Add(x);
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | public ResultList()
|
---|
| 147 | : base() {
|
---|
| 148 | allVariables = new Dictionary<string, List<double>>();
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | public override IView CreateView() {
|
---|
| 152 | return new ResultListView(this);
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | internal Histogram GetHistogram(string variableName) {
|
---|
| 156 | Histogram h = new Histogram(50);
|
---|
| 157 | h.AddValues(allVariables[variableName]);
|
---|
| 158 | return h;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | internal IList<double> GetValues(string variableName) {
|
---|
| 162 | return allVariables[variableName];
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 | }
|
---|