Ejemplo n.º 1
0
def create_nam_model(x_train,
                     dropout,
                     feature_dropout=0.0,
                     num_basis_functions=1000,
                     units_multiplier=2,
                     activation='exu',
                     name_scope='model',
                     shallow=True,
                     trainable=True):
    """Create the NAM model."""
    num_unique_vals = [
        len(np.unique(x_train[:, i])) for i in range(x_train.shape[1])
    ]
    num_units = [
        min(num_basis_functions, i * units_multiplier) for i in num_unique_vals
    ]
    num_inputs = x_train.shape[-1]
    nn_model = models.NAM(num_inputs=num_inputs,
                          num_units=num_units,
                          dropout=np.float32(dropout),
                          feature_dropout=np.float32(feature_dropout),
                          activation=activation,
                          shallow=shallow,
                          trainable=trainable,
                          name_scope=name_scope)
    return nn_model
Ejemplo n.º 2
0
 def test_model(self, architecture):
     """Test whether a model with specified architecture can be run."""
     x = np.random.rand(5, 10).astype('float32')
     sess = tf.InteractiveSession()
     if architecture == 'exu_nam':
         model = models.NAM(num_inputs=x.shape[1],
                            num_units=1024,
                            shallow=True,
                            activation='exu')
     elif architecture == 'relu_nam':
         model = models.NAM(num_inputs=x.shape[1],
                            num_units=64,
                            shallow=False,
                            activation='relu')
     elif architecture == 'dnn':
         model = models.DNN()
     else:
         raise ValueError('Architecture {} not found'.format(architecture))
     out_op = model(x)
     sess.run(tf.global_variables_initializer())
     self.assertIsInstance(sess.run(out_op), np.ndarray)
     sess.close()