
    ~Wh{                        d Z ddlmc mZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ ddl	mZ dd	lmZ dd
lmZ ddlmZ  edddg           ej        d           G d dej                                          ZdS )zBuilt-in linear model classes.    N)activations)initializers)regularizers)
base_layer)
input_spec)training)core)deprecation)keras_exportzkeras.experimental.LinearModelzkeras.models.LinearModel)v1c                   \     e Zd ZdZ	 	 	 	 	 	 	 d fd	Zd Zd Zd	 Zedd
            Z	 xZ
S )LinearModela*  Linear Model for regression and classification problems.

    This model approximates the following function:
    $$y = \beta + \sum_{i=1}^{N} w_{i} * x_{i}$$
    where $$\beta$$ is the bias and $$w_{i}$$ is the weight for each feature.

    Example:

    ```python
    model = LinearModel()
    model.compile(optimizer='sgd', loss='mse')
    model.fit(x, y, epochs=epochs)
    ```

    This model accepts sparse float inputs as well:

    Example:
    ```python
    model = LinearModel()
    opt = tf.keras.optimizers.Adam()
    loss_fn = tf.keras.losses.MeanSquaredError()
    with tf.GradientTape() as tape:
      output = model(sparse_input)
      loss = tf.reduce_mean(loss_fn(target, output))
    grads = tape.gradient(loss, model.weights)
    opt.apply_gradients(zip(grads, model.weights))
    ```

       NTzerosc                    || _         t          j        |          | _        || _        t          j        |          | _        t          j        |          | _        t          j        |          | _	        t          j        |          | _
         t                      j        di | t          j                            d                              d           dS )a  Create a Linear Model.

        Args:
          units: Positive integer, output dimension without the batch size.
          activation: Activation function to use.
            If you don't specify anything, no activation is applied.
          use_bias: whether to calculate the bias/intercept for this model. If
            set to False, no bias/intercept will be used in calculations, e.g.,
            the data is already centered.
          kernel_initializer: Initializer for the `kernel` weights matrices.
          bias_initializer: Initializer for the bias vector.
          kernel_regularizer: regularizer for kernel vectors.
          bias_regularizer: regularizer for bias vector.
          **kwargs: The keyword arguments that are passed on to
            BaseLayer.__init__.
        LinearTN )unitsr   get
activationuse_biasr   kernel_initializerbias_initializerr   kernel_regularizerbias_regularizersuper__init__r   keras_premade_model_gaugeget_cellset)
selfr   r   r   r   r   r   r   kwargs	__class__s
            a/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/keras/premade_models/linear.pyr   zLinearModel.__init__D   s    8 
%/*55 "."23E"F"F , 01A B B"."23E"F"F , 01A B B""6""",55h??CCDIIIII    c                    t          |t                    rt          t          |                                                    }g | _        g | _        |D ]}||         }t          j        | j	        d| j
        | j        |          }|                    |           | j                            t          j        ||                     | j                            |           nt          |t           t          f          r|t#          d |D                       rcg | _        |D ]X}t          j        | j	        d| j
        | j                  }|                    |           | j                            |           YnDt          j        | j	        d| j
        | j                  }|                    |           |g| _        | j        r5|                     d| j	        | j        | j        | j        d          | _        nd | _        d| _        d S )	NF)r   r   r   r   name)shaper'   c              3   J   K   | ]}t          |t          j                  V  d S N)
isinstancetfTensorShape).0r(   s     r$   	<genexpr>z$LinearModel.build.<locals>.<genexpr>}   s?       <
 <
27Jubn--<
 <
 <
 <
 <
 <
r%   )r   r   r   r   biasT)r(   initializerregularizerdtype	trainable)r+   dictsortedlistkeysinput_specsdense_layersr	   Denser   r   r   buildappendr   	InputSpectupleallr   
add_weightr   r   r3   r0   built)r!   input_shapenamesr'   r(   layers         r$   r<   zLinearModel.buildj   sI   k4(( (	(4 0 0 2 23344E!D "D 0 0#D)
*"'+'>'+'>   E""" ''(u4@@@   !((////0 eT]33 	( <
 <
;F<
 <
 <
 9
 9
 	( !#D$ 0 0
*"'+'>'+'>	   E"""!((////0 Jj#'#:#'#:	  E KK$$$!&D= 
	j 1 1j (  DII DI


r%   c           	         d }t          t                    rd | j        D             }t          |          t                                                    z
  }|rDt          dt          |           dt                                                     d|           fd|D             t          | j                  D ]\  }} ||          }||}||z  }nct          t          t          f          r1t          | j                  D ]\  }} ||          }||}||z  }n | j        d                   }| j	        r%t          j                            || j                  }| j        |                     |          S |S )Nc                     g | ]	}|j         
S r   )r'   )r.   rE   s     r$   
<listcomp>z$LinearModel.call.<locals>.<listcomp>   s    ???EUZ???r%   z\The `inputs` dictionary does not match the structure expected by the model.
	Expected keys: z
	Received keys: z
	Missing keys: c                      g | ]
}|         S r   r   )r.   r'   inputss     r$   rH   z$LinearModel.call.<locals>.<listcomp>   s    555tfTl555r%   r   )r+   r5   r:   r    r8   
ValueErrorzipr?   r7   r   r,   nnbias_addr0   r   )r!   rJ   resultrD   different_keysinprE   outputs    `      r$   callzLinearModel.call   s   fd## 	2??T->???E ZZ#fkkmm*<*<<N  :*-e**: : +.fkkmm*<*<: : *8	: :   6555u555F!&$*;<< % %
Us>#FFf$FF% .. 	2!&$*;<< % %
Us>#FFf$FF% *T&q)&11F= 	7U^^FDI66F?&??6***r%   c           	         | j         t          j        | j                  | j        t          j        | j                  t          j        | j                  t          j        | j	                  t          j        | j
                  d}t          j                            |           }t          t          |                                          t          |                                          z             S )N)r   r   r   r   r   r   r   )r   r   	serializer   r   r   r   r   r   r   r   r   Layer
get_configr5   r7   items)r!   configbase_configs      r$   rW   zLinearModel.get_config   s    Z%/@@"."8'# # !- 6t7L M M"."8'# # !- 6t7L M M
 
 !&11$77D**,,--V\\^^0D0DDEEEr%   c                     ~ | di |S )Nr   r   )clsrY   custom_objectss      r$   from_configzLinearModel.from_config   s    s}}V}}r%   )r   NTr   r   NNr*   )__name__
__module____qualname____doc__r   r<   rS   rW   classmethodr^   __classcell__)r#   s   @r$   r   r       s         @ " $J $J $J $J $J $JL6 6 6p" " "HF F F"    [    r%   r   )rb   tensorflow.compat.v2compatv2r,   kerasr   r   r   keras.enginer   r   r   keras.layersr	   tensorflow.python.utilr
    tensorflow.python.util.tf_exportr   deprecated_endpointsModelr   r   r%   r$   <module>ro      sT   % $ ! ! ! ! ! ! ! ! !                   # # # # # # # # # # # # ! ! ! ! ! !       / . . . . . 9 9 9 9 9 9 $(*DE   "!"BCCu u u u u(. u u DC	 
u u ur%   