-
Notifications
You must be signed in to change notification settings - Fork 0
Implemented data-driven testing for dist, related fixes and docs
#19
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
Conversation
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
1. Dependencies:
- Added submodule `github.com:ALFI-library/test_data` to `tests/test_data`,
containing the `dist/dist.toml` file with test data for distributions.
- Added submodule `github.com:marzer/tomlplusplus` to `tests/deps/toml++`,
containing a header-only library for TOML processing.
- In `helper.py`:
- Added `git submodule update --init` to dependency install commands.
- In connection, added `git` to the list of dependencies installed by `apt`.
- Added `submodules: true` to `actions/checkout` in `.github/workflows/*.yml` files.
2. Testing:
- Added distribution function testing using data from the TOML file:
- Updated `tests/CMakeLists.txt` to reflect changes.
- Included `toml++/toml.hpp` in `tests/test_utils.h`.
- Added helper function `to_vector` to `tests/test_utils.h`,
converting `toml::array` to `std::vector`.
- Rewrote `tests/dist/test_dist.cpp` to read TOML data
and use it for testing all distribution functions.
- Removed legacy testing code.
3. New files:
- Added `ALFI/ALFI/util/points.h` containing:
- Functions `lin_map` and `lin_mapped` for mapping points between intervals.
- Functions `stretch` (moved from `ALFI/ALFI/dist.h`) and `stretched`.
4. Fixes:
- In `expect_eq` function in `tests/test_utils.h`:
replaced `EXPECT_NEAR` with `EXPECT_TRUE` and `alfi::util::numeric::are_equal`.
- Revised functions in `alfi::dist` namespace
(`sigmoid`, `sigmoid_stretched`, `erf`, `erf_stretched`)
to improve logical consistency and return values closer to interval boundaries.
- Fixed the `stretch` function:
- Previously subtracted `(a+b)/2` instead of `(min+max)/2`.
- Now implemented via `lin_map`.
- NOTE: Test results show this **significantly** reduces precision
for all `_stretched` functions in `alfi::dist`.
5. Documentation:
- Added descriptions for `alfi::dist::sigmoid` and `alfi::dist::erf`.
dist, related fixes and docs
pasabanov
commented
Jan 26, 2025
| const auto mid2 = (c + d) / 2; | ||
| const auto scale = (d - c) / (b - a); | ||
| for (auto& point : points) { | ||
| point = mid2 + scale * (point - mid1); |
Member
Author
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.
It's unclear whether the mapping should be based on the beginning or the middle of the segment, or if some hybrid approach should be used.
- Which way would be more accurate?
- How does this affect the fact that the points in the library are symmetrical relative to the midpoints of the segments?
This was referenced Jan 23, 2025
This was referenced Feb 3, 2025
Merged
This was referenced Mar 26, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Types of changes
Related: #1 #4 #15 #17 ALFI-lib/test_data#1
Description
1. Dependencies:
github.com:ALFI-library/test_datatotests/test_data, containing a TOML file with test data for distributions.github.com:marzer/tomlplusplustotests/deps/toml++, containing a header-only library for TOML processing.helper.py:git submodule update --initto dependency install commands.gitto the list of dependencies installed byapt.submodules: truetoactions/checkoutin.github/workflows/*.ymlfiles.2. Testing:
tests/CMakeLists.txtto reflect changes.toml++/toml.hppintests/test_utils.h.to_vectortotests/test_utils.h, convertingtoml::arraytostd::vector.tests/dist/test_dist.cppto read TOML data and use it for testing all distribution functions.3. New files:
ALFI/ALFI/util/points.hcontaining:lin_mapandlin_mappedfor mapping points between intervals.stretch(moved fromALFI/ALFI/dist.h) andstretched.4. Fixes:
expect_eqfunction intests/test_utils.h: replacedEXPECT_NEARwithEXPECT_TRUEandalfi::util::numeric::are_equal.alfi::distnamespace (sigmoid,sigmoid_stretched,erf,erf_stretched) to improve logical consistency and return values closer to interval boundaries.stretchfunction:(a+b)/2instead of(min+max)/2.lin_map._stretchedfunctions inalfi::dist.5. Documentation:
alfi::dist::sigmoidandalfi::dist::erf.*), tab-indented descriptions - for readability and space efficiency.Screenshots, demonstrating the differences between the unfixed and fixed versions of the
sigmoid,sigmoid_stretched,erfanderf_stretchedfunctions:Motivation
Why TOML-based testing? This approach was chosen to:
Isolating test data as a separate entity allows seamless reuse across potential future ports (Python, JavaScript, GNU Octave, etc.), avoiding duplication.
Test datasets can be programmatically generated and verified.
Declarative format provides human-readable test cases.
TOML was chosen over YAML/JSON for its simple and whitespace-agnostic syntax.
How to test
Tests now require submodules to run. To download the submodules one may use the following approaches:
--recurse-submodulesoption:git clone --recurse-submodules https://github.com/ALFI-library/ALFI # or git clone --recurse-submodules git@github.com:ALFI-library/ALFIhelper.pyutility to update all the dependencies, includingaptdependencies (requiressudo!) and the submodules:helper.py -d # or helper.py --depsFuture improvements
_stretchedfunctions inalfi::distafter thestretchfunction fix.lin_mapfunction.