Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/NamedIntervals.cs @ 16590

Last change on this file since 16590 was 16590, checked in by chaider, 5 years ago

#2971
Interval-Parser:

  • Changed Parser ==> after last group there can be now an infinite amount of whitepsaces
  • Save userinput as property
  • Save variable case-sensitive

NamedIntervals

  • Changed Storable attribute from IEnumerable to KeyValuePair, because old Persistance cant handle IEnumerable

Added SymbolicRegressionConstraintAnalyzer
SymbolicRegressionSingleObjectiveConstraintPearsonRSquaredEvaluator

  • Fixed checking if a given interval is in another interval
File size: 2.4 KB
Line 
1using HeuristicLab.Collections;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
5using System;
6using System.Collections.Generic;
7using System.Drawing;
8using System.Linq;
9using System.Text;
10using System.Threading.Tasks;
11
12namespace HeuristicLab.Problems.DataAnalysis.Implementation {
13  [Item("NamedIntervals", "Represents variables with their interval ranges.")]
14  [StorableClass]
15  public class NamedIntervals : Item {
16    Dictionary<string, Interval> variableIntervals = new Dictionary<string, Interval>();
17    public Dictionary<string, Interval> VariableIntervals => variableIntervals;
18
19    [Storable(Name = "StorableIntervalInformation")]
20    private KeyValuePair<string, double[]>[] StorableIntervalInformation {
21      get {
22        var l = new List<KeyValuePair<string, double[]>>();
23        foreach (var varInt in variableIntervals)
24
25          l.Add(new KeyValuePair<string, double[]>(varInt.Key,
26            new double[] { varInt.Value.LowerBound, varInt.Value.UpperBound }));
27        return l.ToArray();
28      }
29
30      set {
31        foreach (var varInt in value)
32          variableIntervals.Add(varInt.Key, new Interval(varInt.Value[0], varInt.Value[1]));
33      }
34    }
35
36    public NamedIntervals() : base() { }
37    protected NamedIntervals(bool deserializing) : base(deserializing) { }
38
39    protected NamedIntervals(NamedIntervals original, Cloner cloner) : base(original, cloner) {
40      foreach (var keyValuePair in original.VariableIntervals) {
41        variableIntervals.Add(keyValuePair.Key, keyValuePair.Value);
42      }
43    }
44
45    public override IDeepCloneable Clone(Cloner cloner) {
46      return new NamedIntervals(this, cloner);
47    }
48
49    public bool ReadOnly { get; }
50
51    public bool InsertMany(IEnumerable<KeyValuePair<string, Interval>> entries) {
52      if (entries == null) throw new ArgumentNullException("The given dataset is null.");
53      if (entries.Count() != 0) {
54        foreach (var entry in entries) {
55          if (variableIntervals.ContainsKey(entry.Key))
56            variableIntervals[entry.Key] = entry.Value;
57          else
58            variableIntervals.Add(entry.Key, entry.Value);
59        }
60      }
61      return true;
62    }
63
64    public bool Add(string key, Interval value) {
65      variableIntervals[key] = value;
66      return true;
67    }
68
69  }
70}
71
Note: See TracBrowser for help on using the repository browser.