Oh, Raul's version using +. (or) on the connection matrix is way nicer than my version, and gets rid of my bug with directions. Do that instead. :)
On Fri, Sep 3, 2021 at 12:31 PM Raul Miller <[email protected]> wrote: > I should note that your example connection matrix does not seem to > match the oid, nid values you displayed. > > OID=: 1 9 6 2 10 7 3 11 4 > NID=: 2 10 7 3 11 12 4 8 5 > > Here's the connection matrix I see represented: > ]CM=: 1 (<:OID,.NID)} 0$~,~>./OID,NID > 0 1 0 0 0 0 0 0 0 0 0 0 > 0 0 1 0 0 0 0 0 0 0 0 0 > 0 0 0 1 0 0 0 0 0 0 0 0 > 0 0 0 0 1 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 1 0 0 0 0 0 > 0 0 0 0 0 0 0 0 0 0 0 1 > 0 0 0 0 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 0 1 0 0 > 0 0 0 0 0 0 0 0 0 0 1 0 > 0 0 0 0 0 0 0 1 0 0 0 0 > 0 0 0 0 0 0 0 0 0 0 0 0 > > Note that I am using a recent J version here. In older versions of J, > that would have to be 1 (<"1<:OID,.NID)} 0$~,~>./OID,NID > > Anyways, its transitive closure would be: > (+. +./ .*~)^:_ CM > 0 1 1 1 1 0 0 0 0 0 0 0 > 0 0 1 1 1 0 0 0 0 0 0 0 > 0 0 0 1 1 0 0 0 0 0 0 0 > 0 0 0 0 1 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 1 0 0 0 0 1 > 0 0 0 0 0 0 0 0 0 0 0 1 > 0 0 0 0 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 1 0 1 1 0 > 0 0 0 0 0 0 0 1 0 0 1 0 > 0 0 0 0 0 0 0 1 0 0 0 0 > 0 0 0 0 0 0 0 0 0 0 0 0 > > But that does not match your suggested grouping operation (foo), so > let's assume that connections work both ways: > > ]TC=: (+. +./ .*~)^:_ CM+.|:CM > 1 1 1 1 1 0 0 0 0 0 0 0 > 1 1 1 1 1 0 0 0 0 0 0 0 > 1 1 1 1 1 0 0 0 0 0 0 0 > 1 1 1 1 1 0 0 0 0 0 0 0 > 1 1 1 1 1 0 0 0 0 0 0 0 > 0 0 0 0 0 1 1 0 0 0 0 1 > 0 0 0 0 0 1 1 0 0 0 0 1 > 0 0 0 0 0 0 0 1 1 1 1 0 > 0 0 0 0 0 0 0 1 1 1 1 0 > 0 0 0 0 0 0 0 1 1 1 1 0 > 0 0 0 0 0 0 0 1 1 1 1 0 > 0 0 0 0 0 1 1 0 0 0 0 1 > > That gives us something close to the grouping you asked for: > TC </. 1+i.#TC > +---------+------+---------+ > |1 2 3 4 5|6 7 12|8 9 10 11| > +---------+------+---------+ > > The ordering here is different, but if that's important we could try to > fix it: > > (/: {:@>) TC </. 1+i.#TC > +---------+---------+------+ > |1 2 3 4 5|8 9 10 11|6 7 12| > +---------+---------+------+ > > I hope this helps, > > > -- > Raul > > On Fri, Sep 3, 2021 at 11:21 AM Pablo Landherr <[email protected]> > wrote: > > > > I want to group items that are linked to each other. I tried to use some > > kind of connection matrix > > > > nid =/ oid NB. an example > > > > 0 0 0 1 0 0 0 0 0 > > > > 0 0 0 0 1 0 0 0 0 > > > > 0 0 0 0 0 1 0 0 0 > > > > 0 0 0 0 0 0 1 0 0 > > > > 0 0 0 0 0 0 0 1 0 > > > > 0 0 0 0 0 0 0 0 0 > > > > 0 0 0 0 0 0 0 0 1 > > > > 0 0 0 0 0 0 0 0 0 > > > > 0 0 0 0 0 0 0 0 0 > > > > > > to group items linked to each other but I can't figure out how to proceed > > from there. I'm hoping someone has a trick in their toolbox to share with > > me. > > > > oid is the first number of all connections and nid is the second number. > So > > in this example 6 is connected to 7, 7 is connected to 12 and 12 has no > > further connection. What should foo be? > > > > > > oid,.nid > > > > 1 2 > > > > 9 10 > > > > 6 7 > > > > 2 3 > > > > 10 11 > > > > 7 12 > > > > 3 4 > > > > 11 8 > > > > 4 5 > > > > oid foo nid > > > > ┌─────────┬─────────┬──────┐ > > > > │1 2 3 4 5│9 10 11 8│6 7 12│ > > > > └─────────┴─────────┴──────┘ > > > > > > Thank you, > > > > Pablo > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
