1  #region License Information


2  /* HeuristicLab


3  * Copyright (C) 20022017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)


4  *


5  * This file is part of HeuristicLab.


6  *


7  * HeuristicLab is free software: you can redistribute it and/or modify


8  * it under the terms of the GNU General Public License as published by


9  * the Free Software Foundation, either version 3 of the License, or


10  * (at your option) any later version.


11  *


12  * HeuristicLab is distributed in the hope that it will be useful,


13  * but WITHOUT ANY WARRANTY; without even the implied warranty of


14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the


15  * GNU General Public License for more details.


16  *


17  * You should have received a copy of the GNU General Public License


18  * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.


19  */


20  #endregion


21 


22  using System.Runtime.CompilerServices;


23 


24  namespace HeuristicLab.Algorithms.DataAnalysis {


25  /// <summary>


26  /// Helper class for incremental split calculation.


27  /// Used while moving a potential Splitter along the ordered training Instances


28  /// </summary>


29  internal class NeumaierSum {


30  #region state


31  private double sum;


32  private double correction;


33  #endregion


34 


35  #region Constructors


36  public NeumaierSum(double startvalue) {


37  sum = startvalue;


38  correction = 0;


39  }


40  #endregion


41 


42  [MethodImpl(MethodImplOptions.NoOptimization)]


43  public void Add(double value) {


44  var t = sum + value;


45  var absSum = sum > 0 ? sum : sum;


46  var absv = value > 0 ? value : value;


47  if (absSum >= absv)


48  correction += (sum  t) + value;


49  else


50  correction += (value  t) + sum;


51  sum = t;


52  }


53 


54  public double Get() {


55  return sum + correction;


56  }


57 


58  public void Mul(double value) {


59  sum *= value;


60  correction *= value;


61  }


62  }


63  } 
