Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/10/10 21:01:03 (15 years ago)
Author:
gkronber
Message:

Implemented #834 (IPredictor.Predict() should return an IEnumerable<double> instead of an double[]).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.ArtificialNeuralNetworks/3.2/Predictor.cs

    r2562 r2619  
    3737    }
    3838
    39     public override double[] Predict(Dataset input, int start, int end) {
     39    public override IEnumerable<double> Predict(Dataset input, int start, int end) {
    4040
    4141      if (start < 0 || end <= start) throw new ArgumentException("start must be larger than zero and strictly smaller than end");
    4242      if (end > input.Rows) throw new ArgumentOutOfRangeException("number of rows in input is smaller then end");
    43       double[] result = new double[end - start];
    44       for (int i = 0; i < result.Length; i++) {
    45         try {
    46           double[] output = new double[1];
    47           double[] inputRow = new double[input.Columns - 1];
    48           for (int c = 1; c < inputRow.Length; c++) {
    49             inputRow[c - 1] = input.GetValue(i + start, c);
    50           }
    51           alglib.mlpbase.multilayerperceptron p = perceptron.Perceptron;
    52           alglib.mlpbase.mlpprocess(ref p, ref inputRow, ref output);
    53           perceptron.Perceptron = p;
    54           result[i] = Math.Max(Math.Min(output[0], UpperPredictionLimit), LowerPredictionLimit);
     43
     44      for (int i = 0; i < end - start; i++) {
     45        double[] output = new double[1];
     46        double[] inputRow = new double[input.Columns - 1];
     47        for (int c = 1; c < inputRow.Length; c++) {
     48          inputRow[c - 1] = input.GetValue(i + start, c);
    5549        }
    56         catch (ArgumentException) {
    57           result[i] = double.NaN;
    58         }
     50        alglib.mlpbase.multilayerperceptron p = perceptron.Perceptron;
     51        alglib.mlpbase.mlpprocess(ref p, ref inputRow, ref output);
     52        perceptron.Perceptron = p;
     53        yield return Math.Max(Math.Min(output[0], UpperPredictionLimit), LowerPredictionLimit);
    5954      }
    60       return result;
    6155    }
    6256
Note: See TracChangeset for help on using the changeset viewer.