Search in sources :

Example 6 with Path

use of catdata.fql.decl.Path in project fql by CategoricalData.

the class PSMEval method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    try {
        Quad<Instance, Map<Pair<Node, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>>>, Map<Node, Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>>>, Map<Node, Map<Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>, Object>>> xxx = interp.exps2.get(AB);
        Instance Jw = xxx.first;
        Map<Pair<Node, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>>> map = xxx.second;
        Map<Node, Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>>> map2 = xxx.third;
        FinCat<Node, Path> cat = Jw.thesig.toCategory2().first;
        Instance abb = new Instance(sig, PSMGen.gather(ABB, sig, state));
        // Instance ab = new Instance(sig, PSMGen.gather(AB, sig, state));
        // //already have in interp
        Instance a = new Instance(sig, PSMGen.gather(A, sig, state));
        Instance b = new Instance(sig, PSMGen.gather(B, sig, state));
        Transform fst = new Transform(abb, Jw, PSMGen.gather(ABB + "_fst", sig, state));
        Transform snd = new Transform(abb, b, PSMGen.gather(ABB + "_snd", sig, state));
        List<Pair<String, List<Pair<Object, Object>>>> data = new LinkedList<>();
        for (Node n : sig.nodes) {
            List<Pair<Object, Object>> d = new LinkedList<>();
            Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>> m2 = map2.get(n);
            for (Pair<Object, Object> id : abb.data.get(n.string)) {
                Object id_ab = lookup(fst.data.get(n.string), id.first);
                Object x = lookup(snd.data.get(n.string), id.first);
                Transform t = m2.get(id_ab).second;
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> w = m2.get(id_ab).first;
                Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>> m = map.get(new Pair<>(n, w));
                Object y = m.third.get(n).get(new Pair<>(cat.id(n), x));
                Object f = lookup(t.data.get(n.string), y);
                d.add(new Pair<>(id.first, f));
            }
            data.add(new Pair<>(n.string, d));
        }
        Transform curry = new Transform(abb, a, data);
        PSMGen.shred(pre, curry, state);
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getMessage());
    }
}
Also used : Arr(catdata.fql.cat.Arr) Instance(catdata.fql.decl.Instance) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) Pair(catdata.Pair) Path(catdata.fql.decl.Path) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Transform(catdata.fql.decl.Transform) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 7 with Path

use of catdata.fql.decl.Path in project fql by CategoricalData.

the class CategoryOfElements method dot.

private static JPanel dot(String name, @SuppressWarnings("unused") Instance inst, Graph<Pair<Node, Object>, Pair<Path, Integer>> sgv, Map<Pair<Node, Object>, Map<Attribute<Node>, Object>> map0) {
    String str = "";
    int i = 0;
    Map<Pair<Node, Object>, Integer> map = new HashMap<>();
    for (Pair<Node, Object> p : sgv.getVertices()) {
        String s = p.toString() + map0.get(p);
        s.replace("\"", "\\\"");
        // a [label="Foo"];
        map.put(p, i);
        str += i + " [label=\"" + s + "\"];\n";
        i++;
    }
    for (Pair<Path, Integer> p : sgv.getEdges()) {
        Pair<Node, Object> src = sgv.getSource(p);
        Pair<Node, Object> dst = sgv.getDest(p);
        int src_id = map.get(src);
        int dst_id = map.get(dst);
        str += src_id + " -> " + dst_id + " [label=\"" + p.first + "\"];\n";
    }
    str = "digraph " + name + " {\n" + str.trim() + "\n}";
    JPanel p = new JPanel(new GridLayout(1, 1));
    JTextArea area = new JTextArea(str);
    JScrollPane jsp = new JScrollPane(area);
    p.add(jsp);
    return p;
}
Also used : Path(catdata.fql.decl.Path) JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) HashMap(java.util.HashMap) Node(catdata.fql.decl.Node) Paint(java.awt.Paint) GridLayout(java.awt.GridLayout) Pair(catdata.Pair)

