Skip to content

Commit

Permalink
Fixed optimization tolerances
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffrey-hokanson committed Jan 10, 2019
1 parent f1c7cae commit 2c40919
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion psdr/opt/gn.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def linesearch_armijo(f, g, p, x0, bt_factor=0.5, ftol=1e-4, maxiter=40, traject
return x, alpha, fx


def gauss_newton(f, F, x0, tol=1e-5, tol_normdx=1e-12,
def gauss_newton(f, F, x0, tol=1e-10, tol_normdx=1e-12,
maxiter=100, fdcheck=False, linesearch=None, verbose=0, trajectory=None, gnsolver = None):
r"""A Gauss-Newton solver for unconstrained nonlinear least squares problems.
Expand Down
16 changes: 13 additions & 3 deletions psdr/polyridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def __init__(self, degree, subspace_dimension, basis = 'legendre',


def fit(self, X, fX, U0 = None, **kwargs):
r""" Given samples, fit the polynomial ridge approximation
r""" Given samples, fit the polynomial ridge approximation.
Parameters
----------
Expand All @@ -220,9 +220,19 @@ def fit(self, X, fX, U0 = None, **kwargs):
"""

self.m = X.shape[1]
fX = fX.flatten()
X = np.array(X)
fX = np.array(fX).flatten()

assert X.shape[0] == fX.shape[0], "Dimensions of input do not match"

if U0 is not None:
U0 = np.array(U0)
assert U0.shape[0] == X.shape[1], "U0 has %d rows, expected %d based on X" % (U0.shape[0], X.shape[1])
assert U0.shape[1] == self.subspace_dimension, "U0 has %d columns; expected %d" % (U0.shape[1], self.subspace_dimension)
U0 = orth(U0)


# TODO Implement multiple initializations
if self.norm == 2:
return self._fit_2_norm(X, fX, U0, **kwargs)
else:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_polyridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ def test_exact():

# Random point
U, _ = np.linalg.qr(np.random.randn(m,n))
U, _ = np.linalg.qr(np.vstack([a,b]))

# Actual ridge subspace
#U, _ = np.linalg.qr(np.vstack([a,b]).T)

pra = PolynomialRidgeApproximation(degree = p, subspace_dimension = n, scale = False)
pra.fit(X, fX, U0 = U, verbose = 1)
# Because the data is an exact ridge function, we should (I think) converge to the global solution
Expand Down

0 comments on commit 2c40919

Please sign in to comment.