Пример #1
0
    def testEmptyRnnInput(self):
        observation_values = tf.SparseTensor(
            indices=tf.reshape(tf.constant([], dtype=tf.int64), shape=[0, 3]),
            values=tf.constant([], dtype=tf.float32),
            dense_shape=[2, 0, 1])
        observation_code_ids = tf.SparseTensor(
            indices=observation_values.indices,
            values=tf.constant([], dtype=tf.string),
            dense_shape=observation_values.dense_shape)
        delta_time, obs_values, indicator = osm.construct_input(
            {
                'Observation.code':
                observation_code_ids,
                'Observation.valueQuantity.value':
                observation_values,
                'deltaTime':
                tf.reshape(tf.constant([[], []], dtype=tf.int64), [2, 0, 1])
            }, ['loinc:1', 'loinc:2', 'MISSING'],
            'Observation.code',
            'Observation.valueQuantity.value',
            mode=tf.estimator.ModeKeys.TRAIN,
            normalize=False,
            momentum=0.9,
            min_value=-10000000,
            max_value=10000000,
            input_keep_prob=1.0)

        result = tf.concat([delta_time, indicator, obs_values], axis=2)

        with self.test_session() as sess:
            sess.run(tf.tables_initializer())
            actual_result, = sess.run([tf.shape(result)])
            self.assertAllClose([2, 0, 7], actual_result)
Пример #2
0
    def testRnnInput(self):
        observation_values = tf.SparseTensor(
            indices=[[0, 0, 0], [0, 1, 0], [0, 2, 0], [1, 0, 0], [1, 1, 0],
                     [1, 2, 0]],
            values=[100.0, 2.3, 9999999.0, 0.5, 0.0, 4.0],
            dense_shape=[2, 3, 1])
        observation_code_ids = tf.SparseTensor(
            indices=observation_values.indices,
            values=[
                'loinc:2', 'loinc:1', 'loinc:2', 'loinc:1', 'MISSING',
                'loinc:1'
            ],
            dense_shape=observation_values.dense_shape)
        delta_time, obs_values, indicator = osm.construct_input(
            {
                'Observation.code':
                observation_code_ids,
                'Observation.valueQuantity.value':
                observation_values,
                'deltaTime':
                tf.constant([[[2 * 60 * 60], [3 * 60 * 60], [0]],
                             [[1 * 60 * 60], [3 * 60 * 60], [6 * 60 * 60]]],
                            dtype=tf.int64)
            }, ['loinc:1', 'loinc:2', 'MISSING'],
            'Observation.code',
            'Observation.valueQuantity.value',
            mode=tf.estimator.ModeKeys.TRAIN,
            normalize=False,
            momentum=0.9,
            min_value=-10000000,
            max_value=10000000,
            input_keep_prob=1.0)

        result = tf.concat([delta_time, indicator, obs_values], axis=2)

        expected_result = [
            [
                [0, 0, 1, 0, 0, 100, 0],
                [-1, 1, 0, 0, 2.3, 0, 0],
                # value 9999999.0 was filtered.
                [3, 0, 0, 0, 0, 0, 0]
            ],
            [[0, 1, 0, 0, 0.5, 0, 0], [-2, 0, 0, 1, 0, 0, 0],
             [-3, 1, 0, 0, 4.0, 0, 0]]
        ]

        with self.test_session() as sess:
            sess.run(tf.tables_initializer())
            actual_result = sess.run(result)
            print(actual_result)
            self.assertAllClose(expected_result, actual_result, atol=0.01)