-
Notifications
You must be signed in to change notification settings - Fork 198
Equality-constrained least-squares solver #1046
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
loiseaujc
wants to merge
17
commits into
fortran-lang:master
Choose a base branch
from
loiseaujc:1044-constrained-least-squares-solver
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 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1e02559
Interfaces for the constrained lstsq solver.
loiseaujc a8873d9
Info handling function for gglse.
loiseaujc 728d221
Compilable implementation.
loiseaujc 36c17fb
Working implementation of constrained lstsq.
loiseaujc fc54644
Added test for constrained lstsq.
loiseaujc 9582df2
In-code documentation.
loiseaujc ddc0f0d
Bug fix.
loiseaujc b306f91
Added examples.
loiseaujc ed45fb5
Specs for constrained_lstsq
loiseaujc 816d29e
Specs for solve_constrained_lstsq
loiseaujc e9d10f0
All specs + minor modifs.
loiseaujc f0add5a
Added links to the correct specs section.
loiseaujc 5d53fe8
Update doc/specs/stdlib_linalg.md
loiseaujc c43044a
Update src/stdlib_linalg.fypp
loiseaujc ef6dee6
Update test/linalg/test_linalg_constrained_lstsq.fypp
loiseaujc 5add961
Update src/stdlib_linalg.fypp
loiseaujc fbb198e
Update doc/specs/stdlib_linalg.md
loiseaujc 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
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,40 @@ | ||
| ! Constrained least-squares solver: functional interface | ||
| program example_constrained_lstsq1 | ||
| use stdlib_linalg_constants, only: dp | ||
| use stdlib_linalg, only: constrained_lstsq | ||
| implicit none | ||
| integer, parameter :: m = 5, n = 4, p = 3 | ||
| !> Least-squares cost. | ||
| real(dp) :: A(m, n), b(m) | ||
| !> Equality constraints. | ||
| real(dp) :: C(p, n), d(p) | ||
| !> Solution. | ||
| real(dp) :: x(n), x_true(n) | ||
|
|
||
| !> Least-squares cost. | ||
| A(1, :) = [1.0_dp, 1.0_dp, 1.0_dp, 1.0_dp] | ||
| A(2, :) = [1.0_dp, 3.0_dp, 1.0_dp, 1.0_dp] | ||
| A(3, :) = [1.0_dp, -1.0_dp, 3.0_dp, 1.0_dp] | ||
| A(4, :) = [1.0_dp, 1.0_dp, 1.0_dp, 3.0_dp] | ||
| A(5, :) = [1.0_dp, 1.0_dp, 1.0_dp, -1.0_dp] | ||
|
|
||
| b = [2.0_dp, 1.0_dp, 6.0_dp, 3.0_dp, 1.0_dp] | ||
|
|
||
| !> Equality constraints. | ||
| C(1, :) = [1.0_dp, 1.0_dp, 1.0_dp, -1.0_dp] | ||
| C(2, :) = [1.0_dp, -1.0_dp, 1.0_dp, 1.0_dp] | ||
| C(3, :) = [1.0_dp, 1.0_dp, -1.0_dp, 1.0_dp] | ||
|
|
||
| d = [1.0_dp, 3.0_dp, -1.0_dp] | ||
|
|
||
| ! Compute the solution. | ||
| x = constrained_lstsq(A, b, C, d) | ||
| x_true = [0.5_dp, -0.5_dp, 1.5_dp, 0.5_dp] | ||
|
|
||
| print *, "Exact solution :" | ||
| print *, x_true | ||
| print * | ||
| print *, "Computed solution :" | ||
| print *, x | ||
|
|
||
| end program example_constrained_lstsq1 |
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,48 @@ | ||
| ! Demonstrate expert subroutine interface with pre-allocated arrays | ||
| program example_constrained_lstsq2 | ||
| use stdlib_linalg_constants, only: dp | ||
| use stdlib_linalg, only: solve_constrained_lstsq, constrained_lstsq_space | ||
| implicit none | ||
| integer, parameter :: m = 5, n = 4, p = 3 | ||
| !> Least-squares cost. | ||
| real(dp) :: A(m, n), b(m) | ||
| !> Equality constraints. | ||
| real(dp) :: C(p, n), d(p) | ||
| !> Solution. | ||
| real(dp) :: x(n), x_true(n) | ||
| !> Workspace array. | ||
| integer :: lwork | ||
| real(dp), allocatable :: work(:) | ||
|
|
||
| !> Least-squares cost. | ||
| A(1, :) = [1.0_dp, 1.0_dp, 1.0_dp, 1.0_dp] | ||
| A(2, :) = [1.0_dp, 3.0_dp, 1.0_dp, 1.0_dp] | ||
| A(3, :) = [1.0_dp, -1.0_dp, 3.0_dp, 1.0_dp] | ||
| A(4, :) = [1.0_dp, 1.0_dp, 1.0_dp, 3.0_dp] | ||
| A(5, :) = [1.0_dp, 1.0_dp, 1.0_dp, -1.0_dp] | ||
|
|
||
| b = [2.0_dp, 1.0_dp, 6.0_dp, 3.0_dp, 1.0_dp] | ||
|
|
||
| !> Equality constraints. | ||
| C(1, :) = [1.0_dp, 1.0_dp, 1.0_dp, -1.0_dp] | ||
| C(2, :) = [1.0_dp, -1.0_dp, 1.0_dp, 1.0_dp] | ||
| C(3, :) = [1.0_dp, 1.0_dp, -1.0_dp, 1.0_dp] | ||
|
|
||
| d = [1.0_dp, 3.0_dp, -1.0_dp] | ||
|
|
||
| !> Optimal workspace size. | ||
| call constrained_lstsq_space(A, C, lwork) | ||
| allocate (work(lwork)) | ||
|
|
||
| ! Compute the solution. | ||
| call solve_constrained_lstsq(A, b, C, d, x, & | ||
| storage=work, & | ||
| overwrite_matrices=.true.) | ||
| x_true = [0.5_dp, -0.5_dp, 1.5_dp, 0.5_dp] | ||
|
|
||
| print *, "Exact solution :" | ||
| print *, x_true | ||
| print * | ||
| print *, "Computed solution :" | ||
| print *, x | ||
| end program example_constrained_lstsq2 |
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
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.