Changeset 14236
- Timestamp:
- 08/05/16 11:58:52 (8 years ago)
- Location:
- trunk/sources
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs
r14185 r14236 57 57 58 58 public override IEnumerable<string> VariablesUsedForPrediction { 59 get { return actualModel.Models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); } 59 get 60 { 61 lock (actualModel) { if (actualModel == null) actualModel = RecalculateModel(); } 62 return actualModel.Models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); 63 } 60 64 } 61 65 … … 105 109 // forward message to actual model (recalculate model first if necessary) 106 110 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 107 if (actualModel == null) actualModel = RecalculateModel();111 lock (actualModel) { if (actualModel == null) actualModel = RecalculateModel(); } 108 112 return actualModel.GetEstimatedValues(dataset, rows); 109 113 } … … 119 123 public IEnumerable<IRegressionModel> Models { 120 124 get { 121 if (actualModel == null) actualModel = RecalculateModel();125 lock(actualModel) { if (actualModel == null) actualModel = RecalculateModel();} 122 126 return actualModel.Models; 123 127 } … … 126 130 public IEnumerable<double> Weights { 127 131 get { 128 if (actualModel == null) actualModel = RecalculateModel();132 lock(actualModel) { if (actualModel == null) actualModel = RecalculateModel();} 129 133 return actualModel.Weights; 130 134 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs
r14235 r14236 200 200 x[column] = inputData[row, column]; 201 201 } 202 int actNeighbours = alglib.nearestneighbor.kdtreequeryknn(kdTree, x, k, false); 203 alglib.nearestneighbor.kdtreequeryresultsdistances(kdTree, ref dists); 204 alglib.nearestneighbor.kdtreequeryresultsxy(kdTree, ref neighbours); // gkronber: this call changes the kdTree data structure 202 int numNeighbours; 203 lock (kdTree) { // gkronber: the following calls change the kdTree data structure 204 numNeighbours = alglib.nearestneighbor.kdtreequeryknn(kdTree, x, k, false); 205 alglib.nearestneighbor.kdtreequeryresultsdistances(kdTree, ref dists); 206 alglib.nearestneighbor.kdtreequeryresultsxy(kdTree, ref neighbours); 207 } 205 208 206 209 double distanceWeightedValue = 0.0; 207 210 double distsSum = 0.0; 208 for (int i = 0; i < actNeighbours; i++) {211 for (int i = 0; i < numNeighbours; i++) { 209 212 distanceWeightedValue += neighbours[i, columns] / dists[i]; 210 213 distsSum += 1.0 / dists[i]; … … 233 236 x[column] = inputData[row, column]; 234 237 } 235 int actNeighbours = alglib.nearestneighbor.kdtreequeryknn(kdTree, x, k, false); 236 alglib.nearestneighbor.kdtreequeryresultsdistances(kdTree, ref dists); 237 alglib.nearestneighbor.kdtreequeryresultsxy(kdTree, ref neighbours); 238 238 int numNeighbours; 239 lock (kdTree) { 240 // gkronber: the following calls change the kdTree data structure 241 numNeighbours = alglib.nearestneighbor.kdtreequeryknn(kdTree, x, k, false); 242 alglib.nearestneighbor.kdtreequeryresultsdistances(kdTree, ref dists); 243 alglib.nearestneighbor.kdtreequeryresultsxy(kdTree, ref neighbours); 244 } 239 245 Array.Clear(y, 0, y.Length); 240 for (int i = 0; i < actNeighbours; i++) {246 for (int i = 0; i < numNeighbours; i++) { 241 247 int classValue = (int)Math.Round(neighbours[i, columns]); 242 248 y[classValue]++; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationModel.cs
r14185 r14236 22 22 using System.Collections.Generic; 23 23 namespace HeuristicLab.Problems.DataAnalysis { 24 /// <summary> 25 /// Interface for all classification models. 26 /// <remarks>All methods and properties in in this interface must be implemented thread safely</remarks> 27 /// </summary> 24 28 public interface IClassificationModel : IDataAnalysisModel { 25 29 IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows); -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisModel.cs
r14185 r14236 24 24 25 25 namespace HeuristicLab.Problems.DataAnalysis { 26 /// <summary> 27 /// Interface for all data-analysis models (regression/classification/clustering). 28 /// <remarks>All methods and properties in in this interface must be implemented thread safely</remarks> 29 /// </summary> 26 30 public interface IDataAnalysisModel : INamedItem { 27 31 IEnumerable<string> VariablesUsedForPrediction { get; } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionModel.cs
r14185 r14236 23 23 24 24 namespace HeuristicLab.Problems.DataAnalysis { 25 /// <summary> 26 /// Interface for all regression models. 27 /// <remarks>All methods and properties in in this interface must be implemented thread safely</remarks> 28 /// </summary> 25 29 public interface IRegressionModel : IDataAnalysisModel { 26 30 IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows); -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/TimeSeriesPrognosis/ITimeSeriesPrognosisModel.cs
r14185 r14236 22 22 using System.Collections.Generic; 23 23 namespace HeuristicLab.Problems.DataAnalysis { 24 /// <summary> 25 /// Interface for all time series prognosis models. 26 /// <remarks>All methods and properties in in this interface must be implemented thread safely</remarks> 27 /// </summary> 24 28 public interface ITimeSeriesPrognosisModel : IRegressionModel { 25 29 IEnumerable<IEnumerable<double>> GetPrognosedValues(IDataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons);
Note: See TracChangeset
for help on using the changeset viewer.