private static double sumOutputs(Set<Arc> arcs) { double sum = 0.0; for (Arc arc : arcs) { sum += ((Double) arc.getOutput()).doubleValue(); } return sum; }
result.append(" : "); Object output = arc.getOutput(); String wt = ""; if (output instanceof Number) {
private double getSourceTotal(Object node) { double result = 0.0; Set<Arc> arcs = getArcsBySource(node); if (arcs.isEmpty()) { log.info("No outbound arcs from node."); return result; } for (Arc arc : arcs) { result += ((Double) arc.getOutput()).doubleValue(); } return result; }
private double getSourceTotal(Object node) { double result = 0.0; Set<Arc> arcs = getArcsBySource(node); if (arcs.isEmpty()) { log.info("No outbound arcs from node."); return result; } for (Arc arc : arcs) { result += ((Double) arc.getOutput()).doubleValue(); } return result; }
private static double sumOutputs(Set<Arc> arcs) { double sum = 0.0; for (Arc arc : arcs) { sum += ((Double) arc.getOutput()).doubleValue(); } return sum; }
private double getSourceTotal(Object node) { double result = 0.0; Set<Arc> arcs = getArcsBySource(node); if (arcs.isEmpty()) { log.info("No outbound arcs from node."); return result; } for (Arc arc : arcs) { result += ((Double) arc.getOutput()).doubleValue(); } return result; }
private static double sumOutputs(Set<Arc> arcs) { double sum = 0.0; for (Arc arc : arcs) { sum += ((Double) arc.getOutput()).doubleValue(); } return sum; }
private double sumOutputs(Set<Arc> arcs) { double sum = 0.0; for (Arc arc : arcs) { sum += ((Double) arc.getOutput()).doubleValue(); } return sum; }
public Arc processArc(Arc a) { a = new Arc(a); a.setInput(Generics.newPair(a.getInput(), a.getOutput())); a.setOutput(null); return a; } }
private double getSourceTotal(Object node) { double result = 0.0; Set<Arc> arcs = getArcsBySource(node); if (arcs.isEmpty()) { System.err.println("No outbound arcs from node."); return result; } for (Arc arc : arcs) { result += ((Double) arc.getOutput()).doubleValue(); } return result; }
@Override public Arc processArc(Arc a) { a = new Arc(a); a.setInput(Generics.newPair(a.getInput(), a.getOutput())); a.setOutput(null); return a; } }
Object input = arc.getInput(); String inputString = input.toString(); double output = ((Double) arc.getOutput()).doubleValue(); if (source.equals(startNode)) {
Object newNode = arc.getSourceNode(); Comparable a = (Comparable) arc.getInput(); double k = ((Double) arc.getOutput()).doubleValue(); double newLen = length.getCount(newNode); if (newLen == Double.POSITIVE_INFINITY) {
double sourceLambda = lambda.getCount(arc.getSourceNode()); double targetLambda = lambda.getCount(arc.getTargetNode()); double oldOutput = ((Double) arc.getOutput()).doubleValue(); double newOutput = oldOutput + targetLambda - sourceLambda; arc.setOutput(new Double(newOutput)); double oldOutput = ((Double) arc.getOutput()).doubleValue(); double newOutput = oldOutput + startLambda; arc.setOutput(new Double(newOutput)); double oldOutput = ((Double) arc.getOutput()).doubleValue(); double newOutput = oldOutput - endLambda; arc.setOutput(new Double(newOutput));
public TransducerGraph processGraph(TransducerGraph g) { g = new TransducerGraph(g); Set nodes = g.getNodes(); for (Object node : nodes) { Set<Arc> myArcs = null; if (forward) { myArcs = g.getArcsBySource(node); } else { myArcs = g.getArcsByTarget(node); } // compute a total double total = 0.0; for (Arc a : myArcs) { total += ((Double) a.getOutput()).doubleValue(); } // divide each by total for (Arc a : myArcs) { a.setOutput(new Double(Math.log(((Double) a.getOutput()).doubleValue() / total))); } } return g; } }
protected TransducerGraph buildMinimizedFA() { TransducerGraph minimizedFA = new TransducerGraph(); TransducerGraph unminimizedFA = getUnminimizedFA(); for (TransducerGraph.Arc arc : unminimizedFA.getArcs()) { Object source = projectNode(arc.getSourceNode()); Object target = projectNode(arc.getTargetNode()); try { if (minimizedFA.canAddArc(source, target, arc.getInput(), arc.getOutput())) { minimizedFA.addArc(source, target, arc.getInput(), arc.getOutput()); } } catch (Exception e) { //throw new IllegalArgumentException(); } } minimizedFA.setStartNode(projectNode(unminimizedFA.getStartNode())); for (Object o : unminimizedFA.getEndNodes()) { minimizedFA.setEndNode(projectNode(o)); } return minimizedFA; }
protected TransducerGraph buildMinimizedFA() { TransducerGraph minimizedFA = new TransducerGraph(); TransducerGraph unminimizedFA = getUnminimizedFA(); for (TransducerGraph.Arc arc : unminimizedFA.getArcs()) { Set<Arc> source = projectNode(arc.getSourceNode()); Set<Arc> target = projectNode(arc.getTargetNode()); try { if (minimizedFA.canAddArc(source, target, arc.getInput(), arc.getOutput())) { minimizedFA.addArc(source, target, arc.getInput(), arc.getOutput()); } } catch (Exception e) { //throw new IllegalArgumentException(); } } minimizedFA.setStartNode(projectNode(unminimizedFA.getStartNode())); for (Object o : unminimizedFA.getEndNodes()) { minimizedFA.setEndNode(projectNode(o)); } return minimizedFA; }
/** * For testing only. Doubles combined by addition. */ public double getOutputOfPathInGraph(List path) { double score = 0.0; Object node = getStartNode(); for (Object input : path) { Arc arc = getArcBySourceAndInput(node, input); // next input in path if (arc == null) { System.out.println(" NOT ACCEPTED :" + path); return Double.NEGATIVE_INFINITY; } score += ((Double) arc.getOutput()).doubleValue(); node = arc.getTargetNode(); } return score; }
protected Arc(Arc<NODE,IN,OUT> a) { this(a.getSourceNode(), a.getTargetNode(), a.getInput(), a.getOutput()); }
@Override public Arc processArc(Arc a) { a = new Arc(a); a.setInput(Generics.newPair(a.getInput(), a.getOutput())); a.setOutput(null); return a; } }