Search in sources :

Example 21 with Instance

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

the class PSMCurry method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    try {
        Instance IJ = new Instance(sig, PSMGen.gather(trans_src, sig, state));
        Instance K = new Instance(sig, PSMGen.gather(trans_dst, sig, state));
        Transform t = new Transform(IJ, K, PSMGen.gather(trans, sig, state));
        Instance I = new Instance(sig, PSMGen.gather(inst_src, sig, state));
        Instance J = new Instance(sig, PSMGen.gather(exp, sig, state));
        Instance JK = new Instance(sig, PSMGen.gather(inst_dst, sig, state));
        Transform trans_src0_fst = new Transform(IJ, I, PSMGen.gather(trans_src + "_fst", sig, state));
        Transform trans_src0_snd = new Transform(IJ, J, PSMGen.gather(trans_src + "_snd", sig, state));
        Map<Node, List<Pair<Arr<Node, Path>, Attribute<Node>>>> obs = I.thesig.obs();
        List<Pair<String, List<Pair<Object, Object>>>> l = new LinkedList<>();
        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>>> kkk = interp.exps2.get(inst_dst);
        for (Node c : sig.nodes) {
            List<Pair<Object, Object>> s = new LinkedList<>();
            for (Pair<Object, Object> xx : I.data.get(c.string)) {
                Object x = xx.first;
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> w = I.flag(c, x);
                Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>> HcJ = kkk.second.get(new Pair<>(c, w));
                // construct transform depending on x, lookup in kkk.second
                List<Pair<String, List<Pair<Object, Object>>>> tx = new LinkedList<>();
                for (Node d : sig.nodes) {
                    List<Pair<Object, Object>> tx0 = new LinkedList<>();
                    for (Arr<Node, Path> f : sig.toCategory2().first.hom(c, d)) {
                        for (Pair<Object, Object> y : J.data.get(d.string)) {
                            // only if y(p.a) = w(p.a)
                            if (!PropPSM.truncate2(I.thesig, w, f, obs.get(d)).equals(J.flag(d, y.first))) {
                                continue;
                            }
                            Object Ifx = lookup(I.evaluate(f.arr), x);
                            // Object Ifx = lookup(HcJ.first.evaluate(f.arr), x);
                            Object u = find(d, trans_src0_fst, trans_src0_snd, Ifx, y.first);
                            Object v = lookup(t.data.get(d.string), u);
                            Object iii = HcJ.third.get(d).get(new Pair<>(f, y.first));
                            tx0.add(new Pair<>(iii, v));
                        }
                    }
                    // I*J -> K
                    tx.add(new Pair<>(d.string, tx0));
                }
                Transform xxx = new Transform(HcJ.first, K, tx);
                Object yyy = kkk.fourth.get(c).get(new Pair<>(w, xxx));
                s.add(new Pair<>(x, yyy));
            }
            l.add(new Pair<>(c.string, s));
        }
        Transform zzz = new Transform(I, JK, l);
        PSMGen.shred(ret, zzz, state);
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getMessage());
    }
}
Also used : Arr(catdata.fql.cat.Arr) Path(catdata.fql.decl.Path) Instance(catdata.fql.decl.Instance) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) List(java.util.List) LinkedList(java.util.LinkedList) Transform(catdata.fql.decl.Transform) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Pair(catdata.Pair)

Example 22 with Instance

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

the class FullSigmaTrans method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    Signature C = f.source;
    Signature D = f.target;
    List<Pair<String, List<Pair<Object, Object>>>> I0 = PSMGen.gather(srcH, C, state);
    List<Pair<String, List<Pair<Object, Object>>>> J0 = PSMGen.gather(dstH, C, state);
    List<Pair<String, List<Pair<Object, Object>>>> H0 = PSMGen.gather(h, C, state);
    List<Pair<String, List<Pair<Object, Object>>>> J0X = PSMGen.gather(dst, D, state);
    List<Pair<String, List<Pair<Object, Object>>>> tempI = new LinkedList<>();
    List<Pair<String, List<Pair<Object, Object>>>> tempH = new LinkedList<>();
    for (Node n : C.nodes) {
        Set<Map<Object, Object>> x2 = state.get(dst + "_" + n.string + "_e");
        tempH.add(new Pair<>(n.string, convX(x2)));
        Set<Map<Object, Object>> x1 = state.get(dst + "_" + f.nm.get(n).string);
        tempI.add(new Pair<>(n.string, conv(x1)));
    }
    for (Edge e : C.edges) {
        Set<Map<Object, Object>> x1 = eval(state, dst, f.em.get(e));
        tempI.add(new Pair<>(e.name, conv(x1)));
    }
    for (Attribute<Node> e : C.attrs) {
        Set<Map<Object, Object>> x1 = state.get(dst + "_" + f.am.get(e).name);
        tempI.add(new Pair<>(e.name, conv(x1)));
    }
    try {
        Instance I = new Instance(C, I0);
        Instance J = new Instance(C, J0);
        Transform H = new Transform(I, J, H0);
        // Instance IX = new Instance(D, I0X);
        Instance JX = new Instance(D, J0X);
        Instance temp = new Instance(C, tempI);
        Transform etaJ = new Transform(J, temp, tempH);
        Transform HX = Transform.composeX(H, etaJ);
        // should pass H, but compute etaJ after de-attr.
        // that way, HX.dst and delta JX have attr IDs in common
        // de-attr JX
        Integer current = interp.guid;
        interp.guid = interp.sigmas.get(src);
        Quad<Instance, Map<Node, Map<Object, Integer>>, Map<Node, Map<Integer, Object>>, Map<Object, List<Pair<String, Object>>>> xxx = LeftKanSigma.fullSigmaWithAttrs(interp, f, I, HX, JX, interp.sigmas2.get(src));
        interp.guid = current;
        for (Node n : D.nodes) {
            state.put(pre + "_" + n.string, conv0(xxx.third.get(n)));
        }
        for (Attribute<Node> a : D.attrs) {
            state.put(pre + "_" + a.name, new HashSet<>());
        }
        for (Edge a : D.edges) {
            state.put(pre + "_" + a.name, new HashSet<>());
        }
    } catch (FQLException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : Instance(catdata.fql.decl.Instance) Node(catdata.fql.decl.Node) LinkedList(java.util.LinkedList) FQLException(catdata.fql.FQLException) Signature(catdata.fql.decl.Signature) Transform(catdata.fql.decl.Transform) HashMap(java.util.HashMap) Map(java.util.Map) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair)

