#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Linq;
using System.Windows.Forms;
using HeuristicLab.Data;
using HeuristicLab.Data.Views;
using HeuristicLab.MainForm;
using HeuristicLab.MainForm.WindowsForms;
using System.Collections.Generic;
namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.Views {
[View("Estimated Values View")]
[Content(typeof(IMultiVariateDataAnalysisSolution))]
public partial class EstimatedValuesView : AsynchronousContentView {
private const string TARGETVARIABLE_SERIES_NAME = "TargetVariable";
private const string ESTIMATEDVALUES_SERIES_NAME = "EstimatedValues";
public new IMultiVariateDataAnalysisSolution Content {
get { return (IMultiVariateDataAnalysisSolution)base.Content; }
set {
base.Content = value;
}
}
private StringConvertibleMatrixView matrixView;
public EstimatedValuesView()
: base() {
InitializeComponent();
matrixView = new StringConvertibleMatrixView();
matrixView.Dock = DockStyle.Fill;
this.Controls.Add(matrixView);
}
#region events
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
}
protected override void DeregisterContentEvents() {
base.DeregisterContentEvents();
Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
}
void Content_ProblemDataChanged(object sender, EventArgs e) {
OnContentChanged();
}
protected override void OnContentChanged() {
base.OnContentChanged();
UpdateEstimatedValues();
}
private void UpdateEstimatedValues() {
if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
else {
DoubleMatrix matrix = null;
if (Content != null) {
IEnumerable targetVariables = Content.ProblemData.TargetVariables.CheckedItems.Select(x => x.Value.Value);
List estimatedValues = Content.EstimatedValues.ToList();
double[,] values = new double[estimatedValues.Count, targetVariables.Count() * 2];
for (int row = 0; row < estimatedValues.Count; row++) {
int col = 0;
foreach (string targetVariable in targetVariables) {
values[row, col++] = Content.ProblemData.Dataset[targetVariable, row];
values[row, col++] = estimatedValues[row][(col - 1) / 2];
}
}
matrix = new DoubleMatrix(values);
string[] partitions = new string[] { "(original)", "(estimated)" };
matrix.ColumnNames = from targetVariable in targetVariables
from partition in partitions
select targetVariable + " " + partition;
;
}
matrixView.Content = matrix;
}
}
#endregion
}
}