Index: /branches/SensitivityEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator.cs
===================================================================
--- /branches/SensitivityEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator.cs	(revision 12210)
+++ /branches/SensitivityEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator.cs	(revision 12210)
@@ -0,0 +1,117 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.SingleObjective {
+  [Item("Weighted Performance Measures Evaluator", "Description")]
+  [StorableClass]
+  public class SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator : SymbolicClassificationSingleObjectiveEvaluator {
+    private const string NormalizedMeanSquaredErrorWeightingFactorParameterName = "NormalizedMeanSquaredErrorWeightingFactor";
+    private const string BetaParameterName = "Beta";
+    private const string GammaParameterName = "Gamma";
+    private const string ModelCreatorParameterName = "ModelCreator";
+
+    public override bool Maximization { get { return false; } }
+
+    #region parameter properties
+    public IFixedValueParameter<DoubleValue> NormalizedMeanSquaredErrorWeightingFactorParameter {
+      get { return (IFixedValueParameter<DoubleValue>)Parameters[NormalizedMeanSquaredErrorWeightingFactorParameterName]; }
+    }
+    public IFixedValueParameter<DoubleValue> BetaParameter {
+      get { return (IFixedValueParameter<DoubleValue>)Parameters[BetaParameterName]; }
+    }
+    public IFixedValueParameter<DoubleValue> GammaParameter {
+      get { return (IFixedValueParameter<DoubleValue>)Parameters[GammaParameterName]; }
+    }
+    public ILookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
+      get { return (ILookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
+    }
+    #endregion
+
+    [StorableConstructor]
+    protected SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator(bool deserializing) : base(deserializing) { }
+    protected SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator(SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator original, Cloner cloner)
+      : base(original, cloner) {
+    }
+    public override IDeepCloneable Clone(Cloner cloner) {
+      return new SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator(this, cloner);
+    }
+
+    public SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator()
+      : base() {
+      Parameters.Add(new FixedValueParameter<DoubleValue>(NormalizedMeanSquaredErrorWeightingFactorParameterName, "The weighting factor of the normalized mean squared error.", new DoubleValue(1)));
+      Parameters.Add(new FixedValueParameter<DoubleValue>(BetaParameterName, "Beta1", new DoubleValue(1)));
+      Parameters.Add(new FixedValueParameter<DoubleValue>(GammaParameterName, "Gamma1", new DoubleValue(1)));
+      Parameters.Add(new LookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "ModelCreator"));
+    }
+
+    public override IOperation InstrumentedApply() {
+      IEnumerable<int> rows = GenerateRowsToEvaluate();
+      var solution = SymbolicExpressionTreeParameter.ActualValue;
+      var creator = ModelCreatorParameter.ActualValue;
+      double normalizedMeanSquaredErrorWeightingFactor = NormalizedMeanSquaredErrorWeightingFactorParameter.Value.Value;
+      double beta = BetaParameter.Value.Value;
+      double gamma = GammaParameter.Value.Value;
+      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper,
+              ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, creator, normalizedMeanSquaredErrorWeightingFactor, beta, gamma);
+      QualityParameter.ActualValue = new DoubleValue(quality);
+      return base.InstrumentedApply();
+    }
+
+    public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData,
+                IEnumerable<int> rows, bool applyLinearScaling, ISymbolicClassificationModelCreator modelCreator, double normalizedMeanSquaredErrorWeightingFactor, double betaParameter, double gammaParameter) {
+      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
+      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
+      OnlineCalculatorError errorState;
+      double nmse;
+      
+      //calculate quality measures
+      var model = modelCreator.CreateSymbolicClassificationModel(solution, interpreter, lowerEstimationLimit, upperEstimationLimit);
+      string positiveClassName = problemData.PositiveClass;
+      model.RecalculateModelParameters(problemData, rows);
+      var performanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassName, problemData.GetClassValue(positiveClassName));
+      var estimated = model.GetEstimatedClassValues(problemData.Dataset, rows);
+      performanceCalculator.Calculate(estimated, targetValues);
+      if (performanceCalculator.ErrorState != OnlineCalculatorError.None) return Double.NaN;
+      double falsePositiveRate = performanceCalculator.FalsePositiveRate;
+      double falseNegativeRate = 1 - performanceCalculator.TruePositiveRate;
+
+      if (applyLinearScaling) {
+        var nmseCalculator = new OnlineNormalizedMeanSquaredErrorCalculator();
+        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, nmseCalculator, problemData.Dataset.Rows);
+        errorState = nmseCalculator.ErrorState;
+        nmse = nmseCalculator.NormalizedMeanSquaredError;
+      } else {
+        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
+        nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
+      }
+      if (errorState != OnlineCalculatorError.None) return Double.NaN;
+      return normalizedMeanSquaredErrorWeightingFactor * nmse + betaParameter * falsePositiveRate + gammaParameter * falseNegativeRate;
+    }
+
+    public override double Evaluate(IExecutionContext context, ISymbolicExpressionTree tree, IClassificationProblemData problemData, IEnumerable<int> rows) {
+      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
+      EstimationLimitsParameter.ExecutionContext = context;
+      ApplyLinearScalingParameter.ExecutionContext = context;
+      ModelCreatorParameter.ExecutionContext = context;
+
+      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper,
+                                      problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, ModelCreatorParameter.ActualValue, NormalizedMeanSquaredErrorWeightingFactorParameter.Value.Value, BetaParameter.Value.Value, GammaParameter.Value.Value);
+
+      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
+      EstimationLimitsParameter.ExecutionContext = null;
+      ApplyLinearScalingParameter.ExecutionContext = null;
+      ModelCreatorParameter.ExecutionContext = null;
+
+      return quality;
+    }
+  }
+}
