-
Notifications
You must be signed in to change notification settings - Fork 22
Merge LPGD into diffcp #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
a-paulus
wants to merge
22
commits into
cvxgrp:master
Choose a base branch
from
martius-lab:LPGD
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
20fd10c
Update README.md
a-paulus 26727e1
Add LPGD
a-paulus 8b0f8ac
Update Readme
a-paulus 6e761ce
simplify argument passing
a-paulus e4f8e82
add more lpgd examples
a-paulus 1fa3d05
Catch error if perturbed problem infeasible
a-paulus 133d30d
Give better error message on infeasibility
a-paulus 761b8ba
fix docstrings
a-paulus ca0eb64
minor changes
a-paulus c73b116
cosmetic changes
a-paulus 476faf2
Merge branch 'cvxgrp:master' into master
a-paulus ca78344
update readme
a-paulus 3d1235c
move perturbed solution computation to utils
a-paulus ca1be3f
cosmetics
a-paulus 1f4e4bf
resolve domments on pull request + minor edits
a-paulus d2aada1
add differentiation w.r.t. P
a-paulus dcfa6ba
add examples for differentiating w.r.t. P
a-paulus 8a9069c
minor cosmetic change
a-paulus 31dd6d6
mention in docstring that return_dP is currently only possible in LPG…
a-paulus e8fda9f
Update readme for for quadratic objectives, specify when differentiat…
a-paulus 8a35213
Merge branch 'master' into LPGD
a-paulus 3e7243a
Testing merged version, examples run but remove some ununsed imports
a-paulus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import diffcp | ||
import utils | ||
import IPython as ipy | ||
import time | ||
import numpy as np | ||
|
||
m = 100 | ||
n = 50 | ||
|
||
batch_size = 16 | ||
n_jobs = 1 | ||
|
||
As, bs, cs, Ks = [], [], [], [] | ||
for _ in range(batch_size): | ||
A, b, c, K = diffcp.utils.least_squares_eq_scs_data(m, n) | ||
As += [A] | ||
bs += [b] | ||
cs += [c] | ||
Ks += [K] | ||
|
||
|
||
def time_function(f, N=1): | ||
result = [] | ||
for i in range(N): | ||
tic = time.time() | ||
f() | ||
toc = time.time() | ||
result += [toc - tic] | ||
return np.mean(result), np.std(result) | ||
|
||
for n_jobs in range(1, 8): | ||
def f_forward(): | ||
return diffcp.solve_and_derivative_batch(As, bs, cs, Ks, | ||
n_jobs_forward=n_jobs, n_jobs_backward=n_jobs, solve_method="ECOS", verbose=False, | ||
mode="lpgd", derivative_kwargs=dict(tau=1e-3, rho=0.0)) | ||
xs, ys, ss, D_batch, DT_batch = diffcp.solve_and_derivative_batch(As, bs, cs, Ks, | ||
n_jobs_forward=1, n_jobs_backward=n_jobs, solve_method="ECOS", verbose=False, | ||
mode="lpgd", derivative_kwargs=dict(tau=1e-3, rho=0.0)) | ||
|
||
def f_backward(): | ||
DT_batch(xs, ys, ss) | ||
|
||
mean_forward, std_forward = time_function(f_forward) | ||
mean_backward, std_backward = time_function(f_backward) | ||
print("%03d | %4.4f +/- %2.2f | %4.4f +/- %2.2f" % | ||
(n_jobs, mean_forward, std_forward, mean_backward, std_backward)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import diffcp | ||
import utils | ||
import IPython as ipy | ||
import time | ||
import numpy as np | ||
|
||
m = 100 | ||
n = 50 | ||
|
||
batch_size = 16 | ||
n_jobs = 1 | ||
|
||
As, bs, cs, Ks = [], [], [], [] | ||
for _ in range(batch_size): | ||
A, b, c, K = diffcp.utils.least_squares_eq_scs_data(m, n) | ||
As += [A] | ||
bs += [b] | ||
cs += [c] | ||
Ks += [K] | ||
|
||
def time_function(f, N=1): | ||
result = [] | ||
for i in range(N): | ||
tic = time.time() | ||
f() | ||
toc = time.time() | ||
result += [toc-tic] | ||
return np.mean(result), np.std(result) | ||
|
||
for n_jobs in range(1, 5): | ||
def f_forward(): | ||
return diffcp.solve_and_derivative_batch(As, bs, cs, Ks, | ||
n_jobs_forward=n_jobs, n_jobs_backward=n_jobs) | ||
xs, ys, ss, D_batch, DT_batch = diffcp.solve_and_derivative_batch(As, bs, cs, Ks, | ||
n_jobs_forward=1, n_jobs_backward=n_jobs, mode='lpgd_left') | ||
def f_backward(): | ||
DT_batch(xs, ys, ss, tau=0.1, rho=0.1) | ||
|
||
mean_forward, std_forward = time_function(f_forward) | ||
mean_backward, std_backward = time_function(f_backward) | ||
print ("%03d | %4.4f +/- %2.2f | %4.4f +/- %2.2f" % | ||
(n_jobs, mean_forward, std_forward, mean_backward, std_backward)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import diffcp | ||
|
||
import numpy as np | ||
import utils | ||
np.set_printoptions(precision=5, suppress=True) | ||
|
||
|
||
# We generate a random cone program with a cone | ||
# defined as a product of a 3-d fixed cone, 3-d positive orthant cone, | ||
# and a 5-d second order cone. | ||
K = { | ||
'z': 3, | ||
'l': 3, | ||
'q': [5] | ||
} | ||
|
||
m = 3 + 3 + 5 | ||
n = 5 | ||
|
||
np.random.seed(0) | ||
|
||
A, b, c = utils.random_cone_prog(m, n, K) | ||
|
||
# We solve the cone program and get the derivative and its adjoint | ||
x, y, s, derivative, adjoint_derivative = diffcp.solve_and_derivative( | ||
A, b, c, K, eps=1e-10, mode="lpgd", derivative_kwargs=dict(tau=1e-3, rho=0.1)) | ||
|
||
print("x =", x) | ||
print("y =", y) | ||
print("s =", s) | ||
|
||
# We evaluate the gradient of the objective with respect to A, b and c. | ||
dA, db, dc = adjoint_derivative(c, np.zeros(m), np.zeros(m)) | ||
|
||
# The gradient of the objective with respect to b should be | ||
# equal to minus the dual variable y (see, e.g., page 268 of Convex Optimization by | ||
# Boyd & Vandenberghe). | ||
print("db =", db) | ||
print("-y =", -y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import diffcp | ||
|
||
import numpy as np | ||
import utils | ||
np.set_printoptions(precision=5, suppress=True) | ||
|
||
|
||
# We generate a random cone program with a cone | ||
# defined as a product of a 3-d fixed cone, 3-d positive orthant cone, | ||
PTNobel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# and a 5-d second order cone. | ||
K = { | ||
'z': 3, | ||
'l': 3, | ||
'q': [5] | ||
} | ||
|
||
m = 3 + 3 + 5 | ||
n = 5 | ||
|
||
np.random.seed(0) | ||
|
||
A, b, c = utils.random_cone_prog(m, n, K) | ||
|
||
# We solve the cone program and get the derivative and its adjoint | ||
x, y, s, derivative, adjoint_derivative = diffcp.solve_and_derivative( | ||
A, b, c, K, solve_method="ECOS", verbose=False, mode="lpgd", derivative_kwargs=dict(tau=0.1, rho=0.0)) | ||
|
||
print("x =", x) | ||
print("y =", y) | ||
print("s =", s) | ||
|
||
# We evaluate the gradient of the objective with respect to A, b and c. | ||
dA, db, dc = adjoint_derivative(c, np.zeros(m), np.zeros(m)) | ||
|
||
# The gradient of the objective with respect to b should be | ||
# equal to minus the dual variable y (see, e.g., page 268 of Convex Optimization by | ||
# Boyd & Vandenberghe). | ||
print("db =", db) | ||
print("-y =", -y) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.