
import numpy




class 				lowerCamelCase__							:




	'''simple docstring'''




	def __init__(      self	:Any  ,     a	:numpy.ndarray  ,     a	:numpy.ndarray		)	->				None:
								__UpperCamelCase			:     List[Any]         =      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.
								__UpperCamelCase			:     Any         =      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.
								__UpperCamelCase			:     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.
								__UpperCamelCase			:     Optional[int]         =      numpy.random.rand(3  ,     1		)

								# Real output values provided.
								__UpperCamelCase			:     Tuple         =      output_array

								# Predicted output values by the neural network.
								# Predicted_output array initially consists of zeroes.
								__UpperCamelCase			:     Optional[Any]         =      numpy.zeros(output_array.shape		)







	def      _lowerCamelCase       (      self	:str		)	->				numpy.ndarray:
								__UpperCamelCase			:     Optional[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.
								__UpperCamelCase			:     str         =      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.
								__UpperCamelCase			:     List[Any]         =      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      _lowerCamelCase       (      self	:Dict		)	->				None:
								__UpperCamelCase			:     Optional[int]         =      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		)  ,     )
								__UpperCamelCase			:     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		)  ,     )
								__UpperCamelCase			:     str         =      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      _lowerCamelCase       (      self	:Any  ,     a	:numpy.ndarray  ,     a	:int  ,     a	:bool		)	->				None:
								for iteration in range(1  ,     iterations + 1		):
															__UpperCamelCase			:     Optional[int]         =      self.feedforward()
															self.back_propagation()
															if give_loss:
																						__UpperCamelCase			:     str         =      numpy.mean(numpy.square(output - self.feedforward()		)		)
																						print(f'Iteration {iteration} Loss: {loss}'		)







	def      _lowerCamelCase       (      self	:int  ,     a	:numpy.ndarray		)	->				int:
								__UpperCamelCase			:     Dict         =      input_arr

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

								__UpperCamelCase			:     Optional[int]         =      sigmoid(
								    numpy.dot(
								        self.layer_between_input_and_first_hidden_layer  ,     self.first_hidden_layer_and_second_hidden_layer_weights  ,     )		)

								__UpperCamelCase			:     str         =      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 			_SCREAMING_SNAKE_CASE      (	_lowerCamelCase				:    numpy.ndarray)      ->					numpy.ndarray:






							'''simple docstring'''





							return 1 / (1 + numpy.exp(-value))




def 			_SCREAMING_SNAKE_CASE      (	_lowerCamelCase				:    numpy.ndarray)      ->					numpy.ndarray:






							'''simple docstring'''





							return (value) * (1 - (value))




def 			_SCREAMING_SNAKE_CASE      (	)      ->					int:






							'''simple docstring'''





							__UpperCamelCase			:     Optional[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.
							__UpperCamelCase			:     List[str]         =      numpy.array(([0], [1], [1], [0], [1], [0], [0], [1])		,						dtype=numpy.floataa)

							# Calling neural network class.
							__UpperCamelCase			:     Any         =      TwoHiddenLayerNeuralNetwork(
							    input_array=_lowerCamelCase		,						output_array=_lowerCamelCase)

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

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


if __name__ == "__main__":
		example()

import re
import string

import numpy as np

import datasets


lowercase						:      List[str]									= '\nReturns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.\n'

lowercase						:      List[str]									= '\nArgs:\n    predictions: List of predicted texts.\n    references: List of reference texts.\n    regexes_to_ignore: List, defaults to None. Regex expressions of characters to\n        ignore when calculating the exact matches. Note: these regexes are removed\n        from the input data before the changes based on the options below (e.g. ignore_case,\n        ignore_punctuation, ignore_numbers) are applied.\n    ignore_case: Boolean, defaults to False. If true, turns everything\n        to lowercase so that capitalization differences are ignored.\n    ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\n    ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\nReturns:\n    exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 100.0, inclusive.\nExamples:\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results["exact_match"], 1))\n    25.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results["exact_match"], 1))\n    50.0\n\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results["exact_match"], 1))\n    75.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)\n    >>> print(round(results["exact_match"], 1))\n    100.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["The cat sat on the mat.", "Theaters are great.", "It\'s like comparing oranges and apples."]\n    >>> preds = ["The cat sat on the mat?", "Theaters are great.", "It\'s like comparing apples and oranges."]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results["exact_match"], 1))\n    33.3\n\n'

lowercase						:      List[str]									= '\n'




@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION  ,		_KWARGS_DESCRIPTION)
class 				lowerCamelCase__							(       datasets.Metric):




	'''simple docstring'''




	def      _lowerCamelCase       (      self	:Dict		)	->				Optional[Any]:
								return datasets.MetricInfo(
								    description=_DESCRIPTION  ,     citation=_CITATION  ,     inputs_description=_KWARGS_DESCRIPTION  ,     features=datasets.Features(
								        {
								            "predictions": datasets.Value("string"  ,     id="sequence"		),
								            "references": datasets.Value("string"  ,     id="sequence"		),
								        }		)  ,     reference_urls=[]  ,     )







	def      _lowerCamelCase       (      self	:int  ,     a	:Optional[Any]  ,     a	:Dict  ,     a	:Optional[int]=None  ,     a	:int=False  ,     a	:Tuple=False  ,     a	:Optional[int]=False  ,     )	->				Any:
								if regexes_to_ignore is not None:
															for s in regexes_to_ignore:
																						__UpperCamelCase			:     List[Any]         =      np.array([re.sub(a  ,     ""  ,     a		) for x in predictions]		)
																						__UpperCamelCase			:     Optional[Any]         =      np.array([re.sub(a  ,     ""  ,     a		) for x in references]		)
								else:
															__UpperCamelCase			:     Optional[int]         =      np.asarray(a		)
															__UpperCamelCase			:     List[str]         =      np.asarray(a		)

								if ignore_case:
															__UpperCamelCase			:     Optional[int]         =      np.char.lower(a		)
															__UpperCamelCase			:     str         =      np.char.lower(a		)

								if ignore_punctuation:
															__UpperCamelCase			:     Tuple         =      string.punctuation.maketrans(""  ,     ""  ,     string.punctuation		)
															__UpperCamelCase			:     int         =      np.char.translate(a  ,     table=a		)
															__UpperCamelCase			:     str         =      np.char.translate(a  ,     table=a		)

								if ignore_numbers:
															__UpperCamelCase			:     List[str]         =      string.digits.maketrans(""  ,     ""  ,     string.digits		)
															__UpperCamelCase			:     Tuple         =      np.char.translate(a  ,     table=a		)
															__UpperCamelCase			:     Union[str, Any]         =      np.char.translate(a  ,     table=a		)

								__UpperCamelCase			:     List[Any]         =      predictions == references

								return {"exact_match": np.mean(a		) * 1_0_0}