Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14236 for trunk/sources


Ignore:
Timestamp:
08/05/16 11:58:52 (8 years ago)
Author:
gkronber
Message:

#2653: added synchronization in NearestNeighbourModel and made some related changes to GradientBoostedTreesModelSurrogate

Location:
trunk/sources
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs

    r14185 r14236  
    5757
    5858    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      }
    6064    }
    6165
     
    105109    // forward message to actual model (recalculate model first if necessary)
    106110    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    107       if (actualModel == null) actualModel = RecalculateModel();
     111      lock (actualModel) { if (actualModel == null) actualModel = RecalculateModel(); }
    108112      return actualModel.GetEstimatedValues(dataset, rows);
    109113    }
     
    119123    public IEnumerable<IRegressionModel> Models {
    120124      get {
    121         if (actualModel == null) actualModel = RecalculateModel();
     125        lock(actualModel) { if (actualModel == null) actualModel = RecalculateModel();}
    122126        return actualModel.Models;
    123127      }
     
    126130    public IEnumerable<double> Weights {
    127131      get {
    128         if (actualModel == null) actualModel = RecalculateModel();
     132        lock(actualModel) { if (actualModel == null) actualModel = RecalculateModel();}
    129133        return actualModel.Weights;
    130134      }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs

    r14235 r14236  
    200200          x[column] = inputData[row, column];
    201201        }
    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        }
    205208
    206209        double distanceWeightedValue = 0.0;
    207210        double distsSum = 0.0;
    208         for (int i = 0; i < actNeighbours; i++) {
     211        for (int i = 0; i < numNeighbours; i++) {
    209212          distanceWeightedValue += neighbours[i, columns] / dists[i];
    210213          distsSum += 1.0 / dists[i];
     
    233236          x[column] = inputData[row, column];
    234237        }
    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        }
    239245        Array.Clear(y, 0, y.Length);
    240         for (int i = 0; i < actNeighbours; i++) {
     246        for (int i = 0; i < numNeighbours; i++) {
    241247          int classValue = (int)Math.Round(neighbours[i, columns]);
    242248          y[classValue]++;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationModel.cs

    r14185 r14236  
    2222using System.Collections.Generic;
    2323namespace 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>
    2428  public interface IClassificationModel : IDataAnalysisModel {
    2529    IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisModel.cs

    r14185 r14236  
    2424
    2525namespace 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>
    2630  public interface IDataAnalysisModel : INamedItem {
    2731    IEnumerable<string> VariablesUsedForPrediction { get; }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionModel.cs

    r14185 r14236  
    2323
    2424namespace 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>
    2529  public interface IRegressionModel : IDataAnalysisModel {
    2630    IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/TimeSeriesPrognosis/ITimeSeriesPrognosisModel.cs

    r14185 r14236  
    2222using System.Collections.Generic;
    2323namespace 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>
    2428  public interface ITimeSeriesPrognosisModel : IRegressionModel {
    2529    IEnumerable<IEnumerable<double>> GetPrognosedValues(IDataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons);
Note: See TracChangeset for help on using the changeset viewer.