@Override public IntegerTensor calculate() { return op.apply(inputVertex.getValue()); } }
private DoubleTensor applyReduce(Function<Vertex<DoubleTensor>, DoubleTensor> mapper) { Iterator<? extends Vertex<DoubleTensor>> inputIterator = inputs.iterator(); DoubleTensor result = inputIterator.next().getValue(); while (inputIterator.hasNext()) { result = reduceFunction.apply(result, mapper.apply(inputIterator.next())); } return result; }
/** * This is similar to eval() except it only propagates as far up the graph as required until * there are values present to operate on. On a graph that is completely uninitialized, * this would be the same as eval() * * @return the value of the vertex based on the already calculated upstream values */ public final T lazyEval() { VertexValuePropagation.lazyEval(this); return this.getValue(); }
public List<Vertex<DoubleTensor>> getContinuousLatentVertices() { return getLatentVertices().stream() .filter(v -> v.getValue() instanceof DoubleTensor) .map(v -> (Vertex<DoubleTensor>) v) .collect(Collectors.toList()); }
@Override public DoubleTensor calculate() { return inputVertex.getValue().toDouble(); } }
private static <T> T getPlaceholderVertexValue(Vertex<T> vertex) { if (!vertex.hasValue()) { throw new IllegalStateException("Cannot get value because PlaceholderVertex has not been initialized."); } return vertex.getValue(); } }
@Override public BooleanTensor calculate() { assertion(); return predicate.getValue(); }
@Override public T calculate() { Vertex<T> selector = getSelector(); return selector.getValue(); }
/** * Cause this vertex to observe its own value, for example when generating test data */ public void observeOwnValue() { observe(getValue()); }
public List<Vertex> getDiscreteLatentVertices() { return getLatentVertices().stream() .filter(v -> !(v.getValue() instanceof DoubleTensor)) .collect(Collectors.toList()); }
@Override public void saveValue(Vertex vertex) { if (vertex.hasValue() && vertex.getValue() instanceof Tensor) { setDotLabelWithValue(vertex); } else { dotLabels.add(new VertexDotLabel(vertex)); } }
@Override public IntegerTensor calculate() { final CPTCondition condition = CPTCondition.from(inputs, v -> v.getValue().scalar()); IntegerVertex vertex = conditions.get(condition); return vertex == null ? defaultResult.getValue() : vertex.getValue(); } }
private void assertion() { if (!predicate.getValue().allTrue()) { throw new GraphAssertionException(buildAssertMessage()); } }
private String formatCommandForExecution(Map<VertexLabel, Vertex<? extends Tensor>> inputs, String command) { for (Map.Entry<VertexLabel, io.improbable.keanu.vertices.Vertex<? extends Tensor>> input : inputs.entrySet()) { String argument = "{" + input.getKey().toString() + "}"; command = command.replaceAll(Pattern.quote(argument), input.getValue().getValue().scalar().toString()); } return command; }