Changeset 220 for branches/ExperimentalFunctionsBaking/Division.cs
- Timestamp:
- 05/07/08 00:02:43 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ExperimentalFunctionsBaking/Division.cs
r203 r220 30 30 31 31 namespace HeuristicLab.Functions { 32 public class Division : FunctionBase {32 public sealed class Division : FunctionBase { 33 33 private const double EPSILON = 10.0E-20; // if any divisor is < EPSILON return 0 34 34 … … 52 52 } 53 53 54 public static double Divide(double[] args) {55 // (/ 3) => 1/356 // (/ 2 3) => 2/357 // (/ 3 4 5) => 3/2058 if(args.Length == 1) {59 double divisor = args[0];60 if(Math.Abs(divisor) < EPSILON) return 0;61 else return 1.0 / divisor;62 } else {63 double result = args[0];64 for(int i = 1; i < args.Length; i++) {65 double divisor = args[i];66 if(Math.Abs(divisor) < EPSILON) return 0.0;67 result /= divisor;68 }69 return result;70 }71 }72 73 public override double Apply(Dataset dataset, int sampleIndex, double[] args) {74 return Division.Divide(args);75 }76 77 54 public override void Accept(IFunctionVisitor visitor) { 78 55 visitor.Visit(this);
Note: See TracChangeset
for help on using the changeset viewer.