Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Results.cs @ 1108

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

worked on CEDMA presentation layer (bubble chart, and collection of results) (#419)

File size: 3.8 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.Linq;
25using System.Text;
26using HeuristicLab.Core;
27using System.Collections;
28using HeuristicLab.CEDMA.DB.Interfaces;
29using System.Xml;
30using System.Runtime.Serialization;
31using System.IO;
32using HeuristicLab.PluginInfrastructure;
33using HeuristicLab.Data;
34using HeuristicLab.DataAnalysis;
35using System.Drawing;
36
37namespace HeuristicLab.CEDMA.Core {
38  public class Results {
39    public static string[] CategoricalVariables {
40      get { return new string[] { "TargetVariable" }; }
41    }
42
43    public static string[] OrdinalVariables {
44      get { return new string[] { "ValidationMeanAbsolutePercentageError" }; }
45    }
46
47    private IStore store;
48    public IStore Store {
49      get { return store; }
50      set {
51        store = value;
52      }
53    }
54
55    private Entity dataSetEntity;
56
57    public Results(IStore store) {
58      this.store = store;
59    }
60
61    internal void FilterDataSet(Entity entity) {
62      this.dataSetEntity = entity;
63    }
64
65    public IEnumerable<ResultsEntry> SelectRows() {
66      if (store == null) yield break;
67
68      var results = store.Select(new Statement(dataSetEntity, Ontology.PredicateHasModel, Ontology.AnyEntity))
69         .SelectMany(x => store.Select(new SelectFilter(
70           new Entity[] { (Entity)x.Property },
71           new Entity[] { Ontology.PredicateModelAttribute },
72           new Resource[] { Ontology.AnyEntity })))
73         .SelectMany(x =>
74           store.Select(
75              new SelectFilter(
76              new Entity[] { (Entity)x.Property },
77              new Entity[] { Ontology.PredicateModelAttributeName },
78              new Entity[] { Ontology.AnyEntity })).Select(y =>
79                new {
80                  Model = x.Subject,
81                  Attribute = (Entity)x.Property,
82                  AttributeName = (Literal)y.Property
83                }))
84         .SelectMany(x =>
85           store.Select(
86             new Statement(x.Attribute, Ontology.PredicateModelAttributeValue, Ontology.AnyEntity))
87             .Select(y =>
88               new {
89                 Model = x.Model.Uri,
90                 AttributeName = x.AttributeName.Value,
91                 AttributeValue = ((Literal)y.Property).Value
92               })).GroupBy(x => x.Model);
93
94
95      Random random = new Random();
96      foreach (var row in results) {
97        ResultsEntry entry = new ResultsEntry(row.First().Model);
98        foreach (var attr in row) {
99          entry.Set((string)attr.AttributeName, attr.AttributeValue);
100        }
101        yield return entry;
102      }
103    }
104
105    internal IEnumerable<string> SelectModelAttributes() {
106      if (store == null) yield break;
107
108      var attributeNames =
109        store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateModelAttributeName, Ontology.AnyEntity))
110        .Select(s => (string)((Literal)s.Property).Value)
111        .Distinct();
112      foreach (var name in attributeNames) {
113        yield return name;
114      }
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.