/** * Cause this vertex to observe its own value, for example when generating test data */ public void observeOwnValue() { observe(getValue()); }
private void setOrObserveValue(Vertex vertex, Tensor valueTensor, boolean isObserved) { if (isObserved) { vertex.observe(valueTensor); } else { vertex.setValue(valueTensor); } }
@Override public void observeValues(DoubleTensor input, OUTPUT output) { xVertex.setValue(input); yObservationVertex.observe(output); }
public void observe(double[] values) { super.observe(DoubleTensor.create(values)); }
public void observe(boolean[] values) { super.observe(BooleanTensor.create(values)); }
public void observe(boolean value) { super.observe(BooleanTensor.scalar(value)); }
public void observe(int value) { super.observe(IntegerTensor.scalar(value)); }
public void observe(int[] values) { super.observe(IntegerTensor.create(values)); }
public void observe(double value) { super.observe(DoubleTensor.scalar(value)); }
@Test public void itRestoresTheValueOfAnObservedVertex() { DoubleTensor originalValue = DoubleTensor.create(1., 2., 3.); DoubleTensor otherValue = DoubleTensor.create(4., 5., 6.); Vertex vertex = new GaussianVertex(1., 0.); vertex.observe(originalValue); assertThat(vertex.getValue(), equalTo(originalValue)); assertThat(vertex.isObserved(), is(true)); NetworkSnapshot snapshot = NetworkSnapshot.create(ImmutableSet.of(vertex)); vertex.observe(otherValue); assertThat(vertex.getValue(), equalTo(otherValue)); assertThat(vertex.isObserved(), is(true)); snapshot.apply(); assertThat(vertex.getValue(), equalTo(originalValue)); assertThat(vertex.isObserved(), is(true)); }
@Test public void itRestoresTheObservedStatusOfAnObservedVertex() { DoubleTensor originalValue = DoubleTensor.create(1., 2., 3.); DoubleTensor otherValue = DoubleTensor.create(4., 5., 6.); Vertex vertex = new GaussianVertex(1., 0.); vertex.observe(originalValue); assertThat(vertex.getValue(), equalTo(originalValue)); assertThat(vertex.isObserved(), is(true)); NetworkSnapshot snapshot = NetworkSnapshot.create(ImmutableSet.of(vertex)); vertex.unobserve(); assertThat(vertex.getValue(), equalTo(originalValue)); assertThat(vertex.isObserved(), is(false)); vertex.setValue(otherValue); assertThat(vertex.getValue(), equalTo(otherValue)); assertThat(vertex.isObserved(), is(false)); snapshot.apply(); assertThat(vertex.getValue(), equalTo(originalValue)); assertThat(vertex.isObserved(), is(true)); } }