Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10805


Ignore:
Timestamp:
05/07/14 11:04:44 (11 years ago)
Author:
tsteinre
Message:
  • refactored PowerTransformation
  • repaired Transformations / refactored TransactionalPreprocessingData
Location:
branches/DataPreprocessing
Files:
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/TransactionalPreprocessingData.cs

    r10740 r10805  
    5050    private IList<PDSnapshot> undoHistory;
    5151
    52     private int transactionDepth = 0;
     52    private Stack<DataPreprocessingChangedEventType> eventStack = new Stack<DataPreprocessingChangedEventType>();
     53
     54    private DataPreprocessingChangedEventType lastOccuredChangedType = DataPreprocessingChangedEventType.Any;
     55
     56    public bool IsInTransaction { get { return eventStack.Count > 0; } }
    5357
    5458    public TransactionalPreprocessingData(IDataAnalysisProblemData problemData)
     
    6367
    6468    private void SaveSnapshot(DataPreprocessingChangedEventType changedType, int column, int row) {
    65       if (transactionDepth > 0) return;
     69      if (eventStack.Count > 0) return;
    6670
    6771      PDSnapshot currentSnapshot = new PDSnapshot();
     
    9296      SaveSnapshot(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex);
    9397      base.SetCell<T>(columnIndex, rowIndex, value);
    94       if (transactionDepth <= 0)
     98      if (!IsInTransaction)
    9599        OnChanged(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex);
    96100    }
     
    99103      SaveSnapshot(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1);
    100104      base.SetValues<T>(columnIndex, values);
    101       if (transactionDepth <= 0)
     105      if (!IsInTransaction)
    102106        OnChanged(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1);
    103107    }
     
    106110      SaveSnapshot(DataPreprocessingChangedEventType.DeleteRow, -1, rowIndex);
    107111      base.InsertRow(rowIndex);
    108       if (transactionDepth <= 0)
     112      if (!IsInTransaction)
    109113        OnChanged(DataPreprocessingChangedEventType.AddRow, -1, rowIndex);
    110114    }
     
    113117      SaveSnapshot(DataPreprocessingChangedEventType.AddRow, -1, rowIndex);
    114118      base.DeleteRow(rowIndex);
    115       if (transactionDepth <= 0)
     119      if (!IsInTransaction)
    116120        OnChanged(DataPreprocessingChangedEventType.DeleteRow, -1, rowIndex);
    117121    }
     
    120124      SaveSnapshot(DataPreprocessingChangedEventType.DeleteColumn, columnIndex, -1);
    121125      base.InsertColumn<T>(variableName, columnIndex);
    122       if (transactionDepth <= 0)
     126      if (!IsInTransaction)
    123127        OnChanged(DataPreprocessingChangedEventType.AddColumn, columnIndex, -1);
    124128    }
     
    127131      SaveSnapshot(DataPreprocessingChangedEventType.AddColumn, columnIndex, -1);
    128132      base.DeleteColumn(columnIndex);
    129       if (transactionDepth <= 0)
     133      if (!IsInTransaction)
    130134        OnChanged(DataPreprocessingChangedEventType.DeleteColumn, columnIndex, -1);
    131135    }
     
    166170    public void BeginTransaction(DataPreprocessingChangedEventType type) {
    167171      SaveSnapshot(type, -1, -1);
    168       transactionDepth++;
     172      eventStack.Push(type);
    169173    }
    170174
    171175    public void EndTransaction() {
    172       transactionDepth--;
    173       if (transactionDepth < 0)
     176      if (eventStack.Count == 0)
    174177        throw new InvalidOperationException("There is no open transaction that can be ended.");
    175       if (transactionDepth == 0)
    176         OnChanged(DataPreprocessingChangedEventType.Any, -1, -1);
     178     
     179      var @event = eventStack.Pop();
     180      OnChanged(@event, -1, -1);
    177181    }
    178182
  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Transformations/3.3/HeuristicLab.Problems.DataAnalysis.Transformations-3.3.csproj

    r10784 r10805  
    4949    <Compile Include="CopyColumnTransformation.cs" />
    5050    <Compile Include="DeviationTransformation.cs" />
    51     <Compile Include="ExponentiationTransformation.cs" />
     51    <Compile Include="PowerTransformation.cs" />
    5252    <Compile Include="ExponentialTransformation.cs" />
    5353    <Compile Include="LogarithmicTransformation.cs" />
  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Transformations/3.3/PowerTransformation.cs

    r10804 r10805  
    88
    99namespace HeuristicLab.Problems.DataAnalysis.Transformations {
    10   [Item("ExponentationTransformation", "Represents a exponentation transformation.")]
    11   public class ExponentiationTransformation : Transformation<double> {
    12     protected const string BaseParameterName = "Base";
     10  [Item("PowerTransformation", "Represents a power transformation.")]
     11  public class PowerTransformation : Transformation<double> {
     12    protected const string ExponentParameterName = "Exponent";
    1313
    1414    #region Parameters
    15     public IValueParameter<DoubleValue> BaseParameter {
    16       get { return (IValueParameter<DoubleValue>)Parameters[BaseParameterName]; }
     15    public IValueParameter<DoubleValue> ExponentParameter {
     16      get { return (IValueParameter<DoubleValue>)Parameters[ExponentParameterName]; }
    1717    }
    1818    #endregion
    1919
    2020    #region properties
    21     public double Base {
    22       get { return BaseParameter.Value.Value; }
     21    public double Exponent {
     22      get { return ExponentParameter.Value.Value; }
    2323    }
    2424    #endregion
    2525
    2626    [StorableConstructor]
    27     protected ExponentiationTransformation(bool deserializing) : base(deserializing) { }
    28     protected ExponentiationTransformation(Transformation<double> original, Cloner cloner)
     27    protected PowerTransformation(bool deserializing) : base(deserializing) { }
     28    protected PowerTransformation(Transformation<double> original, Cloner cloner)
    2929      : base(original, cloner) {
    3030    }
    31     public ExponentiationTransformation(IEnumerable<string> allowedColumns)
     31    public PowerTransformation(IEnumerable<string> allowedColumns)
    3232      : base(allowedColumns) {
    33       Parameters.Add(new ValueParameter<DoubleValue>(BaseParameterName, "Base for Exponentation", new DoubleValue(Math.E)));
     33        Parameters.Add(new ValueParameter<DoubleValue>(ExponentParameterName, "Exponent for Exponentation", new DoubleValue(Math.E)));
    3434    }
    3535
    3636    public override IDeepCloneable Clone(Cloner cloner) {
    37       return new ExponentiationTransformation(this, cloner);
     37      return new PowerTransformation(this, cloner);
    3838    }
    3939
    4040    public override IEnumerable<double> Apply(IEnumerable<double> data) {
    4141      foreach (double i in data) {
    42         yield return Math.Pow(Base, i);
     42        yield return Math.Pow(i, Exponent);
    4343      }
    4444    }
Note: See TracChangeset for help on using the changeset viewer.