Standard deviation?

As stated by David in his Unpublished opinion piece : " A computer can calculate the standard deviation of a million numbers before your finger has had time to let go of the Enter key."

… yet I can find no trace of this useful function in GH or in any of the plugins I researched.
Am I missing something obvious ?

Hi Olivier,

What would you use the standard deviation for in Rhino?
Honest question.

-Willem

PointDeviation reports standard deviation. I’ve used it to judge the quality of the overall fit, not just the maximum deviation.

Hi Willem,

I want to use galapagos to minimize the standard deviation of the spacings between objects, depending on a bunch of parameters.

You will find many components on G2

Meanwhile you can use MathNet that has many statistics function (this library is also used in G2)

I also used it a lot on my old work, as all parameters in my models were not a single number but a distribution model (mean + standard deviation for example).

  /// <summary>
        /// Calcule l'écart type d'un ensemble de valeurs connaissant la moyenne (division par n-1 au lieu de n)
        /// </summary>
        /// <param name="arg_lst_values">Liste ou tableau de valeurs</param>
        /// <param name="arg_mean">Moyenne arithmétique</param>
        /// <returns></returns>
        public static double StandardDeviationUnbiased(IEnumerable<double> arg_lst_values, double arg_mean)
        {
            double standardDeviation = 0;
            int number = 0;
            foreach (double val in arg_lst_values)
            {
                if (!double.IsNaN(val))
                {
                    standardDeviation += (val - arg_mean) * (val - arg_mean);
                    number++;
                }
            }
            if (number > 1)
            {
                standardDeviation = Math.Sqrt(standardDeviation / ((double)number - 1.0));
            }


            return standardDeviation;
        }

I looked for math functions in Nautilus of course, but what’s G2 ?

Grasshopper 2 :eyes:

Maybe not exactly obvious, but it does the trick natively in Grasshopper 1: The standard Python library has a statistics module, which has a standard deviation function (and other useful functions):


250521_StandardDeviation_00.gh (6.8 KB)

For more fancy stuff, the new CPython editor in Rhino 8 supports e.g. numpy.

Yes, though I encountered a weird progressive slowdown condition using it a couple years ago:

Of course, searching the forum is always a good idea:

https://discourse.mcneel.com/search?q=standard%20deviation

I can’t seem to replicate the progressive slowdown, but @nathanletwory’s implementation of the variance function is still way faster than the standard library version! That’s good to know, thanks.


250521_StandardDeviation_01.gh (8.5 KB)

1 Like

Hi Luis ! :slightly_smiling_face:
:man_facepalming: of course, GH2 !

Yes Grasshopper 2, G2 is the command to launch Grasshopper 2 . I understand it was not very useful but it shows that some parts will be better covered by Grasshopper 2 (Field, statistics, functions …)
with the C# function
250521_StandardDeviation_02.gh (11.9 KB)

1 Like

Looks like it’s just the IronPython implementation that’s much slower. The standard CPython implementation is on par with @laurent_delrieu’s C# script. But then again the CPython component comes with a potential input cost on large data sets:


250522_StandardDeviation_00.gh (15.7 KB)

1 Like

Just tried this. If we disregard the cost of inputting large lists, the numpy function calls are basically free:


250522_StandardDeviation_01.gh (13.4 KB)