Comments (7)
I agree that the original form of the issue report was not very productive, but the underlying criticism is sound — toFixed
should be used only for formatting, not for numeric operations. In this case it's better not only as a potential micro-optimization, but also for consistency, since the table values are rounded numerically (with Math.round(1e4 * value) / 1e4
):
simple-statistics/src/standard_normal_table.js
Lines 12 to 15 in b4a9c78
from simple-statistics.
So, the lines are:
simple-statistics/src/cumulative_std_normal_probability.js
Lines 29 to 39 in b4a9c78
There's an explanatory comment explaining why, in this method that's trying to return things with 4 significant figures, it uses .toFixed.
And, the expression +(1 - standardNormalTable[index]).toFixed(4);
does not return a string. Does it for you, or was that an assumption?
from simple-statistics.
from simple-statistics.
It's a normal distribution table, which has either four or five digits of precision, in this case, four.
Converting to a string and back is not a costly conversion, relative to virtually everything else. If that's actually a bottleneck in your application, that'd be surprising, but if it is based on a profile, and you have a faster technique, I'm more than happy to merge a pull request to limit significant digits in a faster way.
from simple-statistics.
from simple-statistics.
Okay, I'm happy to accept a PR if you want to write one, to improve performance here. I will say - I'm specifically talking about identifying toFixed as a bottleneck in a real-world program. Microbenchmarks can identify differences between Math.round versus the ~~
bit-twiddling hack, but 98% of those who care about that, including me in a previous iteration, are wrong to focus on it - the difference never rises to 1% of total-application performance budget, and usually gets optimized away once some V8 engineer decides to make Math.random or toFixed or etc faster.
I will say, I'm really happy to discuss this stuff, but in the future - this discussion started with an incorrect assumption based on a misreading of the code, led to a question answered by a comment in the code, and now is about microbenchmarking. It would be certainly nicer and more productive to have fewer assumptions and a generally more collaborative intent.
from simple-statistics.
from simple-statistics.
Related Issues (20)
- Provide function for binning one-dimensional data HOT 8
- Error in linearRegresson HOT 2
- Docs link is broken
- ckmeans is not O(kn log(n))? HOT 1
- Do we have "Coefficient of Variation" function ? HOT 3
- Exports section of the package.json may need to be updated HOT 4
- cdnjs missing simple-statistics > 2.0.0-beta2 HOT 2
- Is there a way to efficiently calculate Skewness and Kurtosis of data having value with repetitions ? HOT 1
- What would the equivalent of NORM.DIST be? HOT 3
- datapoint labels HOT 2
- mean() evaluates nulls as zeros in calculation HOT 2
- Make simple-statistics available as a deno module? HOT 2
- Explicit type-checking HOT 2
- Bring back Jenks HOT 2
- add missing TypeScript typing for sampleRankCorrelation HOT 1
- coefficientOfVariation
- Unexpected results for multiple quantiles HOT 1
- document the revived `ss.jenks`?
- PerceptronModel Typing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-statistics.