Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/28/20 10:56:16 (5 years ago)
Author:
mkommend
Message:

#2521: Merged trunk changes from 15684-HEAD into the branch.

Location:
branches/2521_ProblemRefactoring
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring

  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis

  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4

  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionVariableImpactsCalculator.cs

    r17226 r17457  
    2626using System.Collections.Generic;
    2727using System.Linq;
     28using HEAL.Attic;
    2829using HeuristicLab.Common;
    2930using HeuristicLab.Core;
    3031using HeuristicLab.Data;
    3132using HeuristicLab.Parameters;
    32 using HEAL.Attic;
    3333using HeuristicLab.Random;
    3434
     
    173173
    174174      IList originalValues = null;
    175       IList replacementValues = GetReplacementValues(modifiableDataset, variableName, model, rows, targetValues, out originalValues, replacementMethod, factorReplacementMethod);
    176 
    177       double newValue = CalculateQualityForReplacement(model, modifiableDataset, variableName, originalValues, rows, replacementValues, targetValues);
     175      IList replacementValues = GetReplacementValues(modifiableDataset, variableName, model, problemData.AllowedInputVariables, rows, targetValues, out originalValues, replacementMethod, factorReplacementMethod);
     176
     177      double newValue = CalculateQualityForReplacement(model, modifiableDataset, problemData.AllowedInputVariables, variableName, originalValues, rows, replacementValues, targetValues);
    178178      double impact = quality - newValue;
    179179
     
    184184      string variableName,
    185185      IClassificationModel model,
     186      IEnumerable<string> allowedInputVariables,
    186187      IEnumerable<int> rows,
    187188      IEnumerable<double> targetValues,
     
    196197      } else if (modifiableDataset.VariableHasType<string>(variableName)) {
    197198        originalValues = modifiableDataset.GetReadOnlyStringValues(variableName).ToList();
    198         replacementValues = GetReplacementValuesForString(model, modifiableDataset, variableName, rows, (List<string>)originalValues, targetValues, factorReplacementMethod);
     199        replacementValues = GetReplacementValuesForString(model, modifiableDataset, allowedInputVariables, variableName, rows, (List<string>)originalValues, targetValues, factorReplacementMethod);
    199200      } else {
    200201        throw new NotSupportedException("Variable not supported");
     
    254255    private static IList GetReplacementValuesForString(IClassificationModel model,
    255256      ModifiableDataset modifiableDataset,
     257      IEnumerable<string> allowedInputVariables,
    256258      string variableName,
    257259      IEnumerable<int> rows,
     
    270272            List<string> curReplacementValues = Enumerable.Repeat(repl, modifiableDataset.Rows).ToList();
    271273            //fholzing: this result could be used later on (theoretically), but is neglected for better readability/method consistency
    272             var newValue = CalculateQualityForReplacement(model, modifiableDataset, variableName, originalValues, rows, curReplacementValues, targetValues);
     274            var newValue = CalculateQualityForReplacement(model, modifiableDataset, allowedInputVariables, variableName, originalValues, rows, curReplacementValues, targetValues);
    273275            var curQuality = newValue;
    274276
     
    308310      IClassificationModel model,
    309311      ModifiableDataset modifiableDataset,
     312      IEnumerable<string> allowedInputVariables,
    310313      string variableName,
    311314      IList originalValues,
     
    317320      var discModel = model as IDiscriminantFunctionClassificationModel;
    318321      if (discModel != null) {
    319         var problemData = new ClassificationProblemData(modifiableDataset, modifiableDataset.VariableNames, model.TargetVariable);
     322        var problemData = new ClassificationProblemData(modifiableDataset, allowedInputVariables, model.TargetVariable);
    320323        discModel.RecalculateModelParameters(problemData, rows);
    321324      }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs

    r17226 r17457  
    7474      classValues = (double[])original.classValues.Clone();
    7575      thresholds = (double[])original.thresholds.Clone();
     76      thresholdCalculator = (IDiscriminantFunctionThresholdCalculator)original.thresholdCalculator.Clone();
    7677    }
    7778
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval.cs

    r17333 r17457  
    3737    protected Interval(StorableConstructorFlag _) { }
    3838
     39    /// <summary>
     40    /// Creates an interval with given bounds, where lower bound must be smaller than
     41    /// the upper bound. Floating point precision errors trough calculations are fixed by,
     42    /// checking if the intervals are almost the same (E-12). If this is the case, the bounds
     43    /// will be set to the bound closer to zero.
     44    /// </summary>
     45    /// <param name="lowerBound">Lower bound of the interval</param>
     46    /// <param name="upperBound">Upper bound of the interval</param>
    3947    public Interval(double lowerBound, double upperBound) {
     48      if (lowerBound.IsAlmost(upperBound)) {
     49        //If the bounds go over zero
     50        if (lowerBound <= 0 && upperBound >= 0) {
     51          lowerBound = 0.0;
     52          upperBound = 0.0;
     53          //Interval is negative
     54        } else if (upperBound < 0) {
     55          lowerBound = upperBound;
     56          //Interval is positive
     57        } else {
     58          upperBound = lowerBound;
     59        }
     60      }
     61
    4062      if (lowerBound > upperBound)
    4163        throw new ArgumentException("LowerBound must be smaller than UpperBound.");
     
    5880                double.IsNaN(LowerBound) || double.IsNaN(UpperBound);
    5981      }
     82    }
     83
     84    /// <summary>
     85    /// True if the interval is positive without zero
     86    /// </summary>
     87    public bool IsPositive {
     88      get => LowerBound > 0.0;
     89    }
     90
     91    /// <summary>
     92    /// True if the interval is negative without zero
     93    /// </summary>
     94    public bool IsNegative {
     95      get => UpperBound < 0.0;
    6096    }
    6197
     
    128164    }
    129165
    130     //mkommend: Division by intervals containing 0 is implemented as defined in
     166    //Division by intervals containing 0 is implemented as defined in
    131167    //http://en.wikipedia.org/wiki/Interval_arithmetic
    132168    public static Interval Divide(Interval a, Interval b) {
     
    171207    public static Interval Tangens(Interval a) {
    172208      return Interval.Divide(Interval.Sine(a), Interval.Cosine(a));
    173     } 
     209    }
    174210    public static Interval HyperbolicTangent(Interval a) {
    175211      return new Interval(Math.Tanh(a.LowerBound), Math.Tanh(a.UpperBound));
     
    206242      if (a.UpperBound <= 0) return new Interval(a.UpperBound * a.UpperBound, a.LowerBound * a.LowerBound);     // interval is negative
    207243      else if (a.LowerBound >= 0) return new Interval(a.LowerBound * a.LowerBound, a.UpperBound * a.UpperBound); // interval is positive
    208       else return new Interval(0, Math.Max(a.LowerBound*a.LowerBound, a.UpperBound*a.UpperBound)); // interval goes over zero
     244      else return new Interval(0, Math.Max(a.LowerBound * a.LowerBound, a.UpperBound * a.UpperBound)); // interval goes over zero
    209245    }
    210246
     
    235271      var absLower = Math.Abs(a.LowerBound);
    236272      var absUpper = Math.Abs(a.UpperBound);
    237       return new Interval(Math.Min(absLower, absUpper), Math.Max(absLower, absUpper));
     273      var min = Math.Min(absLower, absUpper);
     274      var max = Math.Max(absLower, absUpper);
     275
     276      if (a.Contains(0.0)) {
     277        min = 0.0;
     278      }
     279
     280      return new Interval(min, max);
     281    }
     282
     283    public static Interval AnalyticalQuotient(Interval a, Interval b) {
     284      var dividend = a;
     285      var divisor = Add(Square(b), new Interval(1.0, 1.0));
     286      divisor = SquareRoot(divisor);
     287
     288      var quotient = Divide(dividend, divisor);
     289      return quotient;
    238290    }
    239291    #endregion
Note: See TracChangeset for help on using the changeset viewer.