Example 23 with Instance

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

the class LeftKanSigma method fullSigmaWithAttrs.

public static Quad<Instance, Map<Node, Map<Object, Integer>>, Map<Node, Map<Integer, Object>>, Map<Object, List<Pair<String, Object>>>> fullSigmaWithAttrs(PSMInterp inter, Mapping f, Instance i, Transform t, Instance JJJ, Integer xxx) throws FQLException {
    Mapping F = deAttr(f);
    Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> I = deAttr(inter, i, F.source);
    Integer kkk = inter.guid;
    Instance JJJ0 = null;
    Transform ttt = null;
    if (JJJ != null) {
        inter.guid = xxx;
        Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> JJJ0X = deAttr(inter, JJJ, F.target);
        Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> qqq = delta(f, F, JJJ0X);
        ttt = deAttr(f.source, I, qqq, t);
        JJJ0 = JJJ0X.first;
        inter.guid = kkk;
    }
    // System.out.println("!!!!!!!!!!!!!!!");
    LeftKan D = new LeftKan(inter.guid, F, I.first, ttt, JJJ0);
    Pair<Instance, Map<Object, List<Pair<String, Object>>>> hhh = sigma(D);
    inter.guid = D.fresh;
    Map<Node, Map<Object, Integer>> etables = makeE(D.ua);
    Instance j = hhh.first;
    Instance ret = reAttr(etables, f.target, j, I.second);
    return new Quad<>(ret, etables, D.utables, hhh.second);
}
Also used : Quad(catdata.Quad) Instance(catdata.fql.decl.Instance) Node(catdata.fql.decl.Node) Mapping(catdata.fql.decl.Mapping) Transform(catdata.fql.decl.Transform) HashMap(java.util.HashMap) Map(java.util.Map) Pair(catdata.Pair)

Example 24 with Instance

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

the class LeftKanSigma method sigma.

private static Pair<Instance, Map<Object, List<Pair<String, Object>>>> sigma(LeftKan lk) throws FQLException {
    if (!lk.compute()) {
        throw new FQLException("Too many sigma iterations.");
    }
    Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
    for (Node e : lk.Pb.keySet()) {
        Set<Pair<Integer, Integer>> t = lk.Pb.get(e);
        data.put(e.string, conc(t));
    }
    for (Edge e : lk.Pg.keySet()) {
        Set<Pair<Integer, Integer>> t = lk.Pg.get(e);
        data.put(e.name, conc(t));
    }
    Instance ret = new Instance(lk.F.target, data);
    return new Pair<>(ret, lk.lineage);
}
Also used : FQLException(catdata.fql.FQLException) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Instance(catdata.fql.decl.Instance) Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair)

Example 25 with Instance

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

the class LeftKanSigma method delta.

private static Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> delta(Mapping f0, Mapping f, Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> p) throws FQLException {
    Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
    for (Node n : f.source.nodes) {
        data.put(n.string, p.first.data.get(f.nm.get(n).string));
    }
    for (Edge e : f.source.edges) {
        data.put(e.name, p.first.evaluate(f.em.get(e)));
    }
    Instance J = new Instance(f.source, data);
    Map<Attribute<Node>, Map<Object, Object>> m = new HashMap<>();
    for (Attribute<Node> a : f0.source.attrs) {
        m.put(a, p.second.get(f0.am.get(a)));
    }
    return new Pair<>(J, m);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Instance(catdata.fql.decl.Instance) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge) HashMap(java.util.HashMap) Map(java.util.Map) Pair(catdata.Pair)

Aggregations

Instance (catdata.fql.decl.Instance)25 Pair (catdata.Pair)23 Node (catdata.fql.decl.Node)22 HashMap (java.util.HashMap)19 Edge (catdata.fql.decl.Edge)15 FQLException (catdata.fql.FQLException)14 HashSet (java.util.HashSet)14 LinkedHashMap (java.util.LinkedHashMap)13 Set (java.util.Set)13 Transform (catdata.fql.decl.Transform)12 Map (java.util.Map)12 Attribute (catdata.fql.decl.Attribute)11 LinkedList (java.util.LinkedList)11 Signature (catdata.fql.decl.Signature)10 Arr (catdata.fql.cat.Arr)9 Path (catdata.fql.decl.Path)8 List (java.util.List)4 IntRef (catdata.IntRef)2 Triple (catdata.Triple)2 Mapping (catdata.fql.decl.Mapping)2