class_docstr: Compute Calinski Harabasz Score (also known as variance ratio criterion) for clustering algorithms.
  
  .. math::
      CHS(X, L) = \frac{B(X, L) \cdot (n_\text{samples} - n_\text{labels})}{W(X, L) \cdot (n_\text{labels} - 1)}
  
  where :math:`B(X, L)` is the between-cluster dispersion, which is the squared distance between the cluster centers
  and the dataset mean, weighted by the size of the clusters, :math:`n_\text{samples}` is the number of samples,
  :math:`n_\text{labels}` is the number of labels, and :math:`W(X, L)` is the within-cluster dispersion e.g. the
  sum of squared distances between each samples and its closest cluster center.
  
  This clustering metric is an intrinsic measure, because it does not rely on ground truth labels for the evaluation.
  Instead it examines how well the clusters are separated from each other. The score is higher when clusters are dense
  and well separated, which relates to a standard concept of a cluster.
  
  As input to ``forward`` and ``update`` the metric accepts the following input:
  
  - ``data`` (:class:`~torch.Tensor`): float tensor with shape ``(N,d)`` with the embedded data. ``d`` is the
    dimensionality of the embedding space.
  - ``labels`` (:class:`~torch.Tensor`): single integer tensor with shape ``(N,)`` with cluster labels
  
  As output of ``forward`` and ``compute`` the metric returns the following output:
  
  - ``chs`` (:class:`~torch.Tensor`): A tensor with the Calinski Harabasz Score
  
  Args:
      kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.
  
  Example::
      >>> import torch
      >>> from torchmetrics.clustering import CalinskiHarabaszScore
      >>> _ = torch.manual_seed(42)
      >>> data = torch.randn(10, 3)
      >>> labels = torch.randint(3, (10,))
      >>> metric = CalinskiHarabaszScore()
      >>> metric(data, labels)
      tensor(3.0053)
class_docstr_tok: ["Compute","Calinski","Harabasz","Score","(","also","known","as","variance","ratio","criterion",")","for","clustering","algorithms",".","..","math",":",":","CHS","(","X",",","L",")","=","\\frac","{","B","(","X",",","L",")","\\cdot","(","n_\\text","{","samples","}","-","n_\\text","{","labels","}",")","}","{","W","(","X",",","L",")","\\cdot","(","n_\\text","{","labels","}","-","1",")","}","where",":","math",":","`","B","(","X",",","L",")","`","is","the","between-cluster","dispersion",",","which","is","the","squared","distance","between","the","cluster","centers","and","the","dataset","mean",",","weighted","by","the","size","of","the","clusters",",",":","math",":","`","n_\\text","{","samples","}","`","is","the","number","of","samples",",",":","math",":","`","n_\\text","{","labels","}","`","is","the","number","of","labels",",","and",":","math",":","`","W","(","X",",","L",")","`","is","the","within-cluster","dispersion","e.g",".","the","sum","of","squared","distances","between","each","samples","and","its","closest","cluster","center",".","This","clustering","metric","is","an","intrinsic","measure",",","because","it","does","not","rely","on","ground","truth","labels","for","the","evaluation",".","Instead","it","examines","how","well","the","clusters","are","separated","from","each","other",".","The","score","is","higher","when","clusters","are","dense","and","well","separated",",","which","relates","to","a","standard","concept","of","a","cluster",".","As","input","to","``","forward","``","and","``","update","``","the","metric","accepts","the","following","input",":","-","``","data","``","(",":","class",":","`","~torch.Tensor","`",")",":","float","tensor","with","shape","``","(","N",",","d",")","``","with","the","embedded","data",".","``","d","``","is","the","dimensionality","of","the","embedding","space",".","-","``","labels","``","(",":","class",":","`","~torch.Tensor","`",")",":","single","integer","tensor","with","shape","``","(","N",",",")","``","with","cluster","labels","As","output","of","``","forward","``","and","``","compute","``","the","metric","returns","the","following","output",":","-","``","chs","``","(",":","class",":","`","~torch.Tensor","`",")",":","A","tensor","with","the","Calinski","Harabasz","Score","Args",":","kwargs",":","Additional","keyword","arguments",",","see",":","ref",":","`","Metric","kwargs","`","for","more","info",".","Example",":",":",">",">",">","import","torch",">",">",">","from","torchmetrics.clustering","import","CalinskiHarabaszScore",">",">",">","_","=","torch.manual_seed","(","42",")",">",">",">","data","=","torch.randn","(","10",",","3",")",">",">",">","labels","=","torch.randint","(","3",",","(","10",",",")",")",">",">",">","metric","=","CalinskiHarabaszScore","(",")",">",">",">","metric","(","data",",","labels",")","tensor","(","3.0053",")"]
code: def __init__(self, **kwargs: Any) -> None:
      super().__init__(**kwargs)
  
      self.add_state("data", default=[], dist_reduce_fx="cat")
      self.add_state("labels", default=[], dist_reduce_fx="cat")
  
file_path: torchmetrics/src/torchmetrics/clustering/calinski_harabasz_score.py
imports: from typing import Any, List, Optional, Sequence, Union
  from torch import Tensor
  from torchmetrics.functional.clustering.calinski_harabasz_score import calinski_harabasz_score
  from torchmetrics.metric import Metric
  from torchmetrics.utilities.data import dim_zero_cat
  from torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE
  from torchmetrics.utilities.plot import _AX_TYPE, _PLOT_OUT_TYPE
label_desc: Use image node_id 1 to create a new CalinskiHarabaszScore object from inherited base classes: Metric with example: obj = CalinskiHarabaszScore()