Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/DistributionGenerator/DistributionGenerator.cs @ 6973

Last change on this file since 6973 was 6973, checked in by sforsten, 12 years ago

#1669: different kinds of distribution have been implemented for the data generation. It hasn't been tested yet.

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Collections.Generic;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25
26namespace HeuristicLab.Problems.DataAnalysis.Benchmarks.DistributionGenerator {
27  public class DistributionGenerator : NamedItem {
28
29    public DistributionType state = DistributionType.Test;
30
31    private Dictionary<string, IList<double>> data;
32    private Dictionary<string, Dictionary<DistributionType, Distribution>> variables;
33
34    private Dictionary<string, StepsDistribution> stepDistributions;
35    private Dictionary<string, Distribution> randomDistributions;
36
37    private bool hasNext;
38    public bool HasNext {
39      get {
40        return hasNext;
41      }
42    }
43
44    public DistributionGenerator(Dictionary<string, IList<double>> data,
45    Dictionary<string, Dictionary<DistributionType, Distribution>> variables) {
46      this.data = data;
47      this.variables = variables;
48
49      spepareteDistributions();
50    }
51
52    #region cloning
53    protected DistributionGenerator(DistributionGenerator original, Cloner cloner)
54      : base(original, cloner) {
55      data = original.data;
56      state = original.state;
57      variables = original.variables;
58      stepDistributions = original.stepDistributions;
59      randomDistributions = original.randomDistributions;
60      hasNext = original.hasNext;
61    }
62    public override IDeepCloneable Clone(Cloner cloner) {
63      return new DistributionGenerator(this, cloner);
64    }
65    #endregion
66
67    private void spepareteDistributions() {
68      foreach (var dic in variables) {
69        if (dic.Value[state] is StepsDistribution) {
70          stepDistributions[dic.Key] = (StepsDistribution)dic.Value[state];
71        } else {
72          randomDistributions[dic.Key] = dic.Value[state];
73        }
74      }
75      //new Values can be generated
76      hasNext = true;
77    }
78
79    public DistributionType ChangeDistributionType(DistributionType type) {
80      state = type;
81      spepareteDistributions();
82      return state;
83    }
84
85    public void generateValues() {
86      if (hasNext) {
87        foreach (var randomDis in randomDistributions) {
88          data[randomDis.Key].Add(randomDis.Value.Next());
89        }
90        if (stepDistributions.Count > 0) {
91          bool newValue = false;
92          foreach (var stepDis in stepDistributions) {
93            if (!newValue && stepDis.Value.HasNext()) {
94              data[stepDis.Key].Add(stepDis.Value.Next());
95              newValue = true;
96              continue;
97            }
98
99            if (!stepDis.Value.HasNext())
100              stepDis.Value.Reset();
101
102            data[stepDis.Key].Add(stepDis.Value.Current());
103          }
104
105          hasNext = !newValue;
106        }
107      }
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.