ArnaoutLab / diversity

Partitioned frequency- and similarity-sensitive diversity in Python
MIT License
6 stars 1 forks source link

Power mean with 0 weights #13

Closed JasperBraun closed 2 years ago

JasperBraun commented 2 years ago

@Elliot-D-Hill: Unit testing power mean revealed the following bugs:

  1. Power mean of order 0 is defined as geometric mean which equals 1 when all weights are 0. However, diversity should be 0 in that case. How and where should we fix this? Some thoughts:

    • Technically power mean is correct, so somehow Metacommunity should take care of this case
    • I wouldn't expect anyone to have a good reason to pass all-0 weights because that is not interesting, so maybe it's a matter of input validation?
  2. When order < -100 or > 100 and all weights are 0, power_mean resorts to "initial" keyword arguments of numpy.amin and numpy.amax, which are inf and -inf, respectively. Technically, the power mean should be undefined. I suggest validating and raising exception.

Originally posted by @JasperBraun in https://github.com/Elliot-D-Hill/metacommunity/issues/7#issuecomment-1008064776

JasperBraun commented 2 years ago

Per discussion with @Elliot-D-Hill: