Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/10/08 16:21:36 (17 years ago)
Author:
gkronber
Message:

added possibility to manually scale data. (ticket #167)

Location:
trunk/sources/HeuristicLab.DataAnalysis
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DataAnalysis/Dataset.cs

    r237 r312  
    4242    private Dictionary<int, Dictionary<int, double>>[] cachedRanges;
    4343    private double[] scalingFactor;
     44
     45    public double[] ScalingFactor {
     46      get { return scalingFactor; }
     47    }
    4448    private double[] scalingOffset;
     49
     50    public double[] ScalingOffset {
     51      get { return scalingOffset; }
     52    }
    4553
    4654    public int Rows {
     
    296304
    297305    internal void ScaleVariable(int column) {
    298       if(scalingFactor[column] == 1.0) {
     306      if(scalingFactor[column] == 1.0 && scalingOffset[column] == 0.0) {
    299307        double min = GetMinimum(column);
    300308        double max = GetMaximum(column);
    301309        double range = max - min;
    302         scalingFactor[column] = range;
    303         scalingOffset[column] = min;
    304         for(int i = 0; i < Rows; i++) {
    305           double origValue = samples[i * columns + column];
    306           samples[i * columns + column] = (origValue - min) / range;
    307         }
     310        if(range == 0) ScaleVariable(column, 1.0, -min);
     311        else ScaleVariable(column, 1.0 / range, -min);
    308312      }
    309313      CreateDictionaries();
     
    311315    }
    312316
     317    internal void ScaleVariable(int column, double factor, double offset) {
     318      scalingFactor[column] = factor;
     319      scalingOffset[column] = offset;
     320      for(int i = 0; i < Rows; i++) {
     321        double origValue = samples[i * columns + column];
     322        samples[i * columns + column] = (origValue + offset) * factor;
     323      }
     324      CreateDictionaries();
     325      FireChanged();
     326    }
     327
    313328    internal void UnscaleVariable(int column) {
    314       if(scalingFactor[column] != 1.0) {
     329      if(scalingFactor[column] != 1.0 || scalingOffset[column]!=0.0) {
    315330        for(int i = 0; i < rows; i++) {
    316331          double scaledValue = samples[i * columns + column];
    317           samples[i * columns + column] = scaledValue * scalingFactor[column] + scalingOffset[column];
     332          samples[i * columns + column] = scaledValue / scalingFactor[column] - scalingOffset[column];
    318333        }
    319334        scalingFactor[column] = 1.0;
  • trunk/sources/HeuristicLab.DataAnalysis/DatasetView.cs

    r276 r312  
    131131      }
    132132    }
     133
     134    private void showScalingToolStripMenuItem_Click(object sender, EventArgs e) {
     135      ManualScalingControl scalingControl = new ManualScalingControl(false);
     136      double[,] scalingParameters = new double[2, Dataset.Columns];
     137      for(int i = 0; i < Dataset.Columns; i++) {
     138        scalingParameters[0, i] = Dataset.ScalingFactor[i];
     139        scalingParameters[1, i] = Dataset.ScalingOffset[i];
     140      }
     141      scalingControl.Data = scalingParameters;
     142      scalingControl.ShowDialog();
     143    }
     144
     145    private void scaleValuesmanuallyToolStripMenuItem_Click(object sender, EventArgs e) {
     146      ManualScalingControl scalingControl = new ManualScalingControl(true);
     147      double[,] scalingParameters = new double[2, Dataset.Columns];
     148      for(int i = 0; i < Dataset.Columns; i++) {
     149        scalingParameters[0, i] = Dataset.ScalingFactor[i];
     150        scalingParameters[1, i] = Dataset.ScalingOffset[i];
     151      }
     152      scalingControl.Data = scalingParameters;
     153      if(scalingControl.ShowDialog() == DialogResult.OK) {
     154        for(int i = 0; i < Dataset.Columns; i++) {
     155          Dataset.ScaleVariable(i, scalingControl.Data[0, i], scalingControl.Data[1, i]);
     156        }
     157      }
     158      Refresh();
     159    }
    133160  }
    134161}
  • trunk/sources/HeuristicLab.DataAnalysis/DatasetView.designer.cs

    r233 r312  
    4949      this.columnsTextBox = new System.Windows.Forms.TextBox();
    5050      this.dataGridView = new System.Windows.Forms.DataGridView();
     51      this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
     52      this.scaleValuesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     53      this.originalValuesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5154      this.rowsLabel = new System.Windows.Forms.Label();
    5255      this.columnsLabel = new System.Windows.Forms.Label();
    5356      this.nameLabel = new System.Windows.Forms.Label();
    5457      this.nameTextBox = new System.Windows.Forms.TextBox();
    55       this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
    56       this.scaleValuesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    57       this.originalValuesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     58      this.showScalingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     59      this.scaleValuesmanuallyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5860      ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
    5961      this.contextMenuStrip.SuspendLayout();
     
    9193      this.dataGridView.CellValidating += new System.Windows.Forms.DataGridViewCellValidatingEventHandler(this.dataGridView_CellValidating);
    9294      //
     95      // contextMenuStrip
     96      //
     97      this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
     98            this.scaleValuesToolStripMenuItem,
     99            this.scaleValuesmanuallyToolStripMenuItem,
     100            this.showScalingToolStripMenuItem,
     101            this.originalValuesToolStripMenuItem});
     102      this.contextMenuStrip.Name = "contextMenuStrip";
     103      this.contextMenuStrip.Size = new System.Drawing.Size(198, 114);
     104      //
     105      // scaleValuesToolStripMenuItem
     106      //
     107      this.scaleValuesToolStripMenuItem.Name = "scaleValuesToolStripMenuItem";
     108      this.scaleValuesToolStripMenuItem.Size = new System.Drawing.Size(197, 22);
     109      this.scaleValuesToolStripMenuItem.Text = "Scale values [0..1]";
     110      this.scaleValuesToolStripMenuItem.Click += new System.EventHandler(this.scaleValuesToolStripMenuItem_Click);
     111      //
     112      // originalValuesToolStripMenuItem
     113      //
     114      this.originalValuesToolStripMenuItem.Name = "originalValuesToolStripMenuItem";
     115      this.originalValuesToolStripMenuItem.Size = new System.Drawing.Size(197, 22);
     116      this.originalValuesToolStripMenuItem.Text = "Unscale values";
     117      this.originalValuesToolStripMenuItem.Click += new System.EventHandler(this.originalValuesToolStripMenuItem_Click);
     118      //
    93119      // rowsLabel
    94120      //
     
    126152      this.nameTextBox.TabIndex = 7;
    127153      //
    128       // contextMenuStrip
    129       //
    130       this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    131             this.scaleValuesToolStripMenuItem,
    132             this.originalValuesToolStripMenuItem});
    133       this.contextMenuStrip.Name = "contextMenuStrip";
    134       this.contextMenuStrip.Size = new System.Drawing.Size(146, 48);
    135       //
    136       // scaleValuesToolStripMenuItem
    137       //
    138       this.scaleValuesToolStripMenuItem.Name = "scaleValuesToolStripMenuItem";
    139       this.scaleValuesToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
    140       this.scaleValuesToolStripMenuItem.Text = "Scale values";
    141       this.scaleValuesToolStripMenuItem.Click += new System.EventHandler(this.scaleValuesToolStripMenuItem_Click);
    142       //
    143       // originalValuesToolStripMenuItem
    144       //
    145       this.originalValuesToolStripMenuItem.Name = "originalValuesToolStripMenuItem";
    146       this.originalValuesToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
    147       this.originalValuesToolStripMenuItem.Text = "Unscale values";
    148       this.originalValuesToolStripMenuItem.Click += new System.EventHandler(this.originalValuesToolStripMenuItem_Click);
     154      // showScalingToolStripMenuItem
     155      //
     156      this.showScalingToolStripMenuItem.Name = "showScalingToolStripMenuItem";
     157      this.showScalingToolStripMenuItem.Size = new System.Drawing.Size(197, 22);
     158      this.showScalingToolStripMenuItem.Text = "Show scaling...";
     159      this.showScalingToolStripMenuItem.Click += new System.EventHandler(this.showScalingToolStripMenuItem_Click);
     160      //
     161      // scaleValuesmanuallyToolStripMenuItem
     162      //
     163      this.scaleValuesmanuallyToolStripMenuItem.Name = "scaleValuesmanuallyToolStripMenuItem";
     164      this.scaleValuesmanuallyToolStripMenuItem.Size = new System.Drawing.Size(197, 22);
     165      this.scaleValuesmanuallyToolStripMenuItem.Text = "Scale values (manually)";
     166      this.scaleValuesmanuallyToolStripMenuItem.Click += new System.EventHandler(this.scaleValuesmanuallyToolStripMenuItem_Click);
    149167      //
    150168      // DatasetView
     
    180198    private System.Windows.Forms.ToolStripMenuItem scaleValuesToolStripMenuItem;
    181199    private System.Windows.Forms.ToolStripMenuItem originalValuesToolStripMenuItem;
     200    private System.Windows.Forms.ToolStripMenuItem scaleValuesmanuallyToolStripMenuItem;
     201    private System.Windows.Forms.ToolStripMenuItem showScalingToolStripMenuItem;
    182202  }
    183203}
  • trunk/sources/HeuristicLab.DataAnalysis/HeuristicLab.DataAnalysis.csproj

    r273 r312  
    6262    <Compile Include="HeuristicLabDataAnalysisPlugin.cs" />
    6363    <Compile Include="IDatasetManipulator.cs" />
     64    <Compile Include="ManualScalingControl.cs">
     65      <SubType>Form</SubType>
     66    </Compile>
     67    <Compile Include="ManualScalingControl.Designer.cs">
     68      <DependentUpon>ManualScalingControl.cs</DependentUpon>
     69    </Compile>
    6470    <Compile Include="Properties\AssemblyInfo.cs" />
    6571    <Compile Include="Regression.cs" />
     
    9298      <SubType>Designer</SubType>
    9399    </EmbeddedResource>
     100    <EmbeddedResource Include="ManualScalingControl.resx">
     101      <DependentUpon>ManualScalingControl.cs</DependentUpon>
     102    </EmbeddedResource>
    94103    <EmbeddedResource Include="SvmExporter.resx">
    95104      <DependentUpon>SvmExporter.cs</DependentUpon>
Note: See TracChangeset for help on using the changeset viewer.