Skip to content
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

Add Rounding to Fix Numeric Error in LinearLeastSquaresFit #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jhazentia
Copy link
Member

@jhazentia jhazentia commented Nov 21, 2024

Fixes #21

This issue is fixed by adding rounding to fix the numeric error in LinearLeastSquaresFit.

Examples of numeric error and rounding correction in LinearLeastSquaresFit are below
(values observed debugging in // comments). The examples include "_r" variables
to observe the rounding fix.

Case 1:

Windows PFL:
d_start / pfl[1] // 1490.9999999999491
int(d_start / pfl[1]) // 1490
int i_start = int(fdim(d_start / pfl[1], 0.0)); // 1490
int i_start_r = int(round(fdim(d_start / pfl[1], 0.0))); // 1491
d_end / pfl[1] // 1498.9999999999945
int(np - (np - (d_end / pfl[1]))) // 1498
int i_end = np - int(fdim(np, d_end / pfl[1])); // 1499
int i_end_r = np - int(round(fdim(np, d_end / pfl[1]))); // 1499

Linux PFL:
d_start / pfl[1] // 1491.0000000000146
int(d_start / pfl[1]) // 1491
int i_start = int(fdim(d_start / pfl[1], 0.0)); // 1491
int i_start_r = int(round(fdim(d_start / pfl[1], 0.0))); // 1491
d_end / pfl[1] // 1499.0000000000018
int(np - (np - (d_end / pfl[1]))) // 1499
int i_end = np - int(fdim(np, d_end / pfl[1])); // 1500
int i_end_r = np - int(round(fdim(np, d_end / pfl[1]))); // 1499

Case 2:

Windows PFL:
d_start / pfl[1] // 1056.9999999999991
int(d_start / pfl[1]) // 1056
int i_start = int(fdim(d_start / pfl[1], 0.0)); // 1056
int i_start_r = int(round(fdim(d_start / pfl[1], 0.0))); // 1057
d_end / pfl[1] // 1064.9999999999998
int(np - (np - (d_end / pfl[1]))) // 1064
int i_end = np - int(fdim(np, d_end / pfl[1])); // 1065
int i_end_r = np - int(round(fdim(np, d_end / pfl[1]))); // 1065

Linux PFL:
d_start / pfl[1] // 1057.0000000000084
int(d_start / pfl[1]) // 1057
int i_start = int(fdim(d_start / pfl[1], 0.0)); // 1057
int i_start_r = int(round(fdim(d_start / pfl[1], 0.0))); // 1057
d_end / pfl[1] // 1065.0000000000009
int(np - (np - (d_end / pfl[1]))) // 1065
int i_end = np - int(fdim(np, d_end / pfl[1])); // 1066
int i_end_r = np - int(round(fdim(np, d_end / pfl[1]))); // 1065

Here are output files after applying the fix for the 2 cases in original issue, showing matching results:
case_1_itm_command_output_linux_pfl.txt
case_1_itm_command_output_windows_pfl.txt
case_2_itm_command_output_linux_pfl.txt
case_2_itm_command_output_windows_pfl.txt

@jhazentia jhazentia marked this pull request as ready for review November 21, 2024 20:57
@aromanielloNTIA aromanielloNTIA self-requested a review November 21, 2024 21:05
Copy link
Member

@aromanielloNTIA aromanielloNTIA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for identifying and fixing this issue. Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent Path Loss with Minor Terrain Differences
2 participants