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;
|
---|
[11068] | 8 | namespace HeuristicLab.Problems.DataAnalysis {
|
---|
[12667] | 9 | [StorableClass]
|
---|
[10909] | 10 | [Item("Reciprocal Transformation", "f(x) = 1 / x | Represents a reciprocal transformation.")]
|
---|
[10781] | 11 | public class ReciprocalTransformation : Transformation<double> {
|
---|
| 12 |
|
---|
[10932] | 13 | #region properties
|
---|
| 14 | public override string ShortName {
|
---|
| 15 | get { return "Inv"; }
|
---|
| 16 | }
|
---|
| 17 | #endregion
|
---|
| 18 |
|
---|
[10781] | 19 | [StorableConstructor]
|
---|
| 20 | protected ReciprocalTransformation(bool deserializing) : base(deserializing) { }
|
---|
[11114] | 21 | protected ReciprocalTransformation(ReciprocalTransformation original, Cloner cloner)
|
---|
[10781] | 22 | : base(original, cloner) {
|
---|
| 23 | }
|
---|
| 24 | public ReciprocalTransformation(IEnumerable<string> allowedColumns)
|
---|
| 25 | : base(allowedColumns) {
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 29 | return new ReciprocalTransformation(this, cloner);
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | public override IEnumerable<double> Apply(IEnumerable<double> data) {
|
---|
[12667] | 33 | return data.Select(d => d > 0 ? 1.0 / d : d);
|
---|
[10781] | 34 | }
|
---|
| 35 |
|
---|
| 36 | public override bool Check(IEnumerable<double> data, out string errorMsg) {
|
---|
| 37 | errorMsg = null;
|
---|
[10821] | 38 | int errorCounter = data.Count(i => i <= 0.0);
|
---|
[10781] | 39 | if (errorCounter > 0) {
|
---|
[10821] | 40 | errorMsg = String.Format("{0} values are zero or below zero. 1/x can not be applied onto these values", errorCounter);
|
---|
[10781] | 41 | return false;
|
---|
| 42 | }
|
---|
| 43 | return true;
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.