





import numpy

# List of input, output pairs
__lowerCamelCase       :     Any   =     (
    ((5, 2, 3), 15),
    ((6, 5, 9), 25),
    ((11, 12, 13), 41),
    ((1, 1, 1), 8),
    ((11, 12, 13), 41),
)
__lowerCamelCase       :     Optional[Any]   =     (((515, 22, 13), 555), ((61, 35, 49), 150))
__lowerCamelCase       :     Tuple   =     [2, 4, 1, 5]
__lowerCamelCase       :     List[str]   =     len(train_data)
__lowerCamelCase       :     Union[str, Any]   =     0.0_0_9



def 		A_				(     _lowerCAmelCase							,   _lowerCAmelCase="train"     )						-> Tuple:
 return calculate_hypothesis_value(_lowerCAmelCase							,   _lowerCAmelCase     ) - output(
     _lowerCAmelCase							,   _lowerCAmelCase     )



def 		A_				(     _lowerCAmelCase     )						-> str:
 UpperCamelCase	:					Dict       	=   0
 for i in range(len(_lowerCAmelCase     ) - 1     ):
  hyp_val += data_input_tuple[i] * parameter_vector[i + 1]
 hyp_val += parameter_vector[0]
 return hyp_val



def 		A_				(     _lowerCAmelCase							,   _lowerCAmelCase     )						-> Any:
 if data_set == "train":
  return train_data[example_no][1]
 elif data_set == "test":
  return test_data[example_no][1]
 return None



def 		A_				(     _lowerCAmelCase							,   _lowerCAmelCase     )						-> Tuple:
 if data_set == "train":
  return _hypothesis_value(train_data[example_no][0]     )
 elif data_set == "test":
  return _hypothesis_value(test_data[example_no][0]     )
 return None



def 		A_				(     _lowerCAmelCase							,   _lowerCAmelCase=m     )						-> Any:
 UpperCamelCase	:					int       	=   0
 for i in range(_lowerCAmelCase     ):
  if index == -1:
   summation_value += _error(_lowerCAmelCase     )
  else:
   summation_value += _error(_lowerCAmelCase     ) * train_data[i][0][index]
 return summation_value



def 		A_				(     _lowerCAmelCase     )						-> Any:
 UpperCamelCase	:					str       	=   summation_of_cost_derivative(_lowerCAmelCase							,   _lowerCAmelCase     ) / m
 return cost_derivative_value



def 		A_				(     )						-> Union[str, Any]:
 global parameter_vector
 # Tune these values to set a tolerance value for predicted output
 UpperCamelCase	:					int       	=   0.000_002
 UpperCamelCase	:					Optional[int]       	=   0
 UpperCamelCase	:					List[str]       	=   0
 while True:
  j += 1
  UpperCamelCase	:					List[Any]       	=   [0, 0, 0, 0]
  for i in range(0							,   len(_lowerCAmelCase     )     ):
   UpperCamelCase	:					List[Any]       	=   get_cost_derivative(i - 1     )
   UpperCamelCase	:					Union[str, Any]       	=   (
       parameter_vector[i] - LEARNING_RATE * cost_derivative
   )
  if numpy.allclose(
      _lowerCAmelCase							,   _lowerCAmelCase							,   atol=_lowerCAmelCase							,   rtol=_lowerCAmelCase							,   ):
   break
  UpperCamelCase	:					Union[str, Any]       	=   temp_parameter_vector
 print(("Number of iterations:", j)     )



def 		A_				(     )						-> Tuple:
 for i in range(len(_lowerCAmelCase     )     ):
  print(("Actual output value:", output(_lowerCAmelCase							,   "test"     ))     )
  print(("Hypothesis output:", calculate_hypothesis_value(_lowerCAmelCase							,   "test"     ))     )


if __name__ == "__main__":
    run_gradient_descent()
    print("""\nTesting gradient descent for a linear hypothesis function.\n""")
    test_gradient_descent()







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__lowerCamelCase       :     Any   =     {
    """configuration_electra""": ["""ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP""", """ElectraConfig""", """ElectraOnnxConfig"""],
    """tokenization_electra""": ["""ElectraTokenizer"""],
}

try:
    if not is_tokenizers_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCamelCase       :     Dict   =     ["""ElectraTokenizerFast"""]

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCamelCase       :     Tuple   =     [
        """ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST""",
        """ElectraForCausalLM""",
        """ElectraForMaskedLM""",
        """ElectraForMultipleChoice""",
        """ElectraForPreTraining""",
        """ElectraForQuestionAnswering""",
        """ElectraForSequenceClassification""",
        """ElectraForTokenClassification""",
        """ElectraModel""",
        """ElectraPreTrainedModel""",
        """load_tf_weights_in_electra""",
    ]

try:
    if not is_tf_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCamelCase       :     List[Any]   =     [
        """TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST""",
        """TFElectraForMaskedLM""",
        """TFElectraForMultipleChoice""",
        """TFElectraForPreTraining""",
        """TFElectraForQuestionAnswering""",
        """TFElectraForSequenceClassification""",
        """TFElectraForTokenClassification""",
        """TFElectraModel""",
        """TFElectraPreTrainedModel""",
    ]

try:
    if not is_flax_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCamelCase       :     List[str]   =     [
        """FlaxElectraForCausalLM""",
        """FlaxElectraForMaskedLM""",
        """FlaxElectraForMultipleChoice""",
        """FlaxElectraForPreTraining""",
        """FlaxElectraForQuestionAnswering""",
        """FlaxElectraForSequenceClassification""",
        """FlaxElectraForTokenClassification""",
        """FlaxElectraModel""",
        """FlaxElectraPreTrainedModel""",
    ]


if TYPE_CHECKING:
    from .configuration_electra import ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP, ElectraConfig, ElectraOnnxConfig
    from .tokenization_electra import ElectraTokenizer

    try:
        if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_electra_fast import ElectraTokenizerFast

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_electra import (
            ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
            ElectraForCausalLM,
            ElectraForMaskedLM,
            ElectraForMultipleChoice,
            ElectraForPreTraining,
            ElectraForQuestionAnswering,
            ElectraForSequenceClassification,
            ElectraForTokenClassification,
            ElectraModel,
            ElectraPreTrainedModel,
            load_tf_weights_in_electra,
        )

    try:
        if not is_tf_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_tf_electra import (
            TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
            TFElectraForMaskedLM,
            TFElectraForMultipleChoice,
            TFElectraForPreTraining,
            TFElectraForQuestionAnswering,
            TFElectraForSequenceClassification,
            TFElectraForTokenClassification,
            TFElectraModel,
            TFElectraPreTrainedModel,
        )

    try:
        if not is_flax_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_flax_electra import (
            FlaxElectraForCausalLM,
            FlaxElectraForMaskedLM,
            FlaxElectraForMultipleChoice,
            FlaxElectraForPreTraining,
            FlaxElectraForQuestionAnswering,
            FlaxElectraForSequenceClassification,
            FlaxElectraForTokenClassification,
            FlaxElectraModel,
            FlaxElectraPreTrainedModel,
        )

else:
    import sys

    __lowerCamelCase       :     Any   =     _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)
