-
Notifications
You must be signed in to change notification settings - Fork 25
[Math] Add least squares method #1591
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
DavidFang03
wants to merge
37
commits into
Shamrock-code:main
Choose a base branch
from
DavidFang03:math_for_tillotson
base: main
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 all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
47bc414
add Euler method
DavidFang03 db367cf
add Cholesky decomposition
DavidFang03 c9dd6fd
add Cholesky solving
DavidFang03 04d385c
oops
DavidFang03 c13398a
typo
DavidFang03 979b3e5
add matrix tranpose
DavidFang03 e7468f3
add vec_update_vals
DavidFang03 594076f
whoops
DavidFang03 9487349
reshape
DavidFang03 39d0094
add dynamic matrices when dimensions are known at runtime
DavidFang03 a10b2d7
add least squares
DavidFang03 b6a165a
authorship
DavidFang03 5e31c24
Merge remote-tracking branch 'upstream/main' into math_for_tillotson
DavidFang03 1c42e54
fixes
DavidFang03 9ce02cd
fix
DavidFang03 3e6e72f
add tolerance on sse for convergence criteria in least_squares
DavidFang03 247e17d
fix
DavidFang03 33629bd
least_squares now also returns R^2
DavidFang03 002ea61
one last thing
DavidFang03 ee1090f
typos
DavidFang03 5e6c1ca
the number of observations needs to be greater than the number of par…
DavidFang03 2d7614b
doxygen
DavidFang03 90d5570
remove magic numbers
DavidFang03 e4d071f
== overload constant
DavidFang03 0ebcc10
std::sqrt instead of sycl::sqrt
DavidFang03 cd3fd51
Merge remote-tracking branch 'upstream/main' into math_for_tillotson
DavidFang03 49fdfb6
last assert
DavidFang03 ef2f577
revert useless change
DavidFang03 087764a
remove last doxygen warnings
DavidFang03 d2cbdd1
Merge remote-tracking branch 'upstream/main' into math_for_tillotson
DavidFang03 e5122ac
Merge remote-tracking branch 'upstream/main' into math_for_tillotson
DavidFang03 65187ce
fixes
DavidFang03 fa09329
doxygen typo
DavidFang03 d6fe7bd
improve doxygen
DavidFang03 e94cf79
tuple to pair
DavidFang03 638e268
minor improvements
DavidFang03 659e8fd
add test for least_squares
DavidFang03 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
|
|
||
| /** | ||
| * @file integrator.hpp | ||
| * @author David Fang (david.fang@ikmail.com) | ||
| * @author Timothée David--Cléris (tim.shamrock@proton.me) | ||
| * @brief | ||
| * | ||
|
|
@@ -30,4 +31,47 @@ namespace shammath { | |
| return acc; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Euler solving of ODE | ||
| * The ode has the form | ||
| * \f{eqnarray*}{ | ||
| * u'(x) &=& f(u,x) \\ | ||
| * u(x_0) &=& u_0 | ||
| * \f} | ||
| * and will be solved between start and end with step \f$ \mathrm{d}t \f$. | ||
| * | ||
| * @param start Lower bound of integration | ||
| * @param end Higher bound of integration | ||
| * @param step Step of integration \f$ \mathrm{d}t \f$ | ||
| * @param ode Ode function \f$ f \f$ | ||
| * @param x0 Initial coordinate \f$ x_0 \f$ | ||
| * @param u0 Initial value \f$ u_0 \f$ | ||
| */ | ||
| template<class T, class Lambda> | ||
| inline constexpr std::pair<std::vector<T>, std::vector<T>> euler_ode( | ||
| T start, T end, T step, Lambda &&ode, T x0, T u0) { | ||
| std::vector<T> U = {u0}; | ||
| std::vector<T> X = {x0}; | ||
|
|
||
| T u_prev = u0; | ||
| T u = u0; | ||
| for (T x = x0 + step; x < end; x += step) { | ||
| u = u_prev + ode(u_prev, x) * step; | ||
| X.push_back(x); | ||
| U.push_back(u); | ||
| u_prev = u; | ||
| }; | ||
| u_prev = u0; | ||
| std::vector<T> X_backward, U_backward; | ||
| for (T x = x0 - step; x > start; x -= step) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| u = u_prev - ode(u_prev, x) * step; | ||
| X_backward.push_back(x); | ||
| U_backward.push_back(u); | ||
| u_prev = u; | ||
| } | ||
| X.insert(X.begin(), X_backward.rbegin(), X_backward.rend()); | ||
| U.insert(U.begin(), U_backward.rbegin(), U_backward.rend()); | ||
| return {X, U}; | ||
| } | ||
|
|
||
| } // namespace shammath | ||
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using floating-point numbers directly in loop conditions like
x < endcan lead to precision issues, potentially causing the loop to terminate one step early or run one step too long due to accumulated floating-point errors. It's generally safer to iterate a fixed number of times or use a small epsilon for comparison, e.g.,x < end - std::numeric_limits<T>::epsilon() * std::abs(end) * Nwhere N is the number of steps.