Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/BinaryFactorVariable.cs @ 16375

Last change on this file since 16375 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
30  [StorableClass]
31  [Item("BinaryFactorVariable", "Represents a categorical variable (comparable to factors as in R) and it's value.")]
32  public sealed class BinaryFactorVariable : VariableBase {
33
34    private readonly Dictionary<string, List<string>> variableValues;
35
36    [Storable]
37    public IEnumerable<KeyValuePair<string, List<string>>> VariableValues {
38      get { return variableValues; }
39      set {
40        if (value == null) throw new ArgumentNullException();
41        variableValues.Clear();
42        foreach (var kvp in value) {
43          variableValues.Add(kvp.Key, new List<string>(kvp.Value));
44        }
45      }
46    }
47
48    [StorableConstructor]
49    private BinaryFactorVariable(bool deserializing)
50      : base(deserializing) {
51      variableValues = new Dictionary<string, List<string>>();
52    }
53    private BinaryFactorVariable(BinaryFactorVariable original, Cloner cloner)
54      : base(original, cloner) {
55      variableValues =
56        original.variableValues.ToDictionary(kvp => kvp.Key, kvp => new List<string>(kvp.Value));
57    }
58    public BinaryFactorVariable() : this("BinaryFactorVariable", "Represents a categorical variable (comparable to factors as in R) and it's value.") { }
59    public BinaryFactorVariable(string name, string description)
60      : base(name, description) {
61      variableValues = new Dictionary<string, List<string>>();
62    }
63
64    public override ISymbolicExpressionTreeNode CreateTreeNode() {
65      return new BinaryFactorVariableTreeNode(this);
66    }
67
68    public override IDeepCloneable Clone(Cloner cloner) {
69      return new BinaryFactorVariable(this, cloner);
70    }
71
72    public IEnumerable<string> GetVariableValues(string variableName) {
73      return variableValues[variableName];
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.