1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Encodings.ConditionActionEncoding;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
31 | using HeuristicLab.Problems.DataAnalysis;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Problems.ConditionActionClassification {
|
---|
34 | public class ConditionActionClassificationProblemData : ParameterizedNamedItem, IConditionActionProblemData {
|
---|
35 |
|
---|
36 | #region default data
|
---|
37 | public static string[] defaultVariableNames = new string[] { "a", "b", "c", "d", "e", "f", "g" };
|
---|
38 | public static double[,] defaultData = new double[,]{
|
---|
39 | {0,0,1,1,0,0,0},
|
---|
40 | {0,1,1,1,0,0,0},
|
---|
41 | {0,0,1,0,0,0,0},
|
---|
42 | {1,0,1,0,1,1,0}
|
---|
43 | };
|
---|
44 | #endregion
|
---|
45 |
|
---|
46 | #region parameter properites
|
---|
47 | public IFixedValueParameter<Dataset> DatasetParameter {
|
---|
48 | get { return (IFixedValueParameter<Dataset>)Parameters["Dataset"]; }
|
---|
49 | }
|
---|
50 | public IFixedValueParameter<ReadOnlyCheckedItemList<StringValue>> ConditionVariablesParameter {
|
---|
51 | get { return (IFixedValueParameter<ReadOnlyCheckedItemList<StringValue>>)Parameters["ConditionVariables"]; }
|
---|
52 | }
|
---|
53 | public IFixedValueParameter<ReadOnlyCheckedItemList<StringValue>> ActionVariablesParameter {
|
---|
54 | get { return (IFixedValueParameter<ReadOnlyCheckedItemList<StringValue>>)Parameters["ActionVariables"]; }
|
---|
55 | }
|
---|
56 | #endregion
|
---|
57 |
|
---|
58 | public Dataset Dataset {
|
---|
59 | get { return DatasetParameter.Value; }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public ICheckedItemList<StringValue> ConditionVariables {
|
---|
63 | get { return ConditionVariablesParameter.Value; }
|
---|
64 | }
|
---|
65 |
|
---|
66 | public ICheckedItemList<StringValue> ActionVariables {
|
---|
67 | get { return ActionVariablesParameter.Value; }
|
---|
68 | }
|
---|
69 |
|
---|
70 | public IEnumerable<string> AllowedConditionVariables {
|
---|
71 | get { return ConditionVariables.CheckedItems.Select(x => x.Value.Value); }
|
---|
72 | }
|
---|
73 | public IEnumerable<string> AllowedActionVariables {
|
---|
74 | get { return ActionVariables.CheckedItems.Select(x => x.Value.Value); }
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | [StorableConstructor]
|
---|
79 | protected ConditionActionClassificationProblemData(bool deserializing) : base(deserializing) { }
|
---|
80 | protected ConditionActionClassificationProblemData(ConditionActionClassificationProblemData original, Cloner cloner)
|
---|
81 | : base(original, cloner) {
|
---|
82 | }
|
---|
83 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
84 | return new ConditionActionClassificationProblemData(this, cloner);
|
---|
85 | }
|
---|
86 |
|
---|
87 | public ConditionActionClassificationProblemData(Dataset dataset, IEnumerable<string> allowedConditionVariables, IEnumerable<string> allowedActionVariables) {
|
---|
88 | if (dataset == null) throw new ArgumentNullException("The dataset must not be null.");
|
---|
89 | if (allowedActionVariables == null) throw new ArgumentNullException("The allowedActionVariables must not be null.");
|
---|
90 | if (allowedConditionVariables == null) throw new ArgumentNullException("The allowedActionVariables must not be null.");
|
---|
91 |
|
---|
92 | if (allowedActionVariables.Except(dataset.DoubleVariables).Any())
|
---|
93 | throw new ArgumentException("All allowed action variables must be present in the dataset and of type double.");
|
---|
94 | if (allowedConditionVariables.Except(dataset.DoubleVariables).Any())
|
---|
95 | throw new ArgumentException("All allowed condition variables must be present in the dataset and of type double.");
|
---|
96 |
|
---|
97 | var actionVariables = new CheckedItemList<StringValue>(dataset.DoubleVariables.Select(x => new StringValue(x)));
|
---|
98 | var conditionVariables = new CheckedItemList<StringValue>(actionVariables);
|
---|
99 | foreach (StringValue x in actionVariables) {
|
---|
100 | actionVariables.SetItemCheckedState(x, allowedActionVariables.Contains(x.Value));
|
---|
101 | conditionVariables.SetItemCheckedState(x, allowedConditionVariables.Contains(x.Value));
|
---|
102 | }
|
---|
103 |
|
---|
104 | Parameters.Add(new FixedValueParameter<Dataset>("Dataset", "", dataset));
|
---|
105 | Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemList<StringValue>>("ActionVariables", "", actionVariables.AsReadOnly()));
|
---|
106 | Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemList<StringValue>>("ConditionVariables", "", conditionVariables.AsReadOnly()));
|
---|
107 |
|
---|
108 | ((ValueParameter<Dataset>)DatasetParameter).ReactOnValueToStringChangedAndValueItemImageChanged = false;
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|