[372] | 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;
|
---|
[357] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using System.Xml;
|
---|
| 28 | using System.ServiceModel;
|
---|
| 29 | using System.ServiceModel.Description;
|
---|
[2223] | 30 | using HeuristicLab.PluginInfrastructure;
|
---|
| 31 | using HeuristicLab.Modeling.Database.SQLServerCompact;
|
---|
[2289] | 32 | using HeuristicLab.SparseMatrix;
|
---|
| 33 | using HeuristicLab.Modeling.Database;
|
---|
| 34 | using HeuristicLab.CEDMA.Charting;
|
---|
[357] | 35 |
|
---|
[377] | 36 | namespace HeuristicLab.CEDMA.Core {
|
---|
[357] | 37 | public class Console : ItemBase, IEditable {
|
---|
[2273] | 38 | private static readonly string sqlServerCompactConnectionString = @"Data Source=";
|
---|
[357] | 39 |
|
---|
[2289] | 40 | public Console()
|
---|
| 41 | : base() {
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[2273] | 44 | private string database;
|
---|
| 45 | public string Database {
|
---|
| 46 | get {
|
---|
| 47 | return database;
|
---|
| 48 | }
|
---|
| 49 | set {
|
---|
| 50 | if (value != database) {
|
---|
| 51 | database = value;
|
---|
[2289] | 52 | matrix = null;
|
---|
| 53 | visualMatrix = null;
|
---|
[2273] | 54 | }
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[2325] | 58 | private Matrix<string,object> matrix;
|
---|
| 59 | public Matrix<string,object> Matrix {
|
---|
[2223] | 60 | get {
|
---|
[2289] | 61 | if (matrix == null) LoadResults();
|
---|
| 62 | return matrix;
|
---|
[2223] | 63 | }
|
---|
[357] | 64 | }
|
---|
[2289] | 65 |
|
---|
| 66 | private VisualMatrix visualMatrix;
|
---|
| 67 | public VisualMatrix VisualMatrix {
|
---|
| 68 | get {
|
---|
| 69 | if (matrix == null)
|
---|
| 70 | visualMatrix = CreateVisualMatrix();
|
---|
| 71 | return visualMatrix;
|
---|
| 72 | }
|
---|
[357] | 73 | }
|
---|
| 74 |
|
---|
| 75 | public IEditor CreateEditor() {
|
---|
| 76 | return new ConsoleEditor(this);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[383] | 79 | public override IView CreateView() {
|
---|
[357] | 80 | return new ConsoleEditor(this);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[2289] | 83 | private void LoadResults() {
|
---|
[2325] | 84 | matrix = new Matrix<string,object>();
|
---|
[2289] | 85 | DatabaseService db = new DatabaseService(sqlServerCompactConnectionString + database);
|
---|
| 86 | db.Connect();
|
---|
| 87 |
|
---|
| 88 | foreach (var model in db.GetAllModels()) {
|
---|
[2325] | 89 | MatrixRow<string, object> row = new MatrixRow<string, object>();
|
---|
[2289] | 90 | foreach (var modelResult in db.GetModelResults(model)) {
|
---|
| 91 | row.Set(modelResult.Result.Name, modelResult.Value);
|
---|
| 92 | }
|
---|
[2325] | 93 | Dictionary<HeuristicLab.Modeling.Database.IVariable, MatrixRow<string, object>> inputVariableResultsEntries =
|
---|
| 94 | new Dictionary<HeuristicLab.Modeling.Database.IVariable, MatrixRow<string, object>>();
|
---|
[2321] | 95 | foreach (IInputVariableResult inputVariableResult in db.GetInputVariableResults(model)) {
|
---|
| 96 | if (!inputVariableResultsEntries.ContainsKey(inputVariableResult.Variable)) {
|
---|
[2325] | 97 | inputVariableResultsEntries[inputVariableResult.Variable] = new MatrixRow<string, object>();
|
---|
[2321] | 98 | inputVariableResultsEntries[inputVariableResult.Variable].Set("InputVariableName", inputVariableResult.Variable.Name);
|
---|
| 99 | }
|
---|
| 100 | inputVariableResultsEntries[inputVariableResult.Variable].Set(inputVariableResult.Result.Name, inputVariableResult.Value);
|
---|
| 101 | }
|
---|
| 102 | row.Set("VariableImpacts", inputVariableResultsEntries.Values);
|
---|
[2382] | 103 | row.Set("PersistedData", db.GetModelPredictor(model));
|
---|
[2289] | 104 | row.Set("TargetVariable", model.TargetVariable.Name);
|
---|
| 105 | row.Set("Algorithm", model.Algorithm.Name);
|
---|
[2321] | 106 |
|
---|
[2289] | 107 | matrix.AddRow(row);
|
---|
| 108 | }
|
---|
| 109 | db.Disconnect();
|
---|
[357] | 110 | }
|
---|
[2289] | 111 |
|
---|
[2321] | 112 | private VisualMatrix CreateVisualMatrix() {
|
---|
[2289] | 113 | DatabaseService db = new DatabaseService(sqlServerCompactConnectionString + database);
|
---|
| 114 | db.Connect();
|
---|
[2295] | 115 | IEnumerable<string> multiDimensionalCategoricalVariables = new List<string> { "VariableImpacts: InputVariableName" };
|
---|
| 116 | IEnumerable<string> multiDimensionalOrdinalVariables = db.GetAllResultsForInputVariables().Select(x => "VariableImpacts: " + x.Name);
|
---|
| 117 | IEnumerable<string> ordinalVariables = db.GetAllResults().Select(r => r.Name);
|
---|
| 118 | IEnumerable<string> categoricalVariables = new List<string> { "TargetVariable", "Algorithm" };
|
---|
[2289] | 119 |
|
---|
| 120 | db.Disconnect();
|
---|
| 121 | VisualMatrix m = new VisualMatrix(Matrix, categoricalVariables, ordinalVariables, multiDimensionalCategoricalVariables, multiDimensionalOrdinalVariables);
|
---|
| 122 | return m;
|
---|
| 123 | }
|
---|
[357] | 124 | }
|
---|
| 125 | }
|
---|