Code Monkey home page Code Monkey logo

Comments (2)

pyuxiang avatar pyuxiang commented on August 11, 2024

Comment by franciumxzf
Monday Feb 20, 2023 at 10:08 GMT
Originally commented as franciumxzf/fpfind#11 (comment)


Using dataset27 as an example, compare the results from method 1 and method 2:

print((1/(1+bob_freq)-1)) # 1.408126167778967e-05
print((-bob_freq)/(1 + bob_freq)) # 1.4081261677757226e-05
print(alice_freq) # 1.4081094847240294e-05

Notice that results from two expressions in method 1 are quite near, but much different from method 2. This is because the frequency convergency test in our pfind doesn't go to exact 1 but a float number very near to 1. In this dataset:

print((1 + alice_freq) * (1 + bob_freq)) # 0.9999999998331718

If we correct for this in method 1, compare the results:

print((0.9999999998331718/(1+bob_freq)-1)) # 1.4081094847240294e-05
print((0.9999999998331718-1-bob_freq)/(1 + bob_freq)) # 1.4081094847190168e-05
print(alice_freq) # 1.4081094847240294e-05

Now the first expression in method 1 gives the same value as method 2, while the second method lost some accuracy (but very small).

In summary, the major accuracy loss is from the near-1 result in the frequency convergency test. The loss from the calculation (multiplication /division of float number) is much less compare with it.

from fpfind.

pyuxiang avatar pyuxiang commented on August 11, 2024

Comment by franciumxzf
Monday Feb 20, 2023 at 10:16 GMT
Originally commented as franciumxzf/fpfind#11 (comment)


To illustrate more on the comparasion of accuracy loss between the two expressions in method 1, we can perform the following calculation:

import numpy as np

for bob_freq in np.geomspace(1e-5, 1e-10, 6):
    print((1/(1+bob_freq)-1))
    print((-bob_freq)/(1 + bob_freq))
    print()

# -9.999900001056439e-06
# -9.99990000099999e-06

# -9.99998999939855e-07
# -9.99999000001e-07

# -9.99999900663795e-08
# -9.999999000000099e-08

# -9.999999828202988e-09
# -9.999999900000002e-09

# -1.000000082740371e-09
# -9.99999999e-10

# -1.000000082740371e-10
# -9.999999999e-11

Up to around 1e-14, we still hold the accuracy. In this way, we can say that the calculation does not remove a lot of accuracy.

from fpfind.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.