Class/Object

com.danylchuk.swiftlearner.softmax

Softmax

Related Docs: object Softmax | package softmax

Permalink

class Softmax extends LazyLogging

Softmax (multinomial logistic) regression with SGD and AdaGrad

Ref: https://en.wikipedia.org/wiki/Multinomial_logistic_regression http://ufldl.stanford.edu/wiki/index.php/Softmax_Regression http://ufldl.stanford.edu/wiki/index.php/Exercise:Softmax_Regression http://blog.datumbox.com/machine-learning-tutorial-the-multinomial-logistic-regression-softmax-regression/ https://xcorr.net/2014/01/23/adagrad-eliminating-learning-rates-in-stochastic-gradient-descent/ https://en.wikipedia.org/wiki/Stochastic_gradient_descent#AdaGrad

Linear Supertypes
LazyLogging, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Softmax
  2. LazyLogging
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Softmax(weights: Array[Double], nClasses: Int, inputDataLength: Int, learnRate: Double, stuckIterationLimit: Int = 10000, batchSize: Int = 1, useStable: Boolean = true)

    Permalink

    weights

    Initial weights (pre-trained or random) weights(i)(j) is the weight for evidence i based on input parameter j i = 0..nClasses j = 0..nInputs (where nInputs = inputLength + 1 for pseudo-input used for bias handling) Modeled as an array of concatenated rows.

    learnRate

    Between 0 and 1. As we use AdaGrad, the effective rate will gradually decrease. You can start relatively high: 0.01 - 0.1

    stuckIterationLimit

    How many more samples to try if there is no improvement. Set based on input size, your patience and target accuaracy.

    batchSize

    Mini-batch size for "mini-batch SGD". Most of the time, 1 is the best size.

    useStable

    Use a numerically stable softmax version, more tolerant to broad input ranges. Recommended most of the time.

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  10. def gradientsOfLoss(): Unit

    Permalink

    Gradients of the loss function used for backprop weight updates.

    Gradients of the loss function used for backprop weight updates. See ref.

    We have nClasses gradient vectors of the form:

    grad(w(j)) = - (1/m) * sum(x * (target(j) - predicted(j))) + lambda * w(j) where j = 0...nClasses; sum is over a batch of m examples; w(j) = vector of weights for input parameter j; x = input(i) = input vector (iterates over a batch); target(j) = known value (0 or 1) indicating if input x belongs to class j (iterates over a batch); predicted(j) = predicted likelihood of "input x belongs to class j" (iterates over a batch); lambda > 0 is the weight decay parameter necessary for convergence.

  11. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  12. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  13. def learn(examples: Traversable[(Array[Double], Array[Double])]): Softmax

    Permalink
  14. def learnSeq(examples: Traversable[(Array[Double], Array[Double])]): Softmax

    Permalink

    Convenience shortcut for feeding a sequence of examples, splitting it into suitable batches.

  15. lazy val logger: Logger

    Permalink
    Attributes
    protected
    Definition Classes
    LazyLogging
  16. val nInputs: Int

    Permalink
  17. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  18. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  19. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  20. def predict(x: Array[Double]): Array[Double]

    Permalink

    Predict the likelihoods of each class given the inputs.

  21. def softmax(x: Array[Double], idx: Int): Array[Double]

    Permalink

    y = softmax(x) = normalize(exp(x)) = exp(x(i)) / sum (exp(x))

    y = softmax(x) = normalize(exp(x)) = exp(x(i)) / sum (exp(x))

    Naive "by the book" version; only works with normalized, stable input.

    idx

    The index of the currently processed example from the mini-batch. Used to save memory by writing the result directly to predicted(idx).

  22. def softmaxStable(x: Array[Double], idx: Int): Array[Double]

    Permalink

    This version works around some numeric issues (overflow/underflow).

    This version works around some numeric issues (overflow/underflow).

    Original form: y(i) = exp(x(i)) / sum (exp(x))

    Stable form: y(i) = exp( x(i) - logSumExp(x) ) where logSumExp(x) = max(x) + log(sum(x-max(x)))

    idx

    The index of the currently processed example from the mini-batch. Used to save memory by writing the result directly to predicted(idx).

  23. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  24. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  25. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  27. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. val weights: Array[Double]

    Permalink

    Initial weights (pre-trained or random) weights(i)(j) is the weight for evidence i based on input parameter j i = 0..nClasses j = 0..nInputs (where nInputs = inputLength + 1 for pseudo-input used for bias handling) Modeled as an array of concatenated rows.

Inherited from LazyLogging

Inherited from AnyRef

Inherited from Any

Ungrouped