# Function Types for GCP

>> Tensor Toolbox >> CP Decompositions >> GCP-OPT >> Function Types for GCP

The GCP capability of the Tensor Toolbox allows the user to specify a fit function. There are a number of ''standard'' choices that we provide via the helper function `tt_gcp_fg_setup` function. These choices are presented in detail below. Motivations and details for these choices can be found in:

- D. Hong, T. G. Kolda, J. A. Duersch, Generalized Canonical Polyadic Tensor Decomposition, SIAM Review, 62:133-163, 2020, https://doi.org/10.1137/18M1203626

These choices can be passed directly to gcp_opt via the 'type' option. To test the options, call the hidden function:

`[f,g,lowerbnd] = tt_gcp_fg_setup(type)`

We discuss the choices for the type below.

## Contents

- Gaussian (real-valued data)
- Poisson (count data)
- Poisson with Log Link (count data)
- Bernoulli with Odds Link (binary data)
- Bernoulli with Logit Link (binary data)
- Rayleigh (real-valued data)
- Gamma (nonnegative real-valued data)
- Huber (nonnegative real-valued data)
- Negative Binomial (count data)
- Beta (nonnegative real-valued data)

## Gaussian (real-valued data)

This is indicated by specifying the type as either `'normal'` or `'gaussian'`. This choice correspond to standard CP, which is implemented in `cp_als` and `cp_opt`. It is useful for continuous real-valued data tensors. This choice specifies

    [f,g,lowerbnd] = tt_gcp_fg_setup('normal')

    f =
      function_handle with value:
        @(x,m)(m-x).^2
    g =
      function_handle with value:
        @(x,m)2.*(m-x)
    lowerbnd =
      -Inf

## Poisson (count data)

This is indicated by specifying the type as either `'count'` or `'poisson'`. This choice is useful for count data tensors, i.e., tensors that have only entries in {0,1,2,...}. This choice corresponds to Poisson CP, which is implemente din `cp_apr`. This choice specifies

The quantity is a fudge factor to avoid divide-by-zero errors.

    [f,g,lowerbnd] = tt_gcp_fg_setup('count')

    f =
      function_handle with value:
        @(x,m)m-x.*log(m+1e-10)
    g =
      function_handle with value:
        @(x,m)1-x./(m+1e-10)
    lowerbnd =
         0

## Poisson with Log Link (count data)

This is indicated by specifying the type as `'poisson-log'`. This choice is useful for count data tensors, i.e., tensors that have only entries in {0,1,2,...}. This choice specifies

    [f,g,lowerbnd] = tt_gcp_fg_setup('poisson-log')

    f =
      function_handle with value:
        @(x,m)exp(m)-x.*m
    g =
      function_handle with value:
        @(x,m)exp(m)-x
    lowerbnd =
      -Inf

## Bernoulli with Odds Link (binary data)

This is indicated by specifying the type as either `'binary'` or `'bernoulli-odds'`. This choice is useful for binary data tensors, i.e., tensors that have only 0 or 1 entries. This choice specifies

The quantity is a fudge factor to avoid divide-by-zero errors.

    [f,g,lowerbnd] = tt_gcp_fg_setup('binary')

    f =
      function_handle with value:
        @(x,m)log(m+1)-x.*log(m+1e-10)
    g =
      function_handle with value:
        @(x,m)1./(m+1)-x./(m+1e-10)
    lowerbnd =
         0

## Bernoulli with Logit Link (binary data)

This is indicated by specifying the type as `'bernoulli-logit'`. This choice is useful for binary data tensors, i.e., tensors that have only 0 or 1 entries. This choice specifies

    [f,g,lowerbnd] = tt_gcp_fg_setup('bernoulli-logit')

    f =
      function_handle with value:
        @(x,m)log(exp(m)+1)-x.*m
    g =
      function_handle with value:
        @(x,m)exp(m)./(exp(m)+1)-x
    lowerbnd =
      -Inf

## Rayleigh (real-valued data)

This is indicated by specifying the type `'rayleigh'`. This choice is useful for nonnegative real-values data tensors, i.e., tensors that have only nonnegative. This choice specifies

The quantity is a fudge factor to avoid divide-by-zero errors.

    [f,g,lowerbnd] = tt_gcp_fg_setup('rayleigh')

    f =
      function_handle with value:
        @(x,m)2*log(m+1e-10)+(pi/4)*(x./(m+1e-10)).^2
    g =
      function_handle with value:
        @(x,m)2./(m+1e-10)-(pi/2)*x.^2./(m+1e-10).^3
    lowerbnd =
         0

## Gamma (nonnegative real-valued data)

This is indicated by specifying the type `'gamma'`. This choice is useful for nonnegative real-values data tensors, i.e., tensors that have only nonnegative. This choice specifies

The quantity is a fudge factor to avoid divide-by-zero errors.

    [f,g,lowerbnd] = tt_gcp_fg_setup('gamma')

    f =
      function_handle with value:
        @(x,m)x./(m+1e-10)+log(m+1e-10)
    g =
      function_handle with value:
        @(x,m)-x./((m+1e-10).^2)+1./(m+1e-10)
    lowerbnd =
         0

## Huber (nonnegative real-valued data)

This is indicated by specifying the type `'huber (DELTA)'`, where `DELTA` is in the equations below. This choice is useful for nonnegative real-values data tensors, i.e., tensors that have only nonnegative. This choice specifies

    [f,g,lowerbnd] = tt_gcp_fg_setup('huber (0.25)')

    f =
      function_handle with value:
        @(x,m)(x-m).^2.*(abs(x-m)<0.25)+(0.5.*abs(x-m)-0.0625).*(abs(x-m)>=0.25)
    g =
      function_handle with value:
        @(x,m)-2.*(x-m).*(abs(x-m)<0.25)-(0.5.*sign(x-m)).*(abs(x-m)>=0.25)
    lowerbnd =
      -Inf

## Negative Binomial (count data)

This is indicated by specifying the type `'negative-binomial (r)'`, where `r` is in the equations below. This choice is useful for count data tensors. This choice specifies

    [f,g,lowerbnd] = tt_gcp_fg_setup('negative-binomial (4)')

    f =
      function_handle with value:
        @(x,m)(4+x).*log(1+m)-x*log(m+1e-10)
    g =
      function_handle with value:
        @(x,m)(5)./(1+m)-x./(m+1e-10)
    lowerbnd =
         0

## Beta (nonnegative real-valued data)

This is indicated by specifying the type `'beta (BETA)'`, where `BETA` is in the equations below. This choice is useful for nonnegative data tensors. Choices of or are not allowed because these correspond to 'gamma' or 'rayleigh'. This choice specifies

    [f,g,lowerbnd] = tt_gcp_fg_setup('beta (0.3)')

    f =
      function_handle with value:
        @(x,m)(3.33333).*(m+1e-10).^(0.3)-(-1.42857).*x.*(m+1e-10).^(-0.7)
    g =
      function_handle with value:
        @(x,m)(m+1e-10).^(-0.7)-x.*(m+1e-10).^(-1.7)
    lowerbnd =
         0