Esempio n. 1
0
class StratifiedFG(FilterGenerator):
    def __init__(self,
                 minVal,
                 maxVal,
                 nbCells,
                 perturbatorGenerator,
                 numberSizeGenerator,
                 squareSized=True,
                 normalisation=FilterGenerator.NORMALISATION_NONE,
                 cellSeed=None):
        """
        Parameters
        ----------
        minVal : number
            The minimum value of a component (included)
        maxVal : number
            The maximum value of a component (excluded)
        nbCells : int > 0
            The number of cells/The number of division on the minVal-maxVal
            segment
        perturbatorGenerator : class:`NumberGenerator` (must be [0, 1) range)
            The generator which will produce the perturbation
        cellSeed : int (default : None = random)
            The seed for the random generator which will draw the chosen
            cells
        """
        FilterGenerator.__init__(self, perturbatorGenerator,
                                 numberSizeGenerator, squareSized,
                                 normalisation)
        self._min = minVal
        self._max = maxVal
        self._nbCells = nbCells
        self._cellChooser = IntegerUniformGenerator(0, nbCells, cellSeed)

    def _createFilter(self, height, width):
        """Overload"""
        linearFilter = np.zeros((height, width))
        for i in xrange(height):
            for j in xrange(width):
                #Locating the middle of the normalized cell
                inc = 1. / self._nbCells
                cell = self._cellChooser.getNumber()
                start = inc * cell
                end = start + inc
                middle = (start + end) / 2.
                #Applying the perturbation
                perturbation = self._valGen.getNumber(0, inc)
                val = middle + perturbation
                #Scaling & shifting
                valRange = self._max - self._min
                val = self._min + valRange * val
                #Assigning the value
                linearFilter[i][j] = val
        return linearFilter
Esempio n. 2
0
class StratifiedFG(FilterGenerator):

    def __init__(self, minVal, maxVal, nbCells, perturbatorGenerator,
                 numberSizeGenerator, squareSized=True,
                 normalisation=FilterGenerator.NORMALISATION_NONE,
                 cellSeed=None):
        """
        Parameters
        ----------
        minVal : number
            The minimum value of a component (included)
        maxVal : number
            The maximum value of a component (excluded)
        nbCells : int > 0
            The number of cells/The number of division on the minVal-maxVal
            segment
        perturbatorGenerator : class:`NumberGenerator` (must be [0, 1) range)
            The generator which will produce the perturbation
        cellSeed : int (default : None = random)
            The seed for the random generator which will draw the chosen
            cells
        """
        FilterGenerator.__init__(self, perturbatorGenerator,
                                 numberSizeGenerator, squareSized,
                                 normalisation)
        self._min = minVal
        self._max = maxVal
        self._nbCells = nbCells
        self._cellChooser = IntegerUniformGenerator(0, nbCells, cellSeed)

    def _createFilter(self, height, width):
        """Overload"""
        linearFilter = np.zeros((height, width))
        for i in xrange(height):
            for j in xrange(width):
                #Locating the middle of the normalized cell
                inc = 1./self._nbCells
                cell = self._cellChooser.getNumber()
                start = inc*cell
                end = start+inc
                middle = (start+end)/2.
                #Applying the perturbation
                perturbation = self._valGen.getNumber(0, inc)
                val = middle+perturbation
                #Scaling & shifting
                valRange = self._max - self._min
                val = self._min + valRange*val
                #Assigning the value
                linearFilter[i][j] = val
        return linearFilter