Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ReciprocalTransformation.cs @ 16628

Last change on this file since 16628 was 16628, checked in by gkronber, 5 years ago

#2971: made branch compile with current version of trunk

File size: 1.6 KB
Line 
1
2using System;
3using System.Collections.Generic;
4using System.Linq;
5using HeuristicLab.Common;
6using HeuristicLab.Core;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8using HEAL.Attic;
9
10namespace HeuristicLab.Problems.DataAnalysis {
11  [StorableType("047CD1E6-8AB3-4DDD-BC09-A1867F754AB0")]
12  [Item("Reciprocal Transformation", "f(x) = 1 / x | Represents a reciprocal transformation.")]
13  public class ReciprocalTransformation : Transformation<double> {
14
15    #region properties
16    public override string ShortName {
17      get { return "Inv"; }
18    }
19    #endregion
20
21    [StorableConstructor]
22    protected ReciprocalTransformation(StorableConstructorFlag _) : base(_) { }
23    protected ReciprocalTransformation(ReciprocalTransformation original, Cloner cloner)
24      : base(original, cloner) {
25    }
26    public ReciprocalTransformation(IEnumerable<string> allowedColumns)
27      : base(allowedColumns) {
28    }
29
30    public override IDeepCloneable Clone(Cloner cloner) {
31      return new ReciprocalTransformation(this, cloner);
32    }
33
34    public override IEnumerable<double> Apply(IEnumerable<double> data) {
35      return data.Select(d => d > 0 ? 1.0 / d : d);
36    }
37
38    public override bool Check(IEnumerable<double> data, out string errorMsg) {
39      errorMsg = null;
40      int errorCounter = data.Count(i => i <= 0.0);
41      if (errorCounter > 0) {
42        errorMsg = String.Format("{0} values are zero or below zero. 1/x can not be applied onto these values", errorCounter);
43        return false;
44      }
45      return true;
46    }
47  }
48}
Note: See TracBrowser for help on using the repository browser.