Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14400 for trunk


Ignore:
Timestamp:
11/17/16 15:41:33 (8 years ago)
Author:
gkronber
Message:

#2697: reverse merge of r14378, r14390, r14391, r14393, r14394, r14396

Location:
trunk/sources
Files:
2 deleted
41 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs

    r14393 r14400  
    165165      try {
    166166        CalculateModel(ds, rows, scaleInputs);
    167       } catch (alglib.alglibexception ae) {
     167      }
     168      catch (alglib.alglibexception ae) {
    168169        // wrap exception so that calling code doesn't have to know about alglib implementation
    169170        throw new ArgumentException("There was a problem in the calculation of the Gaussian process model", ae);
     
    259260    private static double[,] GetData(IDataset ds, IEnumerable<string> allowedInputs, IEnumerable<int> rows, Scaling scaling) {
    260261      if (scaling != null) {
    261         // TODO: completely remove Scaling class
    262         List<ITransformation<double>> transformations = new List<ITransformation<double>>();
    263 
    264         foreach (var varName in allowedInputs) {
    265           double min;
    266           double max;
    267           scaling.GetScalingParameters(varName, out min, out max);
    268           var add = -min / (max - min);
    269           var mult = 1.0 / (max - min);
    270           transformations.Add(new LinearTransformation(allowedInputs) { Addend = add, Multiplier = mult });
    271         }
    272         return ds.ToArray(allowedInputs, transformations, rows);
     262        return AlglibUtil.PrepareAndScaleInputMatrix(ds, allowedInputs, rows, scaling);
    273263      } else {
    274         return ds.ToArray(allowedInputs, rows);
     264        return AlglibUtil.PrepareInputMatrix(ds, allowedInputs, rows);
    275265      }
    276266    }
     
    344334        return Enumerable.Range(0, newN)
    345335          .Select(i => ms[i] + Util.ScalarProd(Ks[i], alpha));
    346       } catch (alglib.alglibexception ae) {
     336      }
     337      catch (alglib.alglibexception ae) {
    347338        // wrap exception so that calling code doesn't have to know about alglib implementation
    348339        throw new ArgumentException("There was a problem in the calculation of the Gaussian process model", ae);
     
    390381        }
    391382        return kss;
    392       } catch (alglib.alglibexception ae) {
     383      }
     384      catch (alglib.alglibexception ae) {
    393385        // wrap exception so that calling code doesn't have to know about alglib implementation
    394386        throw new ArgumentException("There was a problem in the calculation of the Gaussian process model", ae);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj

    r14393 r14400  
    244244      <SubType>Code</SubType>
    245245    </Compile>
     246    <Compile Include="Linear\AlglibUtil.cs" />
     247    <Compile Include="Linear\Scaling.cs" />
    246248    <Compile Include="Linear\LinearDiscriminantAnalysis.cs" />
    247249    <Compile Include="Linear\LinearRegression.cs">
     
    251253    <Compile Include="Linear\MultinomialLogitClassificationSolution.cs" />
    252254    <Compile Include="Linear\MultinomialLogitModel.cs" />
    253     <Compile Include="Linear\Scaling.cs" />
    254255    <Compile Include="MctsSymbolicRegression\Automaton.cs" />
    255256    <Compile Include="MctsSymbolicRegression\CodeGenerator.cs" />
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs

    r14393 r14400  
    7070      IEnumerable<int> rows = problemData.TrainingIndices;
    7171      int nClasses = problemData.ClassNames.Count();
    72       double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows);
     72      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows);
    7373      if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
    7474        throw new NotSupportedException("Linear discriminant analysis does not support NaN or infinity values in the input dataset.");
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs

    r14393 r14400  
    7373      IEnumerable<string> allowedInputVariables = problemData.AllowedInputVariables;
    7474      IEnumerable<int> rows = problemData.TrainingIndices;
    75       double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows);
     75      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows);
    7676      if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
    7777        throw new NotSupportedException("Linear regression does not support NaN or infinity values in the input dataset.");
     
    8181      int nRows = inputMatrix.GetLength(0);
    8282      int nFeatures = inputMatrix.GetLength(1) - 1;
    83       double[] coefficients;
     83      double[] coefficients = new double[nFeatures + 1]; // last coefficient is for the constant
    8484
    8585      int retVal = 1;
     
    9191      alglib.lrunpack(lm, out coefficients, out nFeatures);
    9292
    93       var tree = LinearModelToTreeConverter.CreateTree(allowedInputVariables.ToArray(),
    94         coefficients.Take(nFeatures).ToArray(), @const: coefficients[nFeatures]);
     93      ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode());
     94      ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode();
     95      tree.Root.AddSubtree(startNode);
     96      ISymbolicExpressionTreeNode addition = new Addition().CreateTreeNode();
     97      startNode.AddSubtree(addition);
     98
     99      int col = 0;
     100      foreach (string column in allowedInputVariables) {
     101        VariableTreeNode vNode = (VariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable().CreateTreeNode();
     102        vNode.VariableName = column;
     103        vNode.Weight = coefficients[col];
     104        addition.AddSubtree(vNode);
     105        col++;
     106      }
     107
     108      ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode();
     109      cNode.Value = coefficients[coefficients.Length - 1];
     110      addition.AddSubtree(cNode);
    95111
    96112      SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter()), (IRegressionProblemData)problemData.Clone());
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitClassification.cs

    r14393 r14400  
    7070      IEnumerable<string> allowedInputVariables = problemData.AllowedInputVariables;
    7171      IEnumerable<int> rows = problemData.TrainingIndices;
    72       double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows);
     72      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows);
    7373      if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
    7474        throw new NotSupportedException("Multinomial logit classification does not support NaN or infinity values in the input dataset.");
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitModel.cs

    r14393 r14400  
    8383
    8484    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    85       double[,] inputData = dataset.ToArray( allowedInputVariables, rows);
     85      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    8686
    8787      int n = inputData.GetLength(0);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/Scaling.cs

    r14393 r14400  
    2929
    3030namespace HeuristicLab.Algorithms.DataAnalysis {
    31   [Obsolete("Use transformation classes in Problems.DataAnalysis instead")]
    3231  [StorableClass]
    3332  [Item(Name = "Scaling", Description = "Contains information about scaling of variables for data-analysis algorithms.")]
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/LdaInitializer.cs

    r14393 r14400  
    4444      var attributes = data.AllowedInputVariables.Count();
    4545
    46       var ldaDs = data.Dataset.ToArray(
    47                                        data.AllowedInputVariables.Concat(data.TargetVariable.ToEnumerable()),
    48                                        data.TrainingIndices);
     46      var ldaDs = AlglibUtil.PrepareInputMatrix(data.Dataset,
     47                                                data.AllowedInputVariables.Concat(data.TargetVariable.ToEnumerable()),
     48                                                data.TrainingIndices);
    4949
    5050      // map class values to sequential natural numbers (required by alglib)
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Initialization/PcaInitializer.cs

    r14393 r14400  
    4444      var attributes = data.AllowedInputVariables.Count();
    4545
    46       var pcaDs = data.Dataset.ToArray(data.AllowedInputVariables, data.TrainingIndices);
     46      var pcaDs = AlglibUtil.PrepareInputMatrix(data.Dataset, data.AllowedInputVariables, data.TrainingIndices);
    4747
    4848      int info;
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaGradientCalculator.cs

    r14393 r14400  
    9999      }
    100100
    101       var data = problemData.Dataset.ToArray(problemData.AllowedInputVariables,
    102                                              problemData.TrainingIndices);
     101      var data = AlglibUtil.PrepareInputMatrix(problemData.Dataset, problemData.AllowedInputVariables,
     102                                               problemData.TrainingIndices);
    103103      var classes = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices).ToArray();
    104104
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaModel.cs

    r14393 r14400  
    8686
    8787    public double[,] Reduce(IDataset dataset, IEnumerable<int> rows) {
    88       var data = dataset.ToArray(allowedInputVariables, rows);
     88      var data = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    8989
    9090      var targets = dataset.GetDoubleValues(TargetVariable, rows).ToArray();
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs

    r14393 r14400  
    119119      if (IsCompatibilityLoaded) {
    120120        // no scaling
    121         inputMatrix = dataset.ToArray(
     121        inputMatrix = AlglibUtil.PrepareInputMatrix(dataset,
    122122          this.allowedInputVariables.Concat(new string[] { targetVariable }),
    123123          rows);
     
    167167
    168168    private static double[,] CreateScaledData(IDataset dataset, IEnumerable<string> variables, IEnumerable<int> rows, double[] offsets, double[] factors) {
    169       var transforms =
    170         variables.Select(
    171           (_, colIdx) =>
    172             new LinearTransformation(variables) { Addend = offsets[colIdx] * factors[colIdx], Multiplier = factors[colIdx] });
    173       return dataset.ToArray(variables, transforms, rows);
     169      var x = new double[rows.Count(), variables.Count()];
     170      var colIdx = 0;
     171      foreach (var variableName in variables) {
     172        var rowIdx = 0;
     173        foreach (var val in dataset.GetDoubleValues(variableName, rows)) {
     174          x[rowIdx, colIdx] = (val + offsets[colIdx]) * factors[colIdx];
     175          rowIdx++;
     176        }
     177        colIdx++;
     178      }
     179      return x;
    174180    }
    175181
     
    181187      double[,] inputData;
    182188      if (IsCompatibilityLoaded) {
    183         inputData = dataset.ToArray(allowedInputVariables, rows);
     189        inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    184190      } else {
    185191        inputData = CreateScaledData(dataset, allowedInputVariables, rows, offsets, weights);
     
    217223      double[,] inputData;
    218224      if (IsCompatibilityLoaded) {
    219         inputData = dataset.ToArray(allowedInputVariables, rows);
     225        inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    220226      } else {
    221227        inputData = CreateScaledData(dataset, allowedInputVariables, rows, offsets, weights);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkClassification.cs

    r14393 r14400  
    183183      IEnumerable<string> allowedInputVariables = problemData.AllowedInputVariables;
    184184      IEnumerable<int> rows = problemData.TrainingIndices;
    185       double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows);
     185      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows);
    186186      if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
    187187        throw new NotSupportedException("Neural network classification does not support NaN or infinity values in the input dataset.");
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleClassification.cs

    r14393 r14400  
    124124    public NeuralNetworkEnsembleClassification()
    125125      : base() {
    126       var validHiddenLayerValues = new ItemSet<IntValue>(new IntValue[] {
    127         (IntValue)new IntValue(0).AsReadOnly(),
    128         (IntValue)new IntValue(1).AsReadOnly(),
     126      var validHiddenLayerValues = new ItemSet<IntValue>(new IntValue[] { 
     127        (IntValue)new IntValue(0).AsReadOnly(), 
     128        (IntValue)new IntValue(1).AsReadOnly(), 
    129129        (IntValue)new IntValue(2).AsReadOnly() });
    130130      var selectedHiddenLayerValue = (from v in validHiddenLayerValues
     
    169169      IEnumerable<string> allowedInputVariables = problemData.AllowedInputVariables;
    170170      IEnumerable<int> rows = problemData.TrainingIndices;
    171       double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows);
     171      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows);
    172172      if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
    173173        throw new NotSupportedException("Neural network ensemble classification does not support NaN or infinity values in the input dataset.");
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleModel.cs

    r14393 r14400  
    9191
    9292    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    93       double[,] inputData = dataset.ToArray(allowedInputVariables, rows);
     93      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    9494
    9595      int n = inputData.GetLength(0);
     
    108108
    109109    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    110       double[,] inputData = dataset.ToArray(allowedInputVariables, rows);
     110      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    111111
    112112      int n = inputData.GetLength(0);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleRegression.cs

    r14393 r14400  
    168168      IEnumerable<string> allowedInputVariables = problemData.AllowedInputVariables;
    169169      IEnumerable<int> rows = problemData.TrainingIndices;
    170       double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows);
     170      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows);
    171171      if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
    172172        throw new NotSupportedException("Neural network ensemble regression does not support NaN or infinity values in the input dataset.");
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkModel.cs

    r14393 r14400  
    9595
    9696    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    97       double[,] inputData = dataset.ToArray(allowedInputVariables, rows);
     97      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    9898
    9999      int n = inputData.GetLength(0);
     
    112112
    113113    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    114       double[,] inputData = dataset.ToArray( allowedInputVariables, rows);
     114      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    115115
    116116      int n = inputData.GetLength(0);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkRegression.cs

    r14393 r14400  
    184184      IEnumerable<string> allowedInputVariables = problemData.AllowedInputVariables;
    185185      IEnumerable<int> rows = problemData.TrainingIndices;
    186       double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows);
     186      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows);
    187187      if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
    188188        throw new NotSupportedException("Neural network regression does not support NaN or infinity values in the input dataset.");
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModel.cs

    r14393 r14400  
    139139
    140140    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    141       double[,] inputData = dataset.ToArray(AllowedInputVariables, rows);
     141      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, AllowedInputVariables, rows);
    142142      AssertInputMatrix(inputData);
    143143
     
    157157
    158158    public IEnumerable<double> GetEstimatedVariances(IDataset dataset, IEnumerable<int> rows) {
    159       double[,] inputData = dataset.ToArray(AllowedInputVariables, rows);
     159      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, AllowedInputVariables, rows);
    160160      AssertInputMatrix(inputData);
    161161
     
    175175
    176176    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    177       double[,] inputData = dataset.ToArray(AllowedInputVariables, rows);
     177      double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, AllowedInputVariables, rows);
    178178      AssertInputMatrix(inputData);
    179179
     
    294294      out double rmsError, out double outOfBagRmsError, out double avgRelError, out double outOfBagAvgRelError) {
    295295      var variables = problemData.AllowedInputVariables.Concat(new string[] { problemData.TargetVariable });
    296       double[,] inputMatrix = problemData.Dataset.ToArray(variables, trainingIndices);
     296      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(problemData.Dataset, variables, trainingIndices);
    297297
    298298      alglib.dfreport rep;
     
    316316
    317317      var variables = problemData.AllowedInputVariables.Concat(new string[] { problemData.TargetVariable });
    318       double[,] inputMatrix = problemData.Dataset.ToArray(variables, trainingIndices);
     318      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(problemData.Dataset, variables, trainingIndices);
    319319
    320320      var classValues = problemData.ClassValues.ToArray();
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/TimeSeries/AutoregressiveModeling.cs

    r14391 r14400  
    114114      alglib.lrunpack(lm, out coefficients, out nFeatures);
    115115
    116       var tree = LinearModelToTreeConverter.CreateTree(
    117         variableNames: Enumerable.Repeat(problemData.TargetVariable, nFeatures).ToArray(),
    118         lags: Enumerable.Range(0, timeOffset).Select(i => (i + 1) * -1).ToArray(),
    119         coefficients: coefficients.Take(nFeatures).ToArray(),
    120         @const: coefficients[nFeatures]
    121         );
     116
     117      ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode());
     118      ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode();
     119      tree.Root.AddSubtree(startNode);
     120      ISymbolicExpressionTreeNode addition = new Addition().CreateTreeNode();
     121      startNode.AddSubtree(addition);
     122
     123      for (int i = 0; i < timeOffset; i++) {
     124        LaggedVariableTreeNode node = (LaggedVariableTreeNode)new LaggedVariable().CreateTreeNode();
     125        node.VariableName = targetVariable;
     126        node.Weight = coefficients[i];
     127        node.Lag = (i + 1) * -1;
     128        addition.AddSubtree(node);
     129      }
     130
     131      ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode();
     132      cNode.Value = coefficients[coefficients.Length - 1];
     133      addition.AddSubtree(cNode);
    122134
    123135      var interpreter = new SymbolicTimeSeriesPrognosisExpressionTreeInterpreter(problemData.TargetVariable);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClustering.cs

    r14393 r14400  
    8989      double[,] centers;
    9090      int[] xyc;
    91       double[,] inputMatrix = dataset.ToArray(allowedInputVariables, rows);
     91      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
    9292      if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
    9393        throw new NotSupportedException("k-Means clustering does not support NaN or infinity values in the input dataset.");
  • trunk/sources/HeuristicLab.Common/3.3/EnumerableExtensions.cs

    r14393 r14400  
    133133      }
    134134    }
    135     public static IEnumerable<T> TakeEvery<T>(this IEnumerable<T> xs, int nth) {
    136       int i = 0;
    137       foreach (var x in xs) {
    138         if (i % nth == 0) yield return x;
    139         i++;
    140       }
    141     }
    142135
    143136    /// <summary>
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/PreprocessingTransformator.cs

    r14393 r14400  
    113113      // don't apply when the check fails
    114114      if (success)
    115         return transformation.ConfigureAndApply(data);
     115        return transformation.Apply(data);
    116116      else
    117117        return data;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs

    r14390 r14400  
    5353      //check inputVariables used in the symbolic regression model
    5454      var usedVariables =
    55         Content.Model.VariablesUsedForPrediction;
     55        Content.Model.SymbolicExpressionTree.IterateNodesPostfix().OfType<VariableTreeNode>().Select(
     56          node => node.VariableName).Distinct();
    5657      foreach (var variable in usedVariables) {
    5758        problemData.InputVariables.SetItemCheckedState(
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj

    r14378 r14400  
    102102      <SpecificVersion>False</SpecificVersion>
    103103      <HintPath>..\..\bin\ALGLIB-3.7.0.dll</HintPath>
     104      <Private>False</Private>
     105    </Reference>
     106    <Reference Include="AutoDiff-1.0, Version=1.0.0.14388, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     107      <HintPath>..\..\bin\AutoDiff-1.0.dll</HintPath>
    104108      <Private>False</Private>
    105109    </Reference>
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Plugin.cs.frame

    r14378 r14400  
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")]
     31  [PluginDependency("HeuristicLab.AutoDiff", "1.0")]
    3132  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    3233  [PluginDependency("HeuristicLab.Common", "3.3")]
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs

    r14390 r14400  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using AutoDiff;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    152153    }
    153154
     155    #region derivations of functions
     156    // create function factory for arctangent
     157    private readonly Func<Term, UnaryFunc> arctan = UnaryFunc.Factory(
     158      eval: Math.Atan,
     159      diff: x => 1 / (1 + x * x));
     160    private static readonly Func<Term, UnaryFunc> sin = UnaryFunc.Factory(
     161      eval: Math.Sin,
     162      diff: Math.Cos);
     163    private static readonly Func<Term, UnaryFunc> cos = UnaryFunc.Factory(
     164       eval: Math.Cos,
     165       diff: x => -Math.Sin(x));
     166    private static readonly Func<Term, UnaryFunc> tan = UnaryFunc.Factory(
     167      eval: Math.Tan,
     168      diff: x => 1 + Math.Tan(x) * Math.Tan(x));
     169    private static readonly Func<Term, UnaryFunc> erf = UnaryFunc.Factory(
     170      eval: alglib.errorfunction,
     171      diff: x => 2.0 * Math.Exp(-(x * x)) / Math.Sqrt(Math.PI));
     172    private static readonly Func<Term, UnaryFunc> norm = UnaryFunc.Factory(
     173      eval: alglib.normaldistribution,
     174      diff: x => -(Math.Exp(-(x * x)) * Math.Sqrt(Math.Exp(x * x)) * x) / Math.Sqrt(2 * Math.PI));
     175    #endregion
     176
     177
    154178    public static double OptimizeConstants(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int maxIterations, bool updateVariableWeights = true, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue, bool updateConstantsInTree = true) {
    155179
    156       string[] variableNames;
    157       int[] lags;
    158       double[] constants;
    159 
    160       TreeToAutoDiffTermConverter.ParametricFunction func;
    161       TreeToAutoDiffTermConverter.ParametricFunctionGradient func_grad;
    162       if (!TreeToAutoDiffTermConverter.TryTransformToAutoDiff(tree, updateVariableWeights, out variableNames, out lags, out constants, out func, out func_grad))
     180      List<AutoDiff.Variable> variables = new List<AutoDiff.Variable>();
     181      List<AutoDiff.Variable> parameters = new List<AutoDiff.Variable>();
     182      List<string> variableNames = new List<string>();
     183      List<int> lags = new List<int>();
     184
     185      AutoDiff.Term func;
     186      if (!TryTransformToAutoDiff(tree.Root.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out func))
    163187        throw new NotSupportedException("Could not optimize constants of symbolic expression tree due to not supported symbols used in the tree.");
    164       if (variableNames.Length == 0) return 0.0;
     188      if (variableNames.Count == 0) return 0.0;
     189
     190      AutoDiff.IParametricCompiledTerm compiledFunc = func.Compile(variables.ToArray(), parameters.ToArray());
     191
     192      List<SymbolicExpressionTreeTerminalNode> terminalNodes = null;
     193      if (updateVariableWeights)
     194        terminalNodes = tree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTerminalNode>().ToList();
     195      else
     196        terminalNodes = new List<SymbolicExpressionTreeTerminalNode>(tree.Root.IterateNodesPrefix().OfType<ConstantTreeNode>());
    165197
    166198      //extract inital constants
    167       double[] c = new double[constants.Length + 2];
    168       c[0] = 0.0;
    169       c[1] = 1.0;
    170       Array.Copy(constants, 0, c, 2, constants.Length);
     199      double[] c = new double[variables.Count];
     200      {
     201        c[0] = 0.0;
     202        c[1] = 1.0;
     203        int i = 2;
     204        foreach (var node in terminalNodes) {
     205          ConstantTreeNode constantTreeNode = node as ConstantTreeNode;
     206          VariableTreeNode variableTreeNode = node as VariableTreeNode;
     207          if (constantTreeNode != null)
     208            c[i++] = constantTreeNode.Value;
     209          else if (updateVariableWeights && variableTreeNode != null)
     210            c[i++] = variableTreeNode.Weight;
     211        }
     212      }
    171213      double[] originalConstants = (double[])c.Clone();
    172214      double originalQuality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
     
    176218      int info;
    177219
    178       // TODO: refactor
    179220      IDataset ds = problemData.Dataset;
    180       double[,] x = new double[rows.Count(), variableNames.Length];
     221      double[,] x = new double[rows.Count(), variableNames.Count];
    181222      int row = 0;
    182223      foreach (var r in rows) {
    183         for (int col = 0; col < variableNames.Length; col++) {
     224        for (int col = 0; col < variableNames.Count; col++) {
    184225          int lag = lags[col];
    185226          x[row, col] = ds.GetDoubleValue(variableNames[col], r + lag);
     
    192233      int k = c.Length;
    193234
    194       alglib.ndimensional_pfunc function_cx_1_func = CreatePFunc(func);
    195       alglib.ndimensional_pgrad function_cx_1_grad = CreatePGrad(func_grad);
     235      alglib.ndimensional_pfunc function_cx_1_func = CreatePFunc(compiledFunc);
     236      alglib.ndimensional_pgrad function_cx_1_grad = CreatePGrad(compiledFunc);
    196237
    197238      try {
     
    231272    }
    232273
    233     private static alglib.ndimensional_pfunc CreatePFunc(TreeToAutoDiffTermConverter.ParametricFunction func) {
    234       return (double[] c, double[] x, ref double fx, object o) => {
    235         fx = func(c, x);
     274    private static alglib.ndimensional_pfunc CreatePFunc(AutoDiff.IParametricCompiledTerm compiledFunc) {
     275      return (double[] c, double[] x, ref double func, object o) => {
     276        func = compiledFunc.Evaluate(c, x);
    236277      };
    237278    }
    238279
    239     private static alglib.ndimensional_pgrad CreatePGrad(TreeToAutoDiffTermConverter.ParametricFunctionGradient func_grad) {
    240       return (double[] c, double[] x, ref double fx, double[] grad, object o) => {
    241         var tupel = func_grad(c, x);
    242         fx = tupel.Item2;
     280    private static alglib.ndimensional_pgrad CreatePGrad(AutoDiff.IParametricCompiledTerm compiledFunc) {
     281      return (double[] c, double[] x, ref double func, double[] grad, object o) => {
     282        var tupel = compiledFunc.Differentiate(c, x);
     283        func = tupel.Item2;
    243284        Array.Copy(tupel.Item1, grad, grad.Length);
    244285      };
    245286    }
    246287
     288    private static bool TryTransformToAutoDiff(ISymbolicExpressionTreeNode node, List<AutoDiff.Variable> variables, List<AutoDiff.Variable> parameters, List<string> variableNames, List<int> lags, bool updateVariableWeights, out AutoDiff.Term term) {
     289      if (node.Symbol is Constant) {
     290        var var = new AutoDiff.Variable();
     291        variables.Add(var);
     292        term = var;
     293        return true;
     294      }
     295      if (node.Symbol is Variable) {
     296        var varNode = node as VariableTreeNode;
     297        var par = new AutoDiff.Variable();
     298        parameters.Add(par);
     299        variableNames.Add(varNode.VariableName);
     300        lags.Add(0);
     301
     302        if (updateVariableWeights) {
     303          var w = new AutoDiff.Variable();
     304          variables.Add(w);
     305          term = AutoDiff.TermBuilder.Product(w, par);
     306        } else {
     307          term = varNode.Weight * par;
     308        }
     309        return true;
     310      }
     311      if (node.Symbol is LaggedVariable) {
     312        var varNode = node as LaggedVariableTreeNode;
     313        var par = new AutoDiff.Variable();
     314        parameters.Add(par);
     315        variableNames.Add(varNode.VariableName);
     316        lags.Add(varNode.Lag);
     317
     318        if (updateVariableWeights) {
     319          var w = new AutoDiff.Variable();
     320          variables.Add(w);
     321          term = AutoDiff.TermBuilder.Product(w, par);
     322        } else {
     323          term = varNode.Weight * par;
     324        }
     325        return true;
     326      }
     327      if (node.Symbol is Addition) {
     328        List<AutoDiff.Term> terms = new List<Term>();
     329        foreach (var subTree in node.Subtrees) {
     330          AutoDiff.Term t;
     331          if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, lags, updateVariableWeights, out t)) {
     332            term = null;
     333            return false;
     334          }
     335          terms.Add(t);
     336        }
     337        term = AutoDiff.TermBuilder.Sum(terms);
     338        return true;
     339      }
     340      if (node.Symbol is Subtraction) {
     341        List<AutoDiff.Term> terms = new List<Term>();
     342        for (int i = 0; i < node.SubtreeCount; i++) {
     343          AutoDiff.Term t;
     344          if (!TryTransformToAutoDiff(node.GetSubtree(i), variables, parameters, variableNames, lags, updateVariableWeights, out t)) {
     345            term = null;
     346            return false;
     347          }
     348          if (i > 0) t = -t;
     349          terms.Add(t);
     350        }
     351        if (terms.Count == 1) term = -terms[0];
     352        else term = AutoDiff.TermBuilder.Sum(terms);
     353        return true;
     354      }
     355      if (node.Symbol is Multiplication) {
     356        List<AutoDiff.Term> terms = new List<Term>();
     357        foreach (var subTree in node.Subtrees) {
     358          AutoDiff.Term t;
     359          if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, lags, updateVariableWeights, out t)) {
     360            term = null;
     361            return false;
     362          }
     363          terms.Add(t);
     364        }
     365        if (terms.Count == 1) term = terms[0];
     366        else term = terms.Aggregate((a, b) => new AutoDiff.Product(a, b));
     367        return true;
     368
     369      }
     370      if (node.Symbol is Division) {
     371        List<AutoDiff.Term> terms = new List<Term>();
     372        foreach (var subTree in node.Subtrees) {
     373          AutoDiff.Term t;
     374          if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, lags, updateVariableWeights, out t)) {
     375            term = null;
     376            return false;
     377          }
     378          terms.Add(t);
     379        }
     380        if (terms.Count == 1) term = 1.0 / terms[0];
     381        else term = terms.Aggregate((a, b) => new AutoDiff.Product(a, 1.0 / b));
     382        return true;
     383      }
     384      if (node.Symbol is Logarithm) {
     385        AutoDiff.Term t;
     386        if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) {
     387          term = null;
     388          return false;
     389        } else {
     390          term = AutoDiff.TermBuilder.Log(t);
     391          return true;
     392        }
     393      }
     394      if (node.Symbol is Exponential) {
     395        AutoDiff.Term t;
     396        if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) {
     397          term = null;
     398          return false;
     399        } else {
     400          term = AutoDiff.TermBuilder.Exp(t);
     401          return true;
     402        }
     403      }
     404      if (node.Symbol is Square) {
     405        AutoDiff.Term t;
     406        if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) {
     407          term = null;
     408          return false;
     409        } else {
     410          term = AutoDiff.TermBuilder.Power(t, 2.0);
     411          return true;
     412        }
     413      }
     414      if (node.Symbol is SquareRoot) {
     415        AutoDiff.Term t;
     416        if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) {
     417          term = null;
     418          return false;
     419        } else {
     420          term = AutoDiff.TermBuilder.Power(t, 0.5);
     421          return true;
     422        }
     423      }
     424      if (node.Symbol is Sine) {
     425        AutoDiff.Term t;
     426        if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) {
     427          term = null;
     428          return false;
     429        } else {
     430          term = sin(t);
     431          return true;
     432        }
     433      }
     434      if (node.Symbol is Cosine) {
     435        AutoDiff.Term t;
     436        if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) {
     437          term = null;
     438          return false;
     439        } else {
     440          term = cos(t);
     441          return true;
     442        }
     443      }
     444      if (node.Symbol is Tangent) {
     445        AutoDiff.Term t;
     446        if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) {
     447          term = null;
     448          return false;
     449        } else {
     450          term = tan(t);
     451          return true;
     452        }
     453      }
     454      if (node.Symbol is Erf) {
     455        AutoDiff.Term t;
     456        if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) {
     457          term = null;
     458          return false;
     459        } else {
     460          term = erf(t);
     461          return true;
     462        }
     463      }
     464      if (node.Symbol is Norm) {
     465        AutoDiff.Term t;
     466        if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) {
     467          term = null;
     468          return false;
     469        } else {
     470          term = norm(t);
     471          return true;
     472        }
     473      }
     474      if (node.Symbol is StartSymbol) {
     475        var alpha = new AutoDiff.Variable();
     476        var beta = new AutoDiff.Variable();
     477        variables.Add(beta);
     478        variables.Add(alpha);
     479        AutoDiff.Term branchTerm;
     480        if (TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out branchTerm)) {
     481          term = branchTerm * alpha + beta;
     482          return true;
     483        } else {
     484          term = null;
     485          return false;
     486        }
     487      }
     488      term = null;
     489      return false;
     490    }
     491
    247492    public static bool CanOptimizeConstants(ISymbolicExpressionTree tree) {
    248       return TreeToAutoDiffTermConverter.IsCompatible(tree);
     493      var containsUnknownSymbol = (
     494        from n in tree.Root.GetSubtree(0).IterateNodesPrefix()
     495        where
     496         !(n.Symbol is Variable) &&
     497         !(n.Symbol is LaggedVariable) &&
     498         !(n.Symbol is Constant) &&
     499         !(n.Symbol is Addition) &&
     500         !(n.Symbol is Subtraction) &&
     501         !(n.Symbol is Multiplication) &&
     502         !(n.Symbol is Division) &&
     503         !(n.Symbol is Logarithm) &&
     504         !(n.Symbol is Exponential) &&
     505         !(n.Symbol is SquareRoot) &&
     506         !(n.Symbol is Square) &&
     507         !(n.Symbol is Sine) &&
     508         !(n.Symbol is Cosine) &&
     509         !(n.Symbol is Tangent) &&
     510         !(n.Symbol is Erf) &&
     511         !(n.Symbol is Norm) &&
     512         !(n.Symbol is StartSymbol)
     513        select n).
     514      Any();
     515      return !containsUnknownSymbol;
    249516    }
    250517  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r14390 r14400  
    259259
    260260    private void btnSimplify_Click(object sender, EventArgs e) {
    261       var simplifier = new TreeSimplifier();
     261      var simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();
    262262      var simplifiedExpressionTree = simplifier.Simplify(Content.Model.SymbolicExpressionTree);
    263263      UpdateModel(simplifiedExpressionTree);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r14390 r14400  
    5151      while (dividend > 0) {
    5252        int modulo = (dividend - 1) % 26;
    53         columnName = System.Convert.ToChar(65 + modulo).ToString() + columnName;
     53        columnName = Convert.ToChar(65 + modulo).ToString() + columnName;
    5454        dividend = (int)((dividend - modulo) / 26);
    5555      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r14390 r14400  
    103103      <Private>False</Private>
    104104    </Reference>
    105     <Reference Include="AutoDiff-1.0, Version=1.0.0.14388, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    106       <HintPath>..\..\bin\AutoDiff-1.0.dll</HintPath>
    107       <Private>False</Private>
    108     </Reference>
    109105    <Reference Include="System" />
    110106    <Reference Include="System.Core">
     
    137133      <SubType>Code</SubType>
    138134    </Compile>
    139     <Compile Include="Converters\Convert.cs" />
    140     <Compile Include="Converters\LinearModelToTreeConverter.cs" />
    141     <Compile Include="Converters\TreeSimplifier.cs" />
    142     <Compile Include="Converters\TreeToAutoDiffTermConverter.cs" />
    143135    <Compile Include="Formatters\InfixExpressionFormatter.cs" />
    144136    <Compile Include="Formatters\SymbolicDataAnalysisExpressionMathematicaFormatter.cs" />
     
    151143    <Compile Include="SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs" />
    152144    <Compile Include="SymbolicDataAnalysisModelComplexityCalculator.cs" />
     145    <Compile Include="SymbolicExpressionTreeBacktransformator.cs" />
    153146    <Compile Include="SymbolicDataAnalysisExpressionPruningOperator.cs" />
    154147    <Compile Include="Analyzers\SymbolicDataAnalysisVariableFrequencyAnalyzer.cs" />
     
    193186    <Compile Include="Interfaces\ISymbolicDataAnalysisAnalyzer.cs" />
    194187    <Compile Include="SymbolicDataAnalysisSingleObjectiveProblem.cs" />
     188    <Compile Include="SymbolicDataAnalysisExpressionTreeSimplifier.cs" />
    195189    <Compile Include="SymbolicDataAnalysisProblem.cs" />
    196190    <Compile Include="SymbolicDataAnalysisSolutionImpactValuesCalculator.cs" />
     
    246240    <Compile Include="Symbols\VariableConditionTreeNode.cs" />
    247241    <Compile Include="Symbols\VariableTreeNode.cs" />
    248     <Compile Include="Transformations\SymbolicExpressionTreeBacktransformator.cs" />
    249     <Compile Include="Transformations\TransformationToSymbolicTreeMapper.cs" />
     242    <Compile Include="TransformationToSymbolicTreeMapper.cs" />
    250243    <Compile Include="TreeMatching\SymbolicExpressionTreeBottomUpSimilarityCalculator.cs" />
    251244    <Compile Include="TreeMatching\SymbolicExpressionTreeCanonicalSorter.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Plugin.cs.frame

    r14378 r14400  
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")]
    31   [PluginDependency("HeuristicLab.AutoDiff", "1.0")]
    3231  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    3332  [PluginDependency("HeuristicLab.Collections", "3.3")]
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs

    r14390 r14400  
    3737    }
    3838
    39     private readonly TreeSimplifier simplifier = new TreeSimplifier();
     39    private readonly SymbolicDataAnalysisExpressionTreeSimplifier simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();
    4040
    4141    [StorableConstructor]
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/DatasetExtensions.cs

    r14393 r14400  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    24 using System.Linq;
    2523
    2624namespace HeuristicLab.Problems.DataAnalysis {
    2725  public static class DatasetExtensions {
    28     public static double[,] ToArray(this IDataset dataset, IEnumerable<string> variables, IEnumerable<int> rows) {
    29       return ToArray(dataset,
    30         variables,
    31         transformations: variables.Select(_ => (ITransformation<double>)null),  // no transform
    32         rows: rows);
    33     }
    34     public static double[,] ToArray(this IDataset dataset, IEnumerable<string> variables, IEnumerable<ITransformation<double>> transformations, IEnumerable<int> rows) {
    35       string[] variablesArr = variables.ToArray();
    36       int[] rowsArr = rows.ToArray();
    37       ITransformation<double>[] transformArr = transformations.ToArray();
    38       if (transformArr.Length != variablesArr.Length)
    39         throw new ArgumentException("Number of variables and number of transformations must match.");
    40 
    41       double[,] matrix = new double[rowsArr.Length, variablesArr.Length];
    42 
    43       for (int i = 0; i < variablesArr.Length; i++) {
    44         var origValues = dataset.GetDoubleValues(variablesArr[i], rowsArr);
    45         var values = transformArr[i] != null ? transformArr[i].Apply(origValues) : origValues;
    46         int row = 0;
    47         foreach (var value in values) {
    48           matrix[row, i] = value;
    49           row++;
    50         }
     26    public static IEnumerable<T> TakeEvery<T>(this IEnumerable<T> xs, int nth) {
     27      int i = 0;
     28      foreach (var x in xs) {
     29        if (i % nth == 0) yield return x;
     30        i++;
    5131      }
    52 
    53       return matrix;
    5432    }
    5533  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r14396 r14400  
    7373    }
    7474
    75     public double[,] AllowedInputsTrainingValues {
    76       get { return Dataset.ToArray(AllowedInputVariables, TrainingIndices); }
    77     }
    78 
    79     public double[,] AllowedInputsTestValues { get { return Dataset.ToArray(AllowedInputVariables, TestIndices); } }
    8075    public IntRange TrainingPartition {
    8176      get { return TrainingPartitionParameter.Value; }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LinearTransformation.cs

    r14393 r14400  
    5252    public double Multiplier {
    5353      get { return MultiplierParameter.Value.Value; }
    54       set {
     54      protected set {
    5555        MultiplierParameter.Value.Value = value;
    5656      }
     
    5959    public double Addend {
    6060      get { return AddendParameter.Value.Value; }
    61       set {
     61      protected set {
    6262        AddendParameter.Value.Value = value;
    6363      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ShiftStandardDistributionTransformation.cs

    r14393 r14400  
    7171
    7272    public override IEnumerable<double> Apply(IEnumerable<double> data) {
     73      ConfigureParameters(data);
    7374      if (OriginalStandardDeviation.IsAlmost(0.0)) {
    7475        return data;
     
    9394    }
    9495
    95     public override void ConfigureParameters(IEnumerable<double> data) {
     96    protected void ConfigureParameters(IEnumerable<double> data) {
    9697      OriginalStandardDeviation = data.StandardDeviation();
    9798      OriginalMean = data.Average();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ShiftToRangeTransformation.cs

    r14393 r14400  
    4444    }
    4545
     46    public override IEnumerable<double> Apply(IEnumerable<double> data) {
     47      ConfigureParameters(data);
     48      return base.Apply(data);
     49    }
     50
    4651    public override bool Check(IEnumerable<double> data, out string errorMsg) {
    4752      ConfigureParameters(data);
     
    4954    }
    5055
    51     public override void ConfigureParameters(IEnumerable<double> data) {
     56    protected void ConfigureParameters(IEnumerable<double> data) {
    5257      double originalRangeStart = data.Min();
    5358      double originalRangeEnd = data.Max();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/Transformation.cs

    r14393 r14400  
    6666    protected Transformation(IEnumerable<string> allowedColumns) : base(allowedColumns) { }
    6767
    68     public virtual void ConfigureParameters(IEnumerable<T> data) {
    69       // override in transformations with parameters
    70     }
    71 
    7268    public abstract IEnumerable<T> Apply(IEnumerable<T> data);
    73     public IEnumerable<T> ConfigureAndApply(IEnumerable<T> data) {
    74       ConfigureParameters(data);
    75       return Apply(data);
    76     }
    7769
    7870    public abstract bool Check(IEnumerable<T> data, out string errorMsg);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs

    r14396 r14400  
    3333    IEnumerable<string> AllowedInputVariables { get; }
    3434
    35     double[,] AllowedInputsTrainingValues { get; }
    36     double[,] AllowedInputsTestValues { get; }
    37 
    3835    IntRange TrainingPartition { get; }
    3936    IntRange TestPartition { get; }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/ITransformation.cs

    r14393 r14400  
    3030
    3131  public interface ITransformation<T> : ITransformation {
    32     void ConfigureParameters(IEnumerable<T> data);
    33     IEnumerable<T> ConfigureAndApply(IEnumerable<T> data);
    3432    IEnumerable<T> Apply(IEnumerable<T> data);
    3533  }
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeSimplifierTest.cs

    r14394 r14400  
    3636    public void SimplifierAxiomsTest() {
    3737      SymbolicExpressionImporter importer = new SymbolicExpressionImporter();
    38       TreeSimplifier simplifier = new TreeSimplifier();
     38      SymbolicDataAnalysisExpressionTreeSimplifier simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();
    3939      SymbolicExpressionTreeStringFormatter formatter = new SymbolicExpressionTreeStringFormatter();
    4040      #region single argument arithmetics
Note: See TracChangeset for help on using the changeset viewer.