


'''simple docstring'''






import numpy

# List of input, output pairs
a_   :      Optional[int]				    =      (
    ((5, 2, 3), 1_5),
    ((6, 5, 9), 2_5),
    ((1_1, 1_2, 1_3), 4_1),
    ((1, 1, 1), 8),
    ((1_1, 1_2, 1_3), 4_1),
)
a_   :      int				    =      (((5_1_5, 2_2, 1_3), 5_5_5), ((6_1, 3_5, 4_9), 1_5_0))
a_   :      List[Any]				    =      [2, 4, 1, 5]
a_   :      Optional[int]				    =      len(train_data)
a_   :      str				    =      0.009






def 		_A			(lowerCAmelCase__					:List[Any]			,  lowerCAmelCase__					:List[str]="train"						)				->					int:




     '''simple docstring'''



     return calculate_hypothesis_value(UpperCAmelCase_			,  UpperCAmelCase_						) - output(
         UpperCAmelCase_			,  UpperCAmelCase_						)






def 		_A			(lowerCAmelCase__					:Tuple						)				->					Dict:




     '''simple docstring'''



     _a      =							0
     for i in range(len(UpperCAmelCase_						) - 1						):
          hyp_val += data_input_tuple[i] * parameter_vector[i + 1]
     hyp_val += parameter_vector[0]
     return hyp_val






def 		_A			(lowerCAmelCase__					:str			,  lowerCAmelCase__					:List[Any]						)				->					List[Any]:




     '''simple docstring'''



     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__					:Optional[Any]			,  lowerCAmelCase__					:Optional[int]						)				->					Any:




     '''simple docstring'''



     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__					:Union[str, Any]			,  lowerCAmelCase__					:Any=m						)				->					Union[str, Any]:




     '''simple docstring'''



     _a      =							0
     for i in range(UpperCAmelCase_						):
          if index == -1:
               summation_value += _error(UpperCAmelCase_						)
          else:
               summation_value += _error(UpperCAmelCase_						) * train_data[i][0][index]
     return summation_value






def 		_A			(lowerCAmelCase__					:int						)				->					str:




     '''simple docstring'''



     _a      =							summation_of_cost_derivative(UpperCAmelCase_			,  UpperCAmelCase_						) / m
     return cost_derivative_value






def 		_A			()				->					List[str]:




     '''simple docstring'''



     global parameter_vector
     # Tune these values to set a tolerance value for predicted output
     _a      =							0.0_0_0_0_0_2
     _a      =							0
     _a      =							0
     while True:
          j += 1
          _a      =							[0, 0, 0, 0]
          for i in range(0			,  len(UpperCAmelCase_						)						):
               _a      =							get_cost_derivative(i - 1						)
               _a      =							(
                   parameter_vector[i] - LEARNING_RATE * cost_derivative
               )
          if numpy.allclose(
              UpperCAmelCase_			,  UpperCAmelCase_			,  atol=UpperCAmelCase_			,  rtol=UpperCAmelCase_			,  ):
               break
          _a      =							temp_parameter_vector
     print(('Number of iterations:', j)						)






def 		_A			()				->					int:




     '''simple docstring'''



     for i in range(len(UpperCAmelCase_						)						):
          print(('Actual output value:', output(UpperCAmelCase_			,  'test'						))						)
          print(('Hypothesis output:', calculate_hypothesis_value(UpperCAmelCase_			,  'test'						))						)


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





'''simple docstring'''






import unittest

from diffusers.pipelines.pipeline_utils import is_safetensors_compatible




