Changeset 16538 for branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkModel.cs
- Timestamp:
- 01/18/19 14:39:01 (5 years ago)
- Location:
- branches/2847_M5Regression
- Files:
-
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkModel.cs
r14843 r16538 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 36 36 public sealed class NeuralNetworkModel : ClassificationModel, INeuralNetworkModel { 37 37 38 private object mlpLocker = new object(); 38 39 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 }49 40 50 41 public override IEnumerable<string> VariablesUsedForPrediction { … … 106 97 x[column] = inputData[row, column]; 107 98 } 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 } 109 103 yield return y[0]; 110 104 } … … 112 106 113 107 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 114 double[,] inputData = dataset.ToArray( 108 double[,] inputData = dataset.ToArray(allowedInputVariables, rows); 115 109 116 110 int n = inputData.GetLength(0); … … 123 117 x[column] = inputData[row, column]; 124 118 } 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 } 126 123 // find class for with the largest probability value 127 124 int maxProbClassIndex = 0; … … 137 134 } 138 135 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 139 154 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 140 155 return new NeuralNetworkRegressionSolution(this, new RegressionProblemData(problemData)); … … 143 158 return new NeuralNetworkClassificationSolution(this, new ClassificationProblemData(problemData)); 144 159 } 145 146 #region events147 public event EventHandler Changed;148 private void OnChanged(EventArgs e) {149 var handlers = Changed;150 if (handlers != null)151 handlers(this, e);152 }153 #endregion154 160 155 161 #region persistence
Note: See TracChangeset
for help on using the changeset viewer.