#region License Information /* HeuristicLab * Copyright (C) 2002-2013 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 HeuristicLab.DataImporter.Command.View; using HeuristicLab.DataImporter.Data; using HeuristicLab.DataImporter.Data.CommandBase; using HeuristicLab.DataImporter.Data.Model; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.DataImporter.Command { [StorableClass] [ViewableCommandInfoAttribute("Box-Cox Transformation", 1, ColumnGroupState.DoubleColumnSelected, "Change Values", Position = 6, OptionsView = typeof(BoxCoxTransformationCommandView))] public class BoxCoxTransformationCommand : ColumnGroupCommandWithAffectedColumnsBase { [StorableConstructor] protected BoxCoxTransformationCommand(bool deserializing) : base(deserializing) { } public BoxCoxTransformationCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns) : base(dataSet, columnGroupName, affectedColumns) { } [Storable] private double lambda; public double Lambda { get { return this.lambda; } set { this.lambda = value; } } [Storable] private double c; public double C { get { return this.c; } set { this.c = value; } } public override string Description { get { return "Box-Cox Transformation"; } } public override void Execute() { base.Execute(); DoubleColumn column; foreach (int col in AffectedColumns) { if (ColumnGroup.GetColumn(col) is DoubleColumn) { column = (DoubleColumn)ColumnGroup.GetColumn(col); for (int i = 0; i < column.TotalValuesCount; i++) if (column.GetValue(i) != null) { if (lambda != 0.0) { column.ChangeValue(i, Math.Pow((double)column.GetValue(i) + c, lambda) - 1); } else { column.ChangeValue(i, Math.Log((double)column.GetValue(i) + c)); } } } } ColumnGroup.FireChanged(); ColumnGroup = null; } public override void UndoExecute() { base.UndoExecute(); DoubleColumn column; foreach (int col in AffectedColumns) { if (ColumnGroup.GetColumn(col) is DoubleColumn) { column = (DoubleColumn)ColumnGroup.GetColumn(col); for (int i = 0; i < column.TotalValuesCount; i++) if (column.GetValue(i) != null) { if (lambda != 0.0) { column.ChangeValue(i, Math.Pow((double)column.GetValue(i) + 1, 1.0 / lambda) - c); } else { column.ChangeValue(i, Math.Exp((double)column.GetValue(i)) - c); } } } } ColumnGroup.FireChanged(); ColumnGroup = null; } } }