class 	a       (       unittest.TestCase    ):
 def 							__UpperCAmelCase						(	self  )   ->							int:
      _a      =							[
          'safety_checker/pytorch_model.bin',
          'safety_checker/model.safetensors',
          'vae/diffusion_pytorch_model.bin',
          'vae/diffusion_pytorch_model.safetensors',
          'text_encoder/pytorch_model.bin',
          'text_encoder/model.safetensors',
          'unet/diffusion_pytorch_model.bin',
          'unet/diffusion_pytorch_model.safetensors',
      ]
      self.assertTrue(is_safetensors_compatible(__magic_name__  )  )
 def 							__UpperCAmelCase						(	self  )   ->							Dict:
      _a      =							[
          'unet/diffusion_pytorch_model.bin',
          'unet/diffusion_pytorch_model.safetensors',
      ]
      self.assertTrue(is_safetensors_compatible(__magic_name__  )  )
 def 							__UpperCAmelCase						(	self  )   ->							Optional[int]:
      _a      =							[
          'safety_checker/pytorch_model.bin',
          'safety_checker/model.safetensors',
          'vae/diffusion_pytorch_model.bin',
          'vae/diffusion_pytorch_model.safetensors',
          'text_encoder/pytorch_model.bin',
          'text_encoder/model.safetensors',
          'unet/diffusion_pytorch_model.bin',
          # Removed: 'unet/diffusion_pytorch_model.safetensors',
      ]
      self.assertFalse(is_safetensors_compatible(__magic_name__  )  )
 def 							__UpperCAmelCase						(	self  )   ->							Optional[Any]:
      _a      =							[
          'text_encoder/pytorch_model.bin',
          'text_encoder/model.safetensors',
      ]
      self.assertTrue(is_safetensors_compatible(__magic_name__  )  )
 def 							__UpperCAmelCase						(	self  )   ->							str:
      _a      =							[
          'safety_checker/pytorch_model.bin',
          'safety_checker/model.safetensors',
          'vae/diffusion_pytorch_model.bin',
          'vae/diffusion_pytorch_model.safetensors',
          'text_encoder/pytorch_model.bin',
          # Removed: 'text_encoder/model.safetensors',
          'unet/diffusion_pytorch_model.bin',
          'unet/diffusion_pytorch_model.safetensors',
      ]
      self.assertFalse(is_safetensors_compatible(__magic_name__  )  )
 def 							__UpperCAmelCase						(	self  )   ->							List[Any]:
      _a      =							[
          'safety_checker/pytorch_model.fp16.bin',
          'safety_checker/model.fp16.safetensors',
          'vae/diffusion_pytorch_model.fp16.bin',
          'vae/diffusion_pytorch_model.fp16.safetensors',
          'text_encoder/pytorch_model.fp16.bin',
          'text_encoder/model.fp16.safetensors',
          'unet/diffusion_pytorch_model.fp16.bin',
          'unet/diffusion_pytorch_model.fp16.safetensors',
      ]
      _a      =							'fp16'
      self.assertTrue(is_safetensors_compatible(__magic_name__ ,			variant=__magic_name__  )  )
 def 							__UpperCAmelCase						(	self  )   ->							Any:
      _a      =							[
          'unet/diffusion_pytorch_model.fp16.bin',
          'unet/diffusion_pytorch_model.fp16.safetensors',
      ]
      _a      =							'fp16'
      self.assertTrue(is_safetensors_compatible(__magic_name__ ,			variant=__magic_name__  )  )
 def 							__UpperCAmelCase						(	self  )   ->							int:
      # pass variant but use the non-variant filenames
      _a      =							[
          'unet/diffusion_pytorch_model.bin',
          'unet/diffusion_pytorch_model.safetensors',
      ]
      _a      =							'fp16'
      self.assertTrue(is_safetensors_compatible(__magic_name__ ,			variant=__magic_name__  )  )
 def 							__UpperCAmelCase						(	self  )   ->							List[str]:
      _a      =							[
          'safety_checker/pytorch_model.fp16.bin',
          'safety_checker/model.fp16.safetensors',
          'vae/diffusion_pytorch_model.fp16.bin',
          'vae/diffusion_pytorch_model.fp16.safetensors',
          'text_encoder/pytorch_model.fp16.bin',
          'text_encoder/model.fp16.safetensors',
          'unet/diffusion_pytorch_model.fp16.bin',
          # Removed: 'unet/diffusion_pytorch_model.fp16.safetensors',
      ]
      _a      =							'fp16'
      self.assertFalse(is_safetensors_compatible(__magic_name__ ,			variant=__magic_name__  )  )
 def 							__UpperCAmelCase						(	self  )   ->							Union[str, Any]:
      _a      =							[
          'text_encoder/pytorch_model.fp16.bin',
          'text_encoder/model.fp16.safetensors',
      ]
      _a      =							'fp16'
      self.assertTrue(is_safetensors_compatible(__magic_name__ ,			variant=__magic_name__  )  )
 def 							__UpperCAmelCase						(	self  )   ->							List[Any]:
      # pass variant but use the non-variant filenames
      _a      =							[
          'text_encoder/pytorch_model.bin',
          'text_encoder/model.safetensors',
      ]
      _a      =							'fp16'
      self.assertTrue(is_safetensors_compatible(__magic_name__ ,			variant=__magic_name__  )  )




 def 							__UpperCAmelCase						(	self  )   ->							List[Any]:
      _a      =							[
          'safety_checker/pytorch_model.fp16.bin',
          'safety_checker/model.fp16.safetensors',
          'vae/diffusion_pytorch_model.fp16.bin',
          'vae/diffusion_pytorch_model.fp16.safetensors',
          'text_encoder/pytorch_model.fp16.bin',
          # 'text_encoder/model.fp16.safetensors',
          'unet/diffusion_pytorch_model.fp16.bin',
          'unet/diffusion_pytorch_model.fp16.safetensors',
      ]
      _a      =							'fp16'
      self.assertFalse(is_safetensors_compatible(__magic_name__ ,			variant=__magic_name__  )  )

