




from typing import List, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


a													=			logging.get_logger(__name__)

a													=			{
    "huggingface/time-series-transformer-tourism-monthly": (
        "https://huggingface.co/huggingface/time-series-transformer-tourism-monthly/resolve/main/config.json"
    ),
    # See all TimeSeriesTransformer models at https://huggingface.co/models?filter=time_series_transformer
}




class       _A				(		__lowercase     ):
		__a					    =       """time_series_transformer"""
		__a					    =       {
		    """hidden_size""": """d_model""",
		    """num_attention_heads""": """encoder_attention_heads""",
		    """num_hidden_layers""": """encoder_layers""",
		}






		def __init__(    self						,		_SCREAMING_SNAKE_CASE = None						,		_SCREAMING_SNAKE_CASE = None						,		_SCREAMING_SNAKE_CASE = "student_t"						,		_SCREAMING_SNAKE_CASE = "nll"						,		_SCREAMING_SNAKE_CASE = 1						,		_SCREAMING_SNAKE_CASE = [1, 2, 3, 4, 5, 6, 7]						,		_SCREAMING_SNAKE_CASE = "mean"						,		_SCREAMING_SNAKE_CASE = 0						,		_SCREAMING_SNAKE_CASE = 0						,		_SCREAMING_SNAKE_CASE = 0						,		_SCREAMING_SNAKE_CASE = 0						,		_SCREAMING_SNAKE_CASE = None						,		_SCREAMING_SNAKE_CASE = None						,		_SCREAMING_SNAKE_CASE = 32						,		_SCREAMING_SNAKE_CASE = 32						,		_SCREAMING_SNAKE_CASE = 2						,		_SCREAMING_SNAKE_CASE = 2						,		_SCREAMING_SNAKE_CASE = 2						,		_SCREAMING_SNAKE_CASE = 2						,		_SCREAMING_SNAKE_CASE = True						,		_SCREAMING_SNAKE_CASE = "gelu"						,		_SCREAMING_SNAKE_CASE = 64						,		_SCREAMING_SNAKE_CASE = 0.1						,		_SCREAMING_SNAKE_CASE = 0.1						,		_SCREAMING_SNAKE_CASE = 0.1						,		_SCREAMING_SNAKE_CASE = 0.1						,		_SCREAMING_SNAKE_CASE = 0.1						,		_SCREAMING_SNAKE_CASE = 100						,		_SCREAMING_SNAKE_CASE = 0.02						,		_SCREAMING_SNAKE_CASE=True						,		**_SCREAMING_SNAKE_CASE						,		):
								# time series specific configuration
								_UpperCAmelCase      =			prediction_length
								_UpperCAmelCase      =			context_length or prediction_length
								_UpperCAmelCase      =			distribution_output
								_UpperCAmelCase      =			loss
								_UpperCAmelCase      =			input_size
								_UpperCAmelCase      =			num_time_features
								_UpperCAmelCase      =			lags_sequence
								_UpperCAmelCase      =			scaling
								_UpperCAmelCase      =			num_dynamic_real_features
								_UpperCAmelCase      =			num_static_real_features
								_UpperCAmelCase      =			num_static_categorical_features
								if cardinality and num_static_categorical_features > 0:
														if len(_SCREAMING_SNAKE_CASE			) != num_static_categorical_features:
																				raise ValueError(
																				    """The cardinality should be a list of the same length as `num_static_categorical_features`"""			)
														_UpperCAmelCase      =			cardinality
								else:
														_UpperCAmelCase      =			[0]
								if embedding_dimension and num_static_categorical_features > 0:
														if len(_SCREAMING_SNAKE_CASE			) != num_static_categorical_features:
																				raise ValueError(
																				    """The embedding dimension should be a list of the same length as `num_static_categorical_features`"""			)
														_UpperCAmelCase      =			embedding_dimension
								else:
														_UpperCAmelCase      =			[min(50						,		(cat + 1) // 2			) for cat in self.cardinality]
								_UpperCAmelCase      =			num_parallel_samples

								# Transformer architecture configuration
								_UpperCAmelCase      =			input_size * len(_SCREAMING_SNAKE_CASE			) + self._number_of_features
								_UpperCAmelCase      =			d_model
								_UpperCAmelCase      =			encoder_attention_heads
								_UpperCAmelCase      =			decoder_attention_heads
								_UpperCAmelCase      =			encoder_ffn_dim
								_UpperCAmelCase      =			decoder_ffn_dim
								_UpperCAmelCase      =			encoder_layers
								_UpperCAmelCase      =			decoder_layers

								_UpperCAmelCase      =			dropout
								_UpperCAmelCase      =			attention_dropout
								_UpperCAmelCase      =			activation_dropout
								_UpperCAmelCase      =			encoder_layerdrop
								_UpperCAmelCase      =			decoder_layerdrop

								_UpperCAmelCase      =			activation_function
								_UpperCAmelCase      =			init_std

								_UpperCAmelCase      =			use_cache

								super().__init__(is_encoder_decoder=_SCREAMING_SNAKE_CASE						,		**_SCREAMING_SNAKE_CASE			)






		@property
		def 				UpperCAmelCase (    self			):
								return (
								    sum(self.embedding_dimension			)
								    + self.num_dynamic_real_features
								    + self.num_time_features
								    + self.num_static_real_features
								    + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
								)





import math




def        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case       )						->				float:
						if (
						    not isinstance(snake_case			,     (int, float)       )
						    or power_factor < -1
						    or power_factor > 1
						):
												raise ValueError("""power_factor must be a valid float value between -1 and 1."""       )
						return apparent_power * power_factor




def        _SCREAMING_SNAKE_CASE      (		snake_case			,     snake_case       )						->				float:
						if (
						    not isinstance(snake_case			,     (int, float)       )
						    or power_factor < -1
						    or power_factor > 1
						):
												raise ValueError("""power_factor must be a valid float value between -1 and 1."""       )
						return apparent_power * math.sqrt(1 - power_factor**2       )


if __name__ == "__main__":
				import doctest

				doctest.testmod()