Skip to content

Conversation

@kdorheim
Copy link
Contributor

This PR addresses a rounding issue that is only relevant to the CSV output stream & addresses an inline TODO item related to the csvouput stream visitor.

The Problem

While working on #795, I realized that there were some numerical differences between Hector results written out by the CSV output stream visitor vs. fetched via R.

When we compare the numerical results from hector output via R vs. csv outputter the overall summary table absolute error (this is across multiple scenarios & variables)

Min 1 IQR Median Mean 3 IQR Max
0 0 0.000018 0.081499 0.003465 4.999791


Of the 80 variables considered 57 of them had a MAE > 1E-6

Looking at the variable with the largest error, DO ocean C, while the relative MAE of 4.999791. A visual comparison of DO ocean C reveals a step like behavior in the csv result which seems odd and is most likely due to rounding.

Screenshot 2025-12-31 at 8 48 53 AM

Same data but different perspective.

Screenshot 2025-12-31 at 8 50 07 AM

the solution

It turns out the csvFile has a default precision level of 6 whereas typical C++ double precision is 16. Since R was pulling directly from the C++ precision level we needed to make sure that the csvFile was using the same precision level.

After changing the precision level of the csvFile the MAE between R and the csv output the MAE is now 1.035752e-13. Which is much better! And now no longer see the step behavior we were seeing before.

Screenshot 2025-12-31 at 8 52 57 AM

@kdorheim kdorheim requested a review from bpbond December 31, 2025 13:54
Copy link
Member

@bpbond bpbond left a comment

Choose a reason for hiding this comment

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

Question -- do we want to be constantly changing the precision of the stream?

if (!core->outputEnabled(c->getComponentName()))
return;
streamsize oldPrecision = csvFile.precision(4);
csvFile.precision(15);
Copy link
Member

Choose a reason for hiding this comment

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

Why do this at all here? Should we simply set the precision we want when the stream is opened and leave it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh good point! so would that be in the main.cpp file? where the stream is opened? Or part of the CSVOutputStreamVisitor constructor?

Copy link
Member

Choose a reason for hiding this comment

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

In the class constructor.

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