





import inspect
import tempfile
import unittest

from huggingface_hub import hf_hub_download

from transformers import is_torch_available
from transformers.testing_utils import is_flaky, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


__lowercase       :List[Any]       =  1e-4

if is_torch_available():
				import torch

				from transformers import AutoformerConfig, AutoformerForPrediction, AutoformerModel
				from transformers.models.autoformer.modeling_autoformer import AutoformerDecoder, AutoformerEncoder



@require_torch
class    _a     :






							"""simple docstring"""

							def __init__(      self				:     Tuple							,	a				:     Optional[int]							,	a				:     List[str]=16							,	a				:     str=13							,	a				:     Tuple=7							,	a				:     Any=14							,	a				:     List[str]=10							,	a				:     Any=19							,	a				:     List[Any]=5							,	a				:     Tuple=4							,	a				:     Tuple=True							,	a				:     Union[str, Any]=16							,	a				:     Optional[Any]=2							,	a				:     Union[str, Any]=4							,	a				:     Dict=4							,	a				:     Any="gelu"							,	a				:     List[Any]=0.1							,	a				:     Union[str, Any]=0.1							,	a				:     Optional[int]=[1, 2, 3, 4, 5]							,	a				:     int=25							,	a				:     Optional[int]=5							,	)	->List[Any]:
													SCREAMING_SNAKE_CASE__     :				int   =					d_model
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					parent
													SCREAMING_SNAKE_CASE__     :				List[str]   =					batch_size
													SCREAMING_SNAKE_CASE__     :				int   =					prediction_length
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					context_length
													SCREAMING_SNAKE_CASE__     :				Dict   =					cardinality
													SCREAMING_SNAKE_CASE__     :				int   =					num_time_features
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					lags_sequence
													SCREAMING_SNAKE_CASE__     :				Any   =					embedding_dimension
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					is_training
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					hidden_size
													SCREAMING_SNAKE_CASE__     :				Dict   =					num_hidden_layers
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					num_attention_heads
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					intermediate_size
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					hidden_act
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					hidden_dropout_prob
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					attention_probs_dropout_prob

													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					context_length
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					prediction_length + label_length
													SCREAMING_SNAKE_CASE__     :				List[str]   =					label_length

													SCREAMING_SNAKE_CASE__     :				List[str]   =					moving_average
													SCREAMING_SNAKE_CASE__     :				Dict   =					autocorrelation_factor

							def      A_  (      self				:     Union[str, Any]    )	->Optional[int]:
													return AutoformerConfig(
													    d_model=self.d_model							,	encoder_layers=self.num_hidden_layers							,	decoder_layers=self.num_hidden_layers							,	encoder_attention_heads=self.num_attention_heads							,	decoder_attention_heads=self.num_attention_heads							,	encoder_ffn_dim=self.intermediate_size							,	decoder_ffn_dim=self.intermediate_size							,	dropout=self.hidden_dropout_prob							,	attention_dropout=self.attention_probs_dropout_prob							,	prediction_length=self.prediction_length							,	context_length=self.context_length							,	label_length=self.label_length							,	lags_sequence=self.lags_sequence							,	num_time_features=self.num_time_features							,	num_static_categorical_features=1							,	cardinality=[self.cardinality]							,	embedding_dimension=[self.embedding_dimension]							,	moving_average=self.moving_average							,	)

							def      A_  (      self				:     List[Any]							,	a				:     Any    )	->Union[str, Any]:
													SCREAMING_SNAKE_CASE__     :				List[str]   =					config.context_length + max(config.lags_sequence    )

													SCREAMING_SNAKE_CASE__     :				List[Any]   =					ids_tensor([self.batch_size, 1]							,	config.cardinality[0]    )
													SCREAMING_SNAKE_CASE__     :				str   =					floats_tensor([self.batch_size, _past_length, config.num_time_features]    )
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					floats_tensor([self.batch_size, _past_length]    )
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					floats_tensor([self.batch_size, _past_length]    ) > 0.5

													# decoder inputs
													SCREAMING_SNAKE_CASE__     :				List[str]   =					floats_tensor([self.batch_size, config.prediction_length, config.num_time_features]    )
													SCREAMING_SNAKE_CASE__     :				Any   =					floats_tensor([self.batch_size, config.prediction_length]    )

													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					{
													    "past_values": past_values,
													    "static_categorical_features": static_categorical_features,
													    "past_time_features": past_time_features,
													    "past_observed_mask": past_observed_mask,
													    "future_time_features": future_time_features,
													    "future_values": future_values,
													}
													return inputs_dict

							def      A_  (      self				:     Any    )	->List[str]:
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					self.get_config()
													SCREAMING_SNAKE_CASE__     :				Dict   =					self.prepare_autoformer_inputs_dict(a    )
													return config, inputs_dict

							def      A_  (      self				:     List[Any]    )	->Any:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Optional[int]   =					self.prepare_config_and_inputs()
													return config, inputs_dict






							def      A_  (      self				:     List[str]							,	a				:     Optional[Any]							,	a				:     Any    )	->List[Any]:
													SCREAMING_SNAKE_CASE__     :				Any   =					AutoformerModel(config=a    ).to(a    ).eval()
													SCREAMING_SNAKE_CASE__     :				Tuple   =					model(**a    )

													SCREAMING_SNAKE_CASE__     :				int   =					outputs.encoder_last_hidden_state
													SCREAMING_SNAKE_CASE__     :				Tuple   =					outputs.last_hidden_state

													with tempfile.TemporaryDirectory() as tmpdirname:
																			SCREAMING_SNAKE_CASE__     :				str   =					model.get_encoder()
																			encoder.save_pretrained(a    )
																			SCREAMING_SNAKE_CASE__     :				List[Any]   =					AutoformerEncoder.from_pretrained(a    ).to(a    )

													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Optional[int]   =					model.create_network_inputs(**a    )
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Tuple   =					model.decomposition_layer(transformer_inputs[:, : config.context_length, ...]    )

													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					torch.cat(
													    (transformer_inputs[:, : config.context_length, ...], feature[:, : config.context_length, ...])							,	dim=-1							,	)
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					encoder(inputs_embeds=a    )[0]
													self.parent.assertTrue((encoder_last_hidden_state_a - encoder_last_hidden_state).abs().max().item() < 1E-3    )

													SCREAMING_SNAKE_CASE__     :				Any   =					(
													    torch.mean(transformer_inputs[:, : config.context_length, ...]							,	dim=1    )
													    .unsqueeze(1    )
													    .repeat(1							,	config.prediction_length							,	1    )
													)
													SCREAMING_SNAKE_CASE__     :				int   =					torch.zeros(
													    [transformer_inputs.shape[0], config.prediction_length, transformer_inputs.shape[2]]							,	device=enc_input.device							,	)

													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					torch.cat(
													    (
													        torch.cat((seasonal_input[:, -config.label_length :, ...], zeros)							,	dim=1    ),
													        feature[:, config.context_length - config.label_length :, ...],
													    )							,	dim=-1							,	)
													SCREAMING_SNAKE_CASE__     :				int   =					torch.cat(
													    (
													        torch.cat((trend_input[:, -config.label_length :, ...], mean)							,	dim=1    ),
													        feature[:, config.context_length - config.label_length :, ...],
													    )							,	dim=-1							,	)

													with tempfile.TemporaryDirectory() as tmpdirname:
																			SCREAMING_SNAKE_CASE__     :				List[Any]   =					model.get_decoder()
																			decoder.save_pretrained(a    )
																			SCREAMING_SNAKE_CASE__     :				List[str]   =					AutoformerDecoder.from_pretrained(a    ).to(a    )

													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					decoder(
													    trend=a							,	inputs_embeds=a							,	encoder_hidden_states=a							,	)[0]

													self.parent.assertTrue((last_hidden_state_a - last_hidden_state).abs().max().item() < 1E-3    )







