Last change
on this file since 10854 was
10821,
checked in by pfleck, 11 years ago
|
- Fixed typo in linear transformation error msg.
- removed StringBuilder in transformation error msg.
|
File size:
1.5 KB
|
Line | |
---|
1 |
|
---|
2 | using System;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | using System.Linq;
|
---|
5 | using System.Text;
|
---|
6 | using HeuristicLab.Common;
|
---|
7 | using HeuristicLab.Core;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 | namespace HeuristicLab.Problems.DataAnalysis.Transformations {
|
---|
10 | [Item("ReciprocalTransformation", "f(x) = 1 / x | Represents a reciprocal transformation.")]
|
---|
11 | public class ReciprocalTransformation : Transformation<double> {
|
---|
12 |
|
---|
13 | //TODO: is a special case of Linear
|
---|
14 | [StorableConstructor]
|
---|
15 | protected ReciprocalTransformation(bool deserializing) : base(deserializing) { }
|
---|
16 | protected ReciprocalTransformation(Transformation<double> original, Cloner cloner)
|
---|
17 | : base(original, cloner) {
|
---|
18 | }
|
---|
19 | public ReciprocalTransformation(IEnumerable<string> allowedColumns)
|
---|
20 | : base(allowedColumns) {
|
---|
21 | }
|
---|
22 |
|
---|
23 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
24 | return new ReciprocalTransformation(this, cloner);
|
---|
25 | }
|
---|
26 |
|
---|
27 | public override IEnumerable<double> Apply(IEnumerable<double> data) {
|
---|
28 | foreach (double i in data) {
|
---|
29 | if (i > 0.0)
|
---|
30 | yield return 1.0 / i;
|
---|
31 | else
|
---|
32 | yield return i;
|
---|
33 | }
|
---|
34 | }
|
---|
35 |
|
---|
36 | public override bool Check(IEnumerable<double> data, out string errorMsg) {
|
---|
37 | errorMsg = null;
|
---|
38 | int errorCounter = data.Count(i => i <= 0.0);
|
---|
39 | if (errorCounter > 0) {
|
---|
40 | errorMsg = String.Format("{0} values are zero or below zero. 1/x can not be applied onto these values", errorCounter);
|
---|
41 | return false;
|
---|
42 | }
|
---|
43 | return true;
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.