Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2971: merged r16565:16631 from trunk/HeuristicLab.Problems.DataAnalysis to branch/HeuristicLab.Problems.DataAnalysis (resolving all conflicts)

File size: 1.5 KB
Line 
1
2using System;
3using System.Collections.Generic;
4using System.Linq;
5using HeuristicLab.Common;
6using HeuristicLab.Core;
7using HEAL.Attic;
8using HEAL.Attic;
9
10namespace HeuristicLab.Problems.DataAnalysis {
11  [StorableType("8D242A5A-5EBB-4618-958E-A7EF34151508")]
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.