@require_torch
class    _a     (				lowercase__					,							lowercase__					,							unittest.TestCase							):






							"""simple docstring"""

							snake_case_							 =						(AutoformerModel, AutoformerForPrediction) if is_torch_available() else ()
							snake_case_							 =						(AutoformerForPrediction,) if is_torch_available() else ()
							snake_case_							 =						{"feature-extraction": AutoformerModel} if is_torch_available() else {}
							snake_case_							 =						False
							snake_case_							 =						False
							snake_case_							 =						False
							snake_case_							 =						False
							snake_case_							 =						False
							snake_case_							 =						False

							def      A_  (      self				:     Optional[Any]    )	->Tuple:
													SCREAMING_SNAKE_CASE__     :				List[str]   =					AutoformerModelTester(self    )
													SCREAMING_SNAKE_CASE__     :				Tuple   =					ConfigTester(self							,	config_class=a							,	has_text_modality=a    )

							def      A_  (      self				:     Tuple    )	->str:
													self.config_tester.run_common_tests()

							def      A_  (      self				:     Any    )	->Tuple:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Tuple   =					self.model_tester.prepare_config_and_inputs()
													for model_class in self.all_model_classes:
																			SCREAMING_SNAKE_CASE__     :				str   =					model_class(a    )

																			with tempfile.TemporaryDirectory() as tmpdirname:
																									model.save_pretrained(a    )
																									SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Dict   =					model_class.from_pretrained(a							,	output_loading_info=a    )
																			self.assertEqual(info["missing_keys"]							,	[]    )

							def      A_  (      self				:     str    )	->Dict:
													SCREAMING_SNAKE_CASE__     :				Any   =					self.model_tester.prepare_config_and_inputs_for_common()
													self.model_tester.check_encoder_decoder_model_standalone(*a    )

							@unittest.skip(reason="Model has no tokens embeddings"    )
							def      A_  (      self				:     Optional[Any]    )	->Union[str, Any]:
													pass

							def      A_  (      self				:     Dict    )	->int:
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					inspect.signature(getattr(a							,	"forward"    )    )
													# The main input is the name of the argument after `self`
													SCREAMING_SNAKE_CASE__     :				str   =					list(model_signature.parameters.keys()    )[1]
													self.assertEqual(AutoformerModel.main_input_name							,	a    )

							def      A_  (      self				:     Optional[Any]    )	->Dict:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Tuple   =					self.model_tester.prepare_config_and_inputs_for_common()

													for model_class in self.all_model_classes:
																			SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					model_class(a    )
																			SCREAMING_SNAKE_CASE__     :				List[Any]   =					inspect.signature(model.forward    )
																			# signature.parameters is an OrderedDict => so arg_names order is deterministic
																			SCREAMING_SNAKE_CASE__     :				Tuple   =					[*signature.parameters.keys()]

																			SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					[
																			    "past_values",
																			    "past_time_features",
																			    "past_observed_mask",
																			    "static_categorical_features",
																			    "static_real_features",
																			    "future_values",
																			    "future_time_features",
																			]

																			if model.__class__.__name__ in ["AutoformerForPrediction"]:
																									expected_arg_names.append("future_observed_mask"    )

																			expected_arg_names.extend(
																			    [
																			        "decoder_attention_mask",
																			        "head_mask",
																			        "decoder_head_mask",
																			        "cross_attn_head_mask",
																			        "encoder_outputs",
																			        "past_key_values",
																			        "output_hidden_states",
																			        "output_attentions",
																			        "use_cache",
																			        "return_dict",
																			    ]    )

																			self.assertListEqual(arg_names[: len(a    )]							,	a    )

							def      A_  (      self				:     Any    )	->List[Any]:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				List[str]   =					self.model_tester.prepare_config_and_inputs_for_common()
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					True

													SCREAMING_SNAKE_CASE__     :				List[Any]   =					getattr(self.model_tester							,	"seq_length"							,	a    )
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					getattr(self.model_tester							,	"decoder_seq_length"							,	a    )
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					getattr(self.model_tester							,	"encoder_seq_length"							,	a    )
													SCREAMING_SNAKE_CASE__     :				List[str]   =					getattr(self.model_tester							,	"d_model"							,	a    )
													SCREAMING_SNAKE_CASE__     :				str   =					getattr(self.model_tester							,	"num_attention_heads"							,	a    )
													SCREAMING_SNAKE_CASE__     :				int   =					d_model // num_attention_heads

													for model_class in self.all_model_classes:
																			SCREAMING_SNAKE_CASE__     :				Dict   =					True
																			SCREAMING_SNAKE_CASE__     :				Tuple   =					False
																			SCREAMING_SNAKE_CASE__     :				int   =					True
																			SCREAMING_SNAKE_CASE__     :				Optional[int]   =					model_class(a    )
																			model.to(a    )
																			model.eval()
																			with torch.no_grad():
																									SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					model(**self._prepare_for_class(a							,	a    )    )
																			SCREAMING_SNAKE_CASE__     :				Dict   =					outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
																			self.assertEqual(len(a    )							,	self.model_tester.num_hidden_layers    )

																			# check that output_attentions also work using config
																			del inputs_dict["output_attentions"]
																			SCREAMING_SNAKE_CASE__     :				Any   =					True
																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					model_class(a    )
																			model.to(a    )
																			model.eval()
																			with torch.no_grad():
																									SCREAMING_SNAKE_CASE__     :				str   =					model(**self._prepare_for_class(a							,	a    )    )
																			SCREAMING_SNAKE_CASE__     :				Optional[int]   =					outputs.encoder_attentions
																			self.assertEqual(len(a    )							,	self.model_tester.num_hidden_layers    )

																			self.assertListEqual(
																			    list(attentions[0].shape[-3:]    )							,	[self.model_tester.num_attention_heads, encoder_seq_length, dim]							,	)
																			SCREAMING_SNAKE_CASE__     :				Tuple   =					len(a    )

																			SCREAMING_SNAKE_CASE__     :				int   =					7

																			if "last_hidden_state" in outputs:
																									correct_outlen += 1

																			if "trend" in outputs:
																									correct_outlen += 1

																			if "past_key_values" in outputs:
																									correct_outlen += 1  # past_key_values have been returned

																			if "loss" in outputs:
																									correct_outlen += 1

																			if "params" in outputs:
																									correct_outlen += 1

																			self.assertEqual(a							,	a    )

																			# decoder attentions
																			SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					outputs.decoder_attentions
																			self.assertIsInstance(a							,	(list, tuple)    )
																			self.assertEqual(len(a    )							,	self.model_tester.num_hidden_layers    )
																			self.assertListEqual(
																			    list(decoder_attentions[0].shape[-3:]    )							,	[self.model_tester.num_attention_heads, decoder_seq_length, dim]							,	)

																			# cross attentions
																			SCREAMING_SNAKE_CASE__     :				int   =					outputs.cross_attentions
																			self.assertIsInstance(a							,	(list, tuple)    )
																			self.assertEqual(len(a    )							,	self.model_tester.num_hidden_layers    )
																			self.assertListEqual(
																			    list(cross_attentions[0].shape[-3:]    )							,	[self.model_tester.num_attention_heads, decoder_seq_length, dim]							,	)

													# Check attention is always last and order is fine
													SCREAMING_SNAKE_CASE__     :				List[str]   =					True
													SCREAMING_SNAKE_CASE__     :				int   =					True
													SCREAMING_SNAKE_CASE__     :				int   =					model_class(a    )
													model.to(a    )
													model.eval()
													with torch.no_grad():
																			SCREAMING_SNAKE_CASE__     :				List[str]   =					model(**self._prepare_for_class(a							,	a    )    )

													self.assertEqual(out_len + 2							,	len(a    )    )

													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions

													self.assertEqual(len(a    )							,	self.model_tester.num_hidden_layers    )
													self.assertListEqual(
													    list(self_attentions[0].shape[-3:]    )							,	[self.model_tester.num_attention_heads, encoder_seq_length, dim]							,	)






							@is_flaky()
							def      A_  (      self				:     int    )	->Optional[int]:
													super().test_retain_grad_hidden_states_attentions()







