org.apache.sysds.runtime.compress.cost

## Class DistinctCostEstimator

- java.lang.Object
- - org.apache.sysds.runtime.compress.cost.DistinctCostEstimator

- All Implemented Interfaces:
    Serializable, ICostEstimate

      public class DistinctCostEstimator
      extends Object
      implements ICostEstimate

  A Cost based estimator that based the compression and co-coding cost on the number of distinct elements in the column groups. The base cost of the uncompressed representation is the number of cells in the matrix that has a value. Aka nonzero values.
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from interface org.apache.sysds.runtime.compress.cost.ICostEstimate

      `LOG`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DistinctCostEstimator(int nRows, CompressionSettings cs)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `double` | `getCostOfCollectionOfGroups(Collection<CompressedSizeInfoColGroup> gs)` Get the computation cost of a collection of column groups information.
    `double` | `getCostOfCollectionOfGroups(Collection<CompressedSizeInfoColGroup> gs, CompressedSizeInfoColGroup g)`
    `double` | `getCostOfColumnGroup(CompressedSizeInfoColGroup g)` If the instruction does not care about the inter column group cost, such as in memory cost or in computation cost of right or left matrix multiplication we simply estimate the cost of individual column groups.
    `double` | `getCostOfTwoGroups(CompressedSizeInfoColGroup g1, CompressedSizeInfoColGroup g2)`
    `double` | `getUncompressedCost(int nRows, int nCols, int sparsity)` Calculate the cost of execution if uncompressed.
    `boolean` | `isCompareAll()` Function that returns true if the cost is based an an all compare all column groups false otherwise.
    `boolean` | `shouldAnalyze(CompressedSizeInfoColGroup g1, CompressedSizeInfoColGroup g2)` Decide if the column groups should be analysed, or the worst case join should be expected.
    `boolean` | `shouldTryJoin(CompressedSizeInfoColGroup g1, CompressedSizeInfoColGroup g2)` Decide if the column groups should try to join, this is to filter obviously bad joins out.

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

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

- - ### Constructor Detail

    - #### DistinctCostEstimator

          public DistinctCostEstimator(int nRows,
                                       CompressionSettings cs)

  - ### Method Detail

    - #### getUncompressedCost

          public double getUncompressedCost(int nRows,
                                            int nCols,
                                            int sparsity)

      Description copied from interface: `ICostEstimate`
      Calculate the cost of execution if uncompressed. This is used as an optimization goal to at least achieve, since if the uncompressed cost of calculation is lower than in compressed space we don't want to compress.
      Specified by:
        `getUncompressedCost` in interface `ICostEstimate`
      Parameters:
        `nRows` - Number of rows in compression
        `nCols` - Number of columns in compression
        `sparsity` - Sparsity of the input
      Returns:
        The uncompressed cost.

    - #### getCostOfColumnGroup

          public double getCostOfColumnGroup(CompressedSizeInfoColGroup g)

      Description copied from interface: `ICostEstimate`
      If the instruction does not care about the inter column group cost, such as in memory cost or in computation cost of right or left matrix multiplication we simply estimate the cost of individual column groups.
      Specified by:
        `getCostOfColumnGroup` in interface `ICostEstimate`
      Parameters:
        `g` - Column group to estimate the cost of
      Returns:
        The Cost of this column group

    - #### getCostOfCollectionOfGroups

          public double getCostOfCollectionOfGroups(Collection<CompressedSizeInfoColGroup> gs)

      Description copied from interface: `ICostEstimate`
      Get the computation cost of a collection of column groups information. Since a some operations execution time depends on all compare all calculating the cost needs all the current groups to consider. This method therefore provide a method of comparing cost of all compare all.
      Specified by:
        `getCostOfCollectionOfGroups` in interface `ICostEstimate`
      Parameters:
        `gs` - All the groups considered for this cost calculation
      Returns:
        The cost of the calculation

    - #### getCostOfCollectionOfGroups

          public double getCostOfCollectionOfGroups(Collection<CompressedSizeInfoColGroup> gs,
                                                    CompressedSizeInfoColGroup g)

      Specified by:
        `getCostOfCollectionOfGroups` in interface `ICostEstimate`

    - #### getCostOfTwoGroups

          public double getCostOfTwoGroups(CompressedSizeInfoColGroup g1,
                                           CompressedSizeInfoColGroup g2)

      Specified by:
        `getCostOfTwoGroups` in interface `ICostEstimate`

    - #### isCompareAll

          public boolean isCompareAll()

      Description copied from interface: `ICostEstimate`
      Function that returns true if the cost is based an an all compare all column groups false otherwise.
      Specified by:
        `isCompareAll` in interface `ICostEstimate`
      Returns:
        boolean

    - #### shouldAnalyze

          public boolean shouldAnalyze(CompressedSizeInfoColGroup g1,
                                       CompressedSizeInfoColGroup g2)

      Description copied from interface: `ICostEstimate`
      Decide if the column groups should be analysed, or the worst case join should be expected. This is use full if the column groups are very small and the in practice difference between joining or not is small.
      Specified by:
        `shouldAnalyze` in interface `ICostEstimate`
      Parameters:
        `g1` - Group 1
        `g2` - Group 2
      Returns:
        If the joining should be analyzed.

    - #### shouldTryJoin

          public boolean shouldTryJoin(CompressedSizeInfoColGroup g1,
                                       CompressedSizeInfoColGroup g2)

      Description copied from interface: `ICostEstimate`
      Decide if the column groups should try to join, this is to filter obviously bad joins out.
      Specified by:
        `shouldTryJoin` in interface `ICostEstimate`
      Parameters:
        `g1` - Group 1
        `g2` - Group 2
      Returns:
        Boolean specifying if they should try to join.

Copyright © 2021 The Apache Software Foundation. All rights reserved.