Object/Trait

com.eharmony.aloha.feature

SparsityTransforms

Related Docs: trait SparsityTransforms | package feature

Permalink

object SparsityTransforms extends SparsityTransforms

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

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. def densifyFn[A, B, F[C] <: FilterMonadic[C, F[C]], That](denseDomain: F[A], sparseMapping: (A) ⇒ Option[B], whenMissing: B)(implicit cbf: CanBuildFrom[F[A], B, That]): That

    Permalink

    Given a sparse mapping represented as a function (sparseMapping) from the input domain A to a range of optional values (Option[B]), convert to a dense format of the appropriate container type.

    Given a sparse mapping represented as a function (sparseMapping) from the input domain A to a range of optional values (Option[B]), convert to a dense format of the appropriate container type. This is done by composing f = g ∘ sparseMapping, where g is defined as:

           ⎧ y            if x = Some(y)
    g(x) = ⎨
           ⎩ whenMissing  otherwise
    

    and mapping f over denseDomain.

    An example:

    val denseDomain = 3 to 6
    val sparseKeys = Array(4, 6)
    val sparseVals = Iterable(1, 2)
    val sparseMapping = (sparseKeys zip sparseVals).toMap.get _   // Int => Option[Int]
    val whenMissing = 0
    
    val result = densify(denseDomain, sparseMapping, whenMissing)
    val expected = Vector(0, 1, 0, 2)
    
    // NOTE: The resulting container type is a Vector because of the type of denseDomain.
    assert(result.getClass.getCanonicalName == "scala.collection.immutable.Vector")
    assert(result == expected)
    A

    type of the dense domain

    B

    type of the dense range

    F

    the container type of the input. An attempt is made to make the output container type as close as possible to the input container type. While this is a FilterMonadic, it really only needs to be a functor (because we only care about the map function. Flatmap doesn't matter).

    That

    the resulting type implementation.

    denseDomain

    the domain of dense values provided as the preimage to the sparse mapping specified by the parallel iterables.

    sparseMapping

    a mapping from the input domain to an option of the output domain. Once composed with whenMissing this map all values of the domain an appropriate value in the range of the function.

    whenMissing

    the resulting value when an item from denseDomain isn't contained in sparseKeys.

    cbf

    a CanBuildFrom object

    returns

    the dense image of the mapping from the dense domain, using sparseMapping and whenMissing.

    Definition Classes
    SparsityTransforms
  7. def densifyMap[A, B, F[C] <: FilterMonadic[C, F[C]], That](denseDomain: F[A], sparseFeatures: Map[A, B], whenMissing: B)(implicit cbf: CanBuildFrom[F[A], B, That]): That

    Permalink

    Given a sparse mapping represented as a map (sparseFeatures), convert to a dense format of the appropriate container type.

    Given a sparse mapping represented as a map (sparseFeatures), convert to a dense format of the appropriate container type. This is done by creating a map based on sparseFeatures with a default value specified by whenMissing and mapping the new map's apply function over denseDomain.

    An example:

    val denseDomain = 3 to 6
    val sparseKeys = Array(4, 6)
    val sparseVals = Iterable(1, 2)
    val sparseFeatures = (sparseKeys zip sparseVals).toMap
    val whenMissing = 0
    
    val result = densify(denseDomain, sparseFeatures, whenMissing)
    val expected = Vector(0, 1, 0, 2)
    
    // NOTE: The resulting container type is a Vector because of the type of denseDomain.
    assert(result.getClass.getCanonicalName == "scala.collection.immutable.Vector")
    assert(result == expected)
    A

    type of the dense domain

    B

    type of the dense range

    F

    the container type of the input. An attempt is made to make the output container type as close as possible to the input container type. While this is a FilterMonadic, it really only needs to be a functor (because we only care about the map function. Flatmap doesn't matter).

    That

    the resulting type implementation.

    denseDomain

    the domain of dense values provided as the preimage to the sparse mapping specified by the parallel iterables.

    sparseFeatures

    a map from the domain to range

    whenMissing

    the resulting value when an item from denseDomain isn't contained in sparseKeys.

    cbf

    a CanBuildFrom object

    returns

    the dense image of the mapping from the dense domain, using sparseMapping and whenMissing.

    Definition Classes
    SparsityTransforms
  8. def densifyPI[A, B, F[C] <: FilterMonadic[C, F[C]], That](denseDomain: F[A], sparseKeys: Iterable[A], sparseVals: Iterable[B], whenMissing: B)(implicit cbf: CanBuildFrom[F[A], B, That]): That

    Permalink

    Given a sparse mapping represented as key-value pairs in parallel iterables, convert to a dense format of the appropriate container type.

    Given a sparse mapping represented as key-value pairs in parallel iterables, convert to a dense format of the appropriate container type. This is done by mapping over the denseDomain, determining whether a key exists in sparseKeys. If a key exists, the associated value is substituted; otherwise, substitute with the whenMissing value.

    In the event of duplicate keys, for each pair of duplicate keys, the key-value pair associated with the second encountered key will be used.

    An example:

    val denseDomain = 3 to 6
    val sparseKeys = Array(4, 6)
    val sparseVals = Iterable(1, 2)
    val sparseValOptions = sparseVals.map(Option.apply)
    val whenMissing = None
    
    val result = densify(denseDomain, sparseKeys, sparseValOptions, whenMissing)
    val expected = Vector(None, Some(1), None, Some(2))
    
    // NOTE: The resulting container type is a Vector because of the type of denseDomain.
    assert(result.getClass.getCanonicalName == "scala.collection.immutable.Vector")
    assert(result == expected)

    Notice in the example above that when all of the keys are contained in denseDomain, then when sparsifying the results of densify, we get back the original sparseVals:

    assert(result.flatten == sparseVals)
    A

    type of the dense domain

    B

    type of the dense range

    F

    the container type of the input. An attempt is made to make the output container type as close as possible to the input container type. While this is a FilterMonadic, it really only needs to be a functor (because we only care about the map function. Flatmap doesn't matter).

    That

    the resulting type implementation.

    denseDomain

    the domain of dense values provided as the preimage to the sparse mapping specified by the parallel iterables.

    sparseKeys

    the keys in the sparse mapping (NOTE: (sparseKeys(i), sparseVals(i)) represents a key-value pair)

    sparseVals

    the values in the sparse mapping

    whenMissing

    the resulting value when an item from denseDomain isn't contained in sparseKeys.

    cbf

    a CanBuildFrom object

    returns

    the dense image of the mapping from the dense domain, using the mapping created by sparseKeys, sparseVals and whenMissing.

    Definition Classes
    SparsityTransforms
  9. final def eq(arg0: AnyRef): Boolean

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

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  13. def hashCode(): Int

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

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

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

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

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

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from SparsityTransforms

Inherited from AnyRef

Inherited from Any

Ungrouped