# Changeset 17902

Ignore:
Timestamp:
03/16/21 14:23:41 (16 months ago)
Message:

#3073 merged reintegration branch to trunk

Location:
trunk
Files:
2 deleted
14 edited
17 copied

Unmodified
Removed

• ## trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/DerivativeCalculator.cs

 r17180 return Product(Product(CreateConstant(3.0), Square(f)), Derive(f, variableName)); } if (branch.Symbol is Power) { // HL evaluators handle power strangely (exponent is rounded to an integer) // here we only support the case when the exponent is a constant integer var exponent = branch.GetSubtree(1) as ConstantTreeNode; if (exponent != null && Math.Truncate(exponent.Value) == exponent.Value) { var newPower = (ISymbolicExpressionTreeNode)branch.Clone(); var f = (ISymbolicExpressionTreeNode)newPower.GetSubtree(0).Clone(); var newExponent = (ConstantTreeNode)newPower.GetSubtree(1); newExponent.Value -= 1; return Product(Product(CreateConstant(exponent.Value), newPower), Derive(f, variableName)); } else throw new NotSupportedException("Cannot derive non-integer powers"); } if (branch.Symbol is Absolute) { var f = (ISymbolicExpressionTreeNode)branch.GetSubtree(0).Clone(); !(n.Symbol is Cube) && !(n.Symbol is CubeRoot) && !(n.Symbol is Power) && !(n.Symbol is Absolute) && !(n.Symbol is AnalyticQuotient) && !(n.Symbol is HyperbolicTangent) && !(n.Symbol is Sine) && !(n.Symbol is Cosine) &&

• ## trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

 r17413 False False ..\..\bin\HEAL.Attic.dll
• ## trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs

 r17180 } private class SymbolNameComparer : IEqualityComparer, IComparer { private class SymbolComparer : IEqualityComparer, IComparer { public int Compare(ISymbol x, ISymbol y) { return x.Name.CompareTo(y.Name); public bool Equals(ISymbol x, ISymbol y) { return Compare(x, y) == 0; return x.GetType() == y.GetType(); } public int GetHashCode(ISymbol obj) { return obj.Name.GetHashCode(); return obj.GetType().GetHashCode(); } } // the lookup table is also used in the corresponding formatter internal static readonly BidirectionalLookup knownSymbols = new BidirectionalLookup(StringComparer.InvariantCulture, new SymbolNameComparer()); knownSymbols = new BidirectionalLookup(StringComparer.InvariantCulture, new SymbolComparer()); private Constant constant = new Constant();
• ## trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/IBoundsEstimator.cs

 r17884 ﻿using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; ﻿using System.Collections.Generic; using HEAL.Attic; using HeuristicLab.Core; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; namespace HeuristicLab.Problems.DataAnalysis.Symbolic{ namespace HeuristicLab.Problems.DataAnalysis.Symbolic { [StorableType("C94A360D-5A9F-48A3-A6D3-CF920C77E50D")] public interface IBoundsEstimator : INamedItem, IStatefulItem { Interval GetModelBound(ISymbolicExpressionTree tree, IntervalCollection variableRanges); IDictionary GetModelNodesBounds( IDictionary GetModelNodeBounds( ISymbolicExpressionTree tree, IntervalCollection variableRanges); double CheckConstraint( ISymbolicExpressionTree tree, IntervalCollection variableRanges, IntervalConstraint constraint); // returns the size of the violation which is the distance to one of the bounds double GetConstraintViolation( ISymbolicExpressionTree tree, IntervalCollection variableRanges, ShapeConstraint constraint); bool IsCompatible(ISymbolicExpressionTree tree); int EvaluatedSolutions { get; set; } } } }
• ## trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

 r17579 ﻿#region License Information /* HeuristicLab * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) * along with HeuristicLab. If not, see . */ #endregion namespace HeuristicLab.Problems.DataAnalysis.Symbolic { [StorableType("DE6C1E1E-D7C1-4070-847E-63B68562B10C")] [Item("IntervalInterpreter", "Intperter for calculation of intervals of symbolic models.")] [Item("IntervalInterpreter", "Interpreter for calculation of intervals of symbolic models.")] public sealed class IntervalInterpreter : ParameterizedNamedItem, IStatefulItem { private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; public IFixedValueParameter EvaluatedSolutionsParameter { get { return (IFixedValueParameter)Parameters[EvaluatedSolutionsParameterName]; } } public IFixedValueParameter EvaluatedSolutionsParameter => (IFixedValueParameter)Parameters[EvaluatedSolutionsParameterName]; public int EvaluatedSolutions { get { return EvaluatedSolutionsParameter.Value.Value; } set { EvaluatedSolutionsParameter.Value.Value = value; } get => EvaluatedSolutionsParameter.Value.Value; set => EvaluatedSolutionsParameter.Value.Value = value; } [StorableConstructor] private IntervalInterpreter(StorableConstructorFlag _) : base(_) { } private IntervalInterpreter(IntervalInterpreter original, Cloner cloner) : base(original, cloner) { } : base(original, cloner) { } public IntervalInterpreter() : base("IntervalInterpreter", "Intperter for calculation of intervals of symbolic models.") { Parameters.Add(new FixedValueParameter(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); : base("IntervalInterpreter", "Interpreter for calculation of intervals of symbolic models.") { Parameters.Add(new FixedValueParameter(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); } #region IStatefulItem Members public void InitializeState() { EvaluatedSolutions = 0; } public void ClearState() { } #endregion public Interval GetSymbolicExpressionTreeInterval(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable rows = null) { public Interval GetSymbolicExpressionTreeInterval( ISymbolicExpressionTree tree, IDataset dataset, IEnumerable rows = null) { var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows); return GetSymbolicExpressionTreeInterval(tree, variableRanges); } public Interval GetSymbolicExpressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, out IDictionary nodeIntervals, IEnumerable rows = null) { public Interval GetSymbolicExpressionTreeIntervals( ISymbolicExpressionTree tree, IDataset dataset, out IDictionary nodeIntervals, IEnumerable rows = null) { var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows); return GetSymbolicExpressionTreeIntervals(tree, variableRanges, out nodeIntervals); } public Interval GetSymbolicExpressionTreeInterval(ISymbolicExpressionTree tree, IReadOnlyDictionary variableRanges) { public Interval GetSymbolicExpressionTreeInterval( ISymbolicExpressionTree tree, IReadOnlyDictionary variableRanges) { lock (syncRoot) { EvaluatedSolutions++; } int instructionCount = 0; Interval outputInterval; var instructionCount = 0; var instructions = PrepareInterpreterState(tree, variableRanges); var outputInterval = Evaluate(instructions, ref instructionCount); // because of numerical errors the bounds might be incorrect if (outputInterval.LowerBound <= outputInterval.UpperBound) return outputInterval; else return new Interval(outputInterval.UpperBound, outputInterval.LowerBound); } public Interval GetSymbolicExpressionTreeIntervals(ISymbolicExpressionTree tree, IReadOnlyDictionary variableRanges, out IDictionary nodeIntervals) { outputInterval = Evaluate(instructions, ref instructionCount); return outputInterval.LowerBound <= outputInterval.UpperBound ? outputInterval : new Interval(outputInterval.UpperBound, outputInterval.LowerBound); } public Interval GetSymbolicExpressionTreeIntervals( ISymbolicExpressionTree tree, IReadOnlyDictionary variableRanges, out IDictionary nodeIntervals) { lock (syncRoot) { EvaluatedSolutions++; } int instructionCount = 0; var intervals = new Dictionary(); var instructions = PrepareInterpreterState(tree, variableRanges); var outputInterval = Evaluate(instructions, ref instructionCount, intervals); // fix incorrect intervals if necessary (could occur because of numerical errors) Interval outputInterval; var instructionCount = 0; outputInterval = Evaluate(instructions, ref instructionCount, intervals); nodeIntervals = new Dictionary(); foreach (var kvp in intervals) { if (outputInterval.IsInfiniteOrUndefined || outputInterval.LowerBound <= outputInterval.UpperBound) return outputInterval; else return new Interval(outputInterval.UpperBound, outputInterval.LowerBound); } private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, IReadOnlyDictionary variableRanges) { return new Interval(outputInterval.UpperBound, outputInterval.LowerBound); } private static Instruction[] PrepareInterpreterState( ISymbolicExpressionTree tree, IReadOnlyDictionary variableRanges) { if (variableRanges == null) throw new ArgumentNullException("No variablew ranges are present!", nameof(variableRanges)); //Check if all variables used in the tree are present in the dataset foreach (var variable in tree.IterateNodesPrefix().OfType().Select(n => n.VariableName).Distinct()) { if (!variableRanges.ContainsKey(variable)) throw new InvalidOperationException($"No ranges for variable {variable} is present"); } Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode); foreach (Instruction instr in code.Where(i => i.opCode == OpCodes.Variable)) { foreach (var variable in tree.IterateNodesPrefix().OfType().Select(n => n.VariableName) .Distinct()) if (!variableRanges.ContainsKey(variable)) throw new InvalidOperationException($"No ranges for variable {variable} is present"); var code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode); foreach (var instr in code.Where(i => i.opCode == OpCodes.Variable)) { var variableTreeNode = (VariableTreeNode)instr.dynamicNode; instr.data = variableRanges[variableTreeNode.VariableName]; } return code; } private Interval Evaluate(Instruction[] instructions, ref int instructionCounter, IDictionary nodeIntervals = null) { Instruction currentInstr = instructions[instructionCounter]; //Use ref parameter, because the tree will be iterated through recursively from the left-side branch to the right side //Update instructionCounter, whenever Evaluate is called // Use ref parameter, because the tree will be iterated through recursively from the left-side branch to the right side // Update instructionCounter, whenever Evaluate is called public static Interval Evaluate( Instruction[] instructions, ref int instructionCounter, IDictionary nodeIntervals = null, IReadOnlyDictionary variableIntervals = null) { var currentInstr = instructions[instructionCounter]; instructionCounter++; Interval result = null; Interval result; switch (currentInstr.opCode) { //Variables, Constants, ... case OpCodes.Variable: { var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode; var weightInterval = new Interval(variableTreeNode.Weight, variableTreeNode.Weight); var variableInterval = (Interval)currentInstr.data; Interval variableInterval; if (variableIntervals != null && variableIntervals.ContainsKey(variableTreeNode.VariableName)) variableInterval = variableIntervals[variableTreeNode.VariableName]; else variableInterval = (Interval)currentInstr.data; result = Interval.Multiply(variableInterval, weightInterval); //Elementary arithmetic rules case OpCodes.Add: { result = Evaluate(instructions, ref instructionCounter, nodeIntervals); for (int i = 1; i < currentInstr.nArguments; i++) { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); for (var i = 1; i < currentInstr.nArguments; i++) { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.Add(result, argumentInterval); } break; } case OpCodes.Sub: { result = Evaluate(instructions, ref instructionCounter, nodeIntervals); result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); if (currentInstr.nArguments == 1) result = Interval.Multiply(new Interval(-1, -1), result); for (int i = 1; i < currentInstr.nArguments; i++) { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); for (var i = 1; i < currentInstr.nArguments; i++) { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.Subtract(result, argumentInterval); } break; } case OpCodes.Mul: { result = Evaluate(instructions, ref instructionCounter, nodeIntervals); for (int i = 1; i < currentInstr.nArguments; i++) { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); for (var i = 1; i < currentInstr.nArguments; i++) { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.Multiply(result, argumentInterval); } break; } case OpCodes.Div: { result = Evaluate(instructions, ref instructionCounter, nodeIntervals); result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); if (currentInstr.nArguments == 1) result = Interval.Divide(new Interval(1, 1), result); for (int i = 1; i < currentInstr.nArguments; i++) { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); for (var i = 1; i < currentInstr.nArguments; i++) { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.Divide(result, argumentInterval); } break; } //Trigonometric functions break; } case OpCodes.Sin: { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.Sine(argumentInterval); break; } case OpCodes.Cos: { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.Cosine(argumentInterval); break; } case OpCodes.Tan: { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.Tangens(argumentInterval); break; } case OpCodes.Tanh: { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.HyperbolicTangent(argumentInterval); break; } //Exponential functions case OpCodes.Log: { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.Logarithm(argumentInterval); break; } case OpCodes.Exp: { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.Exponential(argumentInterval); break; } case OpCodes.Square: { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.Square(argumentInterval); break; } case OpCodes.SquareRoot: { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.SquareRoot(argumentInterval); break; } case OpCodes.Cube: { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.Cube(argumentInterval); break; } case OpCodes.CubeRoot: { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.CubicRoot(argumentInterval); break; } case OpCodes.Absolute: { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.Absolute(argumentInterval); break; } case OpCodes.AnalyticQuotient: { result = Evaluate(instructions, ref instructionCounter, nodeIntervals); for (var i = 1; i < currentInstr.nArguments; i++) { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); for (var i = 1; i < currentInstr.nArguments; i++) { var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); result = Interval.AnalyticalQuotient(result, argumentInterval); } } if (nodeIntervals != null) if (!(nodeIntervals == null || nodeIntervals.ContainsKey(currentInstr.dynamicNode))) nodeIntervals.Add(currentInstr.dynamicNode, result); } public static bool IsCompatible(ISymbolicExpressionTree tree) { var containsUnknownSyumbol = ( var containsUnknownSymbols = ( from n in tree.Root.GetSubtree(0).IterateNodesPrefix() where !(n.Symbol is Problems.DataAnalysis.Symbolic.Variable) && !(n.Symbol is Variable) && !(n.Symbol is Constant) && !(n.Symbol is StartSymbol) && !(n.Symbol is Cosine) && !(n.Symbol is Tangent) && !(n.Symbol is HyperbolicTangent) && !(n.Symbol is Logarithm) && !(n.Symbol is Exponential) && !(n.Symbol is AnalyticQuotient) select n).Any(); return !containsUnknownSyumbol; return !containsUnknownSymbols; } }

• ## trunk/HeuristicLab.Problems.DataAnalysis.Views

• Property svn:mergeinfo changed /branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Views (added) merged: 17591,​17607,​17790,​17793,​17876 /branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Views (added) merged: 17887,​17890-17891,​17893-17896
• ## trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

 r17579 UserControl IntervalCollectionView.cs ProblemDataView.cs True True Resources.resx UserControl ConfidenceRegressionSolutionLineChartView.cs UserControl IntervalCollectionView.cs UserControl RegressionSolutionScatterPlotView.cs UserControl ShapeConstraintsView.cs UserControl ShapeConstraintView.cs AbstractFeatureCorrelationView.cs ResXFileCodeGenerator Resources.Designer.cs False ..\..\bin\HEAL.Attic.dll False

• ## trunk/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

 r17579
• ## trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs

 r17583 [Storable] public double UpperBound { get; private set; } public double Width => UpperBound - LowerBound; [StorableConstructor] } private Interval(double v) : this(v, v) { } public bool Contains(double value) { return LowerBound <= value && value <= UpperBound; return false; return (UpperBound.IsAlmost(other.UpperBound) || (double.IsNaN(UpperBound) && double.IsNaN(other.UpperBound))) && (LowerBound.IsAlmost(other.LowerBound) || (double.IsNaN(LowerBound) && double.IsNaN(other.LowerBound))); return (UpperBound==other.UpperBound || (double.IsNaN(UpperBound) && double.IsNaN(other.UpperBound))) && (LowerBound==other.LowerBound || (double.IsNaN(LowerBound) && double.IsNaN(other.LowerBound))); } } #endregion #region arithmetic overloads public static Interval operator +(Interval a, Interval b) => Add(a, b); public static Interval operator +(Interval a, double b) => Add(a, new Interval(b)); public static Interval operator +(double a, Interval b) => Add(new Interval(a), b); public static Interval operator -(Interval a, Interval b) => Subtract(a, b); public static Interval operator -(Interval a, double b) => Subtract(a, new Interval(b)); public static Interval operator -(double a, Interval b) => Subtract(new Interval(a), b); public static Interval operator -(Interval a) => Subtract(new Interval(0), a); public static Interval operator *(Interval a, Interval b) => Multiply(a, b); public static Interval operator *(Interval a, double b) => Multiply(a, new Interval(b)); public static Interval operator *(double a, Interval b) => Multiply(new Interval(a), b); public static Interval operator /(Interval a, Interval b) => Divide(a, b); public static Interval operator /(Interval a, double b) => Divide(a, new Interval(b)); public static Interval operator /(double a, Interval b) => Divide(new Interval(a), b); public static Interval Exponential(double a) { return Exponential(new Interval(a)); } public static Interval Logarithm(double a) { return Logarithm(new Interval(a)); } public static Interval Sine(double a) { return Sine(new Interval(a)); } public static Interval Cosine(double a) { return Cosine(new Interval(a)); } public static Interval Tangens(double a) { return Tangens(new Interval(a)); } public static Interval HyperbolicTangent(double a) { return HyperbolicTangent(new Interval(a)); } public static Interval Square(double a) { return Square(new Interval(a)); } public static Interval Cube(double a) { return Cube(new Interval(a)); } public static Interval SquareRoot(double a) { return SquareRoot(new Interval(a)); } public static Interval CubicRoot(double a) { return CubicRoot(new Interval(a)); } public static Interval Absolute(double a) { return Absolute(new Interval(a)); } public static Interval AnalyticQuotient(Interval a, double b) { return AnalyticalQuotient(a, new Interval(b)); } public static Interval AnalyticQuotient(double a, Interval b) { return AnalyticalQuotient(new Interval(a), b); } public static Interval AnalyticQuotient(double a, double b) { return AnalyticalQuotient(new Interval(a), new Interval(b)); } #endregion } }