encog-dotnet-core icon indicating copy to clipboard operation
encog-dotnet-core copied to clipboard

Performance optimization for NormalizedField.DeNormalize

Open Nathaire opened this issue 11 years ago • 2 comments

Hi,

I've taken a look at method *DeNormalize of the *NormalizedField class. I think we can improve the performance of this method with the following code:

public double DeNormalize(double v)
{
    return ((v - _normalizedLow)*(_actualHigh - _actualLow)
                /(_normalizedHigh - _normalizedLow)) + _actualLow;
    }

I've made some benchmark and it seems that with this equation, the result is 20% quicker. Can someone confirm my implementation.

Thanks

Nathaire avatar Aug 05 '14 14:08 Nathaire

If this is confirmed, I suggest AnalystField.DeNormalize be modified for this performance gain, as well.

jeroldhaas avatar Mar 08 '15 22:03 jeroldhaas

It's best to include your benchmark code with your results for an optimum control environment.

This test was run in F# interactive envrionment, resetting after modify-build:

open Encog
let rnl = [ for i in 1. .. 100000000. ->
              let rnd = new System.Random() in
              rnd.NextDouble()]
let nfl =
    rnl
    |> List.map (fun x -> let foo = new Encog.Util.Arrayutil.NormalizedField()
                                    foo.DeNormalize (float x))
// Old Code
// Real: 00:00:45.398, CPU: 00:00:44.656, GC gen0: 3817, gen1: 754, gen2: 3
// New Code
// Real: 00:00:43.278, CPU: 00:00:42.781, GC gen0: 3816, gen1: 778, gen2: 2

jeroldhaas avatar Mar 09 '15 01:03 jeroldhaas