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