Skip to content

Commit

Permalink
Merge pull request #16 from cmccomb/master
Browse files Browse the repository at this point in the history
Fixing `parthworth` typo
  • Loading branch information
cmccomb committed Dec 27, 2023
2 parents 089866a + 9e7da1a commit ce6a789
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
6 changes: 3 additions & 3 deletions sae/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def objectives(
else:
return global_obj

def parthworth_objectives(
def partworth_objectives(
self,
weights: NDArray = weights_pw_null,
with_subobjs: bool = True,
Expand Down Expand Up @@ -991,13 +991,13 @@ def objectives(
tominimize_and_scaled=tominimize_and_scaled,
)

def parthworth_objectives(
def partworth_objectives(
self,
weights: NDArray = weights_pw_null,
with_subobjs: bool = True,
tominimize_and_scaled: bool = True,
) -> Union[float, tuple[float, NDArray]]:
return self.car.parthworth_objectives(
return self.car.partworth_objectives(
weights=weights,
with_subobjs=with_subobjs,
tominimize_and_scaled=tominimize_and_scaled,
Expand Down
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from setuptools import setup, find_packages

setup(
name='sae',
version='0.1.0',
description='An implementation of an SAE systems design problem',
author='Akash Agrawal',
author_email='ask-drc@andrew.cmu.edu',
url='',
name="sae",
version="0.1.0",
description="An implementation of an SAE systems design problem",
author="Akash Agrawal",
author_email="ask-drc@andrew.cmu.edu",
url="",
install_requires=["numpy", "scipy", "pandas", "openpyxl"],
packages=find_packages(),
include_package_data=True,
)
)
39 changes: 21 additions & 18 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
from sae import COTSCar, Car, weightsNull, weights1, generate_feasible
from numpy import clip

class TestFullProblem(unittest.TestCase):

class TestFullProblem(unittest.TestCase):
def test_random_generation(self):
# generate a random car that always satisfies constraints_bound and constraints_lin_ineq
test_car = Car()
test_car.objectives(weights=weights1, with_subobjs=True, tominimize_and_scaled=True)
test_car.objectives(
weights=weights1, with_subobjs=True, tominimize_and_scaled=True
)

# evaluate constraint violation penalites (square penalty)
test_car.constraints_bound()
Expand All @@ -19,7 +21,9 @@ def test_random_generation(self):
def test_feasible_generation(self):
# generate a random car that always satisfies constraints_bound and constraints_lin_ineq
test_car = generate_feasible()
test_car.objectives(weights=weights1, with_subobjs=True, tominimize_and_scaled=True)
test_car.objectives(
weights=weights1, with_subobjs=True, tominimize_and_scaled=True
)

# evaluate constraint violation penalites (square penalty)
test_car.constraints_bound()
Expand All @@ -29,7 +33,7 @@ def test_feasible_generation(self):

def test_pw(self):
test_car = generate_feasible()
test_car.parthworth_objectives()
test_car.partworth_objectives()

def test_minimize(self):
def round_x(x):
Expand Down Expand Up @@ -61,18 +65,17 @@ def penalty_3(x):
res = scipy.optimize.minimize(
objective,
generate_feasible().vector,
method='trust-constr',
method="trust-constr",
constraints=(
{'type': 'eq', 'fun': penalty_1},
{'type': 'eq', 'fun': penalty_2},
{'type': 'eq', 'fun': penalty_3}
{"type": "eq", "fun": penalty_1},
{"type": "eq", "fun": penalty_2},
{"type": "eq", "fun": penalty_3},
),
)
print(res)


class TestCOTSProblem(unittest.TestCase):

def test_random_generation_cots(self):
# generate a random car that always satisfies constraints_bound and constraints_lin_ineq
test_car = COTSCar()
Expand All @@ -96,12 +99,15 @@ def test_feasible_generation_cots(self):
test_car.cost()

def test_minimize_cots(self):

def round_x(x):
for i in range(len(x)):
rounded = round(x[i])
x[i] = rounded
return clip(x, 0, [12, 12, 12, 12, 12, 6, 6, 20, 33, 4, 63, 191, 4, 4, 215, 215, 215])
return clip(
x,
0,
[12, 12, 12, 12, 12, 6, 6, 20, 33, 4, 63, 191, 4, 4, 215, 215, 215],
)

def objective(x):
c = COTSCar()
Expand All @@ -126,14 +132,11 @@ def penalty_3(x):
res = scipy.optimize.minimize(
objective,
generate_feasible(cots=True).vector,
method='trust-constr',
method="trust-constr",
constraints=(
{'type': 'eq', 'fun': penalty_1},
{'type': 'eq', 'fun': penalty_2},
{'type': 'eq', 'fun': penalty_3}
{"type": "eq", "fun": penalty_1},
{"type": "eq", "fun": penalty_2},
{"type": "eq", "fun": penalty_3},
),
)
print(res)



0 comments on commit ce6a789

Please sign in to comment.