Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/19/16 16:53:37 (8 years ago)
Author:
mkommend
Message:

#2618: Merged r13939, r13963, r14110 into stable.

Location:
stable
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.Instances.DataAnalysis

  • stable/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/VariableNetworks/VariableNetwork.cs

    r13939 r14117  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Text;
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
     
    8685
    8786    protected override List<List<double>> GenerateValues() {
    88       // var shuffledIdx = Enumerable.Range(0, numberOfFeatures).Shuffle(random).ToList();
    89 
    9087      // variable names are shuffled in the beginning (and sorted at the end)
    9188      variableNames = variableNames.Shuffle(random).ToArray();
    9289
    93       // a third of all variables are independen vars
     90      // a third of all variables are independent vars
    9491      List<List<double>> lvl0 = new List<List<double>>();
    9592      int numLvl0 = (int)Math.Ceiling(numberOfFeatures * 0.33);
    9693
    9794      List<string> description = new List<string>(); // store information how the variable is actually produced
     95      List<string[]> inputVarNames = new List<string[]>(); // store information to produce graphviz file
    9896
    9997      var nrand = new NormalDistributedRandom(random, 0, 1);
    10098      for (int c = 0; c < numLvl0; c++) {
    10199        var datai = Enumerable.Range(0, TestPartitionEnd).Select(_ => nrand.NextDouble()).ToList();
     100        inputVarNames.Add(new string[] { });
    102101        description.Add("~ N(0, 1)");
    103102        lvl0.Add(datai);
     
    108107      int numLvl1 = (int)Math.Ceiling(numberOfFeatures * 0.33);
    109108      for (int c = 0; c < numLvl1; c++) {
    110         string desc;
    111         var x = GenerateRandomFunction(random, lvl0, out desc);
     109        string[] selectedVarNames;
     110        var x = GenerateRandomFunction(random, lvl0, out selectedVarNames);
    112111        var sigma = x.StandardDeviation();
    113112        var noisePrng = new NormalDistributedRandom(random, 0, sigma * Math.Sqrt(noiseRatio / (1.0 - noiseRatio)));
    114113        lvl1.Add(x.Select(t => t + noisePrng.NextDouble()).ToList());
     114
     115        inputVarNames.Add(selectedVarNames);
     116        var desc = string.Format("f({0})", string.Join(",", selectedVarNames));
    115117        description.Add(string.Format(" ~ N({0}, {1:N3})", desc, noisePrng.Sigma));
    116118      }
     
    120122      int numLvl2 = (int)Math.Ceiling(numberOfFeatures * 0.2);
    121123      for (int c = 0; c < numLvl2; c++) {
    122         string desc;
    123         var x = GenerateRandomFunction(random, lvl0.Concat(lvl1).ToList(), out desc);
     124        string[] selectedVarNames;
     125        var x = GenerateRandomFunction(random, lvl0.Concat(lvl1).ToList(), out selectedVarNames);
    124126        var sigma = x.StandardDeviation();
    125127        var noisePrng = new NormalDistributedRandom(random, 0, sigma * Math.Sqrt(noiseRatio / (1.0 - noiseRatio)));
    126128        lvl2.Add(x.Select(t => t + noisePrng.NextDouble()).ToList());
     129
     130        inputVarNames.Add(selectedVarNames);
     131        var desc = string.Format("f({0})", string.Join(",", selectedVarNames));
    127132        description.Add(string.Format(" ~ N({0}, {1:N3})", desc, noisePrng.Sigma));
    128133      }
     
    132137      int numLvl3 = numberOfFeatures - numLvl0 - numLvl1 - numLvl2;
    133138      for (int c = 0; c < numLvl3; c++) {
    134         string desc;
    135         var x = GenerateRandomFunction(random, lvl0.Concat(lvl1).Concat(lvl2).ToList(), out desc);
     139        string[] selectedVarNames;
     140        var x = GenerateRandomFunction(random, lvl0.Concat(lvl1).Concat(lvl2).ToList(), out selectedVarNames);
    136141        var sigma = x.StandardDeviation();
    137142        var noisePrng = new NormalDistributedRandom(random, 0, sigma * Math.Sqrt(noiseRatio / (1.0 - noiseRatio)));
    138143        lvl3.Add(x.Select(t => t + noisePrng.NextDouble()).ToList());
     144
     145        inputVarNames.Add(selectedVarNames);
     146        var desc = string.Format("f({0})", string.Join(",", selectedVarNames));
    139147        description.Add(string.Format(" ~ N({0}, {1:N3})", desc, noisePrng.Sigma));
    140148      }
     149
     150      networkDefinition = string.Join(Environment.NewLine, variableNames.Zip(description, (n, d) => n + d));
     151      // for graphviz
     152      networkDefinition += Environment.NewLine + "digraph G {";
     153      foreach (var t in variableNames.Zip(inputVarNames, Tuple.Create).OrderBy(t => t.Item1)) {
     154        var name = t.Item1;
     155        var selectedVarNames = t.Item2;
     156        foreach (var selectedVarName in selectedVarNames) {
     157          networkDefinition += Environment.NewLine + selectedVarName + " -> " + name;
     158        }
     159      }
     160      networkDefinition += Environment.NewLine + "}";
    141161
    142162      // return a random permutation of all variables
    143163      var allVars = lvl0.Concat(lvl1).Concat(lvl2).Concat(lvl3).ToList();
    144       networkDefinition = string.Join(Environment.NewLine, variableNames.Zip(description, (n, d) => n + d));
    145164      var orderedVars = allVars.Zip(variableNames, Tuple.Create).OrderBy(t => t.Item2).Select(t => t.Item1).ToList();
    146165      variableNames = variableNames.OrderBy(n => n).ToArray();
     
    149168
    150169    // sample the input variables that are actually used and sample from a Gaussian process
    151     private IEnumerable<double> GenerateRandomFunction(IRandom rand, List<List<double>> xs, out string desc) {
    152       int nRows = xs.First().Count;
    153 
     170    private IEnumerable<double> GenerateRandomFunction(IRandom rand, List<List<double>> xs, out string[] selectedVarNames) {
    154171      double r = -Math.Log(1.0 - rand.NextDouble()) * 2.0; // r is exponentially distributed with lambda = 2
    155172      int nl = (int)Math.Floor(1.5 + r); // number of selected vars is likely to be between three and four
     
    160177
    161178      var selectedVars = selectedIdx.Select(i => xs[i]).ToArray();
    162       desc = string.Format("f({0})", string.Join(",", selectedIdx.Select(i => VariableNames[i])));
     179      selectedVarNames = selectedIdx.Select(i => VariableNames[i]).ToArray();
    163180      return SampleGaussianProcess(random, selectedVars);
    164181    }
     
    171188      // sample length-scales
    172189      var l = Enumerable.Range(0, nl)
    173         .Select(_ => random.NextDouble()*2+0.5)
     190        .Select(_ => random.NextDouble() * 2 + 0.5)
    174191        .ToArray();
    175192      // calculate covariance matrix
  • stable/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/VariableNetworks/VariableNetworkInstanceProvider.cs

    r13939 r14117  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;                                                         
     24using System.Linq;
    2525using HeuristicLab.Problems.DataAnalysis;
    2626using HeuristicLab.Random;
     
    5656      if (varNetwork == null) throw new ArgumentException("VariableNetworkInstanceProvider expects an VariableNetwork data descriptor.");
    5757      // base call generates a regression problem data
    58       var regProblemData = base.LoadData(varNetwork);
    59       var problemData =
    60         new RegressionProblemData(
    61           regProblemData.Dataset, regProblemData.AllowedInputVariables, regProblemData.TargetVariable);
    62 
    63       // copy values from regProblemData to feature selection problem data
    64       problemData.Name = regProblemData.Name;
     58      var problemData = base.LoadData(varNetwork);
    6559      problemData.Description = varNetwork.Description + Environment.NewLine + varNetwork.NetworkDefinition;
    66       problemData.TrainingPartition.Start = regProblemData.TrainingPartition.Start;
    67       problemData.TrainingPartition.End = regProblemData.TrainingPartition.End;
    68       problemData.TestPartition.Start = regProblemData.TestPartition.Start;
    69       problemData.TestPartition.End = regProblemData.TestPartition.End;
    70 
    7160      return problemData;
    7261    }
Note: See TracChangeset for help on using the changeset viewer.