# Least Squares

class gmmvi.optimization.least_squares.LinFunc(reg_fact: float)

  This class can be used to learn a function that is linear in the inputs.

  Parameters:

    reg_fact – float coefficient for ridge regularization

class gmmvi.optimization.least_squares.QuadFunc(dim: int)

  This class can be used to learn a function that is quadratic in the inputs (or linear in the quadratic features). The approximation takes the form:

  Parameters:

    dim – int the dimension of x

  fit_quadratic(regularizer: float, num_samples: int, inputs: Tensor, outputs: Tensor, weights: Optional[Tensor] = None, sample_mean: Optional[Tensor] = None, sample_chol_cov: Optional[Tensor] = None) → [<class 'tensorflow.python.framework.ops.Tensor'>, <class 'tensorflow.python.framework.ops.Tensor'>, <class 'tensorflow.python.framework.ops.Tensor'>]

    Fits the quadratic model.

    Parameters:

      - regularizer – float Coefficient for ridge regression

      - num_samples – int Number of input samples (we could get this from inputs)

      - inputs – tf.Tensor A two-dimensional tensor containing the inputs x.

      - outputs – tf.Tensor A one-dimensional tensor containing the targets / dependant variables.

      - weights – tf.Tensor (importance) weights used for weighted least-squares

      - sample_mean – tf.Tensor Mean of the Gaussian distribution that sampled the input (used for whitening)

      - sample_chol_cov – tf.Tensor Cholesky matrix of the Gaussian distribution that sampled the input (used for whitening)

    Returns:

      quad_term - the matrix

      lin_term - the vector

      const_term - the scalar bias

    Return type:

      tuple(tf.Tensor, tf.Tensor, tf.Tensor)

class gmmvi.optimization.least_squares.RegressionFunc(bias_entry: Optional[int] = None)

  Base class for least-square regression

  Parameters:

    bias_entry – int index of the weight that corresponds to the constant offset (will not get regularized)

  fit(regularizer: float, num_samples: int, inputs: Tensor, outputs: Tensor, weights: Optional[Tensor] = None) → Tensor

    Compute the coefficients of the linear model.

    Parameters:

      - regularizer – float ridge coefficient

      - num_samples – int number of samples (could be obtained from inputs)

      - inputs – tf.Tensor the data / samples

      - outputs – tf.Tensor the targets / dependent variables

      - weights – tf.Tensor or None (importance) weights for weighted least-squares

    Returns:

      the learned parameters of the linear model

    Return type:

      tf.Tensor