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

getmodel: decreased accuracy of prob due to untimely conversion from float32 to float64 #396

Open
FangWeihua opened this issue Oct 30, 2024 · 0 comments

Comments

@FangWeihua
Copy link

FangWeihua commented Oct 30, 2024

Issue Description

When computing cdf by using getmodel (compiling option: typedef float OASIS_FLOA), the accuracy of prob may decease, due to untimely conversion from float32 to float64.

Steps to Reproduce

  1. In getmodel.cpp (line 49-350), 'prob' is calculated as,
prob += vulnerability[getVulnerabilityIndex(i.first, damage_bin_index)] *
                                         i.second;

The data types of vulnerability[getVulnerabilityIndex(i.first, damage_bin_index)] and i.second are both float32. And the data type of 'prob' is float64. This may lead to slight data accuracy decrease.

  1. Accuracy can be improved by converting float32 to float64 first, as follows,
prob + = static_cast<double>(vulnerability[getVulnerabilityIndex(i.first, damage_bin_index)]) *
                static_cast<double>(i.second);

Version / Environment information

ktools v3.12.4
typedef float OASIS_FLOAT

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

No branches or pull requests

1 participant