io.siddhi.extension.execution.streamingml.bayesian.model

## Class CategoricalDistribution

- java.lang.Object
- - io.siddhi.extension.execution.streamingml.bayesian.model.CategoricalDistribution

- All Implemented Interfaces:
    Serializable

      public class CategoricalDistribution
      extends Object

  implements Categorical distribution.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `CategoricalDistribution(org.nd4j.autodiff.samediff.SDVariable logits, org.nd4j.autodiff.samediff.SameDiff sd)` Construct the categorical distribution.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `org.nd4j.autodiff.samediff.SDVariable` | `getProb()`
    `org.nd4j.autodiff.samediff.SDVariable` | `klDivergence(io.siddhi.extension.execution.streamingml.bayesian.model.Distribution distribution)` returns the kl divergence w.r.t the given distribution.
    `org.nd4j.autodiff.samediff.SDVariable` | `logProbability(org.nd4j.autodiff.samediff.SDVariable values)` categorical log probability is implemented based on softmax-crossentropy the implementation is based on following formula
    `org.nd4j.autodiff.samediff.SDVariable` | `sample()` returns a random sample from the distribution.
    `org.nd4j.autodiff.samediff.SDVariable` | `sample(int n)` returns random samples from the distribution.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CategoricalDistribution

          public CategoricalDistribution(org.nd4j.autodiff.samediff.SDVariable logits,
                                         org.nd4j.autodiff.samediff.SameDiff sd)

      Construct the categorical distribution.
      Parameters:
        `logits` - should be 2-dimensional. the dimensions should follow the order (input_size, num_classes)
        `sd` - SameDiff context

  - ### Method Detail

    - #### logProbability

          public org.nd4j.autodiff.samediff.SDVariable logProbability(org.nd4j.autodiff.samediff.SDVariable values)

      categorical log probability is implemented based on softmax-crossentropy the implementation is based on following formula

      log(p(y)) = sum[1:num_classes]{log(softmax[logits])*y}

      however, log(softmax(logits)) can be infinity for some case. hence, unecessary log computations are avoided using transformed formula

      log(p(y)) = sum[1:num_classes]{log(softmax[logits]*y)}

      output of the both formulas are equivalent if y is one-hot encoded

      Parameters:
        `values` - one-hot encoded labels
      Returns:
        log probability as a SameDiff var

    - #### sample

          public org.nd4j.autodiff.samediff.SDVariable sample()

      returns a random sample from the distribution.
      Returns:
        a differentiable SameDiff variable

    - #### sample

          public org.nd4j.autodiff.samediff.SDVariable sample(int n)

      returns random samples from the distribution.
      Parameters:
        `n` - number of samples
      Returns:
        a differentiable SameDiff variable

    - #### klDivergence

          public org.nd4j.autodiff.samediff.SDVariable klDivergence(io.siddhi.extension.execution.streamingml.bayesian.model.Distribution distribution)
                                                             throws io.siddhi.core.exception.SiddhiAppCreationException

      returns the kl divergence w.r.t the given distribution.
      Parameters:
        `distribution` - reference distribution p(x)
      Returns:
        kl-divergence(this, p(x))
      Throws:
        `io.siddhi.core.exception.SiddhiAppCreationException`

    - #### getProb

          public org.nd4j.autodiff.samediff.SDVariable getProb()

Copyright © 2019 WSO2. All rights reserved.