Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/21/10 13:21:14 (14 years ago)
Author:
mkommend
Message:

removed cloning of dataset and made it readonly (ticket #938)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/SupportVectorMachineCrossValidationEvaluator.cs

    r3884 r3933  
    152152
    153153      int reducedRows = (int)((SamplesEnd.Value - SamplesStart.Value) * reductionRatio);
    154       var reducedProblemData = (DataAnalysisProblemData)DataAnalysisProblemData.Clone();
    155       ShuffleRows(RandomParameter.ActualValue, reducedProblemData.Dataset, SamplesStart.Value, SamplesEnd.Value);
     154      DataAnalysisProblemData reducedProblemData = (DataAnalysisProblemData)DataAnalysisProblemData.Clone();
     155      reducedProblemData.Dataset = CreateReducedDataset(RandomParameter.ActualValue, reducedProblemData.Dataset, reductionRatio, SamplesStart.Value, SamplesEnd.Value);
    156156
    157157      double quality = PerformCrossValidation(reducedProblemData,
     
    164164    }
    165165
    166     private void ShuffleRows(IRandom random, Dataset dataset, int start, int end) {
    167       for (int row = end - 1; row > start ; row--) {
    168         int otherRow = random.Next(start, row);
    169         for (int column = 0; column < dataset.Columns; column++) {
    170           double tmp = dataset[otherRow, column];
    171           dataset[otherRow, column] = dataset[row, column];
    172           dataset[row, column] = tmp;
    173         }
     166    private Dataset CreateReducedDataset(IRandom random, Dataset dataset, double reductionRatio, int start, int end) {
     167      int reducedRows = (int)((end - start) * reductionRatio);
     168      double[,] reducedData = dataset.GetClonedData();
     169      HashSet<int> leftRows = new HashSet<int>(Enumerable.Range(0, end - start));
     170      for (int row = 0; row < reducedRows; row++) {
     171        int rowIndex = random.Next(0, leftRows.Count);
     172        leftRows.Remove(rowIndex);
     173        for (int column = 0; column < dataset.Columns; column++)
     174          reducedData[row, column] = dataset[rowIndex, column];
    174175      }
     176      return new Dataset(dataset.VariableNames, reducedData);
    175177    }
    176178
Note: See TracChangeset for help on using the changeset viewer.