


"""simple docstring"""






import warnings

from ...utils import is_sklearn_available, requires_backends


if is_sklearn_available():
   from scipy.stats import pearsonr, spearmanr
   from sklearn.metrics import fa_score, matthews_corrcoef


__snake_case				=				(
    '''This metric will be removed from the library soon, metrics should be handled with the 🤗 Evaluate '''
    '''library. You can have a look at this example script for pointers: '''
    '''https://github.com/huggingface/transformers/blob/main/examples/pytorch/text-classification/run_glue.py'''
)
def 					A_      (      _lowerCAmelCase   :    Optional[Any],   _lowerCAmelCase   :    Optional[Any]				):






     """simple docstring"""

     warnings.warn(UpperCamelCase__,   UpperCamelCase__				)
     requires_backends(UpperCamelCase__,   '''sklearn'''				)
     return (preds == labels).mean()
def 					A_      (      _lowerCAmelCase   :    Dict,   _lowerCAmelCase   :    Optional[int]				):






     """simple docstring"""

     warnings.warn(UpperCamelCase__,   UpperCamelCase__				)
     requires_backends(UpperCamelCase__,   '''sklearn'''				)
     _a					= simple_accuracy(UpperCamelCase__,   UpperCamelCase__				)
     _a					= fa_score(y_true=UpperCamelCase__,   y_pred=UpperCamelCase__				)
     return {
         "acc": acc,
         "f1": fa,
         "acc_and_f1": (acc + fa) / 2,
     }
def 					A_      (      _lowerCAmelCase   :    Optional[Any],   _lowerCAmelCase   :    Dict				):






     """simple docstring"""

     warnings.warn(UpperCamelCase__,   UpperCamelCase__				)
     requires_backends(UpperCamelCase__,   '''sklearn'''				)
     _a					= pearsonr(UpperCamelCase__,   UpperCamelCase__				)[0]
     _a					= spearmanr(UpperCamelCase__,   UpperCamelCase__				)[0]
     return {
         "pearson": pearson_corr,
         "spearmanr": spearman_corr,
         "corr": (pearson_corr + spearman_corr) / 2,
     }
def 					A_      (      _lowerCAmelCase   :    int,   _lowerCAmelCase   :    Any,   _lowerCAmelCase   :    List[Any]				):






     """simple docstring"""

     warnings.warn(UpperCamelCase__,   UpperCamelCase__				)
     requires_backends(UpperCamelCase__,   '''sklearn'''				)
     assert len(UpperCamelCase__				) == len(UpperCamelCase__				), f'Predictions and labels have mismatched lengths {len(UpperCamelCase__				)} and {len(UpperCamelCase__				)}'
     if task_name == "cola":
          return {"mcc": matthews_corrcoef(UpperCamelCase__,   UpperCamelCase__				)}
     elif task_name == "sst-2":
          return {"acc": simple_accuracy(UpperCamelCase__,   UpperCamelCase__				)}
     elif task_name == "mrpc":
          return acc_and_fa(UpperCamelCase__,   UpperCamelCase__				)
     elif task_name == "sts-b":
          return pearson_and_spearman(UpperCamelCase__,   UpperCamelCase__				)
     elif task_name == "qqp":
          return acc_and_fa(UpperCamelCase__,   UpperCamelCase__				)
     elif task_name == "mnli":
          return {"mnli/acc": simple_accuracy(UpperCamelCase__,   UpperCamelCase__				)}
     elif task_name == "mnli-mm":
          return {"mnli-mm/acc": simple_accuracy(UpperCamelCase__,   UpperCamelCase__				)}
     elif task_name == "qnli":
          return {"acc": simple_accuracy(UpperCamelCase__,   UpperCamelCase__				)}
     elif task_name == "rte":
          return {"acc": simple_accuracy(UpperCamelCase__,   UpperCamelCase__				)}
     elif task_name == "wnli":
          return {"acc": simple_accuracy(UpperCamelCase__,   UpperCamelCase__				)}
     elif task_name == "hans":
          return {"acc": simple_accuracy(UpperCamelCase__,   UpperCamelCase__				)}
     else:
          raise KeyError(UpperCamelCase__				)

def 					A_      (      _lowerCAmelCase   :    Union[str, Any],   _lowerCAmelCase   :    List[Any],   _lowerCAmelCase   :    Optional[Any]				):






     """simple docstring"""

     warnings.warn(UpperCamelCase__,   UpperCamelCase__				)
     requires_backends(UpperCamelCase__,   '''sklearn'''				)
     if len(UpperCamelCase__				) != len(UpperCamelCase__				):
          raise ValueError(f'Predictions and labels have mismatched lengths {len(UpperCamelCase__				)} and {len(UpperCamelCase__				)}'				)
     if task_name == "xnli":
          return {"acc": simple_accuracy(UpperCamelCase__,   UpperCamelCase__				)}
     else:
          raise KeyError(UpperCamelCase__				)







"""simple docstring"""




from __future__ import annotations

def 			lowerCAmelCase__     (     UpperCamelCase__     ,   UpperCamelCase__				):



  '''simple docstring'''
  print(F"""Vertex\tShortest Distance from vertex {src}"""				)
  for i, d in enumerate(UpperCamelCase__				):
    print(F"""{i}\t\t{d}"""				)

def 			lowerCAmelCase__     (     UpperCamelCase__     ,   UpperCamelCase__     ,   UpperCamelCase__				):



  '''simple docstring'''
  for j in range(UpperCamelCase__				):
    _a      ,  _a      ,  _a  :       List[str]             =	(graph[j][k] for k in ["""src""", """dst""", """weight"""])
    if distance[u] != float("""inf"""				) and distance[u] + w < distance[v]:
      return True
  return False

def 			lowerCAmelCase__     (     UpperCamelCase__     ,   UpperCamelCase__     ,   UpperCamelCase__     ,   UpperCamelCase__				):



  '''simple docstring'''
  _a  :       Dict             =	[float("""inf"""				)] * vertex_count
  _a  :       Any             =	0.0

  for _ in range(vertex_count - 1				):
    for j in range(UpperCamelCase__				):
      _a      ,  _a      ,  _a  :       List[Any]             =	(graph[j][k] for k in ["""src""", """dst""", """weight"""])

      if distance[u] != float("""inf"""				) and distance[u] + w < distance[v]:
        _a  :       Any             =	distance[u] + w

  _a  :       Union[str, Any]             =	check_negative_cycle(UpperCamelCase__     ,   UpperCamelCase__     ,   UpperCamelCase__				)
  if negative_cycle_exists:
    raise Exception("""Negative cycle found"""				)

  return distance


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 _snake_case          =   int(input('Enter number of vertices: ').strip())
 _snake_case          =   int(input('Enter number of edges: ').strip())

 _snake_case          =   [{} for _ in range(E)]

 for i in range(E):
  print('Edge ', i + 1)
  _snake_case      , _snake_case      , _snake_case          =   (
      int(x)
      for x in input('Enter source, destination, weight: ').strip().split(' ')
  )
  _snake_case          =   {'src': src, 'dst': dest, 'weight': weight}

 _snake_case          =   int(input('\nEnter shortest path source:').strip())
 _snake_case          =   bellman_ford(graph, V, E, source)
 print_distance(shortest_distance, 0)

