def compute_n_classes(classes, config):
"""The number of cluster centres to use for K-means
Just handles the case where someone specifies k=5 but labels 10 classes
in the training data. This will return k=10.
Parameters
----------
classes : ndarray
an array of hard class assignments given as training data
config : Config
The app config class holding the number of classes asked for
Returns
-------
k : int > 0
The max of k and the number of classes referenced in the training data
"""
k = mpiops.comm.allreduce(np.amax(classes), op=mpiops.MPI.MAX)
k = int(max(k, config.n_classes))
return k
评论列表
文章目录