Changeset 18212
- Timestamp:
- 02/03/22 16:23:50 (3 years ago)
- 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 77 77 public ValueParameter<IntValue> SampleCountParameter => (ValueParameter<IntValue>)Parameters["SampleCount"]; 78 78 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"]; 79 81 #endregion 80 82 … … 85 87 Parameters.Add(new ValueParameter<IntValue>("SampleCount")); // only used when sampling != Exhaustive 86 88 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")); 87 91 } 88 92 public SamplingSegmentOptimizationManipulator(SamplingSegmentOptimizationManipulator original, Cloner cloner) … … 110 114 solutions = SampleIndices(solutions, Sampling, random, SampleCount); 111 115 116 if (CountSamplesAsEvaluationsParameter.Value.Value) { 117 int moves = solutions.Count(); 118 EvaluatedSolutionsParameter.ActualValue.Value += moves - 1; 119 } 120 112 121 var best = FindBest(solutions); 113 122 if (best != null) { … … 119 128 var indices = new IEnumerable<int>[integerVector.Length]; 120 129 int targetIndex = random.Next(indices.Length); // first or second index 121 integerVector = new IntegerVector(new[] { integerVector.Min(), integerVector.Max() });122 130 for (int i = 0; i < indices.Length; i++) { 123 131 var searchRange = dimension == DimensionType.All || targetIndex == i ? indexRange : SearchRangeType.None; -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SegmentOptimization/SegmentOptimizationProblem.cs
r18204 r18212 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 25 using System.Linq.Expressions; 24 26 using HEAL.Attic; 25 27 using HeuristicLab.Common; … … 239 241 return matrix; 240 242 } 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 } 241 316 } 242 317 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r17825 r18212 47 47 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 48 48 <Prefer32Bit>false</Prefer32Bit> 49 <LangVersion>latest</LangVersion> 49 50 </PropertyGroup> 50 51 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> … … 57 58 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 58 59 <Prefer32Bit>false</Prefer32Bit> 60 <LangVersion>latest</LangVersion> 59 61 </PropertyGroup> 60 62 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> … … 67 69 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 68 70 <Prefer32Bit>false</Prefer32Bit> 71 <LangVersion>latest</LangVersion> 69 72 </PropertyGroup> 70 73 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> … … 77 80 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 78 81 <Prefer32Bit>false</Prefer32Bit> 82 <LangVersion>latest</LangVersion> 79 83 </PropertyGroup> 80 84 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> … … 87 91 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 88 92 <Prefer32Bit>false</Prefer32Bit> 93 <LangVersion>latest</LangVersion> 89 94 </PropertyGroup> 90 95 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> … … 97 102 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 98 103 <Prefer32Bit>false</Prefer32Bit> 104 <LangVersion>latest</LangVersion> 99 105 </PropertyGroup> 100 106 <ItemGroup> -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/ShrinkDataAnalysisRunsMenuItem.cs
r17180 r18212 25 25 using System.Collections.Generic; 26 26 using System.Linq; 27 using System.Threading.Tasks; 28 using System.Windows.Forms; 27 29 using HeuristicLab.MainForm; 28 30 using HeuristicLab.Optimization; 29 31 using HeuristicLab.Optimizer; 30 32 using HeuristicLab.Problems.DataAnalysis.Symbolic.SegmentOptimization; 31 33 using MenuItem = HeuristicLab.MainForm.WindowsForms.MenuItem; 32 34 … … 67 69 } 68 70 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)); 70 73 } 71 74 72 public override void Execute() {75 public override async void Execute() { 73 76 IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView; 74 77 var content = activeView.Content; 75 78 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 }); 76 84 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}"); 83 87 } 84 88 }
Note: See TracChangeset
for help on using the changeset viewer.