Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/ChangeValues/BoxCoxTransformationCommand.cs @ 7461

Last change on this file since 7461 was 7267, checked in by gkronber, 13 years ago

#1734 updated copyright year in all files of the DataImporter branch

File size: 3.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using System.Xml;
27using HeuristicLab.DataImporter.Data;
28using HeuristicLab.DataImporter.Data.CommandBase;
29using HeuristicLab.DataImporter.Data.Model;
30using HeuristicLab.DataImporter.Command.View;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32
33namespace HeuristicLab.DataImporter.Command {
34  [StorableClass]
35  [ViewableCommandInfoAttribute("Box-Cox Transformation", 1, ColumnGroupState.DoubleColumnSelected, "Change Values",
36  Position = 6, OptionsView = typeof(BoxCoxTransformationCommandView))]
37  public class BoxCoxTransformationCommand : ColumnGroupCommandWithAffectedColumnsBase {
38    private BoxCoxTransformationCommand()
39      : base(null, string.Empty, null) {
40    }
41
42    public BoxCoxTransformationCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns)
43      : base(dataSet, columnGroupName, affectedColumns) {
44    }
45
46    [Storable]
47    private double lambda;
48    public double Lambda {
49      get { return this.lambda; }
50      set { this.lambda = value; }
51    }
52    [Storable]
53    private double c;
54    public double C {
55      get { return this.c; }
56      set { this.c = value; }
57    }
58
59    public override string Description {
60      get { return "Box-Cox Transformation"; }
61    }
62
63    public override void Execute() {
64      base.Execute();
65      DoubleColumn column;
66      foreach (int col in AffectedColumns) {
67        if (ColumnGroup.GetColumn(col) is DoubleColumn) {
68          column = (DoubleColumn)ColumnGroup.GetColumn(col);
69          for (int i = 0; i < column.TotalValuesCount; i++)
70            if (column.GetValue(i) != null) {
71              if (lambda != 0.0) {
72                column.ChangeValue(i, Math.Pow((double)column.GetValue(i) + c, lambda) - 1);
73              } else {
74                column.ChangeValue(i, Math.Log((double)column.GetValue(i) + c));
75              }
76            }
77        }
78      }
79      ColumnGroup.FireChanged();
80      ColumnGroup = null;
81    }
82
83    public override void UndoExecute() {
84      base.UndoExecute();
85      DoubleColumn column;
86      foreach (int col in AffectedColumns) {
87        if (ColumnGroup.GetColumn(col) is DoubleColumn) {
88          column = (DoubleColumn)ColumnGroup.GetColumn(col);
89          for (int i = 0; i < column.TotalValuesCount; i++)
90            if (column.GetValue(i) != null) {
91              if (lambda != 0.0) {
92                column.ChangeValue(i, Math.Pow((double)column.GetValue(i) + 1, 1.0 / lambda) - c);
93              } else {
94                column.ChangeValue(i, Math.Exp((double)column.GetValue(i)) - c);
95              }
96            }
97        }
98      }
99      ColumnGroup.FireChanged();
100      ColumnGroup = null;
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.