Skip to content

Commit

Permalink
pylint (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgkirsch committed Jul 15, 2021
1 parent 0854d32 commit 63843cd
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 20 deletions.
4 changes: 4 additions & 0 deletions gpfit/classes.py
@@ -1,3 +1,7 @@
"""
Implements the Max Affine, Softmax Affine, and Implicit Softmax Affine function
classes
"""
import numpy as np
from .logsumexp import lse_scaled, lse_implicit

Expand Down
7 changes: 3 additions & 4 deletions gpfit/constraint_set.py
Expand Up @@ -4,11 +4,10 @@
from gpkit import Variable, NomialArray, NamedVariables, VectorVariable
from gpkit.small_scripts import initsolwarning, appendsolwarning


# pylint: disable=too-many-instance-attributes, too-many-locals,
# pylint: disable=too-many-branches, no-member, import-error
# pylint: disable=too-many-arguments


# pylint: disable=too-many-arguments, import-outside-toplevel
class FitConstraintSet(ConstraintSet):
"""
Constraint set for fitted functions
Expand Down Expand Up @@ -104,7 +103,7 @@ def process_result(self, result):
"""
make sure fit result is within bounds of fitted data
"""
super(FitConstraintSet, self).process_result(result)
super().process_result(result)
initsolwarning(result, "Fit Out-of-Bounds")

if self.mfac not in result["sensitivities"]["constants"]:
Expand Down
4 changes: 2 additions & 2 deletions gpfit/fit.py
Expand Up @@ -66,8 +66,8 @@ def residual(params):
r = yhat - ydata
return r, drdp

ydata_col = ydata.reshape(ydata.size, 1)
ba = get_initial_parameters(xdata, ydata_col, K).flatten("F")
ba = get_initial_parameters(xdata, ydata.reshape(ydata.size, 1),
K).flatten("F")
if ftype == "ISMA":
params, _ = levenberg_marquardt(residual, hstack((ba, alpha0*ones(K))))
elif ftype == "SMA":
Expand Down
6 changes: 2 additions & 4 deletions gpfit/least_squares.py
Expand Up @@ -6,7 +6,7 @@
from scipy.sparse import spdiags, issparse


# pylint: disable=too-many-locals,too-many-arguments,too-many-branches,too-many-statements
# pylint: disable=too-many-locals,too-many-arguments,too-many-branches,too-many-statements,no-else-break
def levenberg_marquardt(
residfun,
initparams,
Expand Down Expand Up @@ -63,7 +63,7 @@ def levenberg_marquardt(
# Define display formatting if required
formatstr1 = "%5.0f %9.6g %9.3g\n"
formatstr = (
"%5.0f %9.6g %9.3g " "%12.4g %12.4g %8.4g\n"
"%5.0f %9.6g %9.3g %12.4g %12.4g %8.4g\n"
)

# Get residual values and jacobian at initial point; extract size info
Expand Down Expand Up @@ -102,12 +102,10 @@ def levenberg_marquardt(

# Main Loop
while True:

if itr == maxiter:
if verbose:
print("Reached maximum number of iterations")
break

elif time() - t > maxtime:
if verbose:
print("Reached maxtime (%s seconds)" % maxtime)
Expand Down
2 changes: 1 addition & 1 deletion gpfit/tests/t_constraint_set.py
Expand Up @@ -24,7 +24,7 @@ def test_fit_constraint_set(self):
sol = m.solve(verbosity=0)
self.assertAlmostEqual(sol["cost"], 0.7777593)

def test_fit_constraint_set_outside_bounds(self):
def test_outside_bounds(self):
m = Model(self.wvar, [self.fcs, self.uvar <= 4])
sol = m.solve(verbosity=0)
self.assertTrue(len(sol['warnings']["Fit Out-of-Bounds"]) == 1)
Expand Down
10 changes: 6 additions & 4 deletions gpfit/tests/t_fit.py
@@ -1,9 +1,11 @@
#unit tests for gpfit.fit module"
"""unit tests for fit module"""
import unittest
from numpy import logspace, log10, log, vstack
from gpfit.fit import fit


class TestFit(unittest.TestCase):
"""Test fit function"""

u = logspace(0, log10(3), 501)
w = (u**2 + 3)/(u + 1)**2
Expand All @@ -12,11 +14,11 @@ class TestFit(unittest.TestCase):
K = 3

def test_rms_error(self):
cstrt, rms_error = fit(self.x, self.y, self.K, "SMA")
_, rms_error = fit(self.x, self.y, self.K, "SMA")
self.assertTrue(rms_error < 1e-4)
cstrt, rms_error = fit(self.x, self.y, self.K, "ISMA")
_, rms_error = fit(self.x, self.y, self.K, "ISMA")
self.assertTrue(rms_error < 1e-5)
cstrt, rms_error = fit(self.x, self.y, self.K, "MA")
_, rms_error = fit(self.x, self.y, self.K, "MA")
self.assertTrue(rms_error < 1e-2)

def test_incorrect_inputs(self):
Expand Down
8 changes: 4 additions & 4 deletions gpfit/tests/t_plot_fit.py
Expand Up @@ -6,12 +6,12 @@

class TestPlotFit(unittest.TestCase):
"Unit tests for plot_fit_1d"
N = 51
u = np.logspace(0, np.log10(3), N)
w = (u**2 + 3)/(u + 1)**2

def test_plot_fit_1d(self):
N = 51
U = np.logspace(0, np.log10(3), N)
W = (U**2+3)/(U+1)**2
plot_fit_1d(U, W, K=2, fitclass='SMA', plotspace="linear")
plot_fit_1d(self.u, self.w, K=2, fitclass='SMA', plotspace="linear")


TESTS = [TestPlotFit]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -30,7 +30,7 @@
author_email="gpkit@mit.edu",
url="https://github.com/convexengineering/gpfit",
python_requires=">=3.4",
install_requires=["numpy", "scipy", "gpkit"],
install_requires=["numpy", "scipy", "gpkit", "matplotlib"],
version="0.1.0",
packages=["gpfit", "gpfit.tests"],
license=LICENSE,
Expand Down

0 comments on commit 63843cd

Please sign in to comment.