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

Reworking of the ObserverTimeEvolution #511

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

JanNiklasB
Copy link

@JanNiklasB JanNiklasB commented Dec 19, 2024

Dear All,

in this pull request, I want to introduce a reworked ObserverTimeEvolution.
I replaced the addTimeRange function which filled the detList array with a function
that takes the required index as an argument and returns the time that should be observed.
For that, I also changed other parts of the ObserverTimeEvolution class to
correctly utilize that new getTime function.
I also kept the option of using a detList by utilizing a new constructor.
Furthermore, it is possible to use a user-defined getTime function by utilizing
the setUserDefinedGetTime function.

Additionally, I fixed the issue mentioned in #510.
For that, it was necessary to change some tests, since those handled
the maximum observed time like max = numb * dist when it should
be handled like max = min + numb * dist.

@lukasmerten lukasmerten self-assigned this Jan 9, 2025
Jan-Niklas Bohnensack added 4 commits March 4, 2025 01:08
- fixed wrong scaling in constructor
- fixed unexpected behavior in getTimes
- added more detailed documentation
- replaced customGetTime with virtual on getTime since it is only used inside c++
- modified Test for checkDetection
- added Test for behavior with arrays instead of getTime function
- added clear and empty function
 - further fixed a floating point issue in testBreakCondition
@JanNiklasB
Copy link
Author

After discussing pull request with @JulienDoerner, I added setter and getter functions as well as some older functions that I previously removed to preserve compatibility.

  • The ObserverTimeEvolution now creates the protected vector detList when calling any functions that require detList like addTime or addTimeRange.
  • Futhermore, function to edit detList more freely like clear and setTimes were added.
  • Since it is only necessary to use custom functions inside of c++, the override of the getTime can now be done directly by overriding the virtual function getTime.
  • I added tests to testBreakCondition where the behavior of the arrays is tested in more detail.

For a more detailed description of the single changes, see the comments.

@@ -240,52 +240,119 @@ class ObserverParticleIdVeto: public ObserverFeature {
This observer is very useful if the time evolution of the particle density is needed. It detects all candidates in lin-spaced, log-spaced, or user-defined time intervals and limits the nextStep of candidates to prevent overshooting of detection intervals.
*/
class ObserverTimeEvolution: public ObserverFeature {
private:
protected:
Copy link
Author

Choose a reason for hiding this comment

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

changed private to protected, so the variables can be accessed in derived classes

Use this function to create a detList with can then be modified.
When detList is not empty its entries are used instead of a runtime calculation of the times.
*/
void constructDetListIfEmpty();
Copy link
Author

Choose a reason for hiding this comment

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

this function enables the user to manually construct detList

@@ -246,7 +246,7 @@ std::string ObserverParticleIdVeto::getDescription() const {
ObserverTimeEvolution::ObserverTimeEvolution() {}

ObserverTimeEvolution::ObserverTimeEvolution(double min, double dist, double numb) {
this->max = min + numb * dist;
this->max = min + (numb - 1) * dist;
Copy link
Author

Choose a reason for hiding this comment

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

fixes the original bug, where the last time to observe was too large because of this

times = {1, 1000};
times.clear();
for (int i=0; i<4; i++)
times.push_back(pow(1000., i / 3.));
Copy link
Author

Choose a reason for hiding this comment

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

pow(1000, 2/3) does not exactly return 100 which caused a wrong negative in line 345

Copy link
Member

Choose a reason for hiding this comment

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

maybe you can check for EXPECT_NEAR with some small errorband.

EXPECT_TRUE(c.hasProperty("Detected"));
}

TEST(ObserverFeature, TimeEvolutionArray) {
Copy link
Author

Choose a reason for hiding this comment

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

This test checks if detList is created and used correctly when using the modifying functions.

Copy link
Member

@JulienDoerner JulienDoerner left a comment

Choose a reason for hiding this comment

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

Hey @JanNiklasB,

the overall changes look good for me and it improves the usability for non-uniform observations.
I left some comments about code style (see below).

And can you please add your changes to the CHANGELOG.md.

@@ -240,8 +240,22 @@ class ObserverParticleIdVeto: public ObserverFeature {
This observer is very useful if the time evolution of the particle density is needed. It detects all candidates in lin-spaced, log-spaced, or user-defined time intervals and limits the nextStep of candidates to prevent overshooting of detection intervals.
*/
class ObserverTimeEvolution: public ObserverFeature {
private:
protected:
int numb;
Copy link
Member

Choose a reason for hiding this comment

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

In our coding style all variables should be given with full names. Therefore you should use number or nObservations instead. Also add an inline comment what this value us.

virtual double getTime(std::size_t index) const;
double getMin() const {return min;}
double getMax() const {return max;}
int getNumb() const {return numb;}
Copy link
Member

Choose a reason for hiding this comment

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

Use full names for functions

}

void ObserverTimeEvolution::addTimeRange(double min, double max, double numb, bool log) {
for (size_t i = 0; i < numb; i++) {
if (log == true) {
if (log) {
if ( min == 0 ){
Copy link
Member

Choose a reason for hiding this comment

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

Is it better to prove for min <= 0?

if (!detList.empty()) {
return detList.at(index);
} else if (islog) {
if ( min == 0 ){
Copy link
Member

Choose a reason for hiding this comment

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

Is it necessary to prove this in every getTime call, which is called in every propagation step? I guess a proof only in the setter functions would be enough.

Copy link
Author

Choose a reason for hiding this comment

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

right, if it is set right in the setter functions the check here would be unnecessary

@@ -273,37 +277,91 @@ TEST(ObserverFeature, TimeEvolutionLog) {
obs.setFlag("Detected", "Detected");
// usage of a log scaling for the observer
bool log = true;
obs.add(new ObserverTimeEvolution(5, 5, 2, log));
obs.add(new ObserverTimeEvolution(5, 10.05, 2, log));
Copy link
Member

Choose a reason for hiding this comment

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

Does this test really reflect the log-scaling? If it only has two points it would be the same in linear or log

Copy link
Author

Choose a reason for hiding this comment

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

right, it should at least test 3 points

times = {1, 1000};
times.clear();
for (int i=0; i<4; i++)
times.push_back(pow(1000., i / 3.));
Copy link
Member

Choose a reason for hiding this comment

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

maybe you can check for EXPECT_NEAR with some small errorband.

Jan-Niklas Bohnensack added 3 commits March 6, 2025 18:48
- Replaced EXPECT_TRUE with EXPECT_NEAR in TimeEvolutionArray
- all changes to variables now over setter functions
- valid range check for min if isLogarithmicScaling = true now in setMinimum
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.

3 participants