





import numpy







class 				__lowerCAmelCase       :







      def __init__(    self		,      lowerCAmelCase__		,      lowerCAmelCase__							)   ->						None:



        '''simple docstring'''




        a__	:					int										=input_array

        # Random initial weights are assigned where first argument is the
        # number of nodes in previous layer and second argument is the
        # number of nodes in the next layer.

        # Random initial weights are assigned.
        # self.input_array.shape[1] is used to represent number of nodes in input layer.
        # First hidden layer consists of 4 nodes.
        a__	:					List[str]										=numpy.random.rand(
            self.input_array.shape[1]		,      4							)

        # Random initial values for the first hidden layer.
        # First hidden layer has 4 nodes.
        # Second hidden layer has 3 nodes.
        a__	:					int										=numpy.random.rand(
            4		,      3							)

        # Random initial values for the second hidden layer.
        # Second hidden layer has 3 nodes.
        # Output layer has 1 node.
        a__	:					Any										=numpy.random.rand(3		,      1							)

        # Real output values provided.
        a__	:					str										=output_array

        # Predicted output values by the neural network.
        # Predicted_output array initially consists of zeroes.
        a__	:					str										=numpy.zeros(output_array.shape							)







      def    _lowercase  (    self							)   ->						numpy.ndarray:



        '''simple docstring'''




        a__	:					List[Any]										=sigmoid(
            numpy.dot(self.input_array		,      self.input_layer_and_first_hidden_layer_weights							)							)

        # layer_between_first_hidden_layer_and_second_hidden_layer is the layer
        # connecting the first hidden set of nodes with the second hidden set of nodes.
        a__	:					Optional[Any]										=sigmoid(
            numpy.dot(
                self.layer_between_input_and_first_hidden_layer		,      self.first_hidden_layer_and_second_hidden_layer_weights		,      )							)

        # layer_between_second_hidden_layer_and_output is the layer connecting
        # second hidden layer with the output node.
        a__	:					Dict										=sigmoid(
            numpy.dot(
                self.layer_between_first_hidden_layer_and_second_hidden_layer		,      self.second_hidden_layer_and_output_layer_weights		,      )							)

        return self.layer_between_second_hidden_layer_and_output







      def    _lowercase  (    self							)   ->						None:



        '''simple docstring'''




        a__	:					Any										=numpy.dot(
            self.layer_between_first_hidden_layer_and_second_hidden_layer.T		,      2
            * (self.output_array - self.predicted_output)
            * sigmoid_derivative(self.predicted_output							)		,      )
        a__	:					Any										=numpy.dot(
            self.layer_between_input_and_first_hidden_layer.T		,      numpy.dot(
                2
                * (self.output_array - self.predicted_output)
                * sigmoid_derivative(self.predicted_output							)		,      self.second_hidden_layer_and_output_layer_weights.T		,      )
            * sigmoid_derivative(
                self.layer_between_first_hidden_layer_and_second_hidden_layer							)		,      )
        a__	:					Optional[int]										=numpy.dot(
            self.input_array.T		,      numpy.dot(
                numpy.dot(
                    2
                    * (self.output_array - self.predicted_output)
                    * sigmoid_derivative(self.predicted_output							)		,      self.second_hidden_layer_and_output_layer_weights.T		,      )
                * sigmoid_derivative(
                    self.layer_between_first_hidden_layer_and_second_hidden_layer							)		,      self.first_hidden_layer_and_second_hidden_layer_weights.T		,      )
            * sigmoid_derivative(self.layer_between_input_and_first_hidden_layer							)		,      )

        self.input_layer_and_first_hidden_layer_weights += (
            updated_input_layer_and_first_hidden_layer_weights
        )
        self.first_hidden_layer_and_second_hidden_layer_weights += (
            updated_first_hidden_layer_and_second_hidden_layer_weights
        )
        self.second_hidden_layer_and_output_layer_weights += (
            updated_second_hidden_layer_and_output_layer_weights
        )







      def    _lowercase  (    self		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__							)   ->						None:



        '''simple docstring'''




        for iteration in range(1		,      iterations + 1							):
          a__	:					Optional[Any]										=self.feedforward()
          self.back_propagation()
          if give_loss:
            a__	:					Optional[Any]										=numpy.mean(numpy.square(output - self.feedforward()							)							)
            print(F'''Iteration {iteration} Loss: {loss}'''							)







      def    _lowercase  (    self		,      lowerCAmelCase__							)   ->						int:



        '''simple docstring'''




        a__	:					List[Any]										=input_arr

        a__	:					Optional[int]										=sigmoid(
            numpy.dot(self.array		,      self.input_layer_and_first_hidden_layer_weights							)							)

        a__	:					Union[str, Any]										=sigmoid(
            numpy.dot(
                self.layer_between_input_and_first_hidden_layer		,      self.first_hidden_layer_and_second_hidden_layer_weights		,      )							)

        a__	:					int										=sigmoid(
            numpy.dot(
                self.layer_between_first_hidden_layer_and_second_hidden_layer		,      self.second_hidden_layer_and_output_layer_weights		,      )							)

        return int(self.layer_between_second_hidden_layer_and_output > 0.6							)
