Line | |
---|
1 |
|
---|
2 | using System;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Common;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 | namespace HeuristicLab.Problems.DataAnalysis.Transformations {
|
---|
9 | [Item("ReciprocalTransformation", "Represents a reciprocal transformation.")]
|
---|
10 | public class ReciprocalTransformation : Transformation<double> {
|
---|
11 |
|
---|
12 | [StorableConstructor]
|
---|
13 | protected ReciprocalTransformation(bool deserializing) : base(deserializing) { }
|
---|
14 | protected ReciprocalTransformation(Transformation<double> original, Cloner cloner)
|
---|
15 | : base(original, cloner) {
|
---|
16 | }
|
---|
17 | public ReciprocalTransformation(IEnumerable<string> allowedColumns)
|
---|
18 | : base(allowedColumns) {
|
---|
19 | }
|
---|
20 |
|
---|
21 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
22 | return new ReciprocalTransformation(this, cloner);
|
---|
23 | }
|
---|
24 |
|
---|
25 | public override IEnumerable<double> Apply(IEnumerable<double> data) {
|
---|
26 | foreach (double i in data) {
|
---|
27 | if (i > 0.0)
|
---|
28 | yield return 1.0 / i;
|
---|
29 | else
|
---|
30 | yield return i;
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | public override bool Check(IEnumerable<double> data, out string errorMsg) {
|
---|
35 | StringBuilder sb = new StringBuilder();
|
---|
36 | errorMsg = null;
|
---|
37 | int errorCounter = 0;
|
---|
38 |
|
---|
39 | foreach (double i in data) {
|
---|
40 | if (i <= 0.0) {
|
---|
41 | ++errorCounter;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | if (errorCounter > 0) {
|
---|
46 | sb.Append(String.Format("{0} values are zero or below zero. 1/x can not be applied onto these values", errorCounter));
|
---|
47 | errorMsg = sb.ToString();
|
---|
48 | return false;
|
---|
49 | }
|
---|
50 | return true;
|
---|
51 | }
|
---|
52 | }
|
---|
53 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.