Changeset 16323
- Timestamp:
- 11/23/18 15:19:39 (6 years ago)
- Location:
- branches/2966_interval_calculation
- Files:
-
- 2 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r16322 r16323 199 199 <Compile Include="Interfaces\IVariableSymbol.cs" /> 200 200 <Compile Include="Interpreter\SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs" /> 201 <Compile Include="Interpreter\Intervalnterpreter.cs" /> 201 202 <Compile Include="SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs" /> 202 203 <Compile Include="SymbolicDataAnalysisModelComplexityCalculator.cs" /> -
branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/Intervalnterpreter.cs
r16313 r16323 14 14 [StorableClass] 15 15 [Item("SymbolicDataAnalysisIntervalArithmeticInterpreter", "Interpreter for interval arithmetic within symbolic regression.")] 16 public class SymbolicDataAnalysisIntervalArithmeticInterpreter : ParameterizedNamedItem{16 public class IntervalInterpreter : ParameterizedNamedItem{ 17 17 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 18 18 public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter { … … 27 27 public void ClearState() { } 28 28 29 protected SymbolicDataAnalysisIntervalArithmeticInterpreter(bool deserializing) : base(deserializing) { }30 31 protected SymbolicDataAnalysisIntervalArithmeticInterpreter(SymbolicDataAnalysisIntervalArithmeticInterpreter original,29 protected IntervalInterpreter(bool deserializing) : base(deserializing) { } 30 31 protected IntervalInterpreter(IntervalInterpreter original, 32 32 Cloner cloner) 33 33 : base(original, cloner) { } 34 34 35 public SymbolicDataAnalysisIntervalArithmeticInterpreter()35 public IntervalInterpreter() 36 36 : base("SymbolicDataAnalysisIntervalArithmeticInterpreter", "Interpreter for interval arithmetic within symbolic regression.") { } 37 37 38 38 public override IDeepCloneable Clone(Cloner cloner) { 39 return new SymbolicDataAnalysisIntervalArithmeticInterpreter(this, cloner);39 return new IntervalInterpreter(this, cloner); 40 40 } 41 41 … … 79 79 } 80 80 81 //private static InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows, Dictionary<string, Interval> customIntervals = null) {82 // Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode);83 // int necessaryArgStackSize = 0;84 // foreach (Instruction instr in code) {85 // if (instr.opCode == OpCodes.Variable) {86 // var variableTreeNode = (VariableTreeNode)instr.dynamicNode;87 // IList<double> values = new List<double>();88 89 // if (customIntervals != null && customIntervals.ContainsKey(variableTreeNode.VariableName)) {90 // instr.data = customIntervals[variableTreeNode.VariableName];91 // } else {92 // foreach (var rowEnum in rows) {93 // values.Add(dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName)[rowEnum]);94 // }95 // instr.data = new Interval(values.Min(), values.Max());96 // }97 // //instr.data = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName);98 // } else if (instr.opCode == OpCodes.FactorVariable) {99 // var factorTreeNode = instr.dynamicNode as FactorVariableTreeNode;100 // instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName);101 // } else if (instr.opCode == OpCodes.BinaryFactorVariable) {102 // var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode;103 // instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName);104 // } else if (instr.opCode == OpCodes.LagVariable) {105 // var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode;106 // instr.data = dataset.GetReadOnlyDoubleValues(laggedVariableTreeNode.VariableName);107 // } else if (instr.opCode == OpCodes.VariableCondition) {108 // var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode;109 // instr.data = dataset.GetReadOnlyDoubleValues(variableConditionTreeNode.VariableName);110 // } else if (instr.opCode == OpCodes.Call) {111 // necessaryArgStackSize += instr.nArguments + 1;112 // }113 // }114 // return new InterpreterState(code, necessaryArgStackSize);115 //}116 117 81 private Interval Evaluate(InterpreterState state, Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) { 118 82 Instruction currentInstr = state.NextInstruction(); … … 186 150 return s; 187 151 } 152 case OpCodes.Square: { 153 var s = Interval.Square(Evaluate(state, intervals)); 154 intervals.Add(currentInstr.dynamicNode, s); 155 return s; 156 } 188 157 case OpCodes.Root: { 189 158 var s = Evaluate(state, intervals); … … 191 160 s = Interval.Root(s, Evaluate(state, intervals)); 192 161 } 162 intervals.Add(currentInstr.dynamicNode, s); 163 return s; 164 } 165 case OpCodes.SquareRoot: { 166 var s = Interval.SquareRoot(Evaluate(state, intervals)); 193 167 intervals.Add(currentInstr.dynamicNode, s); 194 168 return s; … … 213 187 EvaluatedSolutions = 0; 214 188 } 215 216 //public InterpreterState GetInstructions(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows, Dictionary<string, Interval> customIntervals = null) {217 // var state = PrepareInterpreterState(tree, dataset, rows, customIntervals);218 // var x = Evaluate(dataset, state);219 // state.Reset();220 221 // return state;222 //}223 224 // public Interval GetSymbolicExressionTreeInterval(tree,variableIntervals)225 //public Interval GetSymbolicExressionTreeInterval(tree,Dataset,intervals = null)226 189 227 190 public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IEnumerable<int> rows, out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) { -
branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r16322 r16323 191 191 <Compile Include="Implementation\ConstantModel.cs" /> 192 192 <Compile Include="Implementation\DataAnalysisModel.cs" /> 193 <Compile Include="Implementation\Interval.cs" /> 193 194 <Compile Include="Implementation\Regression\ConfidenceBoundRegressionSolution.cs" /> 194 195 <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" /> -
branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval.cs
r16303 r16323 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 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 using System.Text;5 using System.Threading.Tasks;6 25 using HeuristicLab.Common; 7 26 … … 11 30 public double LowerBound { 12 31 get { return lowerBound; } 13 set { lowerBound = value; }32 private set { lowerBound = value; } 14 33 } 15 34 private double upperBound; 16 35 public double UpperBound { 17 36 get { return upperBound; } 18 set { lowerBound = value; } 19 } 20 21 public Interval() { } 37 private set { lowerBound = value; } 38 } 22 39 23 40 public Interval(double lowerBound, double upperBound) { … … 165 182 } 166 183 184 public static Interval Square(Interval a) { 185 return Power(a, new Interval(2, 2)); 186 } 187 188 public static Interval Cubic(Interval a) { 189 return Power(a, new Interval(3, 3)); 190 } 167 191 168 192 public static Interval Root(Interval a, Interval b) { … … 173 197 } 174 198 175 public static Interval Average(IEnumerable<Interval> intervals) { 176 if (intervals == null || !intervals.Any()) throw new ArgumentException(); 177 178 int count = intervals.Count(); 179 Interval result = intervals.First(); 180 foreach (Interval i in intervals.Skip(1)) 181 result = Interval.Add(result, i); 182 183 return new Interval(result.lowerBound / count, result.upperBound / count); 199 public static Interval SquareRoot(Interval a) { 200 return Root(a, new Interval(2, 2)); 201 } 202 203 public static Interval CubicRoot(Interval a) { 204 return Root(a, new Interval(3, 3)); 184 205 } 185 206 #endregion
Note: See TracChangeset
for help on using the changeset viewer.