Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18212


Ignore:
Timestamp:
02/03/22 16:23:50 (2 years ago)
Author:
pfleck
Message:

#3040

  • Count batch evaluation as number of evaluations for SOP manipulator.
  • Added the functionality to remove duplicate data matrices or similar to duplicated datasets to remove the size of segment optimization experiment runs.
Location:
branches/3040_VectorBasedGP
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Mutators/SegmentOptimization/SamplingSegmentOptimizationManipulator.cs

    r18204 r18212  
    7777    public ValueParameter<IntValue> SampleCountParameter => (ValueParameter<IntValue>)Parameters["SampleCount"];
    7878    public ValueParameter<EnumValue<SamplingPointsType>> SamplingPointsParameter => (ValueParameter<EnumValue<SamplingPointsType>>)Parameters["SamplingPoints"];
     79    public ValueParameter<BoolValue> CountSamplesAsEvaluationsParameter => (ValueParameter<BoolValue>)Parameters["CountSamplesAsEvaluations"];
     80    public LookupParameter<IntValue> EvaluatedSolutionsParameter => (LookupParameter<IntValue>)Parameters["EvaluatedSolutions"];
    7981    #endregion
    8082
     
    8587      Parameters.Add(new ValueParameter<IntValue>("SampleCount")); // only used when sampling != Exhaustive
    8688      Parameters.Add(new ValueParameter<EnumValue<SamplingPointsType>>("SamplingPoints", new EnumValue<SamplingPointsType>(SamplingPointsType.BeforeCombinations | SamplingPointsType.AfterCombinations)));
     89      Parameters.Add(new ValueParameter<BoolValue>("CountSamplesAsEvaluations", new BoolValue(false)));
     90      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions"));
    8791    }
    8892    public SamplingSegmentOptimizationManipulator(SamplingSegmentOptimizationManipulator original, Cloner cloner)
     
    110114        solutions = SampleIndices(solutions, Sampling, random, SampleCount);
    111115
     116      if (CountSamplesAsEvaluationsParameter.Value.Value) {
     117        int moves = solutions.Count();
     118        EvaluatedSolutionsParameter.ActualValue.Value += moves - 1;
     119      }
     120
    112121      var best = FindBest(solutions);
    113122      if (best != null) {
     
    119128      var indices = new IEnumerable<int>[integerVector.Length];
    120129      int targetIndex = random.Next(indices.Length); // first or second index
    121       integerVector = new IntegerVector(new[] { integerVector.Min(), integerVector.Max() });
    122130      for (int i = 0; i < indices.Length; i++) {
    123131        var searchRange = dimension == DimensionType.All || targetIndex == i ? indexRange : SearchRangeType.None;
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SegmentOptimization/SegmentOptimizationProblem.cs

    r18204 r18212  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
     25using System.Linq.Expressions;
    2426using HEAL.Attic;
    2527using HeuristicLab.Common;
     
    239241      return matrix;
    240242    }
     243
     244    private class DoubleArrayComparer : IEqualityComparer<double[,]> {
     245      public bool Equals(double[,] x, double[,] y) {
     246        if (ReferenceEquals(x, y)) return true;
     247        if (x.Length != y.Length) return false;
     248        if (x.GetLength(0) != y.GetLength(0)) return false;
     249        if (x.GetLength(1) != y.GetLength(1)) return false;
     250
     251        int rows = x.GetLength(0), cols = x.GetLength(1);
     252        for (int i = 0; i < rows; i++) {
     253          for (int j = 0; j < cols; j++) {
     254            if (x[i, j] != y[i, j])
     255              return false;
     256          }
     257        }
     258
     259        return true;
     260      }
     261
     262      public int GetHashCode(double[,] obj) {
     263        return GetSequenceHashCode(obj.Cast<double>())/*gives matrix enumerated*/;
     264      }
     265
     266      //https://stackoverflow.com/questions/7278136/create-hash-value-on-a-list
     267      public static int GetSequenceHashCode<T>(IEnumerable<T> sequence) {
     268        const int seed = 487;
     269        const int modifier = 31;
     270
     271        unchecked {
     272          return sequence.Aggregate(seed, (current, item) => (current * modifier) + item.GetHashCode());
     273        }
     274      }
     275    }
     276
     277    private static readonly Action<DoubleMatrix, double[,]> setValues;
     278    private static readonly Func<DoubleMatrix, double[,]> getValues;
     279    static SegmentOptimizationProblem() {
     280      var dataset = Expression.Parameter(typeof(DoubleMatrix));
     281      var variableValues = Expression.Parameter(typeof(double[,]));
     282      var valuesExpression = Expression.Field(dataset, "matrix");
     283      var assignExpression = Expression.Assign(valuesExpression, variableValues);
     284
     285      var variableValuesSetExpression = Expression.Lambda<Action<DoubleMatrix, double[,]>>(assignExpression, dataset, variableValues);
     286      setValues = variableValuesSetExpression.Compile();
     287
     288      var variableValuesGetExpression = Expression.Lambda<Func<DoubleMatrix, double[,]>>(valuesExpression, dataset);
     289      getValues = variableValuesGetExpression.Compile();
     290    }
     291
     292    public static Tuple<int, int, int> RemoveDuplicateMatrices(IContent content) {
     293      int overallTests = 0, removedDuplicated = 0;
     294      var mappings = new Dictionary<double[,], double[,]>(new DoubleArrayComparer());
     295       foreach (var parameter in content.GetObjectGraphObjects(excludeStaticMembers: true).OfType<DoubleMatrix>()) {
     296         var originalValue = getValues(parameter);
     297         overallTests++;
     298         if (mappings.TryGetValue(originalValue, out var mappedValue)) {
     299           setValues(parameter, mappedValue);
     300           removedDuplicated++;
     301         } else {
     302           mappings.Add(originalValue, originalValue);
     303         }
     304       }
     305     
     306      int removedQualities = 0;
     307      // foreach (var run in content.GetObjectGraphObjects(excludeStaticMembers: true).OfType<IRun>()) {
     308      //   if (run.Results.ContainsKey("Qualities")) {
     309      //     run.Results.Remove("Qualities");
     310      //     removedQualities++;
     311      //   }
     312      // }
     313
     314      return Tuple.Create(overallTests, removedDuplicated, removedQualities);
     315    }
    241316  }
    242317}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r17825 r18212  
    4747    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    4848    <Prefer32Bit>false</Prefer32Bit>
     49    <LangVersion>latest</LangVersion>
    4950  </PropertyGroup>
    5051  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     
    5758    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    5859    <Prefer32Bit>false</Prefer32Bit>
     60    <LangVersion>latest</LangVersion>
    5961  </PropertyGroup>
    6062  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
     
    6769    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    6870    <Prefer32Bit>false</Prefer32Bit>
     71    <LangVersion>latest</LangVersion>
    6972  </PropertyGroup>
    7073  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
     
    7780    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    7881    <Prefer32Bit>false</Prefer32Bit>
     82    <LangVersion>latest</LangVersion>
    7983  </PropertyGroup>
    8084  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     
    8791    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    8892    <Prefer32Bit>false</Prefer32Bit>
     93    <LangVersion>latest</LangVersion>
    8994  </PropertyGroup>
    9095  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
     
    97102    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    98103    <Prefer32Bit>false</Prefer32Bit>
     104    <LangVersion>latest</LangVersion>
    99105  </PropertyGroup>
    100106  <ItemGroup>
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/ShrinkDataAnalysisRunsMenuItem.cs

    r17180 r18212  
    2525using System.Collections.Generic;
    2626using System.Linq;
     27using System.Threading.Tasks;
     28using System.Windows.Forms;
    2729using HeuristicLab.MainForm;
    2830using HeuristicLab.Optimization;
    2931using HeuristicLab.Optimizer;
    30 
     32using HeuristicLab.Problems.DataAnalysis.Symbolic.SegmentOptimization;
    3133using MenuItem = HeuristicLab.MainForm.WindowsForms.MenuItem;
    3234
     
    6769      }
    6870
    69       ToolStripItem.Enabled = runCollection.Any(run => run.Parameters.Any(p => p.Value is IDataAnalysisProblemData));
     71      ToolStripItem.Enabled = true;
     72      //ToolStripItem.Enabled = runCollection.Any(run => run.Parameters.Any(p => p.Value is IDataAnalysisProblemData));
    7073    }
    7174
    72     public override void Execute() {
     75    public override async void Execute() {
    7376      IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
    7477      var content = activeView.Content;
    7578      Progress.Show(content, "Removing duplicate datasets.", ProgressMode.Indeterminate);
     79     
     80      var results = await Task.Run(() => {
     81        DatasetUtil.RemoveDuplicateDatasets(content);
     82        return SegmentOptimizationProblem.RemoveDuplicateMatrices(content);
     83      });
    7684
    77       Action<IContentView> action = (view) => DatasetUtil.RemoveDuplicateDatasets(view.Content);
    78 
    79       action.BeginInvoke(activeView, delegate (IAsyncResult result) {
    80         action.EndInvoke(result);
    81         Progress.Hide(content);
    82       }, null);
     85      Progress.Hide(content);
     86      MessageBox.Show($"DoubleMatrix-Count:{results.Item1}\nDoubleMatrix-RemovedDuplicates:{results.Item2}\nQualities-Removed:{results.Item3}");
    8387    }
    8488  }
Note: See TracChangeset for help on using the changeset viewer.