Git Product home page Git Product logo

Comments (8)

clbarnes avatar clbarnes commented on July 22, 2024

I probably have the most up-to-date py3 branch here https://github.com/clbarnes/bctpy/tree/py3 as it's not a priority for @aestrivex . Although all I've been doing is

#!/bin/bash
set -e
if [ "$(git symbolic-ref --short -q HEAD)" = "master" ]; then
    git checkout py3
    git checkout master -- .
    git commit -a -m "update from master"
    2to3 -W -n bct test setup.py
    git commit -a -m "run 2to3"
    nosetests --ignore-files="very_long_tests|nbs_tests""
    git checkout master
fi

Unfortunately, this means the merges aren't fast-forwardable, which means it's a bit of hassle for aestrivex each time.

In this test, the sum is off by 4 (probably 3 edges). I'll have a look into it now.

from bctpy.

clbarnes avatar clbarnes commented on July 22, 2024

There are a lot of other tests which depend on the threshold_proportional method which pass, which is interesting...

from bctpy.

aestrivex avatar aestrivex commented on July 22, 2024

I will try and look at this in a few days, but I don't have time right now.

Thanks for all your help @clbarnes

from bctpy.

clbarnes avatar clbarnes commented on July 22, 2024

Don't worry, I should have an answer in the next hour or so, I'm just noting stuff down here as I go (sorry if that's peppering you with emails!).

The difference is that the py3 version zeros one more element than py2. That element is [107, 111], and has value 1.85 (which is doubled when the matrix is re-symmetrised). I'm digging into the root cause now; I suspect it's something to do with this line en = int(round((n * n - n) * p / ud)) rounding either up or down after the division.

from bctpy.

clbarnes avatar clbarnes commented on July 22, 2024

Here we go!

py3's round(0.5) rounds towards the even choice (i.e. 0). py2's round(0.5) rounds away from 0 (i.e. 1). The py3 version is in accordance with the IEEE-754 specification default, R, and .NET, and removes sign bias as well as making the mean of a large set of rounded numbers the same as the mean if they were not rounded.

The pythonic fix would be to make the py2 version depend on future, and then do from builtins import round (alternatively, use np.round(), as this has the new behaviour in both versions). This opens the door to writing more cross-compatible code in future, thus cutting down on effort required to maintain the two versions. It also means that using 2to3 to maintain the two versions is still viable. Also, because np.round() is already used in some places in the code, it would improve consistency.

However, this would be a departure from the behaviour of matlab, which rounds in a py2-like fashion.

It is also possible to make the py3 version depend on past, and use the builtins from that package. However, this change which would need to be checked every time the py3 codebase was regenerated with 2to3.

from bctpy.

aestrivex avatar aestrivex commented on July 22, 2024

I think it is better to keep as much compatibility from the matlab version where possible, and in the past when I have come across similar choices I have tried to always get the similar behavior. That is probably why I chose to use python stdlib round and not np.round in the first place.

Making py3 branch not work very easily with 2to3 doesn't sound like a good solution either.

What do you think of simply using a custom (integer only) round that does the right thing?

from bctpy.

clbarnes avatar clbarnes commented on July 22, 2024

That's a good option, although there still might be some minor inconsistencies as numpy.round() is used in a few other places in the reference module.

from bctpy.

aestrivex avatar aestrivex commented on July 22, 2024

Fixed by implementing teachers round

from bctpy.

Related Issues (20)

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.