Example 8 with Path

use of catdata.fql.decl.Path in project fql by CategoricalData.

the class CategoryOfElements method makePanel.

public static Pair<JPanel, JPanel> makePanel(String name, Instance i, Color c) {
    try {
        JPanel ret;
        JPanel ret2;
        Pair<Graph<Pair<Node, Object>, Pair<Path, Integer>>, HashMap<Pair<Node, Object>, Map<Attribute<Node>, Object>>> g = build(i);
        ret = g.first.getVertexCount() == 0 ? new JPanel() : doView(c, i, g.first, g.second);
        ret2 = dot(name, i, g.first, g.second);
        return new Pair<>(ret, ret2);
    } catch (FQLException e) {
        JPanel p = new JPanel(new GridLayout(1, 1));
        JTextArea a = new JTextArea(e.getMessage());
        p.add(new JScrollPane(a));
        return new Pair<>(p, p);
    }
}
Also used : Path(catdata.fql.decl.Path) JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) HashMap(java.util.HashMap) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) FQLException(catdata.fql.FQLException) GridLayout(java.awt.GridLayout) Graph(edu.uci.ics.jung.graph.Graph) Pair(catdata.Pair)

Example 9 with Path

use of catdata.fql.decl.Path in project fql by CategoricalData.

the class LeftKan method beta2.

// beta, delta, gamma
private boolean beta2() {
    boolean ret = false;
    try {
        for (Edge e : A.edges) {
            Path g = F.appy(B, new Path(A, e));
            Set<Pair<Object, Integer>> lhs = Instance.compose(X.data.get(e.name), ua.get(e.target));
            Set<Pair<Object, Integer>> rhs = Instance.compose(ua.get(e.source), eval(g));
            // System.out.println(lhs);
            // System.out.println(rhs);
            Node n = g.target;
            ret = ret || addCoincidences(lhs, rhs, n);
        }
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getMessage());
    }
    return ret;
}
Also used : Path(catdata.fql.decl.Path) FQLException(catdata.fql.FQLException) Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair)

Example 10 with Path

use of catdata.fql.decl.Path in project fql by CategoricalData.

the class Inst method stuff.

