protected static function calcAverageDegree($graph)
    {
        $sum = 0;
        foreach ($graph as $neighbors) {
            foreach ($neighbors as $neighbor) {
                // Ignore empty neighbors.
                if (null !== $neighbor) {
                    ++$sum;
                }
            }
        }

        return $sum / count(array_keys($graph));
    }