Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/29/20 10:17:19 (4 years ago)
Author:
dpiringe
Message:

#3076

  • changed the relevant code in SymbolicRegressionConstraintAnalyzer for the new class Region
  • added the .editorconfig file from trunk (to satisfy the coding guidelines)
Location:
branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj

    r17744 r17766  
    211211    <Compile Include="SymbolicRegressionSolution.cs" />
    212212    <Compile Include="SymbolicRegressionSolutionImpactValuesCalculator.cs" />
     213    <None Include=".editorconfig" />
    213214    <None Include="HeuristicLab.snk" />
    214215    <None Include="Plugin.cs.frame" />
  • branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionConstraintAnalyzer.cs

    r17764 r17766  
    1717  [StorableType("4318C6BD-E0A1-45FE-AC30-96E7F73B51FB")]
    1818  public class SymbolicRegressionConstraintAnalyzer : SymbolicDataAnalysisAnalyzer, ISymbolicExpressionTreeAnalyzer {
    19     private const string ConstraintViolationsResultName   = "Constraint Violations";
    20     private const string ProblemDataParameterName         = "ProblemData";
     19    private const string ConstraintViolationsResultName = "Constraint Violations";
     20    private const string ProblemDataParameterName = "ProblemData";
    2121    private const string ConstraintViolationParameterName = "ConstraintViolations";
    2222    private const string PenalityMultiplierParameterName = "ConstraintsPenalityMultiplier";
    2323    private const string PenalityMultiplierResultParameterName = "PenalityMultiplierResultParameter";
    2424    private const string StepSizeParameterName = "Step Size";
     25    private const string MaximumStepsParameterName = "Maximum Steps";
     26    private const string StartPenalityParameterName = "Start Penality";
    2527
    2628    #region parameter properties
    2729
    2830    public ILookupParameter<IRegressionProblemData> RegressionProblemDataParameter =>
    29       (ILookupParameter<IRegressionProblemData>) Parameters[ProblemDataParameterName];
     31      (ILookupParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName];
    3032
    3133    public IResultParameter<DataTable> ConstraintViolationParameter =>
    32       (IResultParameter<DataTable>) Parameters[ConstraintViolationParameterName];
     34      (IResultParameter<DataTable>)Parameters[ConstraintViolationParameterName];
    3335
    3436    public ILookupParameter<DoubleValue> PenalityMultiplierParameter =>
    3537      (ILookupParameter<DoubleValue>)Parameters[PenalityMultiplierParameterName];
     38
    3639    public IValueParameter<IntValue> StepSizeParameter =>
    3740      (IValueParameter<IntValue>)Parameters[StepSizeParameterName];
    3841
     42    public IValueParameter<IntValue> MaximumStepsParameter =>
     43      (IValueParameter<IntValue>)Parameters[MaximumStepsParameterName];
     44
    3945    public IResultParameter<DataTable> PenalityMultiplierResultParameter =>
    4046      (IResultParameter<DataTable>)Parameters[PenalityMultiplierResultParameterName];
     47    public IValueParameter<DoubleValue> StartPenalityParameter =>
     48      (IValueParameter<DoubleValue>)Parameters[StartPenalityParameterName];
    4149
    4250    #endregion
     
    6674      Parameters.Add(new ValueParameter<IntValue>(StepSizeParameterName,
    6775        "Defines the step size for the increasing penality multiplier.", new IntValue(1)));
     76      Parameters.Add(new ValueParameter<IntValue>(MaximumStepsParameterName,
     77        "Defines maximum steps for the increasing penality multiplier.", new IntValue(1000)));
     78      Parameters.Add(new ValueParameter<DoubleValue>(StartPenalityParameterName,
     79        "The start value for the penality multiplier.", new DoubleValue(0.5)));
     80
     81
     82
    6883
    6984      ConstraintViolationParameter.DefaultValue = new DataTable(ConstraintViolationParameterName) {
    70         VisualProperties = 
     85        VisualProperties =
    7186          {
    7287            XAxisTitle = "Generations",
     
    7590      };
    7691
    77       PenalityMultiplierResultParameter.DefaultValue = new DataTable(PenalityMultiplierResultParameterName)
    78       {
     92      PenalityMultiplierResultParameter.DefaultValue = new DataTable(PenalityMultiplierResultParameterName) {
    7993        VisualProperties =
    8094          {
     
    8599    }
    86100
    87     public override void InitializeState()
    88     {
     101    public override void InitializeState() {
    89102      Iterations = 0;
    90103      base.InitializeState();
    91104    }
    92105
    93     public override void ClearState()
    94     {
     106    public override void ClearState() {
    95107      Iterations = 0;
    96108      base.ClearState();
     
    104116        "Lookup parameter for the penality multiplier.", "PenalityMultiplier"));
    105117
    106       if (!Parameters.ContainsKey(PenalityMultiplierResultParameterName))
    107       {
     118      if (!Parameters.ContainsKey(PenalityMultiplierResultParameterName)) {
    108119        Parameters.Add(new ResultParameter<DataTable>(PenalityMultiplierResultParameterName,
    109120        "Shows the behavior of the penality multiplier."));
    110121
    111         PenalityMultiplierResultParameter.DefaultValue = new DataTable(PenalityMultiplierResultParameterName)
    112         {
     122        PenalityMultiplierResultParameter.DefaultValue = new DataTable(PenalityMultiplierResultParameterName) {
    113123          VisualProperties =
    114124          {
     
    123133        "Defines the step size for the increasing penality multiplier.", new IntValue(1)));
    124134
    125     }
    126 
    127     public override IOperation Apply()
    128     {
     135      if (!Parameters.ContainsKey(MaximumStepsParameterName))
     136        Parameters.Add(new ValueParameter<IntValue>(MaximumStepsParameterName,
     137        "Defines maximum steps for the increasing penality multiplier.", new IntValue(1000)));
     138
     139
     140
     141      if (!Parameters.ContainsKey(StartPenalityParameterName))
     142        Parameters.Add(new ValueParameter<DoubleValue>(StartPenalityParameterName,
     143        "The start value for the penality multiplier.", new DoubleValue(0.5)));
     144    }
     145
     146    public override IOperation Apply() {
    129147      Iterations++;
    130148      var rowName = "GeneralizedExponentialDiscreteDoubleValueModifier";
    131149      var stepSize = StepSizeParameter?.Value?.Value ?? 1;
    132       var penalityMultiplier = new DoubleValue(LinearDiscreteDoubleValueModifier.Apply(0, 0.1, 1.0, (int)(Iterations / stepSize) * stepSize, 0, 1000));
     150      var startValue = StartPenalityParameter?.Value?.Value ?? 0.5;
     151      var maximumSteps = MaximumStepsParameter?.Value?.Value ?? 1000;
     152      var penalityMultiplier = new DoubleValue(LinearDiscreteDoubleValueModifier.Apply(0, startValue, 1.0, (int)(Iterations / stepSize) * stepSize, 0, maximumSteps));
    133153      PenalityMultiplierParameter.ActualValue = penalityMultiplier;
    134154      //GeneralizedExponentialDiscreteDoubleValueModifier
     
    137157
    138158      var problemData = RegressionProblemDataParameter.ActualValue;
    139       var trees       = SymbolicExpressionTreeParameter.ActualValue;
    140 
    141       var results        = ResultCollectionParameter.ActualValue;
    142       var constraints    = problemData.IntervalConstraints.EnabledConstraints;
     159      var trees = SymbolicExpressionTreeParameter.ActualValue;
     160
     161      var results = ResultCollectionParameter.ActualValue;
     162      var constraints = problemData.IntervalConstraints.EnabledConstraints;
    143163      var variableRanges = problemData.VariableRanges.GetReadonlyDictionary();
    144       var newDataTable   = ConstraintViolationParameter.ActualValue;
     164      var newDataTable = ConstraintViolationParameter.ActualValue;
    145165
    146166      if (newDataTable.Rows.Count == 0)
     
    177197      // create new variable ranges for defined regions
    178198      IDictionary<string, Interval> regionRanges = new Dictionary<string, Interval>();
    179       foreach (var kvp in variableRanges)
    180       {
    181         if (kvp.Key != constraint.Target && constraint.Regions.TryGetValue(kvp.Key, out Interval val))
    182         {
    183           regionRanges.Add(kvp.Key, val);
    184         }
    185         else
    186         {
     199      foreach (var kvp in variableRanges) {
     200        var value = constraint.Regions.Where(r => r.VariableName == kvp.Key).FirstOrDefault();
     201        if (kvp.Key != constraint.Target && value != null) {
     202          regionRanges.Add(kvp.Key, value.Interval);
     203        } else {
    187204          regionRanges.Add(kvp);
    188205        }
     
    192209      if (!constraint.IsDerivative) {
    193210        resultInterval = intervalInterpreter.GetSymbolicExpressionTreeInterval(solution, new ReadOnlyDictionary<string, Interval>(regionRanges));
    194       }
    195       else {
     211      } else {
    196212        var tree = solution;
    197213        for (var i = 0; i < constraint.NumberOfDerivations; ++i) {
     
    206222      error = 0.0;
    207223      bool satisfied = true;
    208       if(!constraint.Interval.Contains(resultInterval.LowerBound))
    209       {
     224      if (!constraint.Interval.Contains(resultInterval.LowerBound)) {
    210225        satisfied = false;
    211226        error += Math.Abs(resultInterval.LowerBound - constraint.Interval.LowerBound);
    212227      }
    213228
    214       if (!constraint.Interval.Contains(resultInterval.UpperBound))
    215       {
     229      if (!constraint.Interval.Contains(resultInterval.UpperBound)) {
    216230        satisfied = false;
    217231        error += Math.Abs(resultInterval.UpperBound - constraint.Interval.UpperBound);
Note: See TracChangeset for help on using the changeset viewer.