Skip to content

A Python decorator that jitters the parameters of a function to test its robustness.

License

Notifications You must be signed in to change notification settings

yfiua/jitterator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jitterator

A Python decorator that jitters the parameters of a function to test its robustness.

Installation

pip install git+https://github.com/yfiua/jitterator

Usage

Add the decorator @jitterate(jitter, mode) to the function.

  • jitter is the amount of jittering, which defaults to 0.05
  • mode can be '+' (additive, default) or '*' (multiplicative)

For example:

from jitterator import jitterate

def test_fun(x, y, z):
    return x + y * z

@jitterate(.01)
def test_fun_jittered(x, y, z):
    return test_fun(x, y, z)

x, y, z = 1, 2, 3

val = test_fun(x, y, z)
res_jittered = [test_fun_jittered(1, 2, 3) for i in range(10)]
vals_jittered, args_jittered = zip(*res_jittered)

You can then plot the jittered results.

Example plot

The input parameters of the jittered function can be of different types such as numpy arrays, but must be additive or multiplicative, depending on the mode. For example

def test_fun_np(x, y):
    return np.dot(x, y)

@jitterate(.01, '+')
def test_fun_np_jittered(x, y):
    return test_fun_np(x, y)

x, y = np.array([1, 2, 3]), np.array([4, 5, 6])

The jitter can be a single value or a list / numpy array of the same length as the input parameters. The mode can also be a single value or a list of the same length as the input parameters. For example

def test_fun_list(x, y):
    return np.dot(x, y)

@jitterate([.01, .02], ['+', '*'])
def test_fun_list_jittered(x, y):
    return test_fun_list(x, y)

x, y = np.array([1, 2, 3]), np.array([4, 5, 6])

TODOs

  • Distribution of the jitter
  • Test

About

A Python decorator that jitters the parameters of a function to test its robustness.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages