Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/29/11 00:39:18 (13 years ago)
Author:
mkommend
Message:

#1455: Implemented first draft of ClusteringSolutionView.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Clustering/ClusteringSolutionEstimatedClusterView.cs

    r5851 r5853  
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Views {
    31   [View("ClassificationSolution EstimatedClassValues")]
    32   [Content(typeof(IClassificationSolution))]
    33   public partial class ClassificationSolutionEstimatedClassValuesView : ItemView, IClassificationSolutionEvaluationView {
    34     private const string TARGETVARIABLE_SERIES_NAME = "TargetVariable";
    35     private const string ESTIMATEDVALUES_SERIES_NAME = "EstimatedClassValues";
     31  [View("ClusteringSolution EstimatedCluster")]
     32  [Content(typeof(IClusteringSolution))]
     33  public partial class ClusteringSolutionEstimatedClusterView : ItemView, IClusteringSolutionEvaluationView {
     34    private const string CLUSTER_NAMES = "Cluster";
    3635
    37     public new IClassificationSolution Content {
    38       get { return (IClassificationSolution)base.Content; }
     36    public new IClusteringSolution Content {
     37      get { return (IClusteringSolution)base.Content; }
    3938      set {
    4039        base.Content = value;
     
    4443    private StringConvertibleMatrixView matrixView;
    4544
    46     public ClassificationSolutionEstimatedClassValuesView()
     45    public ClusteringSolutionEstimatedClusterView()
    4746      : base() {
    4847      InitializeComponent();
     
    7776    protected override void OnContentChanged() {
    7877      base.OnContentChanged();
    79       UpdateEstimatedValues();
     78      UpdateClusterValues();
    8079    }
    8180
    82     private void UpdateEstimatedValues() {
    83       if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
     81    private void UpdateClusterValues() {
     82      if (InvokeRequired) Invoke((Action)UpdateClusterValues);
    8483      else {
    8584        DoubleMatrix matrix = null;
    8685        if (Content != null) {
    87           double[,] values = new double[Content.ProblemData.Dataset.Rows, 2];
     86          int[] clusters = Content.Model.GetClusterValues(Content.ProblemData.Dataset, Enumerable.Range(0, Content.ProblemData.Dataset.Rows)).ToArray();
     87          var dataset = Content.ProblemData.Dataset;
     88          int columns = Content.ProblemData.AllowedInputVariables.Count() + 1;
     89          var columnsIndixes = Content.ProblemData.AllowedInputVariables.Select(x => dataset.GetVariableIndex(x)).ToList();
    8890
    89           double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
    90           double[] estimated = Content.EstimatedClassValues.ToArray();
    91           for (int row = 0; row < target.Length; row++) {
    92             values[row, 0] = target[row];
    93             values[row, 1] = estimated[row];
     91          double[,] values = new double[dataset.Rows, columns];
     92          for (int row = 0; row < dataset.Rows; row++) {
     93            values[row, 0] = clusters[row];
     94
     95            int column = 1;
     96            foreach (int columnIndex in columnsIndixes) {
     97              values[row, column] = dataset[row, columnIndex];
     98              column++;
     99            }
    94100          }
    95101
    96102          matrix = new DoubleMatrix(values);
    97           matrix.ColumnNames = new string[] { TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME };
     103          var columnNames = dataset.VariableNames.ToList();
     104          columnNames.Insert(0, CLUSTER_NAMES);
     105          matrix.ColumnNames = columnNames;
    98106        }
    99107        matrixView.Content = matrix;
Note: See TracChangeset for help on using the changeset viewer.