def      _A       (		SCREAMING_SNAKE_CASE     :   numpy.ndarray						):





  """simple docstring"""



  return 1 / (1 + numpy.exp(-value						))
def      _A       (		SCREAMING_SNAKE_CASE     :   numpy.ndarray						):





  """simple docstring"""



  return (value) * (1 - (value))
def      _A       (		):





  """simple docstring"""



  a__	:					List[Any]										=numpy.array(
      (
          [0, 0, 0],
          [0, 0, 1],
          [0, 1, 0],
          [0, 1, 1],
          [1, 0, 0],
          [1, 0, 1],
          [1, 1, 0],
          [1, 1, 1],
      )       ,       dtype=numpy.floataa       ,       )

  # True output values for the given input values.
  a__	:					Dict										=numpy.array(([0], [1], [1], [0], [1], [0], [0], [1])       ,       dtype=numpy.floataa						)

  # Calling neural network class.
  a__	:					Dict										=TwoHiddenLayerNeuralNetwork(
      input_array=SCREAMING_SNAKE_CASE       ,       output_array=SCREAMING_SNAKE_CASE						)

  # Calling training function.
  # Set give_loss to True if you want to see loss in every iteration.
  neural_network.train(output=SCREAMING_SNAKE_CASE       ,       iterations=10       ,       give_loss=SCREAMING_SNAKE_CASE						)

  return neural_network.predict(numpy.array(([1, 1, 1])       ,       dtype=numpy.floataa						)						)


if __name__ == "__main__":
     example()













import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image

     from transformers import MobileViTImageProcessor







class 				__lowerCAmelCase       (    unittest.TestCase):







      def __init__(    self		,      lowerCAmelCase__		,      lowerCAmelCase__=7		,      lowerCAmelCase__=3		,      lowerCAmelCase__=1_8		,      lowerCAmelCase__=3_0		,      lowerCAmelCase__=4_0_0		,      lowerCAmelCase__=True		,      lowerCAmelCase__=None		,      lowerCAmelCase__=True		,      lowerCAmelCase__=None		,      lowerCAmelCase__=True		,      )   ->						Optional[Any]:



        '''simple docstring'''




        a__	:					Union[str, Any]										=size if size is not None else {"shortest_edge": 2_0}
        a__	:					List[str]										=crop_size if crop_size is not None else {"height": 1_8, "width": 1_8}
        a__	:					Tuple										=parent
        a__	:					Union[str, Any]										=batch_size
        a__	:					List[str]										=num_channels
        a__	:					List[Any]										=image_size
        a__	:					str										=min_resolution
        a__	:					Optional[int]										=max_resolution
        a__	:					Tuple										=do_resize
        a__	:					Union[str, Any]										=size
        a__	:					List[Any]										=do_center_crop
        a__	:					List[str]										=crop_size
        a__	:					Optional[int]										=do_flip_channel_order







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



        '''simple docstring'''




        return {
            "do_resize": self.do_resize,
            "size": self.size,
            "do_center_crop": self.do_center_crop,
            "crop_size": self.crop_size,
            "do_flip_channel_order": self.do_flip_channel_order,
        }







