On 20/09/2010 22:42, Astley Le Jasper wrote:
I have a list of tuples that indicate a relationship, ie a is related
to b, b is related to c etc etc. What I want to do is cluster these
relationships into groups. An item will only be associated with a
single cluster.
Before I started, I wondered i
On Sep 22, 8:30 am, Peter Otten <__pete...@web.de> wrote:
> Arnaud Delobelle wrote:
> > I think I would go for the two-step approach of constructing the graph
> > first and then recursively building connected components. It sounds
> > more complicated at first but when you implement it it turns ou
Arnaud Delobelle wrote:
> I think I would go for the two-step approach of constructing the graph
> first and then recursively building connected components. It sounds
> more complicated at first but when you implement it it turns out quite
> simple:
>
> from collections import defaultdict
> from
On 21 Sep, 11:13, Peter Otten <__pete...@web.de> wrote:
[...]
>
> A straightforward implementation:
>
> $ cat group_edges.py
> def find_groups(edges):
> lookup = {} # node --> group
> groups = {} # id(group) --> group
> for a, b in edges:
> if a in lookup:
> I think you have the same bug as Alf's code, you never merge existing
> groups. Have you tried Arnaud's counterexample?
>
> By the way, are ('a', 'b') and ('b', 'a') to be considered equivalent for
> your problem?
>
> Peter
Hi Peter,
Yes. I realise that this doesn't take into account existing
Astley Le Jasper wrote:
> Thanks all. I was playing around with this and came up with another
> solution using dictionaries (... comfort zone ...!!)
> from operator import itemgetter
>
> def group_stuff(data):
>
> group_dic = {}
> group_id = 0
>
> for line in data:
> i = 0
Thanks all. I was playing around with this and came up with another
solution using dictionaries (... comfort zone ...!!)
<<< Code
>>
from operator import itemgetter
def group_stuff(data):
group_dic = {}
group_id = 0
Astley Le Jasper wrote:
> I have a list of tuples that indicate a relationship, ie a is related
> to b, b is related to c etc etc. What I want to do is cluster these
> relationships into groups. An item will only be associated with a
> single cluster.
>
> Before I started, I wondered if there wa
* Arnaud Delobelle, on 21.09.2010 11:13:
On Sep 21, 7:19 am, "Alf P. Steinbach /Usenet" wrote:
* Alf P. Steinbach /Usenet, on 21.09.2010 01:09:
* Astley Le Jasper, on 20.09.2010 23:42:
I have a list of tuples that indicate a relationship, ie a is related
to b, b is related to c etc etc.
On Sep 21, 7:19 am, "Alf P. Steinbach /Usenet" wrote:
> * Alf P. Steinbach /Usenet, on 21.09.2010 01:09:
>
>
>
>
>
> > * Astley Le Jasper, on 20.09.2010 23:42:
> >> I have a list of tuples that indicate a relationship, ie a is related
> >> to b, b is related to c etc etc. What I want to do is clus
Thanks for the feedback both. I'll have a look at these.
One of the frustrating things I find about python is that there are so
many modules. There have been times when I've spend ages doing
something and then some has said, "Oh yeah, there is a module for
that".
Anyway. Nearly finished.
Cheers
On Sep 20, 10:42 pm, Astley Le Jasper
wrote:
> I have a list of tuples that indicate a relationship, ie a is related
> to b, b is related to c etc etc. What I want to do is cluster these
> relationships into groups. An item will only be associated with a
> single cluster.
>
> Before I started, I
On Tue, Sep 21, 2010 at 12:19 AM, Alf P. Steinbach /Usenet <
alf.p.steinbach+use...@gmail.com >wrote:
> Uhm, thinking about it (it must have been my unconscious mind doing the
> work, it just popped into my head), if you first sort each individual
> equivalence relation so that you never have e.g.
* Alf P. Steinbach /Usenet, on 21.09.2010 01:09:
* Astley Le Jasper, on 20.09.2010 23:42:
I have a list of tuples that indicate a relationship, ie a is related
to b, b is related to c etc etc. What I want to do is cluster these
relationships into groups. An item will only be associated with a
si
On Mon, Sep 20, 2010 at 5:09 PM, Alf P. Steinbach /Usenet <
alf.p.steinbach+use...@gmail.com >wrote:
> It seems to be the same problem as "equivalence sets".
>
> This problem was solved early on because e.g. Fortran compilers had to
> construct such sets (equivalence partitions of a set).
>
> I th
* Astley Le Jasper, on 20.09.2010 23:42:
I have a list of tuples that indicate a relationship, ie a is related
to b, b is related to c etc etc. What I want to do is cluster these
relationships into groups. An item will only be associated with a
single cluster.
Before I started, I wondered if th
I have a list of tuples that indicate a relationship, ie a is related
to b, b is related to c etc etc. What I want to do is cluster these
relationships into groups. An item will only be associated with a
single cluster.
Before I started, I wondered if there was any particular tool within
Python I
17 matches
Mail list logo