- Timestamp:
- 05/25/09 15:09:44 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Modeling/3.2/SimpleR2Evaluator.cs
r1869 r1888 8 8 9 9 namespace HeuristicLab.Modeling { 10 public class SimpleR2Evaluator : OperatorBase {10 public class SimpleR2Evaluator : SimpleEvaluatorBase { 11 11 12 public SimpleR2Evaluator()13 : base(){14 AddVariableInfo(new VariableInfo("Values", "Target vs predicted values", typeof(DoubleMatrixData), VariableKind.In));15 AddVariableInfo(new VariableInfo("R2", "Coefficient of determination", typeof(DoubleData), VariableKind.New | VariableKind.Out));12 public override string OutputVariableName { 13 get { 14 return "R2"; 15 } 16 16 } 17 17 18 public override IOperation Apply(IScope scope) { 19 DoubleMatrixData values = GetVariableValue<DoubleMatrixData>("Values", scope, true); 18 public override double Evaluate(double[,] values) { 19 return Calculate(values); 20 } 20 21 22 public static double Calculate(double[,] values) { 21 23 double targetMean = 0; 22 24 double sse = 0; 23 25 double cnt = 0; 24 for (int i = 0; i < values. Data.GetLength(0); i++) {25 double estimated = values .Data[i, 0];26 double target = values .Data[i, 1];26 for (int i = 0; i < values.GetLength(0); i++) { 27 double estimated = values[i, 0]; 28 double target = values[i, 1]; 27 29 if (!double.IsNaN(estimated) && !double.IsInfinity(estimated) && 28 30 !double.IsNaN(target) && !double.IsInfinity(target)) { … … 36 38 37 39 double targetDeviationTotalSumOfSquares = 0; 38 for (int i = 0; i < values. Data.GetLength(0); i++) {39 double target = values .Data[i, 1];40 for (int i = 0; i < values.GetLength(0); i++) { 41 double target = values[i, 1]; 40 42 if (!double.IsNaN(target) && !double.IsInfinity(target)) { 41 43 target = target - targetMean; … … 48 50 throw new InvalidProgramException(); 49 51 50 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("R2"), new DoubleData(quality))); 51 return null; 52 return quality; 52 53 } 53 54 }
Note: See TracChangeset
for help on using the changeset viewer.