@require_torch
@require_vision
class 				__lowerCAmelCase       (    UpperCamelCase__						,				unittest.TestCase):
      _lowercase				:					int						=			MobileViTImageProcessor if is_vision_available() else None







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



        '''simple docstring'''




        a__	:					Tuple										=MobileViTImageProcessingTester(self							)







      @property
      def    _lowercase  (    self							)   ->						List[str]:



        '''simple docstring'''




        return self.image_processor_tester.prepare_image_processor_dict()







      def    _lowercase  (    self							)   ->						List[str]:



        '''simple docstring'''




        a__	:					str										=self.image_processing_class(**self.image_processor_dict							)
        self.assertTrue(hasattr(lowerCAmelCase__		,      "do_resize"							)							)
        self.assertTrue(hasattr(lowerCAmelCase__		,      "size"							)							)
        self.assertTrue(hasattr(lowerCAmelCase__		,      "do_center_crop"							)							)
        self.assertTrue(hasattr(lowerCAmelCase__		,      "center_crop"							)							)
        self.assertTrue(hasattr(lowerCAmelCase__		,      "do_flip_channel_order"							)							)







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



        '''simple docstring'''




        a__	:					List[Any]										=self.image_processing_class.from_dict(self.image_processor_dict							)
        self.assertEqual(image_processor.size		,      {"shortest_edge": 2_0}							)
        self.assertEqual(image_processor.crop_size		,      {"height": 1_8, "width": 1_8}							)

        a__	:					Union[str, Any]										=self.image_processing_class.from_dict(self.image_processor_dict		,      size=4_2		,      crop_size=8_4							)
        self.assertEqual(image_processor.size		,      {"shortest_edge": 4_2}							)
        self.assertEqual(image_processor.crop_size		,      {"height": 8_4, "width": 8_4}							)







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



        '''simple docstring'''




        pass







      def    _lowercase  (    self							)   ->						Tuple:



        '''simple docstring'''




        a__	:					List[str]										=self.image_processing_class(**self.image_processor_dict							)
        # create random PIL images
        a__	:					Any										=prepare_image_inputs(self.image_processor_tester		,      equal_resolution=lowerCAmelCase__							)
        for image in image_inputs:
          self.assertIsInstance(lowerCAmelCase__		,      Image.Image							)

        # Test not batched input
        a__	:					Tuple										=image_processing(image_inputs[0]		,      return_tensors="pt"							).pixel_values
        self.assertEqual(
            encoded_images.shape		,      (
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size["height"],
                self.image_processor_tester.crop_size["width"],
            )		,      )

        # Test batched
        a__	:					List[Any]										=image_processing(lowerCAmelCase__		,      return_tensors="pt"							).pixel_values
        self.assertEqual(
            encoded_images.shape		,      (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size["height"],
                self.image_processor_tester.crop_size["width"],
            )		,      )







      def    _lowercase  (    self							)   ->						Any:



        '''simple docstring'''




        a__	:					Optional[Any]										=self.image_processing_class(**self.image_processor_dict							)
        # create random numpy tensors
        a__	:					List[Any]										=prepare_image_inputs(self.image_processor_tester		,      equal_resolution=lowerCAmelCase__		,      numpify=lowerCAmelCase__							)
        for image in image_inputs:
          self.assertIsInstance(lowerCAmelCase__		,      np.ndarray							)

        # Test not batched input
        a__	:					Tuple										=image_processing(image_inputs[0]		,      return_tensors="pt"							).pixel_values
        self.assertEqual(
            encoded_images.shape		,      (
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size["height"],
                self.image_processor_tester.crop_size["width"],
            )		,      )

        # Test batched
        a__	:					int										=image_processing(lowerCAmelCase__		,      return_tensors="pt"							).pixel_values
        self.assertEqual(
            encoded_images.shape		,      (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size["height"],
                self.image_processor_tester.crop_size["width"],
            )		,      )







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



        '''simple docstring'''




        a__	:					int										=self.image_processing_class(**self.image_processor_dict							)
        # create random PyTorch tensors
        a__	:					Tuple										=prepare_image_inputs(self.image_processor_tester		,      equal_resolution=lowerCAmelCase__		,      torchify=lowerCAmelCase__							)
        for image in image_inputs:
          self.assertIsInstance(lowerCAmelCase__		,      torch.Tensor							)

        # Test not batched input
        a__	:					List[str]										=image_processing(image_inputs[0]		,      return_tensors="pt"							).pixel_values
        self.assertEqual(
            encoded_images.shape		,      (
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size["height"],
                self.image_processor_tester.crop_size["width"],
            )		,      )

        # Test batched
        a__	:					List[str]										=image_processing(lowerCAmelCase__		,      return_tensors="pt"							).pixel_values
        self.assertEqual(
            encoded_images.shape		,      (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size["height"],
                self.image_processor_tester.crop_size["width"],
            )		,      )






