#region License Information /* HeuristicLab * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.MainForm; using HeuristicLab.Problems.DataAnalysis.Symbolic.Views; namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views { public partial class InteractiveSymbolicRegressionSolutionSimplifierView : InteractiveSymbolicDataAnalysisSolutionSimplifierView { public new SymbolicRegressionSolution Content { get { return (SymbolicRegressionSolution)base.Content; } set { base.Content = value; } } public InteractiveSymbolicRegressionSolutionSimplifierView() : base(new SymbolicRegressionSolutionImpactValuesCalculator()) { InitializeComponent(); this.Caption = "Interactive Regression Solution Simplifier"; } protected override void UpdateModel(ISymbolicExpressionTree tree) { var model = new SymbolicRegressionModel(Content.ProblemData.TargetVariable, tree, Content.Model.Interpreter, Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit); model.Scale(Content.ProblemData); Content.Model = model; } protected override ISymbolicExpressionTree OptimizeConstants(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IProgress progress) { const int constOptIterations = 50; var regressionModel = (ISymbolicDataAnalysisModel)model.Clone(); var regressionProblemData = (IRegressionProblemData)problemData; SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(regressionModel.Interpreter, regressionModel.SymbolicExpressionTree, regressionProblemData, regressionProblemData.TrainingIndices, applyLinearScaling: true, maxIterations: constOptIterations, updateVariableWeights: true, lowerEstimationLimit: regressionModel.LowerEstimationLimit, upperEstimationLimit: regressionModel.UpperEstimationLimit, iterationCallback: (args, func, obj) => { double newProgressValue = progress.ProgressValue + 1.0 / (constOptIterations + 2); // (maxIterations + 2) iterations are reported progress.ProgressValue = Math.Min(newProgressValue, 1.0); }); return regressionModel.SymbolicExpressionTree; } } }