Changeset 17005
- Timestamp:
- 06/11/19 20:59:44 (5 years ago)
- Location:
- branches/2994-AutoDiffForIntervals
- Files:
-
- 1 deleted
- 30 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/2994-AutoDiffForIntervals
- Property svn:mergeinfo changed
/trunk merged: 16944-16945,16978-16983,16992,16997
- Property svn:mergeinfo changed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Common/3.3/Content/ContentManager.cs
r16565 r17005 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using System.Threading; 26 using System.Threading.Tasks; 27 using HEAL.Attic; 24 28 25 29 namespace HeuristicLab.Common { 26 30 public abstract class ContentManager { 31 public class Info { 32 public Info() { } 33 34 public Info(string filename, TimeSpan duration) { 35 Filename = filename; 36 Duration = duration; 37 } 38 39 public Info(string filename, SerializationInfo serInfo) { 40 Filename = filename; 41 Duration = serInfo.Duration; 42 UnknownTypeGuids = serInfo.UnknownTypeGuids; 43 NumberOfSerializedObjects = serInfo.NumberOfSerializedObjects; 44 SerializedTypes = serInfo.SerializedTypes; 45 } 46 47 public TimeSpan Duration { get; internal set; } 48 public IEnumerable<Guid> UnknownTypeGuids { get; internal set; } = Enumerable.Empty<Guid>(); 49 public int NumberOfSerializedObjects { get; internal set; } 50 public IEnumerable<Type> SerializedTypes { get; internal set; } = Enumerable.Empty<Type>(); 51 public string Filename { get; internal set; } = string.Empty; 52 } 53 27 54 private static ContentManager instance; 28 55 … … 36 63 37 64 public static IStorableContent Load(string filename) { 65 return Load(filename, out var _); 66 } 67 68 public static IStorableContent Load(string filename, out Info serializationInfo) { 38 69 if (instance == null) throw new InvalidOperationException("ContentManager is not initialized."); 39 IStorableContent content = instance.LoadContent(filename); 40 content.Filename = filename; 70 IStorableContent content = instance.LoadContent(filename, out serializationInfo); 71 72 if (content != null) content.Filename = filename; 41 73 return content; 42 74 } 43 public static void LoadAsync(string filename, Action<IStorableContent, Exception> loadingCompletedCallback) { 75 76 77 public static Task LoadAsync(string filename, Action<IStorableContent, Exception> loadingCompletedCallback) { 78 return LoadAsync(filename, (content, error, info) => loadingCompletedCallback(content, error)); // drop info 79 } 80 81 public static async Task LoadAsync(string filename, Action<IStorableContent, Exception, Info> loadingCompletedCallback) { 44 82 if (instance == null) throw new InvalidOperationException("ContentManager is not initialized."); 45 var func = new Func<string, IStorableContent>(instance.LoadContent); 46 func.BeginInvoke(filename, delegate (IAsyncResult result) { 47 Exception error = null; 48 IStorableContent content = null; 49 try { 50 content = func.EndInvoke(result); 51 content.Filename = filename; 52 } catch (Exception ex) { 53 error = ex; 54 } 55 loadingCompletedCallback(content, error); 56 }, null); 83 84 Exception error = null; 85 IStorableContent result = null; 86 Info serializationInfo = null; 87 try { 88 result = await Task.Run(() => { 89 var content = instance.LoadContent(filename, out serializationInfo); 90 if(content!=null) content.Filename = filename; 91 return content; 92 }); 93 } catch(Exception ex) { 94 error = ex; 95 } 96 loadingCompletedCallback(result, error, serializationInfo); 57 97 } 58 protected abstract IStorableContent LoadContent(string filename); 98 99 protected abstract IStorableContent LoadContent(string filename, out Info serializationInfo); 59 100 60 101 public static void Save(IStorableContent content, string filename, bool compressed, CancellationToken cancellationToken = default(CancellationToken)) { -
branches/2994-AutoDiffForIntervals/HeuristicLab.Core
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Core merged: 16945,16992
- Property svn:mergeinfo changed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Core.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Core.Views (added) merged: 16992,16997
- Property svn:mergeinfo changed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Core.Views/3.3/Clipboard.cs
r16565 r17005 24 24 using System.Collections.Generic; 25 25 using System.IO; 26 using System.IO.Compression;27 26 using System.Linq; 28 27 using System.Threading; … … 31 30 using HeuristicLab.Common; 32 31 using HeuristicLab.MainForm; 33 using HeuristicLab.Persistence.Default.Xml;34 32 using HeuristicLab.PluginInfrastructure; 35 33 … … 157 155 foreach (string filename in items) { 158 156 try { 159 var ser = new ProtoBufSerializer(); 160 T item = (T)ser.Deserialize(filename); 157 T item = (T)ContentManager.Load(filename); 161 158 OnItemLoaded(item, progressBar.Maximum / items.Length); 162 } catch (Exception) { 163 try { 164 // try old format if protobuf deserialization fails 165 T item = XmlParser.Deserialize<T>(filename); 166 OnItemLoaded(item, progressBar.Maximum / items.Length); 167 } catch (Exception) { } 159 } catch(Exception) { 160 // ignore if loading a clipboad item fails. 168 161 } 169 162 } -
branches/2994-AutoDiffForIntervals/HeuristicLab.Core.Views/3.3/HeuristicLab.Core.Views-3.3.csproj
r16658 r17005 375 375 <Private>False</Private> 376 376 </ProjectReference> 377 <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">378 <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>379 <Name>HeuristicLab.Persistence-3.3</Name>380 <Private>False</Private>381 </ProjectReference>382 377 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj"> 383 378 <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project> -
branches/2994-AutoDiffForIntervals/HeuristicLab.Core.Views/3.3/Plugin.cs.frame
r16658 r17005 35 35 [PluginDependency("HeuristicLab.MainForm", "3.3")] 36 36 [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")] 37 [PluginDependency("HeuristicLab.Persistence", "3.3")]38 37 public class HeuristicLabCoreViewsPlugin : PluginBase { 39 38 } -
branches/2994-AutoDiffForIntervals/HeuristicLab.Core/3.3/PersistenceContentManager.cs
r16943 r17005 25 25 using HEAL.Attic; 26 26 using System; 27 using System.Diagnostics; 27 28 28 29 namespace HeuristicLab.Core { … … 30 31 public PersistenceContentManager() : base() { } 31 32 32 protected override IStorableContent LoadContent(string filename) { 33 // first try to load using the new persistence format 34 var ser = new ProtoBufSerializer(); 35 try { 36 return (IStorableContent)ser.Deserialize(filename, out SerializationInfo info); 37 } catch (Exception e) { 38 try { 39 // try old format if new format fails 40 return XmlParser.Deserialize<IStorableContent>(filename); 41 } catch (Exception e2) { 42 throw new AggregateException($"Cannot open file {filename}", e, e2); 43 } 33 protected override IStorableContent LoadContent(string filename, out Info info) { 34 bool useOldPersistence = XmlParser.CanOpen(filename); 35 IStorableContent content = null; 36 if (useOldPersistence) { 37 var sw = new Stopwatch(); 38 sw.Start(); 39 content = XmlParser.Deserialize<IStorableContent>(filename); 40 sw.Stop(); 41 info = new Info(filename, sw.Elapsed); 42 } else { 43 var ser = new ProtoBufSerializer(); 44 content = (IStorableContent)ser.Deserialize(filename, out SerializationInfo serInfo); 45 info = new Info(filename, serInfo); 44 46 } 47 if (content == null) throw new PersistenceException($"Cannot deserialize root element of {filename}"); 48 return content; 45 49 } 50 46 51 47 52 protected override void SaveContent(IStorableContent content, string filename, bool compressed, CancellationToken cancellationToken) { -
branches/2994-AutoDiffForIntervals/HeuristicLab.DataPreprocessing.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.DataPreprocessing.Views merged: 16982
- Property svn:mergeinfo changed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs
r16565 r17005 411 411 var foundIndices = new List<int>(); 412 412 for (int idx = 0; idx < filteredRows.Length; ++idx) { 413 var notFilteredThusFound = !filteredRows[idx]; 414 if (notFilteredThusFound) { 413 if (filteredRows[idx]) { 415 414 foundIndices.Add(idx); 416 415 } -
branches/2994-AutoDiffForIntervals/HeuristicLab.ExtLibs
- Property svn:mergeinfo changed
/trunk/HeuristicLab.ExtLibs merged: 16944
- Property svn:mergeinfo changed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.ExtLibs/HeuristicLab.OrTools/7.0.0/HeuristicLab.OrTools-7.0.0/HeuristicLab.OrTools-7.0.0.csproj
r16910 r17005 43 43 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> 44 44 <DebugSymbols>true</DebugSymbols> 45 <OutputPath> bin\x64\Debug\</OutputPath>45 <OutputPath>..\..\..\..\bin\</OutputPath> 46 46 <DefineConstants>DEBUG;TRACE</DefineConstants> 47 47 <AllowUnsafeBlocks>true</AllowUnsafeBlocks> … … 52 52 </PropertyGroup> 53 53 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> 54 <OutputPath> bin\x64\Release\</OutputPath>54 <OutputPath>..\..\..\..\bin\</OutputPath> 55 55 <DefineConstants>TRACE</DefineConstants> 56 56 <AllowUnsafeBlocks>true</AllowUnsafeBlocks> … … 63 63 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> 64 64 <DebugSymbols>true</DebugSymbols> 65 <OutputPath> bin\x86\Debug\</OutputPath>65 <OutputPath>..\..\..\..\bin\</OutputPath> 66 66 <DefineConstants>DEBUG;TRACE</DefineConstants> 67 67 <AllowUnsafeBlocks>true</AllowUnsafeBlocks> … … 72 72 </PropertyGroup> 73 73 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> 74 <OutputPath> bin\x86\Release\</OutputPath>74 <OutputPath>..\..\..\..\bin\</OutputPath> 75 75 <DefineConstants>TRACE</DefineConstants> 76 76 <AllowUnsafeBlocks>true</AllowUnsafeBlocks> -
branches/2994-AutoDiffForIntervals/HeuristicLab.Optimizer
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Optimizer (added) merged: 16992,16997
- Property svn:mergeinfo changed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Optimizer/3.3/FileManager.cs
r16565 r17005 23 23 using System.Collections.Generic; 24 24 using System.IO; 25 using System.Linq; 25 26 using System.Threading; 26 27 using System.Windows.Forms; … … 73 74 } 74 75 75 private static void LoadingCompleted(IStorableContent content, Exception error ) {76 private static void LoadingCompleted(IStorableContent content, Exception error, ContentManager.Info info) { 76 77 try { 77 78 if (error != null) throw error; 79 if (info!=null && info.UnknownTypeGuids.Any()) { 80 var message = "Unknown type guids: " + string.Join(Environment.NewLine, info.UnknownTypeGuids); 81 MessageBox.Show((Control)MainFormManager.MainForm, message, $"File {info.Filename} not restored completely", MessageBoxButtons.OK, MessageBoxIcon.Information); 82 } 78 83 IView view = MainFormManager.MainForm.ShowContent(content); 79 84 if (view == null) -
branches/2994-AutoDiffForIntervals/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj
r16658 r17005 312 312 <Private>False</Private> 313 313 </ProjectReference> 314 <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">315 <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>316 <Name>HeuristicLab.Persistence-3.3</Name>317 <Private>False</Private>318 </ProjectReference>319 314 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj"> 320 315 <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project> -
branches/2994-AutoDiffForIntervals/HeuristicLab.Optimizer/3.3/Plugin.cs.frame
r16658 r17005 43 43 [PluginDependency("HeuristicLab.Optimization", "3.3")] 44 44 [PluginDependency("HeuristicLab.Parameters", "3.3")] 45 [PluginDependency("HeuristicLab.Persistence", "3.3")]46 45 [PluginDependency("HeuristicLab.Problems.Instances", "3.3")] 47 46 public class HeuristicLabOptimizerPlugin : PluginBase { -
branches/2994-AutoDiffForIntervals/HeuristicLab.Optimizer/3.3/StartPage.cs
r16565 r17005 30 30 using HeuristicLab.Core; 31 31 using HeuristicLab.MainForm; 32 using HeuristicLab.Persistence.Default.Xml;33 32 34 33 namespace HeuristicLab.Optimizer { … … 121 120 using (var stream = assembly.GetManifestResourceStream(name)) { 122 121 WriteStreamToTempFile(stream, path); // create a file in a temporary folder (persistence cannot load these files directly from the stream) 123 var item = XmlParser.Deserialize<INamedItem>(path);122 var item = (INamedItem)ContentManager.Load(path); 124 123 OnSampleLoaded(item, group, 1.0 / count); 125 124 } -
branches/2994-AutoDiffForIntervals/HeuristicLab.Persistence
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Persistence merged: 16945
- Property svn:mergeinfo changed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs
r16565 r17005 288 288 } 289 289 } 290 291 /// <summary> 292 /// Checks if the given file can be opened as <see cref="ZipArchive" />. 293 /// </summary> 294 /// <param name="filename">The filename.</param> 295 /// <returns><see langword="true" /> if the file can be opened as <see cref="ZipArchive" />; otherwise, <see langword="false" />.</returns> 296 public static bool CanOpen(string filename) { 297 try { 298 using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { 299 using (ZipArchive zip = new ZipArchive(fs)) { 300 return true; 301 } 302 } 303 } catch (InvalidDataException) { 304 return false; 305 } 306 } 290 307 } 291 308 } -
branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 16978-16981,16983
- Property svn:mergeinfo changed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression merged: 16978
- Property svn:mergeinfo changed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 merged: 16978
- Property svn:mergeinfo changed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredAverageSimilarityEvaluator.cs
r16565 r17005 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Diagnostics; 25 using System.Linq; 24 using HEAL.Attic; 26 25 using HeuristicLab.Common; 27 26 using HeuristicLab.Core; … … 29 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 30 29 using HeuristicLab.Parameters; 31 using HEAL.Attic;32 30 33 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 36 34 public class PearsonRSquaredAverageSimilarityEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 37 35 private const string StrictSimilarityParameterName = "StrictSimilarity"; 36 private const string AverageSimilarityParameterName = "AverageSimilarity"; 38 37 39 38 private readonly object locker = new object(); 40 39 40 private readonly SymbolicDataAnalysisExpressionTreeAverageSimilarityCalculator SimilarityCalculator = new SymbolicDataAnalysisExpressionTreeAverageSimilarityCalculator(); 41 41 42 public IFixedValueParameter<BoolValue> StrictSimilarityParameter { 42 43 get { return (IFixedValueParameter<BoolValue>)Parameters[StrictSimilarityParameterName]; } 44 } 45 46 public ILookupParameter<DoubleValue> AverageSimilarityParameter { 47 get { return (ILookupParameter<DoubleValue>)Parameters[AverageSimilarityParameterName]; } 43 48 } 44 49 … … 58 63 public PearsonRSquaredAverageSimilarityEvaluator() : base() { 59 64 Parameters.Add(new FixedValueParameter<BoolValue>(StrictSimilarityParameterName, "Use strict similarity calculation.", new BoolValue(false))); 65 Parameters.Add(new LookupParameter<DoubleValue>(AverageSimilarityParameterName)); 60 66 } 61 67 62 public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } } // maximize R² and minimize model complexity68 public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } } // maximize R² and minimize average similarity 63 69 64 70 public override IOperation InstrumentedApply() { … … 73 79 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, ConstantOptimizationIterations, updateVariableWeights: ConstantOptimizationUpdateVariableWeights, lowerEstimationLimit: estimationLimits.Lower, upperEstimationLimit: estimationLimits.Upper); 74 80 } 75 double[] qualities = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, applyLinearScaling, DecimalPlaces);76 QualitiesParameter.ActualValue = new DoubleArray(qualities);77 return base.InstrumentedApply();78 }79 81 80 public double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 81 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 82 if (decimalPlaces >= 0) 83 r2 = Math.Round(r2, decimalPlaces); 82 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, applyLinearScaling); 84 83 85 var variables = ExecutionContext.Scope.Variables; 86 if (!variables.ContainsKey("AverageSimilarity")) { 87 lock (locker) { 88 CalculateAverageSimilarities(ExecutionContext.Scope.Parent.SubScopes.Where(x => x.Variables.ContainsKey("SymbolicExpressionTree")).ToArray(), StrictSimilarity); 84 if (DecimalPlaces >= 0) 85 r2 = Math.Round(r2, DecimalPlaces); 89 86 87 lock (locker) { 88 if (AverageSimilarityParameter.ActualValue == null) { 89 var context = new ExecutionContext(null, SimilarityCalculator, ExecutionContext.Scope.Parent); 90 SimilarityCalculator.StrictSimilarity = StrictSimilarity; 91 SimilarityCalculator.Execute(context, CancellationToken); 90 92 } 91 93 } 94 var avgSimilarity = AverageSimilarityParameter.ActualValue.Value; 92 95 93 double avgSim = ((DoubleValue)variables["AverageSimilarity"].Value).Value;94 return new double[2] { r2, avgSim };96 QualitiesParameter.ActualValue = new DoubleArray(new[] { r2, avgSimilarity }); 97 return base.InstrumentedApply(); 95 98 } 96 99 97 100 public override double[] Evaluate(IExecutionContext context, ISymbolicExpressionTree tree, IRegressionProblemData problemData, IEnumerable<int> rows) { 98 101 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context; 102 AverageSimilarityParameter.ExecutionContext = context; 99 103 EstimationLimitsParameter.ExecutionContext = context; 100 104 ApplyLinearScalingParameter.ExecutionContext = context; 101 // DecimalPlaces parameter is a FixedValueParameter and doesn't need the context.102 105 103 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 106 var estimationLimits = EstimationLimitsParameter.ActualValue; 107 var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value; 108 109 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, applyLinearScaling); 110 111 lock (locker) { 112 if (AverageSimilarityParameter.ActualValue == null) { 113 var ctx = new ExecutionContext(null, SimilarityCalculator, context.Scope.Parent); 114 SimilarityCalculator.StrictSimilarity = StrictSimilarity; 115 SimilarityCalculator.Execute(context, CancellationToken); 116 } 117 } 118 var avgSimilarity = AverageSimilarityParameter.ActualValue.Value; 104 119 105 120 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; … … 107 122 ApplyLinearScalingParameter.ExecutionContext = null; 108 123 109 return quality; 110 } 111 112 private readonly Stopwatch sw = new Stopwatch(); 113 public void CalculateAverageSimilarities(IScope[] treeScopes, bool strict) { 114 var trees = treeScopes.Select(x => (ISymbolicExpressionTree)x.Variables["SymbolicExpressionTree"].Value).ToArray(); 115 var similarityMatrix = SymbolicExpressionTreeHash.ComputeSimilarityMatrix(trees, simplify: false, strict: strict); 116 117 for (int i = 0; i < treeScopes.Length; ++i) { 118 var scope = treeScopes[i]; 119 var avgSimilarity = 0d; 120 for (int j = 0; j < trees.Length; ++j) { 121 if (i == j) continue; 122 avgSimilarity += similarityMatrix[i, j]; 123 } 124 avgSimilarity /= trees.Length - 1; 125 126 if (scope.Variables.ContainsKey("AverageSimilarity")) { 127 ((DoubleValue)scope.Variables["AverageSimilarity"].Value).Value = avgSimilarity; 128 } else { 129 scope.Variables.Add(new Core.Variable("AverageSimilarity", new DoubleValue(avgSimilarity))); 130 } 131 } 124 return new[] { r2, avgSimilarity }; 132 125 } 133 126 } -
branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers
-
Property
svn:ignore
set to
SymbolicDataAnalysisBuildingBlockAnalyzer.cs
SymbolicDataAnalysisHashBasedDiversityAnalyzer.cs
-
Property
svn:ignore
set to
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDiversityPreservingCrossover.cs
r16565 r17005 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; 4 25 using HEAL.Attic; 5 26 using HeuristicLab.Common; 6 27 using HeuristicLab.Core; … … 8 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 9 30 using HeuristicLab.Parameters; 10 using HEAL.Attic;11 31 using HeuristicLab.Random; 12 32 using static HeuristicLab.Problems.DataAnalysis.Symbolic.SymbolicExpressionHashExtensions; 13 33 14 34 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 15 [Item("DiversityCrossover", "Simple crossover operator pr ioritizing internal nodes according to the given probability.")]35 [Item("DiversityCrossover", "Simple crossover operator preventing swap between subtrees with the same hash value.")] 16 36 [StorableType("ED35B0D9-9704-4D32-B10B-8F9870E76781")] 17 37 public sealed class SymbolicDataAnalysisExpressionDiversityPreservingCrossover<T> : SymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData { … … 20 40 private const string WindowingParameterName = "Windowing"; 21 41 private const string ProportionalSamplingParameterName = "ProportionalSampling"; 42 private const string StrictHashingParameterName = "StrictHashing"; 22 43 23 44 private static readonly Func<byte[], ulong> hashFunction = HashUtil.JSHash; … … 35 56 get { return (IValueLookupParameter<BoolValue>)Parameters[ProportionalSamplingParameterName]; } 36 57 } 58 59 public IFixedValueParameter<BoolValue> StrictHashingParameter { 60 get { return (IFixedValueParameter<BoolValue>)Parameters[StrictHashingParameterName]; } 61 } 37 62 #endregion 38 63 … … 49 74 get { return ProportionalSamplingParameter.ActualValue; } 50 75 } 76 77 bool StrictHashing { 78 get { return StrictHashingParameter.Value.Value; } 79 } 51 80 #endregion 81 82 83 [StorableHook(HookType.AfterDeserialization)] 84 private void AfterDeserialization() { 85 if (!Parameters.ContainsKey(StrictHashingParameterName)) { 86 Parameters.Add(new FixedValueParameter<BoolValue>(StrictHashingParameterName, "Use strict hashing when calculating subtree hash values.")); 87 } 88 } 52 89 53 90 public SymbolicDataAnalysisExpressionDiversityPreservingCrossover() { … … 56 93 Parameters.Add(new ValueLookupParameter<BoolValue>(WindowingParameterName, "Use proportional sampling with windowing for cutpoint selection.", new BoolValue(false))); 57 94 Parameters.Add(new ValueLookupParameter<BoolValue>(ProportionalSamplingParameterName, "Select cutpoints proportionally using probabilities as weights instead of randomly.", new BoolValue(true))); 95 Parameters.Add(new FixedValueParameter<BoolValue>(StrictHashingParameterName, "Use strict hashing when calculating subtree hash values.")); 58 96 } 59 97 … … 72 110 } 73 111 74 public static ISymbolicExpressionTree Cross(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1, double internalCrossoverPointProbability, int maxLength, int maxDepth, bool windowing, bool proportionalSampling = false) { 75 var leafCrossoverPointProbability = 1 - internalCrossoverPointProbability; 76 77 var nodes0 = ActualRoot(parent0).MakeNodes().Sort(hashFunction); 78 var nodes1 = ActualRoot(parent1).MakeNodes().Sort(hashFunction); 112 public static ISymbolicExpressionTree Cross(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1, double internalCrossoverPointProbability, int maxLength, int maxDepth, bool windowing, bool proportionalSampling = false, bool strictHashing = false) { 113 var nodes0 = ActualRoot(parent0).MakeNodes(strictHashing).Sort(hashFunction); 114 var nodes1 = ActualRoot(parent1).MakeNodes(strictHashing).Sort(hashFunction); 79 115 80 116 IList<HashNode<ISymbolicExpressionTreeNode>> sampled0; … … 126 162 var proportionalSampling = ProportionalSampling.Value; 127 163 128 return Cross(random, parent0, parent1, internalCrossoverPointProbability, maxLength, maxDepth, windowing, proportionalSampling );164 return Cross(random, parent0, parent1, internalCrossoverPointProbability, maxLength, maxDepth, windowing, proportionalSampling, StrictHashing); 129 165 } 130 166 -
branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/HashExtensions.cs
r16565 r17005 21 21 22 22 using System; 23 using System. Collections.Generic;23 using System.Linq; 24 24 25 25 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 38 38 public SimplifyAction Simplify; 39 39 40 public IComparer<T> Comparer;40 //public IComparer<T> Comparer; 41 41 42 42 public bool IsLeaf => Arity == 0; 43 43 44 public HashNode(IComparer<T> comparer) {45 Comparer = comparer;46 }47 48 privateHashNode() { }44 //public HashNode(IComparer<T> comparer) { 45 // Comparer = comparer; 46 //} 47 48 //public HashNode() { } 49 49 50 50 public int CompareTo(HashNode<T> other) { 51 var res = Comparer.Compare(Data, other.Data); 52 return res == 0 ? CalculatedHashValue.CompareTo(other.CalculatedHashValue) : res; 51 return CalculatedHashValue.CompareTo(other.CalculatedHashValue); 53 52 } 54 53 … … 103 102 104 103 public static HashNode<T>[] Simplify<T>(this HashNode<T>[] nodes, Func<byte[], ulong> hashFunction) where T : class { 105 var reduced = nodes.UpdateNodeSizes().Reduce().Sort(hashFunction); 106 107 for (int i = 0; i < reduced.Length; ++i) { 108 var node = reduced[i]; 109 if (node.IsLeaf) { 110 continue; 111 } 112 node.Simplify?.Invoke(ref reduced, i); 113 } 114 // detect if anything was simplified 115 var count = 0; 116 foreach (var node in reduced) { 117 if (!node.Enabled) { ++count; } 118 } 119 if (count == 0) { 120 return reduced; 121 } 122 123 var simplified = new HashNode<T>[reduced.Length - count]; 124 int j = 0; 125 foreach (var node in reduced) { 126 if (node.Enabled) { 127 simplified[j++] = node; 128 } 129 } 130 return simplified.UpdateNodeSizes().Reduce().Sort(hashFunction); 104 bool simplified = false; 105 nodes = nodes.UpdateNodeSizes().Reduce().Sort(hashFunction); 106 do { 107 if (simplified) { 108 simplified = false; 109 nodes = nodes.Where(x => x.Enabled).ToArray().UpdateNodeSizes().Reduce().Sort(hashFunction); 110 } 111 112 for (int i = 0; i < nodes.Length; ++i) { 113 var node = nodes[i]; 114 if (node.IsLeaf) { 115 continue; 116 } 117 node.Simplify?.Invoke(ref nodes, i); 118 for (int j = i - node.Size; j < i; ++j) { 119 // detect if anything was simplified 120 if (!nodes[j].Enabled) { 121 simplified = true; 122 break; 123 } 124 } 125 } 126 } while (simplified); 127 return nodes.UpdateNodeSizes().Sort(hashFunction); 131 128 } 132 129 … … 207 204 } 208 205 209 p rivatestatic HashNode<T>[] Reduce<T>(this HashNode<T>[] nodes) where T : class {206 public static HashNode<T>[] Reduce<T>(this HashNode<T>[] nodes) where T : class { 210 207 int count = 0; 211 208 for (int i = 0; i < nodes.Length; ++i) { -
branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs
r16478 r17005 38 38 private static readonly Constant constant = new Constant(); 39 39 40 private static readonly ISymbolicExpressionTreeNodeComparer comparer = new SymbolicExpressionTreeNodeComparer();41 40 private static ISymbolicExpressionTreeNode ActualRoot(this ISymbolicExpressionTree tree) => tree.Root.GetSubtree(0).GetSubtree(0); 42 41 … … 74 73 } 75 74 var hash = (ulong)name.GetHashCode(); 76 var hashNode = new HashNode<ISymbolicExpressionTreeNode> (comparer){75 var hashNode = new HashNode<ISymbolicExpressionTreeNode> { 77 76 Data = node, 78 77 Arity = node.SubtreeCount, -
branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r16674 r17005 132 132 <ItemGroup> 133 133 <Compile Include="Analyzers\SymbolicDataAnalysisBottomUpDiversityAnalyzer.cs" /> 134 <Compile Include="Analyzers\SymbolicDataAnalysisBuildingBlockAnalyzer.cs" />135 134 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" /> 136 135 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer.cs" /> … … 173 172 <Compile Include="Interpreter\SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs" /> 174 173 <Compile Include="Selectors\DiversitySelector.cs" /> 174 <Compile Include="SymbolicDataAnalysisExpressionTreeAverageSimilarityCalculator.cs" /> 175 175 <Compile Include="SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs" /> 176 176 <Compile Include="SymbolicDataAnalysisModelComplexityCalculator.cs" /> -
branches/2994-AutoDiffForIntervals/HeuristicLab.Tests
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Tests merged: 16997
- Property svn:mergeinfo changed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Persistence.Attic/PersistenceConsistencyChecks.cs
r16911 r17005 18 18 var dict = new Dictionary<Guid, string>(); 19 19 var duplicates = new Dictionary<string, string>(); 20 //get all non-generic and instantiable classes which implement IContentView21 20 foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(object))) { 22 21 var attr = StorableTypeAttribute.GetStorableTypeAttribute(type);
Note: See TracChangeset
for help on using the changeset viewer.