Free cookie consent management tool by TermsFeed Policy Generator

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

#2891: merged r15739 and r16168 from trunk to stable

Location:
stable
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.DataAnalysis

  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4

  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleModel.cs

    r15584 r16387  
    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 {
     
    10293          x[column] = inputData[row, column];
    10394        }
    104         alglib.mlpeprocess(mlpEnsemble, x, ref y);
     95        // mlpeprocess writes data in mlpEnsemble and is therefore not thread-safe
     96        lock (mlpEnsembleLocker) {
     97          alglib.mlpeprocess(mlpEnsemble, x, ref y);
     98        }
    10599        yield return y[0];
    106100      }
     
    119113          x[column] = inputData[row, column];
    120114        }
    121         alglib.mlpeprocess(mlpEnsemble, x, ref y);
     115        // mlpeprocess writes data in mlpEnsemble and is therefore not thread-safe
     116        lock (mlpEnsembleLocker) {
     117          alglib.mlpeprocess(mlpEnsemble, x, ref y);
     118        }
    122119        // find class for with the largest probability value
    123120        int maxProbClassIndex = 0;
     
    139136      return new NeuralNetworkEnsembleClassificationSolution(this, new ClassificationEnsembleProblemData(problemData));
    140137    }
    141 
    142     #region events
    143     public event EventHandler Changed;
    144     private void OnChanged(EventArgs e) {
    145       var handlers = Changed;
    146       if (handlers != null)
    147         handlers(this, e);
    148     }
    149     #endregion
    150 
     138   
    151139    #region persistence
    152140    [Storable]
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkModel.cs

    r15584 r16387  
    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 {
     
    10697          x[column] = inputData[row, column];
    10798        }
    108         alglib.mlpprocess(multiLayerPerceptron, x, ref y);
     99        // NOTE: mlpprocess changes data in multiLayerPerceptron and is therefore not thread-save!
     100        lock (mlpLocker) {
     101          alglib.mlpprocess(multiLayerPerceptron, x, ref y);
     102        }
    109103        yield return y[0];
    110104      }
     
    112106
    113107    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    114       double[,] inputData = dataset.ToArray( allowedInputVariables, rows);
     108      double[,] inputData = dataset.ToArray(allowedInputVariables, rows);
    115109
    116110      int n = inputData.GetLength(0);
     
    123117          x[column] = inputData[row, column];
    124118        }
    125         alglib.mlpprocess(multiLayerPerceptron, x, ref y);
     119        // NOTE: mlpprocess changes data in multiLayerPerceptron and is therefore not thread-save!
     120        lock (mlpLocker) {
     121          alglib.mlpprocess(multiLayerPerceptron, x, ref y);
     122        }
    126123        // find class for with the largest probability value
    127124        int maxProbClassIndex = 0;
     
    144141    }
    145142
    146     #region events
    147     public event EventHandler Changed;
    148     private void OnChanged(EventArgs e) {
    149       var handlers = Changed;
    150       if (handlers != null)
    151         handlers(this, e);
    152     }
    153     #endregion
    154 
    155143    #region persistence
    156144    [Storable]
Note: See TracChangeset for help on using the changeset viewer.