def       UpperCAmelCase							(     _lowerCamelCase      :  Any="train-batch.pt"     ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					hf_hub_download(repo_id="hf-internal-testing/tourism-monthly-batch"			,   filename=_lowerCamelCase			,   repo_type="dataset"     )
						SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					torch.load(_lowerCamelCase			,   map_location=_lowerCamelCase     )
						return batch



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






							"""simple docstring"""

							def      A_  (      self				:     str    )	->List[str]:
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					AutoformerModel.from_pretrained("huggingface/autoformer-tourism-monthly"    ).to(a    )
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					prepare_batch()

													with torch.no_grad():
																			SCREAMING_SNAKE_CASE__     :				Optional[int]   =					model(
																			    past_values=batch["past_values"]							,	past_time_features=batch["past_time_features"]							,	past_observed_mask=batch["past_observed_mask"]							,	static_categorical_features=batch["static_categorical_features"]							,	future_values=batch["future_values"]							,	future_time_features=batch["future_time_features"]							,	)[0]

													SCREAMING_SNAKE_CASE__     :				int   =					torch.Size(
													    (64, model.config.prediction_length + model.config.label_length, model.config.feature_size)    )
													self.assertEqual(output.shape							,	a    )

													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					torch.tensor(
													    [[0.3593, -1.3398, 0.6330], [0.2279, 1.5396, -0.1792], [0.0450, 1.3225, -0.2335]]							,	device=a    )
													self.assertTrue(torch.allclose(output[0, :3, :3]							,	a							,	atol=a    )    )

							def      A_  (      self				:     int    )	->Any:
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					AutoformerForPrediction.from_pretrained("huggingface/autoformer-tourism-monthly"    ).to(a    )
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					prepare_batch("val-batch.pt"    )
													with torch.no_grad():
																			SCREAMING_SNAKE_CASE__     :				Optional[int]   =					model(
																			    past_values=batch["past_values"]							,	past_time_features=batch["past_time_features"]							,	past_observed_mask=batch["past_observed_mask"]							,	static_categorical_features=batch["static_categorical_features"]							,	).encoder_last_hidden_state
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					torch.Size((64, model.config.context_length, model.config.d_model)    )
													self.assertEqual(output.shape							,	a    )

													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					torch.tensor(
													    [[-0.0734, -0.9036, 0.8358], [4.7186, 2.4113, 1.9581], [1.7953, 2.3558, 1.2970]]							,	device=a    )
													self.assertTrue(torch.allclose(output[0, :3, :3]							,	a							,	atol=a    )    )






							def      A_  (      self				:     Any    )	->Tuple:
													SCREAMING_SNAKE_CASE__     :				Tuple   =					AutoformerForPrediction.from_pretrained("huggingface/autoformer-tourism-monthly"    ).to(a    )
													SCREAMING_SNAKE_CASE__     :				List[str]   =					prepare_batch("val-batch.pt"    )
													with torch.no_grad():
																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					model.generate(
																			    static_categorical_features=batch["static_categorical_features"]							,	past_time_features=batch["past_time_features"]							,	past_values=batch["past_values"]							,	future_time_features=batch["future_time_features"]							,	past_observed_mask=batch["past_observed_mask"]							,	)
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					torch.Size((64, model.config.num_parallel_samples, model.config.prediction_length)    )
													self.assertEqual(outputs.sequences.shape							,	a    )

													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					torch.tensor([3130.6763, 4056.5293, 7053.0786]							,	device=a    )
													SCREAMING_SNAKE_CASE__     :				List[str]   =					outputs.sequences.mean(dim=1    )
													self.assertTrue(torch.allclose(mean_prediction[0, -3:]							,	a							,	rtol=1E-1    )    )






import numpy



class    _a     :






							"""simple docstring"""

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

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

													# Real output values provided.
													SCREAMING_SNAKE_CASE__     :				str   =					output_array

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

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






							def      A_  (      self				:     Tuple							,	a				:     numpy.ndarray    )	->int:
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					input_arr

													SCREAMING_SNAKE_CASE__     :				Dict   =					sigmoid(
													    numpy.dot(self.array							,	self.input_layer_and_first_hidden_layer_weights    )    )

													SCREAMING_SNAKE_CASE__     :				Any   =					sigmoid(
													    numpy.dot(
													        self.layer_between_input_and_first_hidden_layer							,	self.first_hidden_layer_and_second_hidden_layer_weights							,	)    )

													SCREAMING_SNAKE_CASE__     :				Optional[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       UpperCAmelCase							(     _lowerCamelCase      :  numpy.ndarray     ):





						'''simple docstring'''


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







def       UpperCAmelCase							(     _lowerCamelCase      :  numpy.ndarray     ):





						'''simple docstring'''


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







def       UpperCAmelCase							(     ):





						'''simple docstring'''


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

						# Calling neural network class.
						SCREAMING_SNAKE_CASE__     :				List[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()