mechanoChemML.src.idnn¶
Module Contents¶
Functions¶
convex(M) |
|
convexMult(Ms) |
|
find_wells(idnn, x, dim=4, bounds=[0, 0.25], rereference=True) |
-
class
mechanoChemML.src.idnn.IDNN(input_dim, hidden_units, activation='softplus', dropout=None, transforms=None, unique_inputs=False, final_bias=False)[source]¶ Bases:
tensorflow.keras.ModelIntegrable deep neural network (idnn) Keras model class.
Parameters: - input_dim (int) – Size of input vector
- hidden_units ([int]) – List containing the number of neurons in each hidden layer
- dropout (float) – Dropout parameter applied after each hidden layer (default is None)
- transforms ([function]) – List of functions to transform the input vector, applied before the first hidden layer (default is None)
- unique_inputs (bool) – if True, requires separate input vectors for the function, its gradient, and its Hessian; if False, assumes the same input vector will be used for function and all derivatives
- final_bias (bool) – if True, a bias is applied to the output layer (this cannot be used if only derivative data is used in training); if False, no bias is applied to the output layer (default is False)
The idnn can be trained with first derivative (gradient) data, second derivative (Hessian) data, and/or data from the function itself. (If only derivative data is used then the
final_biasparameter must beFalse.) The training data for the function and its derivatives can be given at the same input values (in which case,unique_inputsshould beFalse), or at different input values, e.g. providing the function values at \(x \in \{0,1,2,3\}\) and the derivative values at \(x \in \{0.5,1.5,2.5,3.5\}\) (requiringunique_inputsto beTrue). Even whenunique_inputsisTrue, however, the same number of data points must be given for the derivatives and function, even though the input values themselves are different. So, for example, if one had first derivative values at \(x \in \{0,1,2,3\}\) and second derivative values only at \(x \in \{0.5,1.5,2.5\}\), then some of the second derivative data would need to be repeated to that the number of data points are equal, e.g. \(x \in \{0.5,1.5,2.5,2.5\}\). Currently, the IDNN structure assumes the function output is a scalar, the gradient is a vector, and the Hessian is a matrix.The following is an example where values for the function and the first derivative are used for training, but they are known at different input values. Note that the loss and loss_weights are defined only for the given data (function data and first derivatative data), but fictitious data has to be given for the second derivative or an error will be thrown:
idnn = IDNN(1, [20,20], unique_inputs=True, final_bias=True) idnn.compile(loss=['mse','mse',None], loss_weights=[0.01,1,None], optimizer=keras.optimizers.RMSprop(lr=0.01)) idnn.fit([c_train0,c_train,0*c_train], [g_train0,mu_train,0*mu_train], epochs=50000, batch_size=20)