// base^exp
public static FinCat<Mapping, Map<Node, Path>> stuff(Signature base, Signature exp) throws FQLException {
    Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> xxx = base.toCategory2();
    FinCat<Node, Path> base0 = xxx.first;
    Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> yyy = exp.toCategory2();
    FinCat<Node, Path> exp0 = yyy.first;
    List<LinkedHashMap<Node, Node>> nms = homomorphs(exp.nodes, base.nodes);
    List<Mapping> mappings = new LinkedList<>();
    for (LinkedHashMap<Node, Node> nm : nms) {
        LinkedHashMap<Attribute<Node>, List<Attribute<Node>>> ams = new LinkedHashMap<>();
        for (Attribute<Node> a : exp.attrs) {
            ams.put(a, base.attrsFor(nm.get(a.source)));
        }
        LinkedHashMap<Edge, List<Path>> ems = new LinkedHashMap<>();
        for (Edge e : exp.edges) {
            Set<Arr<Node, Path>> s = base0.hom(nm.get(e.source), nm.get(e.target));
            List<Path> p = new LinkedList<>();
            for (Arr<Node, Path> sx : s) {
                p.add(sx.arr);
            }
            ems.put(e, p);
        }
        List<LinkedHashMap<Attribute<Node>, Attribute<Node>>> ams0 = homomorphs(ams);
        List<LinkedHashMap<Edge, Path>> ems0 = homomorphs(ems);
        for (LinkedHashMap<Attribute<Node>, Attribute<Node>> am : ams0) {
            for (LinkedHashMap<Edge, Path> em : ems0) {
                try {
                    Mapping m = new Mapping(true, exp, base, nm, em, am);
                    mappings.add(m);
                } catch (Exception e) {
                }
            }
        }
    }
    List<Arr<Mapping, Map<Node, Path>>> arrows = new LinkedList<>();
    for (Mapping s : mappings) {
        for (Mapping t : mappings) {
            Map<Node, List<Path>> map = new HashMap<>();
            for (Node n : exp.nodes) {
                List<Path> p = new LinkedList<>();
                for (Arr<Node, Path> k : base0.hom(s.nm.get(n), t.nm.get(n))) {
                    p.add(k.arr);
                }
                map.put(n, p);
            }
            List<LinkedHashMap<Node, Path>> map0 = homomorphs(map);
            outer: for (Map<Node, Path> k : map0) {
                for (Node x : k.keySet()) {
                    for (Node y : k.keySet()) {
                        for (Arr<Node, Path> f : exp0.hom(x, y)) {
                            Path lhs = Path.append(base, k.get(x), t.appy(base, f.arr));
                            Path rhs = Path.append(base, s.appy(base, f.arr), k.get(y));
                            if (!xxx.second.of(lhs).equals(xxx.second.of(rhs))) {
                                continue outer;
                            }
                        }
                    }
                }
                arrows.add(new Arr<>(k, s, t));
            }
        }
    }
    Map<Mapping, Arr<Mapping, Map<Node, Path>>> identities = new HashMap<>();
    for (Mapping m : mappings) {
        Map<Node, Path> map = new HashMap<>();
        for (Node n : m.source.nodes) {
            map.put(n, new Path(m.target, m.nm.get(n)));
        }
        Arr<Mapping, Map<Node, Path>> uuu = new Arr<>(map, m, m);
        identities.put(m, new Arr<>(map, m, m));
        if (!arrows.contains(uuu)) {
            arrows.add(uuu);
        }
    }
    Map<Pair<Arr<Mapping, Map<Node, Path>>, Arr<Mapping, Map<Node, Path>>>, Arr<Mapping, Map<Node, Path>>> composition = new HashMap<>();
    for (Arr<Mapping, Map<Node, Path>> a1 : arrows) {
        for (Arr<Mapping, Map<Node, Path>> a2 : arrows) {
            if (!a1.dst.equals(a2.src)) {
                continue;
            }
            Map<Node, Path> m = new HashMap<>();
            for (Node n : exp.nodes) {
                m.put(n, xxx.second.of(Path.append(base, a1.arr.get(n), a2.arr.get(n))).arr);
            }
            composition.put(new Pair<>(a1, a2), new Arr<>(m, a1.src, a2.dst));
        }
    }
    return new FinCat<>(mappings, arrows, composition, identities);
}
Also used : Attribute(catdata.fql.decl.Attribute) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(catdata.fql.decl.Node) Mapping(catdata.fql.decl.Mapping) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) Path(catdata.fql.decl.Path) Fn(catdata.fql.Fn) LinkedList(java.util.LinkedList) FQLException(catdata.fql.FQLException) Edge(catdata.fql.decl.Edge) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Node (catdata.fql.decl.Node)21 Path (catdata.fql.decl.Path)21 Pair (catdata.Pair)17 FQLException (catdata.fql.FQLException)14 HashMap (java.util.HashMap)14 LinkedHashMap (java.util.LinkedHashMap)13 LinkedList (java.util.LinkedList)12 Arr (catdata.fql.cat.Arr)11 Edge (catdata.fql.decl.Edge)11 Attribute (catdata.fql.decl.Attribute)10 Map (java.util.Map)9 Instance (catdata.fql.decl.Instance)8 Signature (catdata.fql.decl.Signature)6 List (java.util.List)6 Triple (catdata.Triple)5 Transform (catdata.fql.decl.Transform)5 HashSet (java.util.HashSet)5 Fn (catdata.fql.Fn)4 Set (java.util.Set)4 FinCat (catdata.fql.cat.FinCat)3