def robustness(ds, name='PCM_POST', classdimname='pcm_class', outname=
    'PCM_ROBUSTNESS'):
    """ Compute classification robustness

        Parameters
        ----------
        name: str, default is 'PCM_POST'
            Name of the :class:`xarray.DataArray` with prediction probability (posteriors)

        classdimname: str, default is 'pcm_class'
            Name of the dimension holding classes

        outname: 'PCM_ROBUSTNESS' or str
            Name of the :class:`xarray.DataArray` with robustness

        inplace: boolean, False by default
            If False, return a :class:`xarray.DataArray` with robustness
            If True, return the input :class:`xarray.Dataset` with robustness added as a new :class:`xarray.DataArray`

        Returns
        -------
        :class:`xarray.Dataset` if inplace=True
        or
        :class:`xarray.DataArray` if inplace=False

    """
    maxpost = ds[name].max(dim=classdimname)
    K = len(ds[classdimname])
    robust = (maxpost - 1.0 / K) * K / (K - 1.0)
    id = dict()
    id[classdimname] = 0
    da = ds[name][id].rename(outname)
    da.values = robust
    da.attrs['long_name'] = 'PCM classification robustness'
    da.attrs['units'] = ''
    da.attrs['valid_min'] = 0
    da.attrs['valid_max'] = 1
    da.attrs['llh'] = ds[name].attrs['llh']
    return da
