com.eharmony.aloha.models.reg

PolynomialEvaluator

case class PolynomialEvaluator(value: Coefficient, descendants: Map[String, PolynomialEvaluator] = ...) extends MapTreeLike[String, Coefficient] with PolynomialEvaluationAlgo with Product with Serializable

Provides a method to evaluate polynomials given an input. Default implementation of com.eharmony.aloha.models.reg.PolynomialEvaluationAlgo.

value
descendants

Linear Supertypes
Serializable, Serializable, Product, Equals, PolynomialEvaluationAlgo, MapTreeLike[String, Coefficient], Tree[Coefficient, [+V]Map[String, V], MapTreeLike[String, Coefficient]], AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. PolynomialEvaluator
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. PolynomialEvaluationAlgo
  7. MapTreeLike
  8. Tree
  9. AnyRef
  10. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new PolynomialEvaluator(value: Coefficient, descendants: Map[String, PolynomialEvaluator] = ...)

    value
    descendants

Value Members

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

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

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

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def at(x: IndexedSeq[Iterable[(String, Double)]]): Double

    Evaluate the polynomial represented by this object at the point x.

    Evaluate the polynomial represented by this object at the point x.

    x

    A representation of a point. The representation is as follows: The outer indexed sequence represents groups of features in feature space generated by the same feature expander. The inner sequence is an iterable sequence of key value pairs. This representation is used because it allows efficient encoding of sparse feature spaces. For instance, we can very easily encode multi-part bag of word models as follows. Let's say the 0th index in the outer sequence represents the title of HTML documents and the 1st index represents text inside the body tags in the HTML document.

    case class Doc(title: String, body: String) {
      def multiPartBagOfWords = IndexedSeq(tokens(title), tokens(body))
      private[this] def tokens(s: String) = s.trim.toLowerCase.split("\\W+").groupBy(identity).mapValues(_.size.toDouble)
    }
    
    val fox = Doc("fox story", "The quick brown fox jumps over the lazy dog")
    val p: PolynomialEvaluationAlgo = ...
    p at fox.multiPartBagOfWords
    returns

    this polynomial evaluated at x.

    Definition Classes
    PolynomialEvaluationAlgo
  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. val descendants: Map[String, PolynomialEvaluator]

    Definition Classes
    PolynomialEvaluatorTree
  10. def dfs(): Iterator[(MapTreeLike[String, Coefficient], Int)]

    Get a NON thread-safe iterator over the nodes in the tree for a DFS ordering.

    Get a NON thread-safe iterator over the nodes in the tree for a DFS ordering. Each iterator value contains the node in the tree and the depth (root has 0 depth). This iterator requires O(B * D) auxiliary space where B is the branching factor and D is the tree depth.

    returns

    a NON thread-safe iterator over the nodes in the tree for a DFS ordering.

    Definition Classes
    Tree
  11. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  12. def finalize(): Unit

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

    Definition Classes
    AnyRef → Any
  14. final def hBig(x: IndexedSeq[Iterable[(String, Double)]], s: Stack[(MapTreeLike[String, Coefficient], Double)], sum: Double): Double

    A tail-recursive variant of hSmall that won't stack overflow on deep trees.

    A tail-recursive variant of hSmall that won't stack overflow on deep trees. This function is slower in empirical tests that hSmall.

    x

    an input vector

    s

    a stack of trees and current sums at those trees (replaces call stack in non-tail-recursive hSmall).

    sum

    the current sum.

    returns

    this polynomial evaluated at x.

    Attributes
    protected[this]
    Definition Classes
    PolynomialEvaluationAlgo
  15. final def hSmall(x: IndexedSeq[Iterable[(String, Double)]], xSize: Int, t: MapTreeLike[String, Coefficient], prod: Double): Double

    Accumulate, in a depth-first way, the evaluation of the polynomial.

    Accumulate, in a depth-first way, the evaluation of the polynomial.

    NOTE: This algorithm is recursive (but not tail-recursive) by seems to be about 20% faster than the following tail-recursive equivalent. This is probably due to additional object creation in the tail-recursive method. Tuple2 instances must be created and the linked list containers probably needs to be created. In the non-tail recursive version, we don't do any of this and only perform arithmetic operations (aside from the iterators and the Options created in the descendant lookup).

    We aren't too afraid of stack overflows because these trees will typically be shallow. This is because most use cases don't involve polynomials in thousands of variables (or of degree in the thousands). That being said, stack overflows are a real possibility (in test at a depth of ~3000). To combat this, hBig is provided but not yet integrated into the at function.

    import collection.mutable.{Stack => MStack}
    def h3(x: IndexedSeq[Seq[(String, Double)]], s: MStack[(MapTreeLike[String, Value], Double)], z: Double): Double = {
      if (s.isEmpty) z
      else {
        val h = s.pop
        for (i <- h._1.value.applicableFeatures; p <- x(i); c <- h._1.descendants.get(p._1)) s.push((c, p._2 * h._2))
        h3(x, s, z + h._1.value.weight * h._2)
      }
    }
    x

    an input vector

    xSize

    size of input vector (computed once for possible speed improvement).

    t

    a tree containing the information necessary to compute the higher order inner product

    prod

    product of the items in the path from the root to leaf.

    returns

    this polynomial evaluated at x.

    Attributes
    protected[this]
    Definition Classes
    PolynomialEvaluationAlgo
  16. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  17. final def ne(arg0: AnyRef): Boolean

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

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

    Definition Classes
    AnyRef
  20. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  21. def toString(): String

    Need to overload so that calling toString doesn't stack overflow like it would with the default implementation.

    Need to overload so that calling toString doesn't stack overflow like it would with the default implementation.

    returns

    Definition Classes
    PolynomialEvaluator → AnyRef → Any
  22. val value: Coefficient

    Definition Classes
    PolynomialEvaluatorTree
  23. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from PolynomialEvaluationAlgo

Inherited from MapTreeLike[String, Coefficient]

Inherited from Tree[Coefficient, [+V]Map[String, V], MapTreeLike[String, Coefficient]]

Inherited from AnyRef

Inherited from Any

Ungrouped