Skip to content

Commit

Permalink
CustomSum
Browse files Browse the repository at this point in the history
  • Loading branch information
Enric Grau committed Apr 23, 2024
1 parent 39917e8 commit 3d8dca3
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pudu/perturbation.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,23 @@ def apply(self, x, row, col, window, bias):
return x, None


class CustomSum:
"""
Sums a custom vector as a perturbation to the array.
:type func: callable
:param func: A function that takes a single argument and returns a single value.
:rtype: 4d array
:return: Custom perturbated array
"""
def __init__(self, custom):
self.custom = custom
def apply(self, x, row, col, window, bias):
x[0, row:row+window[0], col:col+window[1], 0] = x[0, row:row+window[0], col:col+window[1], 0] + self.custom[0, row:row+window[0], col:col+window[1], 0]
return x, None


class UpperThreshold:
"""
Sets values above a certain threshold to a specified value.
Expand Down

0 comments on commit 3d8dca3

Please sign in to comment.