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);
}
}
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;
}
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);
}
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);
}
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;
}
Aggregations