Skip to content

Commit

Permalink
documented utility modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jmason42 committed Jun 11, 2018
1 parent 13eb27d commit 2d20b58
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 4 deletions.
10 changes: 10 additions & 0 deletions utils/ks_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

'''
Performs the two-sample KS test, a non-parameteric test on whether two
distributions are significantly different. Not used.
TODO: delete
'''


from __future__ import division

import numpy as np
Expand Down
8 changes: 7 additions & 1 deletion utils/l1min.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@

# TODO: delete?
'''
Defines a function to perform constrained L1-norm minimization. Unused.
TODO: delete
'''

from __future__ import division

Expand Down
24 changes: 23 additions & 1 deletion utils/linalg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@

# TODO: delete?
'''
Functions for performing various, specialized linear algebra optimizations.
Largely unutilized, except for bilevel_elementwise_pseudoinverse and
approx_jac.
'''

from __future__ import division

Expand Down Expand Up @@ -42,6 +48,11 @@ def nullspace_basis(matrix, rcond = _RES):
return null

def pinv(matrix, rcond = _RES):
'''
Finds the Moore-Penrose pseudo-inverse using the singular value
decomposition.
'''

u, s, vT = np.linalg.svd(matrix, full_matrices = False)

retain = (s / s[0] > rcond)
Expand Down Expand Up @@ -78,6 +89,13 @@ def bilevel_pseudoinverse(first_matrix, second_matrix, rcond = _RES):
return second_nullspace_projector.dot(first_matrix_pseudoinverse)

def bilevel_elementwise_pseudoinverse(first_matrix, second_matrix, rcond = _RES):
'''
Creates the pseudo-inverse matrix that solves a bilevel least-squares
optimization problem.
'''

n, size = first_matrix.shape

vectors = [first_matrix[[i], :] for i in xrange(n)]
Expand All @@ -102,6 +120,10 @@ def bilevel_elementwise_pseudoinverse(first_matrix, second_matrix, rcond = _RES)
return np.concatenate(bilevel_pinvs, 1)

def approx_jac(f, x, d = 1e-3):
'''
Computes an approximate Jacobian on a function f with respect to parameter
values x using centered differences with a size of d.
'''
f0 = f(x)

j = np.empty((f0.size, x.size))
Expand Down
7 changes: 7 additions & 0 deletions utils/liveout.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

'''
Defines functions and classes for outputing data to a shell in a live, updating
table.
'''

import sys

from itertools import izip
Expand Down
6 changes: 5 additions & 1 deletion utils/plotting.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

# TODO: delete?
'''
Deifnes a plotting utility function. Unused but helpful for inspecting matrices.
'''

from __future__ import division

Expand Down
7 changes: 7 additions & 0 deletions utils/rdp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

'''
Defines a function for performing the RDP algorithm on data, useful for
reducing the number of points in a plot. Not used.
'''

from __future__ import division

import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion utils/residuals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

'''
Plotting code for drawing the condensed box-plots for figures 5 and 6.
Plotting code for drawing the condensed box-plots for figures 4 and 6.
'''

from __future__ import division
Expand Down
6 changes: 6 additions & 0 deletions utils/svm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

'''
Defines a function for performing soft-margin SVM. Not used.
'''

from __future__ import division

import numpy as np
Expand Down

0 comments on commit 2d20b58

Please sign in to comment.