Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/07/19 14:20:33 (5 years ago)
Author:
gkronber
Message:

#2915: Corrected calculation of cuberoot function in all interpreters and updated all formatters.
I tested a run with all interpreters and got the same results with all of them.

Location:
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/BatchOperations.cs

    r16656 r16905  
    101101    public static void CubeRoot(double[] a, double[] b) {
    102102      for (int i = 0; i < BATCHSIZE; ++i)
    103         a[i] = Math.Pow(b[i], 1d / 3d);
     103        a[i] = b[i] < 0 ? -Math.Pow(-b[i], 1d / 3d) : Math.Pow(b[i], 1d / 3d);
    104104    }
    105105
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs

    r16668 r16905  
    247247        case OpCodes.CubeRoot: {
    248248            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
    249             return Expression.Power(arg, Expression.Constant(1.0 / 3.0));
     249            return Expression.Condition(Expression.LessThan(arg, Expression.Constant(0.0)),
     250              Expression.Negate(Expression.Power(Expression.Negate(arg), Expression.Constant(1.0 / 3.0))),
     251              Expression.Power(arg, Expression.Constant(1.0 / 3.0)));
    250252          }
    251253        case OpCodes.Root: {
     
    514516            var x1 = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
    515517            var x2 = MakeExpr(node.GetSubtree(1), variableIndices, row, columns);
    516             return Expression.Divide(x1, 
    517               Expression.Call(Sqrt, 
     518            return Expression.Divide(x1,
     519              Expression.Call(Sqrt,
    518520              Expression.Add(
    519521                Expression.Constant(1.0),
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r16670 r16905  
    336336        case OpCodes.CubeRoot: {
    337337            CompileInstructions(il, state, ds);
     338            var c1 = il.DefineLabel();
     339            var end = il.DefineLabel();
     340
     341            il.Emit(System.Reflection.Emit.OpCodes.Dup); // x
     342            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0);
     343            il.Emit(System.Reflection.Emit.OpCodes.Clt); // x < 0?
     344            il.Emit(System.Reflection.Emit.OpCodes.Brfalse, c1);
     345            il.Emit(System.Reflection.Emit.OpCodes.Neg); // x = -x
    338346            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0 / 3.0);
    339347            il.Emit(System.Reflection.Emit.OpCodes.Call, power);
     348            il.Emit(System.Reflection.Emit.OpCodes.Neg); // -Math.Pow(-x, 1/3)
     349            il.Emit(System.Reflection.Emit.OpCodes.Br, end);
     350            il.MarkLabel(c1);
     351            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0 / 3.0);
     352            il.Emit(System.Reflection.Emit.OpCodes.Call, power);
     353            il.MarkLabel(end);
    340354            return;
    341355          }
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r16670 r16905  
    232232          }
    233233        case OpCodes.CubeRoot: {
    234             return Math.Pow(Evaluate(dataset, ref row, state), 1.0 / 3.0);
     234            var arg = Evaluate(dataset, ref row, state);
     235            return arg < 0 ? -Math.Pow(-arg, 1.0 / 3.0) : Math.Pow(arg, 1.0 / 3.0);
    235236          }
    236237        case OpCodes.Root: {
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs

    r16656 r16905  
    245245          instr.value = Math.Sqrt(code[instr.childIndex].value);
    246246        } else if (instr.opCode == OpCodes.CubeRoot) {
    247           instr.value = Math.Pow(code[instr.childIndex].value, 1.0 / 3.0);
     247          var arg = code[instr.childIndex].value;
     248          instr.value = arg < 0 ? -Math.Pow(-arg, 1.0 / 3.0) : Math.Pow(arg, 1.0 / 3.0);
    248249        } else if (instr.opCode == OpCodes.Root) {
    249250          double x = code[instr.childIndex].value;
Note: See TracChangeset for help on using the changeset viewer.