





"""simple docstring"""
import unittest

import numpy as np
import torch

from diffusers import PNDMPipeline, PNDMScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()






class  _SCREAMING_SNAKE_CASE(       unittest.TestCase  ):




       @property
       def    _UpperCamelCase					(						self							)      ->				int:





             """simple docstring"""






             torch.manual_seed(0							)
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  UNetaDModel(
                 block_out_channels=(32, 64)		,layers_per_block=2		,sample_size=32		,in_channels=3		,out_channels=3		,down_block_types=('''DownBlock2D''', '''AttnDownBlock2D''')		,up_block_types=('''AttnUpBlock2D''', '''UpBlock2D''')		,)
             return model




       def    _UpperCamelCase					(						self							)      ->				Optional[int]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :List[Any]		    =  self.dummy_uncond_unet
             __SCREAMING_SNAKE_CASE       :int		    =  PNDMScheduler()

             __SCREAMING_SNAKE_CASE       :int		    =  PNDMPipeline(unet=SCREAMING_SNAKE_CASE__		,scheduler=SCREAMING_SNAKE_CASE__							)
             pndm.to(SCREAMING_SNAKE_CASE__							)
             pndm.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__							)

             __SCREAMING_SNAKE_CASE       :List[Any]		    =  torch.manual_seed(0							)
             __SCREAMING_SNAKE_CASE       :Any		    =  pndm(generator=SCREAMING_SNAKE_CASE__		,num_inference_steps=20		,output_type='''numpy'''							).images

             __SCREAMING_SNAKE_CASE       :Any		    =  torch.manual_seed(0							)
             __SCREAMING_SNAKE_CASE       :str		    =  pndm(generator=SCREAMING_SNAKE_CASE__		,num_inference_steps=20		,output_type='''numpy'''		,return_dict=SCREAMING_SNAKE_CASE__							)[0]

             __SCREAMING_SNAKE_CASE       :Any		    =  image[0, -3:, -3:, -1]
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  image_from_tuple[0, -3:, -3:, -1]

             assert image.shape == (1, 32, 32, 3)
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  np.array([1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0]							)

             assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-2
             assert np.abs(image_from_tuple_slice.flatten() - expected_slice							).max() < 1E-2






@slow
@require_torch
class  _SCREAMING_SNAKE_CASE(       unittest.TestCase  ):




       def    _UpperCamelCase					(						self							)      ->				Optional[Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :List[Any]		    =  '''google/ddpm-cifar10-32'''

             __SCREAMING_SNAKE_CASE       :Tuple		    =  UNetaDModel.from_pretrained(SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE       :List[Any]		    =  PNDMScheduler()

             __SCREAMING_SNAKE_CASE       :List[Any]		    =  PNDMPipeline(unet=SCREAMING_SNAKE_CASE__		,scheduler=SCREAMING_SNAKE_CASE__							)
             pndm.to(SCREAMING_SNAKE_CASE__							)
             pndm.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  torch.manual_seed(0							)
             __SCREAMING_SNAKE_CASE       :Any		    =  pndm(generator=SCREAMING_SNAKE_CASE__		,output_type='''numpy'''							).images

             __SCREAMING_SNAKE_CASE       :Tuple		    =  image[0, -3:, -3:, -1]

             assert image.shape == (1, 32, 32, 3)
             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  np.array([0.1_5_6_4, 0.1_4_6_4_5, 0.1_4_0_6, 0.1_4_7_1_5, 0.1_2_4_2_5, 0.1_4_0_4_5, 0.1_3_1_1_5, 0.1_2_1_7_5, 0.1_2_5]							)

             assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-2






"""simple docstring"""
import math
import random



def 					__lowerCamelCase       (							a_					:		float			,       a_					:		bool = False							)      ->				float:
      if deriv:
            return value * (1 - value)
      return 1 / (1 + math.exp(-value							))


# Initial Value
lowerCamelCase_       =		0.02



def 					__lowerCamelCase       (							a_					:		int			,       a_					:		int							)      ->				float:
      __SCREAMING_SNAKE_CASE       :Any		    =  float(2 * (random.randint(1			,       1_00							)) - 1							)

      for _ in range(a_							):
            # Forward propagation
            __SCREAMING_SNAKE_CASE       :Any		    =  sigmoid_function(INITIAL_VALUE * weight							)
            # How much did we miss?
            __SCREAMING_SNAKE_CASE       :Tuple		    =  (expected / 1_00) - layer_a
            # Error delta
            __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  layer_1_error * sigmoid_function(a_			,       a_							)
            # Update weight
            weight += INITIAL_VALUE * layer_1_delta

      return layer_a * 1_00


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  lowerCamelCase_       =		int(input("Expected value: "))
  lowerCamelCase_       =		int(input("Number of propagations: "))
  print(forward_propagation(expected, number_propagations))