Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16092 for branches


Ignore:
Timestamp:
08/29/18 09:44:07 (6 years ago)
Author:
jkarder
Message:

#2839: merged [16057-16091/trunk] into branch

Location:
branches/2839_HiveProjectManagement
Files:
21 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/2839_HiveProjectManagement

  • branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.DataAnalysis

  • branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.DataAnalysis/3.4

  • branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs

    r16057 r16092  
    210210    protected override void Run(CancellationToken cancellationToken) {
    211211      // Set up the algorithm
    212       if (SetSeedRandomly) Seed = new System.Random().Next();
     212      if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed();
    213213      var rand = new MersenneTwister((uint)Seed);
    214214
  • branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs

    r16057 r16092  
    186186    protected override void Run(CancellationToken cancellationToken) {
    187187      // Set up the algorithm
    188       if (SetSeedRandomly) Seed = new System.Random().Next();
     188      if (SetSeedRandomly) Seed = Random.RandomSeedGenerator.GetSeed();
    189189
    190190      // Set up the results display
  • branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs

    r16057 r16092  
    130130          // automatic determination of weights (all features should have variance = 1)
    131131          this.weights = this.allowedInputVariables
    132             .Select(name => 1.0 / dataset.GetDoubleValues(name, rows).StandardDeviationPop())
     132            .Select(name => {
     133              var pop = dataset.GetDoubleValues(name, rows).StandardDeviationPop();
     134              return  pop.IsAlmost(0) ? 1.0 : 1.0/pop;
     135            })
    133136            .Concat(new double[] { 1.0 }) // no scaling for target variable
    134137            .ToArray();
  • branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs

    r16057 r16092  
    186186        qualityTable.Rows.Add(testRMSERow);
    187187        Results.Add(new Result(qualityTable.Name, qualityTable.Name + " for all restarts", qualityTable));
    188         if (SetSeedRandomly) Seed = (new System.Random()).Next();
     188        if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed();
    189189        var rand = new MersenneTwister((uint)Seed);
    190190        bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, ApplyLinearScaling, rand);
  • branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassification.cs

    r16057 r16092  
    135135    protected override void Run(CancellationToken cancellationToken) {
    136136      double rmsError, relClassificationError, outOfBagRmsError, outOfBagRelClassificationError;
    137       if (SetSeedRandomly) Seed = new System.Random().Next();
     137      if (SetSeedRandomly) Seed = Random.RandomSeedGenerator.GetSeed();
    138138
    139139      var model = CreateRandomForestClassificationModel(Problem.ProblemData, NumberOfTrees, R, M, Seed, out rmsError, out relClassificationError, out outOfBagRmsError, out outOfBagRelClassificationError);
  • branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegression.cs

    r16057 r16092  
    134134    protected override void Run(CancellationToken cancellationToken) {
    135135      double rmsError, avgRelError, outOfBagRmsError, outOfBagAvgRelError;
    136       if (SetSeedRandomly) Seed = new System.Random().Next();
     136      if (SetSeedRandomly) Seed = Random.RandomSeedGenerator.GetSeed();
    137137      var model = CreateRandomForestRegressionModel(Problem.ProblemData, NumberOfTrees, R, M, Seed,
    138138        out rmsError, out avgRelError, out outOfBagRmsError, out outOfBagAvgRelError);
  • branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/TSNEAlgorithm.cs

    r16057 r16092  
    275275      if (wdist != null) wdist.Initialize(problemData);
    276276      if (state == null) {
    277         if (SetSeedRandomly) Seed = new System.Random().Next();
     277        if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed();
    278278        var random = new MersenneTwister((uint)Seed);
    279279        var dataset = problemData.Dataset;
  • branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.MOCMAEvolutionStrategy

  • branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/MOCMAEvolutionStrategy.cs

    r16057 r16092  
    285285    #region Initialization
    286286    protected override void Initialize(CancellationToken cancellationToken) {
    287       if (SetSeedRandomly) Seed = new System.Random().Next();
     287      if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed();
    288288      random.Reset(Seed);
    289289      gauss = new NormalDistributedRandom(random, 0, 1);
  • branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs

    r16057 r16092  
    231231    protected override void Initialize(CancellationToken cancellationToken) {
    232232      // Set up the algorithm
    233       if (SetSeedRandomly) Seed = new System.Random().Next();
     233      if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed();
    234234      pyramid = new List<Population>();
    235235      seen.Clear();
  • branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis

  • branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/LinearModelToTreeConverter.cs

    r16057 r16092  
    3737      string[] variableNames, double[] coefficients,
    3838      double @const = 0) {
     39
    3940      if (factorCoefficients.Length == 0 && coefficients.Length == 0) throw new ArgumentException();
    40       ISymbolicExpressionTree p1 = null;
     41
     42      // Create tree for double variables
     43      ISymbolicExpressionTree tree = null;     
    4144      if (coefficients.Length > 0) {
    42         p1 = CreateTree(variableNames, new int[variableNames.Length], coefficients, @const);
    43         if (factorCoefficients.Length == 0)
    44           return p1;
     45        tree = CreateTree(variableNames, new int[variableNames.Length], coefficients, @const);
     46        if (factorCoefficients.Length == 0) return tree;
    4547      }
     48
     49      // Create tree for string variables
     50      ISymbolicExpressionTree factorTree = null;     
    4651      if (factorCoefficients.Length > 0) {
    47         var p2 = CreateTree(factors, factorCoefficients);
    48         if (p1 == null) return p2;
     52        factorTree = CreateTree(factors, factorCoefficients, @const);
     53        if (tree == null) return factorTree; 
     54      }
    4955
    50         // combine
    51         ISymbolicExpressionTreeNode add = p1.Root.GetSubtree(0).GetSubtree(0);
    52         foreach (var binFactorNode in p2.IterateNodesPrefix().OfType<BinaryFactorVariableTreeNode>())
    53           add.AddSubtree(binFactorNode);
    54         return p1;
    55       }
     56      // Combine both trees
     57      ISymbolicExpressionTreeNode add = tree.Root.GetSubtree(0).GetSubtree(0);
     58      foreach (var binFactorNode in factorTree.IterateNodesPrefix().OfType<BinaryFactorVariableTreeNode>())
     59        add.InsertSubtree(add.SubtreeCount - 1, binFactorNode);
     60      return tree;
     61
    5662      throw new ArgumentException();
    5763    }
  • branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs

    r16057 r16092  
    116116
    117117    public ModifiableDataset ToModifiable() {
    118       var values = new List<IList>();
    119       foreach (var v in variableNames) {
    120         if (VariableHasType<double>(v)) {
    121           values.Add(new List<double>((IList<double>)variableValues[v]));
    122         } else if (VariableHasType<string>(v)) {
    123           values.Add(new List<string>((IList<string>)variableValues[v]));
    124         } else if (VariableHasType<DateTime>(v)) {
    125           values.Add(new List<DateTime>((IList<DateTime>)variableValues[v]));
    126         } else {
    127           throw new ArgumentException("Unknown variable type.");
    128         }
    129       }
    130       return new ModifiableDataset(variableNames, values);
     118      return new ModifiableDataset(variableNames, variableNames.Select(v => variableValues[v]), true);
    131119    }
    132120
     
    141129    }
    142130
    143     protected Dataset(Dataset dataset) : this(dataset.variableNames, dataset.variableValues.Values) { }
     131
    144132
    145133    #region Backwards compatible code, remove with 3.5
     
    318306    #region IStringConvertibleMatrix Members
    319307    [Storable]
    320     protected int rows;
     308    private int rows;
    321309    public int Rows {
    322310      get { return rows; }
     311      protected set { rows = value; }
    323312    }
    324313    int IStringConvertibleMatrix.Rows {
  • branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r16057 r16092  
    163163
    164164      var variables = dataset.VariableNames.Where(variable => dataset.VariableHasType<double>(variable) || dataset.VariableHasType<string>(variable));
    165       var inputVariables = new CheckedItemList<StringValue>(variables.Select(x => new StringValue(x)));
     165      var inputVariables = new CheckedItemList<StringValue>(variables.Select(x => new StringValue(x).AsReadOnly()));
    166166      foreach (StringValue x in inputVariables)
    167167        inputVariables.SetItemCheckedState(x, allowedInputVariables.Contains(x.Value));
  • branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs

    r16057 r16092  
    4747    public ModifiableDataset() { }
    4848
    49     public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues) :
    50       base(variableNames, variableValues, cloneValues: false) { }
    51 
     49    public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues, bool cloneValues = false) :
     50      base(variableNames, variableValues, cloneValues) { }
     51
     52    public Dataset ToDataset() {
     53      return new Dataset(variableNames, variableNames.Select(v => variableValues[v]));
     54    }
    5255    public void ReplaceRow(int row, IEnumerable<object> values) {
    5356      var list = values.ToList();
     
    9194        variableValues[variableNames[i]].Add(list[i]);
    9295      }
    93       rows++;
     96      Rows++;
    9497      OnRowsChanged();
    9598      OnReset();
     
    98101    // adds a new variable to the dataset
    99102    public void AddVariable(string variableName, IList values) {
     103      InsertVariable(variableName, Columns, values);
     104    }
     105
     106
     107    public void InsertVariable(string variableName, int position, IList values) {
    100108      if (variableValues.ContainsKey(variableName))
    101109        throw new ArgumentException(string.Format("Variable {0} is already present in the dataset.", variableName));
    102110
    103       if (values == null || values.Count == 0)
    104         throw new ArgumentException("Cannot add variable with no values.");
     111      if (position < 0 || position > Columns)
     112        throw new ArgumentException(string.Format("Incorrect position {0} specified. The position must be between 0 and {1}.", position, Columns));
     113
     114      if (values == null)
     115        throw new ArgumentNullException("values", "Values must not be null. At least an empty list of values has to be provided.");
     116
     117      if (values.Count != Rows)
     118        throw new ArgumentException(string.Format("{0} values are provided, but {1} rows are present in the dataset.", values.Count, Rows));
    105119
    106120      if (!IsAllowedType(values))
    107121        throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName));
    108122
     123      variableNames.Insert(position, variableName);
    109124      variableValues[variableName] = values;
    110       variableNames.Add(variableName);
    111125
    112126      OnColumnsChanged();
     
    129143      foreach (var list in variableValues.Values)
    130144        list.RemoveAt(row);
    131       rows--;
     145      Rows--;
    132146      OnRowsChanged();
    133147      OnReset();
  • branches/2839_HiveProjectManagement/HeuristicLab.Random/3.3/HeuristicLab.Random-3.3.csproj

    r14407 r16092  
    120120    <Compile Include="GammaDistributedRandom.cs" />
    121121    <Compile Include="ListExtensions.cs" />
     122    <Compile Include="RandomSeedGenerator.cs" />
    122123    <Compile Include="UniformDistributedRandom.cs" />
    123124    <Compile Include="FastRandom.cs" />
  • branches/2839_HiveProjectManagement/HeuristicLab.Random/3.3/RandomCreator.cs

    r16057 r16092  
    9494      IntValue seed = SeedParameter.ActualValue;
    9595
    96       if (setSeedRandomly) seed.Value = new System.Random().Next();
     96      if (setSeedRandomly) seed.Value = RandomSeedGenerator.GetSeed();
    9797      IRandom random = (IRandom)RandomType.Clone();
    9898      random.Reset(seed.Value);
Note: See TracChangeset for help on using the changeset viewer.