Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15297


Ignore:
Timestamp:
07/29/17 16:03:05 (7 years ago)
Author:
gkronber
Message:

#2695: added a parameter to DataAnalysisProblemData to select an id column and extended RegressionLinechartViewBase to show the id on the xAxis

Location:
branches/dataset-ids-2695
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/dataset-ids-2695/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartViewBase.cs

    r14531 r15297  
    2020#endregion
    2121using System;
     22using System.Collections;
    2223using System.Collections.Generic;
    2324using System.Drawing;
     25using System.Globalization;
    2426using System.Linq;
    2527using System.Windows.Forms;
    2628using System.Windows.Forms.DataVisualization.Charting;
     29using HeuristicLab.Common;
    2730using HeuristicLab.MainForm;
    2831using HeuristicLab.Visualization.ChartControlsExtensions;
     
    5962    protected abstract void GetTrainingSeries(out int[] idx, out double[] y);
    6063
    61     protected abstract void GetTestSeries(out int[] x, out double[] y);
    62 
    63     protected abstract void GetAllValuesSeries(out int[] x, out double[] y);
     64    protected abstract void GetTestSeries(out int[] idx, out double[] y);
     65
     66    protected abstract void GetAllValuesSeries(out int[] idx, out double[] y);
    6467
    6568    protected virtual void RedrawChart() {
    6669      this.chart.Series.Clear();
    6770      if (Content != null) {
     71        var allIds = Content.ProblemData.AllIds;
    6872        this.chart.ChartAreas[0].AxisX.Minimum = 0;
    69         this.chart.ChartAreas[0].AxisX.Maximum = Content.ProblemData.Dataset.Rows - 1;
     73        this.chart.ChartAreas[0].AxisX.Maximum = Content.ProblemData.AllIndices.Last();
    7074
    7175        this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
    7276        this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = TARGETVARIABLE_SERIES_NAME;
    7377        this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    74         this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(),
    75           Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray());
     78        var ids = Content.ProblemData.AllIds.OfType<object>().Select(o => o.ToString()).ToArray();
     79        var vals = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
     80
     81        for (int i = 0; i < ids.Length; i++) {
     82          chart.Series[TARGETVARIABLE_SERIES_NAME].Points.Add(new DataPoint() { AxisLabel = ids[i], XValue = i, YValues = new double[] { vals[i] } });
     83        }
     84        // this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Content.ProblemData.AllIndices.ToArray(),
     85        //   Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray());
     86        // chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Content.ProblemData.AllIndices.ToArray(),
     87        //   "AxisLabel", Content.ProblemData.AllIds.OfType<object>().Select(o => o.ToString()).ToArray(), string.Empty);
    7688        // training series
    7789        this.chart.Series.Add(ESTIMATEDVALUES_TRAINING_SERIES_NAME);
     
    133145
    134146        UpdateCursorInterval();
    135         this.UpdateStripLines();
     147        UpdateStripLines();
    136148      }
    137149    }
  • branches/dataset-ids-2695/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r14843 r15297  
    2121
    2222using System;
     23using System.Collections;
    2324using System.Collections.Generic;
    2425using System.Linq;
     
    3940    protected const string TestPartitionParameterName = "TestPartition";
    4041    protected const string TransformationsParameterName = "Transformations";
    41 
     42    protected const string IdVariableParameterName = "Id Variable";
     43    protected const string EmptyIdVariableName = "-";
    4244    #region parameter properites
    4345    //mkommend: inserted parameter caching due to performance reasons
     
    5860    }
    5961
     62    private IConstrainedValueParameter<StringValue> idVariableParameter;
     63    public IConstrainedValueParameter<StringValue> IdVariableParameter {
     64      get {
     65        if (idVariableParameter == null) idVariableParameter = (IConstrainedValueParameter<StringValue>)Parameters[IdVariableParameterName];
     66        return idVariableParameter;
     67      }
     68    }
     69
    6070    private IFixedValueParameter<IntRange> trainingPartitionParameter;
    6171    public IFixedValueParameter<IntRange> TrainingPartitionParameter {
     
    92102    public IEnumerable<string> AllowedInputVariables {
    93103      get { return InputVariables.CheckedItems.Select(x => x.Value.Value); }
     104    }
     105    public string IdVariable {
     106      get { return IdVariableParameter.Value.Value; }
     107      // set only possible via parameter
     108    }
     109    public IEnumerable AllIds {
     110      get {
     111        var idVar = IdVariable;
     112        if (idVar == EmptyIdVariableName) return Enumerable.Range(0, Dataset.Rows);
     113        else if (Dataset.VariableHasType<double>(idVar)) return Dataset.GetDoubleValues(idVar);
     114        else if (Dataset.VariableHasType<DateTime>(idVar)) return Dataset.GetDateTimeValues(idVar);
     115        else if (Dataset.VariableHasType<string>(idVar)) return Dataset.GetStringValues(idVar);
     116        else throw new NotSupportedException("The data type of the id variable is not supported");
     117      }
     118    }
     119    public IEnumerable TrainingIds {
     120      get {
     121        var idVar = IdVariable;
     122        if (idVar == EmptyIdVariableName) return TrainingIndices;
     123        else if (Dataset.VariableHasType<double>(idVar)) return Dataset.GetDoubleValues(idVar, TrainingIndices);
     124        else if (Dataset.VariableHasType<DateTime>(idVar)) return Dataset.GetDateTimeValues(idVar, TrainingIndices);
     125        else if (Dataset.VariableHasType<string>(idVar)) return Dataset.GetStringValues(idVar, TrainingIndices);
     126        else throw new NotSupportedException("The data type of the id variable is not supported");
     127      }
     128    }
     129    public IEnumerable TestIds {
     130      get {
     131        var idVar = IdVariable;
     132        if (idVar == EmptyIdVariableName) return TestIndices;
     133        else if (Dataset.VariableHasType<double>(idVar)) return Dataset.GetDoubleValues(idVar, TestIndices);
     134        else if (Dataset.VariableHasType<DateTime>(idVar)) return Dataset.GetDateTimeValues(idVar, TestIndices);
     135        else if (Dataset.VariableHasType<string>(idVar)) return Dataset.GetStringValues(idVar, TestIndices);
     136        else throw new NotSupportedException("The data type of the id variable is not supported");
     137      }
    94138    }
    95139
     
    152196        TransformationsParameter.Hidden = true;
    153197      }
     198      if (!Parameters.ContainsKey(IdVariableParameterName)) {
     199        var allIdVars = new ItemSet<StringValue>(GetIdVariableNames());
     200        var idVar = allIdVars.First();
     201        Parameters.Add(new ConstrainedValueParameter<StringValue>(IdVariableParameterName, "", allIdVars, idVar));
     202        TransformationsParameter.Hidden = true;
     203      }
    154204      RegisterEventHandlers();
     205    }
     206
     207    private IEnumerable<StringValue> GetIdVariableNames() {
     208      // all variables with number of different values == number of rows
     209      // + a separate entry for row id
     210      // select separate entry for row id as default
     211      // use event to update when the dataset is changed
     212      var nRows = Dataset.Rows;
     213      var potentialDoubleIdVars = Dataset.DoubleVariables
     214        .Where(vn => Dataset.GetReadOnlyDoubleValues(vn).Distinct().Count() == nRows).ToArray();
     215      var potentialStringIdVars = Dataset.StringVariables
     216        .Where(vn => Dataset.GetReadOnlyStringValues(vn).Distinct().Count() == nRows).ToArray();
     217      var potentialDateTimeIdVars = Dataset.DateTimeVariables
     218        .Where(vn => Dataset.GetReadOnlyDateTimeValues(vn).Distinct().Count() == nRows).ToArray();
     219      return
     220        new string[] { EmptyIdVariableName }
     221        .Concat(potentialStringIdVars)
     222        .Concat(potentialDateTimeIdVars)
     223        .Concat(potentialDoubleIdVars)
     224        .Select(s => new StringValue(s));
    155225    }
    156226
     
    179249      Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", new IntRange(testPartitionStart, testPartitionEnd)));
    180250      Parameters.Add(new FixedValueParameter<ReadOnlyItemList<ITransformation>>(TransformationsParameterName, "", transformationsList.AsReadOnly()));
    181 
    182251      TransformationsParameter.Hidden = true;
     252      var allIdVars = new ItemSet<StringValue>(GetIdVariableNames());
     253      Parameters.Add(new ConstrainedValueParameter<StringValue>(IdVariableParameterName, "The variable to use as an ID column", allIdVars, allIdVars.First()));
    183254
    184255      ((ValueParameter<Dataset>)DatasetParameter).ReactOnValueToStringChangedAndValueItemImageChanged = false;
     
    199270
    200271    private void Parameter_ValueChanged(object sender, EventArgs e) {
     272      // update list of possible id variables and set currently set id variable if possible
     273      var curId = IdVariable;
     274      var newIdVars = GetIdVariableNames().ToArray();
     275      var matchingIdVar = newIdVars.FirstOrDefault(var => var.Value == curId);
     276      if (matchingIdVar == null) matchingIdVar = newIdVars.First();
     277      IdVariableParameter.ValidValues.Clear();
     278      var validValues = IdVariableParameter.ValidValues;
     279      foreach(var entry in newIdVars) validValues.Add(entry);
     280      IdVariableParameter.Value = matchingIdVar;
     281
    201282      OnChanged();
    202283    }
  • branches/dataset-ids-2695/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs

    r14843 r15297  
    2121
    2222using System;
     23using System.Collections;
    2324using System.Collections.Generic;
    2425using HeuristicLab.Core;
     
    3233    ICheckedItemList<StringValue> InputVariables { get; }
    3334    IEnumerable<string> AllowedInputVariables { get; }
     35    string IdVariable { get; }
    3436
    3537    double[,] AllowedInputsTrainingValues { get; }
     
    3941    IntRange TestPartition { get; }
    4042
     43    IEnumerable AllIds { get; }
     44    IEnumerable TrainingIds { get; }
     45    IEnumerable TestIds { get; }
    4146    IEnumerable<int> AllIndices { get; }
    4247    IEnumerable<int> TrainingIndices { get; }
Note: See TracChangeset for help on using the changeset viewer.