Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/15/18 12:36:08 (6 years ago)
Author:
gkronber
Message:

#2892: Merging r15750:16382 (HEAD) from trunk to branch, resolving conflicts

Location:
branches/2892_LR-prediction-intervals
Files:
27 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/2892_LR-prediction-intervals

  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis

  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4

  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs

    r15583 r16388  
    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
     
    258258
    259259          modifiableDataset.RemoveVariable(targetVarName);
    260           modifiableDataset.AddVariable(targetVarName, curY.Concat(curYTest));
     260          modifiableDataset.AddVariable(targetVarName, curY.Concat(curYTest).ToList());
    261261
    262262          SampleTrainingData(rand, modifiableDataset, rRows, problemData.Dataset, curY, problemData.TargetVariable, problemData.TrainingIndices); // all training indices from the original problem data are allowed
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs

    r15583 r16388  
    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/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj

    r15744 r16388  
    131131      <SubType>Code</SubType>
    132132    </Compile>
     133    <Compile Include="DoubleArrayExtensions.cs" />
    133134    <Compile Include="FixedDataAnalysisAlgorithm.cs" />
    134135    <Compile Include="GaussianProcess\CovarianceFunctions\CovarianceSpectralMixture.cs" />
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs

    r15583 r16388  
    8080      inputMatrix = factorMatrix.HorzCat(inputMatrix);
    8181
    82       if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     82      if (inputMatrix.ContainsNanOrInfinity())
    8383        throw new NotSupportedException("Linear discriminant analysis does not support NaN or infinity values in the input dataset.");
    8484
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs

    r15744 r16388  
    9292      int nVarCoeff = doubleVariables.Count();
    9393      var tree = LinearModelToTreeConverter.CreateTree(factorVariables, coefficients.Take(nFactorCoeff).ToArray(),
    94         doubleVariables.ToArray(), coefficients.Skip(nFactorCoeff).Take(nVarCoeff).ToArray(), 
     94        doubleVariables.ToArray(), coefficients.Skip(nFactorCoeff).Take(nVarCoeff).ToArray(),
    9595        @const: coefficients[nFeatures]);
    96      
     96
    9797      SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeLinearInterpreter()), (IRegressionProblemData)problemData.Clone());
    9898      solution.Model.Name = "Linear Regression Model";
     
    147147      inputMatrix = binaryMatrix.HorzCat(doubleVarMatrix);
    148148
    149       if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     149      if (inputMatrix.ContainsNanOrInfinity())
    150150        throw new NotSupportedException("Linear regression does not support NaN or infinity values in the input dataset.");
    151151    }
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitClassification.cs

    r15583 r16388  
    7878      inputMatrix = factorMatrix.HorzCat(inputMatrix);
    7979
    80       if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     80      if (inputMatrix.ContainsNanOrInfinity())
    8181        throw new NotSupportedException("Multinomial logit classification does not support NaN or infinity values in the input dataset.");
    8282
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaModel.cs

    r15583 r16388  
    6565
    6666      var ds = ReduceDataset(dataset, rows);
    67       nnModel = new NearestNeighbourModel(ds, Enumerable.Range(0, ds.Rows), k, ds.VariableNames.Last(), ds.VariableNames.Take(transformationMatrix.GetLength(1)), classValues);
     67      nnModel = new NearestNeighbourModel(ds, Enumerable.Range(0, ds.Rows), k, ds.VariableNames.Last(), ds.VariableNames.Take(transformationMatrix.GetLength(1)), classValues: classValues);
    6868    }
    6969
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs

    r15583 r16388  
    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();
     
    142145      }
    143146
    144       if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     147      if (inputMatrix.ContainsNanOrInfinity())
    145148        throw new NotSupportedException(
    146149          "Nearest neighbour model does not support NaN or infinity values in the input dataset.");
     
    259262
    260263
     264    public bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) {
     265      return RegressionModel.IsProblemDataCompatible(this, problemData, out errorMessage);
     266    }
     267
     268    public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
     269      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     270
     271      var regressionProblemData = problemData as IRegressionProblemData;
     272      if (regressionProblemData != null)
     273        return IsProblemDataCompatible(regressionProblemData, out errorMessage);
     274
     275      var classificationProblemData = problemData as IClassificationProblemData;
     276      if (classificationProblemData != null)
     277        return IsProblemDataCompatible(classificationProblemData, out errorMessage);
     278
     279      throw new ArgumentException("The problem data is not a regression nor a classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     280    }
     281
    261282    IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    262283      return new NearestNeighbourRegressionSolution(this, new RegressionProblemData(problemData));
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkClassification.cs

    r15583 r16388  
    115115    public NeuralNetworkClassification()
    116116      : base() {
    117       var validHiddenLayerValues = new ItemSet<IntValue>(new IntValue[] { 
    118         (IntValue)new IntValue(0).AsReadOnly(), 
    119         (IntValue)new IntValue(1).AsReadOnly(), 
     117      var validHiddenLayerValues = new ItemSet<IntValue>(new IntValue[] {
     118        (IntValue)new IntValue(0).AsReadOnly(),
     119        (IntValue)new IntValue(1).AsReadOnly(),
    120120        (IntValue)new IntValue(2).AsReadOnly() });
    121121      var selectedHiddenLayerValue = (from v in validHiddenLayerValues
     
    185185      IEnumerable<int> rows = problemData.TrainingIndices;
    186186      double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows);
    187       if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     187      if (inputMatrix.ContainsNanOrInfinity())
    188188        throw new NotSupportedException("Neural network classification does not support NaN or infinity values in the input dataset.");
    189189
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleClassification.cs

    r15583 r16388  
    171171      IEnumerable<int> rows = problemData.TrainingIndices;
    172172      double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows);
    173       if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     173      if (inputMatrix.ContainsNanOrInfinity())
    174174        throw new NotSupportedException("Neural network ensemble classification does not support NaN or infinity values in the input dataset.");
    175175
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleModel.cs

    r15739 r16388  
    3636  public sealed class NeuralNetworkEnsembleModel : ClassificationModel, INeuralNetworkEnsembleModel {
    3737
     38    private object mlpEnsembleLocker = new object();
    3839    private alglib.mlpensemble mlpEnsemble;
    39     public alglib.mlpensemble MultiLayerPerceptronEnsemble {
    40       get { return mlpEnsemble; }
    41       set {
    42         if (value != mlpEnsemble) {
    43           if (value == null) throw new ArgumentNullException();
    44           mlpEnsemble = value;
    45           OnChanged(EventArgs.Empty);
    46         }
    47       }
    48     }
    4940
    5041    public override IEnumerable<string> VariablesUsedForPrediction {
     
    10394        }
    10495        // mlpeprocess writes data in mlpEnsemble and is therefore not thread-safe
    105         lock (mlpEnsemble) {
     96        lock (mlpEnsembleLocker) {
    10697          alglib.mlpeprocess(mlpEnsemble, x, ref y);
    10798        }
     
    123114        }
    124115        // mlpeprocess writes data in mlpEnsemble and is therefore not thread-safe
    125         lock (mlpEnsemble) {
     116        lock (mlpEnsembleLocker) {
    126117          alglib.mlpeprocess(mlpEnsemble, x, ref y);
    127118        }
     
    139130    }
    140131
     132
     133    public bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) {
     134      return RegressionModel.IsProblemDataCompatible(this, problemData, out errorMessage);
     135    }
     136
     137    public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
     138      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     139
     140      var regressionProblemData = problemData as IRegressionProblemData;
     141      if (regressionProblemData != null)
     142        return IsProblemDataCompatible(regressionProblemData, out errorMessage);
     143
     144      var classificationProblemData = problemData as IClassificationProblemData;
     145      if (classificationProblemData != null)
     146        return IsProblemDataCompatible(classificationProblemData, out errorMessage);
     147
     148      throw new ArgumentException("The problem data is not a regression nor a classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     149    }
     150
    141151    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    142152      return new NeuralNetworkEnsembleRegressionSolution(this, new RegressionEnsembleProblemData(problemData));
     
    145155      return new NeuralNetworkEnsembleClassificationSolution(this, new ClassificationEnsembleProblemData(problemData));
    146156    }
    147 
    148     #region events
    149     public event EventHandler Changed;
    150     private void OnChanged(EventArgs e) {
    151       var handlers = Changed;
    152       if (handlers != null)
    153         handlers(this, e);
    154     }
    155     #endregion
    156 
     157   
    157158    #region persistence
    158159    [Storable]
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleRegression.cs

    r15583 r16388  
    125125    public NeuralNetworkEnsembleRegression()
    126126      : base() {
    127       var validHiddenLayerValues = new ItemSet<IntValue>(new IntValue[] { 
    128         (IntValue)new IntValue(0).AsReadOnly(), 
    129         (IntValue)new IntValue(1).AsReadOnly(), 
     127      var validHiddenLayerValues = new ItemSet<IntValue>(new IntValue[] {
     128        (IntValue)new IntValue(0).AsReadOnly(),
     129        (IntValue)new IntValue(1).AsReadOnly(),
    130130        (IntValue)new IntValue(2).AsReadOnly() });
    131131      var selectedHiddenLayerValue = (from v in validHiddenLayerValues
     
    170170      IEnumerable<int> rows = problemData.TrainingIndices;
    171171      double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows);
    172       if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     172      if (inputMatrix.ContainsNanOrInfinity())
    173173        throw new NotSupportedException("Neural network ensemble regression does not support NaN or infinity values in the input dataset.");
    174174
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkModel.cs

    r15739 r16388  
    3636  public sealed class NeuralNetworkModel : ClassificationModel, INeuralNetworkModel {
    3737
     38    private object mlpLocker = new object();
    3839    private alglib.multilayerperceptron multiLayerPerceptron;
    39     public alglib.multilayerperceptron MultiLayerPerceptron {
    40       get { return multiLayerPerceptron; }
    41       set {
    42         if (value != multiLayerPerceptron) {
    43           if (value == null) throw new ArgumentNullException();
    44           multiLayerPerceptron = value;
    45           OnChanged(EventArgs.Empty);
    46         }
    47       }
    48     }
    4940
    5041    public override IEnumerable<string> VariablesUsedForPrediction {
     
    10798        }
    10899        // NOTE: mlpprocess changes data in multiLayerPerceptron and is therefore not thread-save!
    109         lock (multiLayerPerceptron) {
     100        lock (mlpLocker) {
    110101          alglib.mlpprocess(multiLayerPerceptron, x, ref y);
    111102        }
     
    127118        }
    128119        // NOTE: mlpprocess changes data in multiLayerPerceptron and is therefore not thread-save!
    129         lock (multiLayerPerceptron) {
     120        lock (mlpLocker) {
    130121          alglib.mlpprocess(multiLayerPerceptron, x, ref y);
    131122        }
     
    143134    }
    144135
     136    public bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) {
     137      return RegressionModel.IsProblemDataCompatible(this, problemData, out errorMessage);
     138    }
     139
     140    public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
     141      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     142
     143      var regressionProblemData = problemData as IRegressionProblemData;
     144      if (regressionProblemData != null)
     145        return IsProblemDataCompatible(regressionProblemData, out errorMessage);
     146
     147      var classificationProblemData = problemData as IClassificationProblemData;
     148      if (classificationProblemData != null)
     149        return IsProblemDataCompatible(classificationProblemData, out errorMessage);
     150
     151      throw new ArgumentException("The problem data is not a regression nor a classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     152    }
     153
    145154    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    146155      return new NeuralNetworkRegressionSolution(this, new RegressionProblemData(problemData));
     
    149158      return new NeuralNetworkClassificationSolution(this, new ClassificationProblemData(problemData));
    150159    }
    151 
    152     #region events
    153     public event EventHandler Changed;
    154     private void OnChanged(EventArgs e) {
    155       var handlers = Changed;
    156       if (handlers != null)
    157         handlers(this, e);
    158     }
    159     #endregion
    160160
    161161    #region persistence
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkRegression.cs

    r15583 r16388  
    115115    public NeuralNetworkRegression()
    116116      : base() {
    117       var validHiddenLayerValues = new ItemSet<IntValue>(new IntValue[] { 
    118         (IntValue)new IntValue(0).AsReadOnly(), 
    119         (IntValue)new IntValue(1).AsReadOnly(), 
     117      var validHiddenLayerValues = new ItemSet<IntValue>(new IntValue[] {
     118        (IntValue)new IntValue(0).AsReadOnly(),
     119        (IntValue)new IntValue(1).AsReadOnly(),
    120120        (IntValue)new IntValue(2).AsReadOnly() });
    121121      var selectedHiddenLayerValue = (from v in validHiddenLayerValues
     
    186186      IEnumerable<int> rows = problemData.TrainingIndices;
    187187      double[,] inputMatrix = dataset.ToArray(allowedInputVariables.Concat(new string[] { targetVariable }), rows);
    188       if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     188      if (inputMatrix.ContainsNanOrInfinity())
    189189        throw new NotSupportedException("Neural network regression does not support NaN or infinity values in the input dataset.");
    190190
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs

    r15583 r16388  
    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/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassification.cs

    r15583 r16388  
    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/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModel.cs

    r15583 r16388  
    286286    }
    287287
     288    public bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) {
     289      return RegressionModel.IsProblemDataCompatible(this, problemData, out errorMessage);
     290    }
     291
     292    public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
     293      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     294
     295      var regressionProblemData = problemData as IRegressionProblemData;
     296      if (regressionProblemData != null)
     297        return IsProblemDataCompatible(regressionProblemData, out errorMessage);
     298
     299      var classificationProblemData = problemData as IClassificationProblemData;
     300      if (classificationProblemData != null)
     301        return IsProblemDataCompatible(classificationProblemData, out errorMessage);
     302
     303      throw new ArgumentException("The problem data is not a regression nor a classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     304    }
     305
    288306    public static RandomForestModel CreateRegressionModel(IRegressionProblemData problemData, int nTrees, double r, double m, int seed,
    289307      out double rmsError, out double outOfBagRmsError, out double avgRelError, out double outOfBagAvgRelError) {
     
    310328    public static RandomForestModel CreateClassificationModel(IClassificationProblemData problemData, int nTrees, double r, double m, int seed,
    311329      out double rmsError, out double outOfBagRmsError, out double relClassificationError, out double outOfBagRelClassificationError) {
    312       return CreateClassificationModel(problemData, problemData.TrainingIndices, nTrees, r, m, seed, 
     330      return CreateClassificationModel(problemData, problemData.TrainingIndices, nTrees, r, m, seed,
    313331        out rmsError, out outOfBagRmsError, out relClassificationError, out outOfBagRelClassificationError);
    314332    }
     
    370388
    371389    private static void AssertInputMatrix(double[,] inputMatrix) {
    372       if (inputMatrix.Cast<double>().Any(x => Double.IsNaN(x) || Double.IsInfinity(x)))
     390      if (inputMatrix.ContainsNanOrInfinity())
    373391        throw new NotSupportedException("Random forest modeling does not support NaN or infinity values in the input dataset.");
    374392    }
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegression.cs

    r15583 r16388  
    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/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineModel.cs

    r15583 r16388  
    126126      return new SupportVectorRegressionSolution(this, new RegressionProblemData(problemData));
    127127    }
    128     #endregion
     128
     129    public bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) {
     130      return RegressionModel.IsProblemDataCompatible(this, problemData, out errorMessage);
     131    }
     132    #endregion
     133
     134    public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
     135      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     136
     137      var regressionProblemData = problemData as IRegressionProblemData;
     138      if (regressionProblemData != null)
     139        return IsProblemDataCompatible(regressionProblemData, out errorMessage);
     140
     141      var classificationProblemData = problemData as IClassificationProblemData;
     142      if (classificationProblemData != null)
     143        return IsProblemDataCompatible(classificationProblemData, out errorMessage);
     144
     145      throw new ArgumentException("The problem data is not a regression nor a classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     146    }
    129147
    130148    #region IClassificationModel Members
     
    153171    }
    154172    #endregion
     173
    155174    private IEnumerable<double> GetEstimatedValuesHelper(IDataset dataset, IEnumerable<int> rows) {
    156175      // calculate predictions for the currently requested rows
    157       svm_problem problem = SupportVectorMachineUtil.CreateSvmProblem(dataset, TargetVariable, allowedInputVariables, rows);
     176      svm_problem problem = SupportVectorMachineUtil.CreateSvmProblem(dataset, allowedInputVariables, rows);
    158177      svm_problem scaledProblem = rangeTransform.Scale(problem);
    159178
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineUtil.cs

    r15583 r16388  
    3535  public class SupportVectorMachineUtil {
    3636    /// <summary>
    37     /// Transforms <paramref name="problemData"/> into a data structure as needed by libSVM.
    38     /// </summary>
    39     /// <param name="problemData">The problem data to transform</param>
     37    /// Transforms <paramref name="dataset"/> into a data structure as needed by libSVM.
     38    /// </summary>
     39    /// <param name="dataset">The source dataset</param>
     40    /// <param name="targetVariable">The target variable</param>
     41    /// <param name="inputVariables">The selected input variables to include in the svm_problem.</param>
    4042    /// <param name="rowIndices">The rows of the dataset that should be contained in the resulting SVM-problem</param>
    4143    /// <returns>A problem data type that can be used to train a support vector machine.</returns>
    4244    public static svm_problem CreateSvmProblem(IDataset dataset, string targetVariable, IEnumerable<string> inputVariables, IEnumerable<int> rowIndices) {
    43       double[] targetVector = dataset.GetDoubleValues(targetVariable, rowIndices).ToArray();
    44       svm_node[][] nodes = new svm_node[targetVector.Length][];
     45      double[] targetVector ;
     46      var nRows = rowIndices.Count();
     47      if (string.IsNullOrEmpty(targetVariable)) {
     48        // if the target variable is not set (e.g. for prediction of a trained model) we just use a zero vector
     49        targetVector = new double[nRows];
     50      } else {
     51        targetVector = dataset.GetDoubleValues(targetVariable, rowIndices).ToArray();
     52      }
     53      svm_node[][] nodes = new svm_node[nRows][];
    4554      int maxNodeIndex = 0;
    4655      int svmProblemRowIndex = 0;
     
    6675
    6776    /// <summary>
     77    /// Transforms <paramref name="dataset"/> into a data structure as needed by libSVM for prediction.
     78    /// </summary>
     79    /// <param name="dataset">The problem data to transform</param>
     80    /// <param name="inputVariables">The selected input variables to include in the svm_problem.</param>
     81    /// <param name="rowIndices">The rows of the dataset that should be contained in the resulting SVM-problem</param>
     82    /// <returns>A problem data type that can be used for prediction with a trained support vector machine.</returns>
     83    public static svm_problem CreateSvmProblem(IDataset dataset, IEnumerable<string> inputVariables, IEnumerable<int> rowIndices) {
     84      // for prediction we don't need a target variable
     85      return CreateSvmProblem(dataset, string.Empty, inputVariables, rowIndices);
     86    }
     87
     88    /// <summary>
    6889    /// Instantiate and return a svm_parameter object with default values.
    6990    /// </summary>
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/TSNEAlgorithm.cs

    r15583 r16388  
    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/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/TimeSeries/AutoregressiveModeling.cs

    r15583 r16388  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
    28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2928using HeuristicLab.Optimization;
    3029using HeuristicLab.Parameters;
     
    9796        inputMatrix[i, timeOffset] = targetValues[i + problemData.TrainingPartition.Start];
    9897
    99       if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     98      if (inputMatrix.ContainsNanOrInfinity())
    10099        throw new NotSupportedException("Linear regression does not support NaN or infinity values in the input dataset.");
    101100
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClustering.cs

    r15583 r16388  
    9191      int[] xyc;
    9292      double[,] inputMatrix = dataset.ToArray(allowedInputVariables, rows);
    93       if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     93      if (inputMatrix.ContainsNanOrInfinity())
    9494        throw new NotSupportedException("k-Means clustering does not support NaN or infinity values in the input dataset.");
    9595
  • branches/2892_LR-prediction-intervals/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClusteringModel.cs

    r15583 r16388  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Drawing;
     
    3435  [StorableClass]
    3536  [Item("KMeansClusteringModel", "Represents a k-Means clustering model.")]
    36   public sealed class KMeansClusteringModel : NamedItem, IClusteringModel {
     37  public sealed class KMeansClusteringModel : DataAnalysisModel, IClusteringModel {
    3738    public static new Image StaticItemImage {
    3839      get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; }
    3940    }
    4041
    41     public IEnumerable<string> VariablesUsedForPrediction {
     42    public override IEnumerable<string> VariablesUsedForPrediction {
    4243      get { return allowedInputVariables; }
    4344    }
     
    8485    }
    8586
     87    public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
     88      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     89      return IsDatasetCompatible(problemData.Dataset, out errorMessage);
     90    }
     91
    8692
    8793    public IEnumerable<int> GetClusterValues(IDataset dataset, IEnumerable<int> rows) {
Note: See TracChangeset for help on using the changeset viewer.