clusterphobia | Unassisted clustering algorithms and data | Machine Learning library
kandi X-RAY | clusterphobia Summary
kandi X-RAY | clusterphobia Summary
This crate is based on ideas and algorithms originally developed in C# in this repository:.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of clusterphobia
clusterphobia Key Features
clusterphobia Examples and Code Snippets
Community Discussions
Trending Discussions on clusterphobia
QUESTION
I have implemented an approximate natural log function based on a Padé Approximation of a truncated Taylor Series. The accuracy is acceptable (±0.000025) but despite several rounds of optimizations, its exec time is still about 2.5x that of the standard library ln
function! If it isn't faster and it isn't as accurate, it is worthless! Nevertheless, I am using this as a way to learn how to optimize my Rust code. (My timings come from using the criterion
crate. I used blackbox, summed the values in the loop and created a string from the result to defeat the optimizer.)
On Rust Playground, my code is:
AlgorithmAn overview of my algorithm, which works on a ratio of unsigned integers:
- Range reduction to the interval [1, 2] by dividing by the largest power of two not exceeding the value:
- Change representation of numerator →
2ⁿ·N where 1 ≤ N ≤ 2
- Change representation of denominator →
2ᵈ·D where 1 ≤ D ≤ 2
- Change representation of numerator →
- This makes the result
log(numerator/denominator) = log(2ⁿ·N / 2ᵈ·D) = (n-d)·log(2) + log(N) - log(D)
- To perform log(N), Taylor series does not converge in the neighborhood of zero, but it does near one...
- ... since N is near one, substitute x = N - 1 so that we now need to evaluate log(1 + x)
- Perform a substitution of
y = x/(2+x)
- Consider the related function
f(y) = Log((1+y)/(1-y))
= Log((1 + x/(2+x)) / (1 - x/(2+x)))
= Log( (2+2x) / 2)
= Log(1 + x)
- f(y) has a Taylor Expansion which converges must faster than the expansion for Log(1+x) ...
- For Log(1+x) →
x - x²/2 + x³/3 - y⁴/4 + ...
- For Log((1+y)/(1-y)) →
y + y³/3 + y⁵/5 + ...
- For Log(1+x) →
- Use the Padé Approximation for the truncated series
y + y³/3 + y⁵/5 ...
- ... Which is
2y·(15 - 4y²)/(15 - 9y²)
- Repeat for the denominator and combine the results.
Here is the Padé Approximation part of the code:
...ANSWER
Answered 2019-Dec-06 at 15:22A single optimization cut the time in half!
I rewrote my msb (most significant bit) function to use the library function u64::leading_zeroes
that internally uses intrinsics:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install clusterphobia
Rust is installed and managed by the rustup tool. Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time. Please refer rust-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page