def test_categorical_indicator_node_create_and_eval_keras(): alpha = 0.0 data = numpy.array([[1, 1, 1, 0], [0, 0, 1, 0], [0, 0, 1, 0], [1, 0, 0, 0], [1, 0, 1, 0], [0, 1, 1, 0], [MARG_IND, 0, 0, 1], [MARG_IND, MARG_IND, MARG_IND, MARG_IND]]).astype(numpy.int32) input = K.placeholder(ndim=2, dtype='int32') for i, var in enumerate(vars): for j in [0, 1]: log_vals = [] print('var {} val {}'.format(i, j)) smi = CategoricalIndicatorNode(i, j) print(smi) smi.build_k(input) for d in data: # print(d) smi.eval(d) log_vals.append(smi.log_val) print('smi values') print(smi.log_val) eval_input_node_f = K.function([input], [smi.log_vals]) keras_log_vals = eval_input_node_f([data])[0] print('keras vals') print(keras_log_vals) assert_array_almost_equal(numpy.array(log_vals)[:, numpy.newaxis], keras_log_vals, decimal=4)
def test_categorical_indicator_node_create_and_eval(): # created a node on the first var and its first value ind = CategoricalIndicatorNode(0, 0) # seen x0 = 0 -> 1. ind.eval(0) assert ind.log_val == 0. # this indicator is not fired ind.eval(1) assert ind.log_val == LOG_ZERO # all indicators for that var are fired ind.eval(MARG_IND) assert ind.log_val == 0. # the var has only 2 values, but the node does not know! ind.eval(2) assert ind.log_val == LOG_ZERO