Interface WeightedPattern

All Superinterfaces:
Pattern
All Known Implementing Classes:
AbstractWeightedPattern

public interface WeightedPattern extends Pattern
  • Method Details

    • weight

      double weight(IPoint point)
      Returns the weight of the given point of the pattern. The result is undefined if this point is outside the pattern.
      Parameters:
      point - some integer point.
      Returns:
      the weight of this point.
      Throws:
      NullPointerException - if the argument is null.
      IllegalArgumentException - if point.coordCount()!=Pattern.dimCount().
    • weightRange

      Range weightRange()
      Returns the minimal and maximal weights of all points of this pattern.
      Returns:
      the minimal and maximal weights of all points of this pattern.
    • isConstant

      boolean isConstant()
      Returns true if the weights of all points are the same. Equivalent to weightRange().size()==0.0.
      Returns:
      true if the weights of all points are the same.
    • shift

      WeightedPattern shift(IPoint shift)
      Returns the pattern shifted by the argument, that is consisting of points with the same weights, generated from points of this instance by adding the argument via IPoint.add(IPoint) method.
      Parameters:
      shift - the shift.
      Returns:
      the shifted pattern.
      Throws:
      NullPointerException - if the argument is null.
      IllegalArgumentException - if point.coordCount()!=Pattern.dimCount().
    • multiply

      WeightedPattern multiply(double multiplier)
      Returns the pattern consisting of points, generated from points of this instance by multiplying on the mult argument via IPoint.multiply(double) method.

      If mult is not an integer, the generated real coordinates are rounded to integer values. If several source points are rounded to the same integer point, the weights of the resulting points may differ from the weights of the source ones, but the sum of all weights will be approximately same. If the all source points are transformed to different points, their weights are preserved.

      Please note: if mult is not an integer, the algorithm of rounding is not strictly specified! However, you can be sure that the new pattern will be near from the precise result.

      Specified by:
      multiply in interface Pattern
      Parameters:
      multiplier - the multiplier.
      Returns:
      the product of this pattern and the given scalar mult.
      See Also:
    • scale

      WeightedPattern scale(double... multipliers)
      Description copied from interface: Pattern
      Returns this pattern, scaled by the specified multipliers along all coordinates.

      More precisely, the resulting pattern consists of the points, obtained from all points of this pattern by the call point.scale(multipliers).

      The returned pattern always implements DirectPointSetPattern if this pattern implements DirectPointSetPattern

      The returned pattern always implements RectangularPattern if this pattern implements RectangularPattern.

      The returned pattern always implements UniformGridPattern if this pattern implements UniformGridPattern.

      There is a guarantee, that this method does not try to allocate much more memory, that it is required for storing this pattern itself, and that it never throws TooManyPointsInPatternError. For comparison, an attempt to do the same operation via getting all points (Pattern.points() method), correcting them and forming a new pattern via Patterns.newPattern(java.util.Collection) will lead to TooManyPointsInPatternError / OutOfMemoryError for some forms of large patterns.

      Warning: this method can fail with TooLargePatternCoordinatesException, if some of new points violate restrictions, described in the comments to this interface, section "Coordinate restrictions" (for example, due to very large multipliers). However, such failure is obviously impossible, if all multipliers are in range -1.0<=multipliers[k]<=1.0.

      Specified by:
      scale in interface Pattern
      Parameters:
      multipliers - the scales along coordinates.
      Returns:
      the scaled pattern.
      See Also:
    • symmetric

      WeightedPattern symmetric()
      Returns the symmetric pattern: equivalent to multiply(-1.0).
      Specified by:
      symmetric in interface Pattern
      Returns:
      the symmetric pattern.
    • productDecomposition

      List<WeightedPattern> productDecomposition(int minimalPointCount)
      Returns the product decomposition: the list of patterns such that the convolution with this pattern is equivalent to sequential convolution with all patterns from the list.

      Let the pattern consists of n-dimensional points p1p2, ... with weights w1w2, ..., and let the integer vector i defines the position of some element of the n-dimensional numeric matrix A. Here the convolution by this pattern means transforming the matrix A to another matrix B by the following rules:

      B[i] = wkA[i-pk]

      This method allows to optimize calculation of this convolution with help of several passes: first you calculate the convolution with the 1st element of the returned list, then you calculate the convolution of the new matrix with the 2nd element of the returned list, etc. The last convolution will be equal (or almost equal, due to possible rounding errors) to the convolution of the source matrix with full this pattern.

      The simplest example of such decomposition is a case of the rectangular constant pattern. In this case, this method should return a list of Pattern.dimCount() linear constant patterns (one-dimensional segments), the minkowski sum of which is equal to this one. The linear constant segments should not be further decomposed, because there is an optimal algorithm for convolution of any matrix with a linear constant segment, requiring 2 operations per element only.

      There is no guarantee that this method returns a good decomposition. If this method cannot find required decomposition, it returns the list containing this instance as the only element.

      The number of space dimensions in all returned patterns (Pattern.dimCount() is the same as in this one.

      The result of this method is immutable (Collections.unmodifiableList).

      Parameters:
      minimalPointCount - this method does not try to decompose patterns that contain less than minimalPointCount points.
      Returns:
      the decomposition of this pattern to the "product" (convolution) of smaller patterns.
      Throws:
      IllegalArgumentException - if the argument is negative.