Git Product home page Git Product logo

humble-benchmarks's People

Contributors

john-colvin avatar kazakhai avatar rillki avatar ryuukk avatar sergiusthebest avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

humble-benchmarks's Issues

numerical errors

If (in the D code) you change all the doubles to reals you will get 0.131584 instead of 0.1368. This is a pretty bad sign...

fischerExact algorithm improvements

I noted in #4 (comment) that there was a lot of work done that was then cancelled out.

So I did this: John-Colvin@0337184 John-Colvin@8b219af which really shows how little work actually depends on the loop variable i.

Which then leads us to #4 (comment). In combination with the commit above, I think it's quite clear that - for a given contingency table - there is a constant (fs[data[0] + data[1]] + fs[data[2] + data[3]] + fs[data[0] + data[2]] + fs[data[1] + data[3]] - fs[data[0] + data[1] + data[2] + data[3]]) that is added n + 1 times where n is the number of iterations, then a pair of indices that sweep down through factorials at a fixed offset to each other (data[2] - data[1]) and a pair that sweep up similarly (offset data[3] - data[0]).

From this it seems evident that there is a way to be found to calculate the a[n]s from #4 (comment) and avoid jumping around in factorials altogether.

I still don't know what fischerExact is ๐Ÿคฃ, but I can read code ๐Ÿ˜„

Most of the time is spent filling the factorial table

If you were expecting to call fisherExact many times, you'd be doing a lot of duplicate work. log factorials are such a key thing in stats that I would imagine a "log factorial store" that lazily caches the results, where you can ask for a slice of them or just one-by-one, plus options to clear the cache etc. would be really valuable for performance across a multitude of tasks.

struct LogFactorialCache {
    private static double[] data;

    static void cacheTo(size_t n) {
        size_t oldLength = data.length;
        if (data.length <= n) {
            data.length = n + 1;
            if (oldLength == 0) {
                data[0] = 0;
                oldLength = 1;
            }
            foreach (i; oldLength .. n + 1) {
                data[i] = data[i - 1] + log(i);
            }
        }
    }

    // this is a rubbish function, because you'll never free
    // the memory. Needs redesign.
    static void shrinkTo(size_t n) {
        data.length = n + 1;
    }

    /// for one-off or non-contiguous usage,
    /// slight overhead per access
    static double opIndex(size_t i) {
        cacheTo(i);
        return data[i];
    }

    /// for when you know you want a block of them
    /// and want fast access inside.
    static double[] opSlice(size_t i0, size_t i1) {
        cacheTo(i1);
        return data[i0 .. i1];
    }
}

or something like that. Untested. Of course the same idea applies to other languages, not just D.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.