On Wednesday, 27 January 2016 at 22:36:37 UTC, Chris Wright wrote:

Longevity is an awkward one. If I create a project, do nothing with it for four years, then make a release, will that count as well as making a release once a month for four years? But the other metrics should account for that.


Code I wrote below incorporates some of what you're talking about.

For simplicity, I represented the date of each release as a dynamic array of doubles. I applied a weighting function to each and then calculated the entropy. The score is 1 if you only have one release. The score is higher, the more releases you have. If you have one release five years ago and one release recently, then your score is only marginally higher than 1. But if you have lots of recent releases, then the score is much more favorable.

You could probably adjust this in a number of ways. For instance, adjusting the denominator in
return weight.map!(a => a / weight.sum());
you could make it so that a release today is better than a release five years ago.


auto weight(double[] x, double lambda)
{
        import std.algorithm : sum, map;
        import std.math : exp;
        import std.array : array;
        
auto weight = x.map!(a => lambda * exp(-lambda * a)); // weights given by
                                                                // exponential
                                                                // distribution
        return weight.map!(a => a / weight.sum());
}

double entropy(T)(T x)
{
        import std.algorithm : sum, map;
        import std.math : exp, log;
        
        auto e = x.map!(a => a * log(a));
        return exp(-sum(e));
}

double calc_score(double[] x, double lambda)
{
        return x.weight(lambda).entropy();
}

void main()
{
        import std.stdio : writeln;
        
        double lambda = 0.5; // controls decay in weighting function
        double[] x;          // represents years since last update
        x = [0.1, 0.25, 1, 2, 5];
        
        auto score = calc_score(x, lambda);

        writeln(score);
}

Reply via email to