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

Hamming Distance #893

Closed
wants to merge 11 commits into from
Closed

Hamming Distance #893

wants to merge 11 commits into from

Conversation

jac2130
Copy link

@jac2130 jac2130 commented Jun 26, 2013

I added a file that calculates the simple Hamming Distance between two (possibly directed) graphs.

@hagberg
Copy link
Member

hagberg commented Jun 26, 2013

Maybe it is simpler and faster to not use numpy? e.g. (untested)

def hd(G, H):
    count = 0
    for e in G.edges_iter():
        if not H.has_edge(*e):
            count+=1
    for e in H.edges_iter():
        if not G.has_edge(*e):
            count+=1
    return count

@jac2130
Copy link
Author

jac2130 commented Jun 26, 2013

That is probably better and it would equally work; sure! Actually, you
might have an idea about how to compute a "Generalized Hamming Distance"
which is what I happen to need for a problem that I'm working on: I have an
alphabet of 8 types of relations (positive, negative, zero, non-zero,
non-positive, non-negative, non-zero, missing) and I need that the
differences between members of the alphabet are ordered as follows:

d(positive, negative)>d(positive, non-positive)=d(negative,
non-negative)>d(non-positive, non-negative)=d(non-positive,
non-zero)=d(non-negative, non-zero)>d(positive, missing)=d(negative,
missing)>d(non-negative, missing)=d(non-positive, missing) >d(positive,
zero)=d(negative, zero)>d(non-negative, zero)=d(non-positive, zero)
....etc.

Any ideas?

JC

On Wed, Jun 26, 2013 at 11:58 AM, Aric Hagberg notifications@github.comwrote:

Maybe it is simpler and faster to not use numpy? e.g. (untested)

def hd(G, H):
count = 0
for e in G.edges_iter():
if not H.has_edge(_e):
count+=1
for e in H.edges_iter():
if not G.has_edge(_e):
count+=1
return count


Reply to this email directly or view it on GitHubhttps://github.com//pull/893#issuecomment-20067337
.

Johannes http://www.columbia.edu/~jac2130


"I can calculate the motions of the heavenly bodies, but not the madness of
people."

  • Isaac Newton

@dschult
Copy link
Member

dschult commented Jul 11, 2013

I made a pull request to your pull request with some format changes and file placement changes.
jac2130#1

Just for completeness the text of that pull request comment is:

Hi JC,
I'm reviewing your pull request to NetworkX with Hamming distance functions. I've moved the file into the algorithms folder and changed the formatting of the doc_string for your first function. Could you update the doc_strings into a similar format for the other functions? Also I added some lines at the top--see if you are OK with the more verbose names I proposed there. Its the networkx style not to abbreviate in function names. When the doc_strings are updated you can push back to your master branch and it will update the pull request too. Let me know if git causes trouble.

Finally, we will need some simple tests before merging. If you can come up with some simple graphs and compute correct values for them that's a good start--and maybe all the testing we need at first. You can create a test_hamming.py file in the tests directory inside algorithms (use test_cycles.py as an example if you want). Or if that's too much, just put the code for the tests in your hamming.py file after a line like:

if name == "main":
#test_code here

Thanks!

Johannes Castner added 2 commits July 11, 2013 15:57
Move hamming.py into algorithms and format docs for hamming_distance
@ghost ghost assigned dschult Jul 16, 2013
@jac2130
Copy link
Author

jac2130 commented Oct 9, 2013

Dear networkx team, I have added a class named BayesNet, which inherits from your DiGraph class, as well as from Allan Downey's Joint class. This class is meant to represent a Bayes Net, which is both, a directed graph with causal interpretation of the directed edges and a joint distribution. Although, right now the code is far from ideal, I hope that it may be of use to you and others!

@CrazyPython
Copy link

@jac2130 even if they did accept your code, the checks have failed.

Base automatically changed from master to main March 4, 2021 18:20
@MridulS
Copy link
Member

MridulS commented May 18, 2022

I'll go ahead and close this PR, this hasn't been touched in a long time and the code bits from BayesNet can't go in NetworkX as it's GPL.

@jac2130 I have created a new draft PR #5653 with only the new distances and made some changes to make it work with main branch of NX (it's not really tested) but feel free to pick it up from there if you interested in getting this in NetworkX 🎉

@MridulS MridulS closed this May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

6 participants