Search in sources :

Example 31 with Edge

use of catdata.fql.decl.Edge 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 32 with Edge

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

the class LeftKan method alpha.

private boolean alpha() {
    Pair<Integer, Edge> p = smallest();
    if (p == null) {
        return false;
    }
    Integer x = p.first;
    Edge g = p.second;
    Node b2 = g.target;
    Integer y = fresh();
    Pb.get(b2).add(new Pair<>(y, y));
    Pg.get(g).add(new Pair<>(x, y));
    updateLineage(g.name, x, y);
    if (alpha != null) {
        Object xxx = lookup(J.data.get(p.second.name), utables.get(p.second.source).get(p.first));
        utables.get(p.second.target).put(y, xxx);
    }
    return true;
}
Also used : Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge)

Example 33 with Edge

use of catdata.fql.decl.Edge 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 34 with Edge

use of catdata.fql.decl.Edge 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)

Example 35 with Edge

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

the class LeftKanSigma method deAttr.

private static Mapping deAttr(Mapping f) throws FQLException {
    Mapping ret = f.clone();
    deAttr(ret.source);
    deAttr(ret.target);
    for (Attribute<Node> k : ret.am.keySet()) {
        Attribute<Node> v = ret.am.get(k);
        Node src = new Node(k.name);
        Node dst = new Node(v.name);
        Edge srcE = new Edge(k.name + "_edge", k.source, src);
        Edge dstE = new Edge(v.name + "_edge", v.source, dst);
        ret.nm.put(src, dst);
        ret.em.put(srcE, new Path(ret.target, dstE));
    }
    ret.am.clear();
    return ret;
}
Also used : Path(catdata.fql.decl.Path) Node(catdata.fql.decl.Node) Mapping(catdata.fql.decl.Mapping) Edge(catdata.fql.decl.Edge)

Aggregations

Edge (catdata.fql.decl.Edge)37 Node (catdata.fql.decl.Node)33 HashMap (java.util.HashMap)27 Pair (catdata.Pair)25 HashSet (java.util.HashSet)19 LinkedList (java.util.LinkedList)19 LinkedHashMap (java.util.LinkedHashMap)17 Instance (catdata.fql.decl.Instance)15 Set (java.util.Set)13 Map (java.util.Map)12 FQLException (catdata.fql.FQLException)11 Path (catdata.fql.decl.Path)11 Attribute (catdata.fql.decl.Attribute)10 Signature (catdata.fql.decl.Signature)9 List (java.util.List)7 Arr (catdata.fql.cat.Arr)6 Fn (catdata.fql.Fn)4 Transform (catdata.fql.decl.Transform)4 Triple (catdata.Triple)3 FinCat (catdata.fql.cat.FinCat)3