use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.
the class AverageCombinerTest method testSimpleTensorCase.
@Test
public void testSimpleTensorCase() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException {
List<SeldonMessage> predictorReturns = new ArrayList<>();
String[] names = { "c", "d" };
Double[] values1 = { 1.0, 1.0 };
predictorReturns.add(SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(names)).setTensor(Tensor.newBuilder().addShape(1).addShape(2).addAllValues(Arrays.asList(values1)).build()).build()).build());
Double[] values2 = { 1.0, 0.5 };
predictorReturns.add(SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(names)).setTensor(Tensor.newBuilder().addShape(1).addShape(2).addAllValues(Arrays.asList(values2)).build()).build()).build());
Double[] values3 = { 2.2, 0.9 };
predictorReturns.add(SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(names)).setTensor(Tensor.newBuilder().addShape(1).addShape(2).addAllValues(Arrays.asList(values3)).build()).build()).build());
AverageCombinerUnit averageCombinerUnit = new AverageCombinerUnit();
SeldonMessage average = averageCombinerUnit.aggregate(predictorReturns, null);
Assert.assertThat(average.getData().getNamesList().get(0), is(names[0]));
Double[][] expected_values = { { (1.0 + 1.0 + 2.2) / 3, (1.0 + 0.5 + 0.9) / 3 } };
Assert.assertEquals(expected_values[0][0], average.getData().getTensor().getValuesList().get(0), 1e-7);
}
use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.
the class AverageCombinerTest method testGetOutputNoChildren.
@Test
public void testGetOutputNoChildren() throws InterruptedException, ExecutionException, InvalidProtocolBufferException {
SeldonMessage p = SeldonMessage.newBuilder().build();
PredictiveUnitState state = new PredictiveUnitState("Cool_name", null, new ArrayList<PredictiveUnitState>(), null, null, null, null, PredictiveUnitImplementation.AVERAGE_COMBINER);
PredictiveUnitBean predictiveUnit = new PredictiveUnitBean();
SimpleModelUnit simpleModel = new SimpleModelUnit();
SimpleRouterUnit simpleRouterUnit = new SimpleRouterUnit();
AverageCombinerUnit averageCombiner = new AverageCombinerUnit();
RandomABTestUnit randomABTest = new RandomABTestUnit();
PredictorConfigBean predictorConfig = new PredictorConfigBean(simpleModel, simpleRouterUnit, averageCombiner, randomABTest);
predictiveUnit.predictorConfig = predictorConfig;
predictiveUnit.getOutput(p, state);
}
use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.
the class AverageCombinerTest method testUniqueValue.
@Test
public void testUniqueValue() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException {
List<SeldonMessage> predictorReturns = new ArrayList<>();
String[] names = { "c" };
Double[] values1 = { 1.0 };
predictorReturns.add(SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(names)).setTensor(Tensor.newBuilder().addShape(1).addShape(1).addAllValues(Arrays.asList(values1)).build()).build()).build());
Double[] values2 = { 1.0 };
predictorReturns.add(SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(names)).setTensor(Tensor.newBuilder().addShape(1).addShape(1).addAllValues(Arrays.asList(values2)).build()).build()).build());
AverageCombinerUnit averageCombinerUnit = new AverageCombinerUnit();
SeldonMessage average = averageCombinerUnit.aggregate(predictorReturns, null);
Assert.assertThat(average.getData().getNamesList().get(0), is(names[0]));
Double[][] expected_values = { { 2.0 / 2 } };
Assert.assertThat(average.getData().getTensor().getValuesList().get(0), is(expected_values[0][0]));
}
use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.
the class RandomABTestUnitInternalTest method failureOneChild.
@Test(expected = APIException.class)
public void failureOneChild() throws Throwable {
SeldonMessage request = SeldonMessage.newBuilder().build();
PredictiveUnitParameter<Float> ratioParam = new PredictiveUnitParameter<Float>(0.5F);
Map<String, PredictiveUnitParameterInterface> params = new HashMap<>();
params.put("ratioA", ratioParam);
PredictiveUnitState state = new PredictiveUnitState("Cool_name", null, new ArrayList<PredictiveUnitState>(), params, null, null, null, PredictiveUnitImplementation.RANDOM_ABTEST);
PredictiveUnitState childA = new PredictiveUnitState("A", null, null, null, null, null, null, null);
state.addChild(childA);
PredictiveUnitImpl predictiveUnit = new RandomABTestUnit();
predictiveUnit.route(request, state);
}
use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.
the class RandomABTestUnitInternalTest method simpleCase.
@Test
public void simpleCase() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvalidProtocolBufferException {
SeldonMessage request = SeldonMessage.newBuilder().build();
PredictiveUnitParameter<Float> ratioParam = new PredictiveUnitParameter<Float>(0.5F);
Map<String, PredictiveUnitParameterInterface> params = new HashMap<>();
params.put("ratioA", ratioParam);
PredictiveUnitState state = new PredictiveUnitState("Cool_name", null, new ArrayList<PredictiveUnitState>(), params, null, null, null, PredictiveUnitImplementation.RANDOM_ABTEST);
PredictiveUnitState childA = new PredictiveUnitState("A", null, null, null, null, null, null, null);
PredictiveUnitState childB = new PredictiveUnitState("B", null, null, null, null, null, null, null);
state.addChild(childA);
state.addChild(childB);
PredictiveUnitImpl predictiveUnit = new RandomABTestUnit();
// The following values are from random seed 1337
int routing1 = (int) predictiveUnit.route(request, state);
Assert.assertEquals(1, routing1);
int routing2 = (int) predictiveUnit.route(request, state);
Assert.assertEquals(0, routing2);
int routing3 = (int) predictiveUnit.route(request, state);
Assert.assertEquals(1, routing3);
}
Aggregations