def create_model(Bias_layer,
                 low,
                 up,
                 F,
                 beta,
                 gamma,
                 Co,
                 m,
                 a0RNN,
                 batch_input_shape,
                 selectbias,
                 selectidx,
                 selectdk,
                 selectwk,
                 myDtype,
                 return_sequences=False,
                 unroll=False):

    batch_adjusted_shape = (batch_input_shape[2] + 1, )  #Adding state
    placeHolder = Input(shape=(batch_input_shape[2] + 1, ))  #Adding state

    filterBias = inputsSelection(batch_adjusted_shape, selectbias)(placeHolder)

    filterSig = inputsSelection(batch_adjusted_shape, selectidx)(placeHolder)

    filterdK = inputsSelection(batch_adjusted_shape, selectdk)(placeHolder)

    filterda = inputsSelection(batch_adjusted_shape, selectwk)(placeHolder)

    MLP_min = low
    MLP_range = up - low

    Bias_layer = Bias_layer(filterBias)
    MLP = Lambda(lambda x: ((x * MLP_range) + MLP_min))(Bias_layer)

    Filter = Lambda(lambda x: sign(x))(filterSig)

    Bias_filtered_layer = Multiply()([MLP, Filter])

    dk_input_shape = filterdK.get_shape()

    dkLayer = StressIntensityRange(input_shape=dk_input_shape,
                                   dtype=myDtype,
                                   trainable=False)
    dkLayer.build(input_shape=dk_input_shape)
    dkLayer.set_weights([np.asarray([F], dtype=dkLayer.dtype)])
    dkLayer = dkLayer(filterdK)

    wmInput = Concatenate(axis=-1)([dkLayer, filterda])
    wm_input_shape = wmInput.get_shape()

    wmLayer = WalkerModel(input_shape=wm_input_shape,
                          dtype=myDtype,
                          trainable=False)
    wmLayer.build(input_shape=wm_input_shape)
    wmLayer.set_weights(
        [np.asarray([beta, gamma, Co, m], dtype=wmLayer.dtype)])
    wmLayer = wmLayer(wmInput)

    da_layer = Add()([Bias_filtered_layer, wmLayer])

    functionalModel = Model(inputs=[placeHolder], outputs=[da_layer])
    "-------------------------------------------------------------------------"
    CDMCellHybrid = CumulativeDamageCell(model=functionalModel,
                                         batch_input_shape=batch_input_shape,
                                         dtype=myDtype,
                                         initial_damage=a0RNN)

    CDMRNNhybrid = RNN(cell=CDMCellHybrid,
                       return_sequences=return_sequences,
                       return_state=False,
                       batch_input_shape=batch_input_shape,
                       unroll=unroll)

    model = Sequential()
    model.add(CDMRNNhybrid)
    model.compile(loss=mape, optimizer=RMSprop(1e-11), metrics=['mse'])
    return model
def create_pinn_model(a,
                      b,
                      Pu,
                      grid_array_aSKF,
                      bounds_aSKF,
                      table_shape_aSKF,
                      grid_array_kappa,
                      bounds_kappa,
                      table_shape_kappa,
                      grid_array_etac,
                      bounds_etac,
                      table_shape_etac,
                      d0RNN,
                      batch_input_shape,
                      selectdKappa,
                      selectCycle,
                      selectLoad,
                      selectBTemp,
                      myDtype,
                      return_sequences=False,
                      unroll=False):

    batch_adjusted_shape = (batch_input_shape[2] + 1, )  #Adding states
    placeHolder = Input(shape=(batch_input_shape[2] + 1, ))  #Adding states

    filterdKappaLayer = inputsSelection(batch_adjusted_shape,
                                        selectdKappa)(placeHolder)
    filterCycleLayer = inputsSelection(batch_adjusted_shape,
                                       selectCycle)(placeHolder)
    filterLoadLayer = inputsSelection(batch_adjusted_shape,
                                      selectLoad)(placeHolder)
    filterBTempLayer = inputsSelection(batch_adjusted_shape,
                                       selectBTemp)(placeHolder)

    physicalSpaceInvLoadLayer = Lambda(lambda x: (1 / (10**x)))(
        filterLoadLayer)

    xvalKappaLayer = Concatenate(axis=-1)(
        [filterBTempLayer, filterdKappaLayer])

    kappaLayer = TableInterpolation(table_shape=table_shape_kappa,
                                    dtype=myDtype,
                                    trainable=False)
    kappaLayer.build(input_shape=xvalKappaLayer.shape)
    kappaLayer.set_weights([grid_array_kappa, bounds_kappa])
    kappaLayer = kappaLayer(xvalKappaLayer)

    xvalEtacLayer = Concatenate(axis=-1)([kappaLayer, filterdKappaLayer])

    etacLayer = TableInterpolation(table_shape=table_shape_etac,
                                   dtype=myDtype,
                                   trainable=False)
    etacLayer.build(input_shape=xvalEtacLayer.shape)
    etacLayer.set_weights([grid_array_etac, bounds_etac])
    etacLayer = etacLayer(xvalEtacLayer)

    xvalLayer1 = Lambda(lambda x: Pu * x)(etacLayer)
    xvalLayer2 = Multiply()([xvalLayer1, physicalSpaceInvLoadLayer])

    xvalLayer = Concatenate(axis=-1)([xvalLayer2, kappaLayer])

    aSKFLayer = TableInterpolation(table_shape=table_shape_aSKF,
                                   dtype=myDtype,
                                   trainable=False)
    aSKFLayer.build(input_shape=xvalLayer.shape)
    aSKFLayer.set_weights([grid_array_aSKF, bounds_aSKF])
    aSKFLayer = aSKFLayer(xvalLayer)

    inverseaSKFLayer = Lambda(lambda x: (1 / x))(aSKFLayer)

    sn_input_shape = (batch_input_shape[0], batch_input_shape[2])

    SNLayer = SNCurve(input_shape=sn_input_shape,
                      dtype=myDtype,
                      trainable=False)
    SNLayer.build(input_shape=sn_input_shape)
    SNLayer.set_weights([np.asarray([a, b], dtype=SNLayer.dtype)])
    SNLayer = SNLayer(filterLoadLayer)

    multiplyLayer1 = Multiply()([SNLayer, filterCycleLayer])

    multiplyLayer2 = Multiply()([multiplyLayer1, inverseaSKFLayer])

    functionalModel = Model(inputs=[placeHolder], outputs=[multiplyLayer2])

    "-------------------------------------------------------------------------"
    CDMCellHybrid = CumulativeDamageCell(model=functionalModel,
                                         batch_input_shape=batch_input_shape,
                                         dtype=myDtype,
                                         initial_damage=d0RNN)

    CDMRNNhybrid = RNN(cell=CDMCellHybrid,
                       return_sequences=return_sequences,
                       return_state=False,
                       batch_input_shape=batch_input_shape,
                       unroll=unroll)

    model = Sequential()
    model.add(CDMRNNhybrid)
    model.compile(loss='mse', optimizer=RMSprop(5e-4), metrics=['mae'])
    return model
def create_physics_model(radius, length, thickness, poisson, inertia,
                         storage_data, storage_bounds, storage_table_shape,
                         loss_data, loss_bounds, loss_table_shape, select_freq,
                         select_temp, batch_input_shape, myDtype):
    batch_adjusted_shape = (batch_input_shape[1], )
    inputLayer = Input(shape=(batch_input_shape[1], ))

    freqLayer = inputsSelection(batch_adjusted_shape, select_freq)(inputLayer)
    tempLayer = inputsSelection(batch_adjusted_shape, select_temp)(inputLayer)

    omegaLayer = Lambda(lambda x: 2 * np.pi * x)(freqLayer)

    moduliInputLayer = Concatenate(axis=-1)([tempLayer, freqLayer])

    storageModulusLayer = TableInterpolation(table_shape=storage_table_shape,
                                             dtype=myDtype,
                                             trainable=False)
    storageModulusLayer.build(input_shape=moduliInputLayer.shape)
    storageModulusLayer.set_weights([storage_data, storage_bounds])
    storageModulusLayer = storageModulusLayer(moduliInputLayer)

    lossModulusLayer = TableInterpolation(table_shape=loss_table_shape,
                                          dtype=myDtype,
                                          trainable=False)
    lossModulusLayer.build(input_shape=moduliInputLayer.shape)
    lossModulusLayer.set_weights([loss_data, loss_bounds])
    lossModulusLayer = lossModulusLayer(moduliInputLayer)

    stiffnessLayer = Stiffness(input_shape=storageModulusLayer.shape,
                               dtype=myDtype,
                               trainable=False)
    stiffnessLayer.build(input_shape=storageModulusLayer.shape)
    stiffnessLayer.set_weights(
        [np.asarray([poisson], dtype=stiffnessLayer.dtype)])
    stiffnessLayer = stiffnessLayer(storageModulusLayer)
    artificialDelta1Layer = Lambda(lambda x: x[0] - x[1] * 10 + x[0] / x[1])(
        [freqLayer, tempLayer])
    modifiedStiffnessLayer = Lambda(lambda x: x[0] + x[1])(
        [stiffnessLayer, artificialDelta1Layer])

    dampingInputLayer = Concatenate(axis=-1)(
        [modifiedStiffnessLayer, storageModulusLayer, lossModulusLayer])

    dampingLayer = Damping(input_shape=dampingInputLayer.shape,
                           dtype=myDtype,
                           trainable=False)
    dampingLayer.build(input_shape=dampingInputLayer.shape)
    dampingLayer.set_weights([np.asarray([inertia], dtype=dampingLayer.dtype)])
    dampingLayer = dampingLayer(dampingInputLayer)
    artificialDelta2Layer = Lambda(lambda x: x[0] / 250 - x[1] / 50 + x[0] /
                                   (10 * x[1]))([freqLayer, tempLayer])
    modifiedDampingLayer = Lambda(lambda x: x[0] + x[1])(
        [dampingLayer, artificialDelta2Layer])

    FRFAmpInputLayer = Concatenate(axis=-1)(
        [omegaLayer, modifiedStiffnessLayer, modifiedDampingLayer])

    FRFAmpLayer = FRFAmplitude(input_shape=FRFAmpInputLayer.shape,
                               dtype=myDtype,
                               trainable=False)
    FRFAmpLayer.build(input_shape=FRFAmpInputLayer.shape)
    FRFAmpLayer.set_weights([np.asarray([inertia], dtype=FRFAmpLayer.dtype)])
    FRFAmpLayer = FRFAmpLayer(FRFAmpInputLayer)

    functionalModel = Model(inputs=[inputLayer], outputs=[FRFAmpLayer])

    functionalModel.compile(
        loss='mean_squared_error',
        optimizer=Adam(1e-2),
        metrics=['mean_absolute_error', 'mean_squared_error'])
    return functionalModel
def create_calibration_model(
        storage_coefs, loss_coefs, radius, length, thickness, poisson, inertia,
        storage_data, storage_bounds, storage_table_shape, loss_data,
        loss_bounds, loss_table_shape, delta_stiffness_mlp, delta_damping_mlp,
        stiffness_low, stiffness_up, damping_low, damping_up, input_min,
        input_range, select_freq, select_temp, batch_input_shape, myDtype):
    batch_adjusted_shape = (batch_input_shape[1], )
    inputLayer = Input(shape=(batch_input_shape[1], ))

    normalizedInputLayer = Lambda(
        lambda x, input_min=input_min, input_range=input_range:
        (x - input_min) / input_range)(inputLayer)

    freqLayer = inputsSelection(batch_adjusted_shape, select_freq)(inputLayer)
    tempLayer = inputsSelection(batch_adjusted_shape, select_temp)(inputLayer)

    omegaLayer = Lambda(lambda x: 2 * np.pi * x)(freqLayer)

    moduliInputLayer = Concatenate(axis=-1)([tempLayer, freqLayer])

    storageModulusLayer = TableInterpolation(table_shape=storage_table_shape,
                                             dtype=myDtype,
                                             trainable=False)
    storageModulusLayer.build(input_shape=moduliInputLayer.shape)
    storageModulusLayer.set_weights([storage_data, storage_bounds])
    storageModulusLayer = storageModulusLayer(moduliInputLayer)

    lossModulusLayer = TableInterpolation(table_shape=loss_table_shape,
                                          dtype=myDtype,
                                          trainable=False)
    lossModulusLayer.build(input_shape=moduliInputLayer.shape)
    lossModulusLayer.set_weights([loss_data, loss_bounds])
    lossModulusLayer = lossModulusLayer(moduliInputLayer)

    stiffnessLayer = Stiffness(input_shape=storageModulusLayer.shape,
                               dtype=myDtype,
                               trainable=True,
                               kernel_constraint=MinMaxNorm(min_value=-1.0,
                                                            max_value=0.5,
                                                            rate=1.0))
    stiffnessLayer.build(input_shape=storageModulusLayer.shape)
    stiffnessLayer.set_weights(
        [np.asarray([poisson], dtype=stiffnessLayer.dtype)])
    stiffnessLayer = stiffnessLayer(storageModulusLayer)

    deltaStiffnessLayer = delta_stiffness_mlp(normalizedInputLayer)
    scaledDeltaStiffnessLayer = Lambda(
        lambda x, stiffness_low=stiffness_low, stiffness_up=stiffness_up: x *
        (stiffness_up - stiffness_low) + stiffness_low)(deltaStiffnessLayer)
    correctedStiffnessLayer = Lambda(lambda x: x[0] + x[1])(
        [stiffnessLayer, scaledDeltaStiffnessLayer])

    dampingInputLayer = Concatenate(axis=-1)(
        [correctedStiffnessLayer, storageModulusLayer, lossModulusLayer])

    dampingLayer = Damping(input_shape=dampingInputLayer.shape,
                           dtype=myDtype,
                           trainable=False)
    dampingLayer.build(input_shape=dampingInputLayer.shape)
    dampingLayer.set_weights([np.asarray([inertia], dtype=dampingLayer.dtype)])
    dampingLayer = dampingLayer(dampingInputLayer)

    deltaDampingLayer = delta_damping_mlp(normalizedInputLayer)
    scaledDeltaDampingLayer = Lambda(
        lambda x, damping_low=damping_low, damping_up=damping_up: x *
        (damping_up - damping_low) + damping_low)(deltaDampingLayer)
    correctedDampingLayer = Lambda(lambda x: x[0] + x[1])(
        [dampingLayer, scaledDeltaDampingLayer])

    FRFAmpInputLayer = Concatenate(axis=-1)(
        [omegaLayer, correctedStiffnessLayer, correctedDampingLayer])

    FRFAmpLayer = FRFAmplitude(input_shape=FRFAmpInputLayer.shape,
                               dtype=myDtype,
                               trainable=False)
    FRFAmpLayer.build(input_shape=FRFAmpInputLayer.shape)
    FRFAmpLayer.set_weights([np.asarray([inertia], dtype=FRFAmpLayer.dtype)])
    FRFAmpLayer = FRFAmpLayer(FRFAmpInputLayer)

    functionalModel = Model(inputs=[inputLayer], outputs=[FRFAmpLayer])

    functionalModel.compile(
        loss='mean_squared_error',
        optimizer=Adam(5e-2),
        metrics=['mean_absolute_error', 'mean_squared_error'])
    return functionalModel
Beispiel #5
0
def create_model(MLP_C_layer,
                 MLP_m_layer,
                 low_C,
                 up_C,
                 low_m,
                 up_m,
                 F,
                 a0RNN,
                 batch_input_shape,
                 selectaux,
                 selectdk,
                 myDtype,
                 return_sequences=False,
                 unroll=False):

    batch_adjusted_shape = (batch_input_shape[2] + 1, )  #Adding state
    placeHolder = Input(shape=(batch_input_shape[2] + 1, ))  #Adding state

    filterLayer = inputsSelection(batch_adjusted_shape, selectaux)(placeHolder)

    filterdkLayer = inputsSelection(batch_adjusted_shape,
                                    selectdk)(placeHolder)

    MLP_C_min = low_C
    MLP_C_range = up_C - low_C

    MLP_C_layer = MLP_C_layer(filterLayer)
    C_layer = Lambda(lambda x: ((x * MLP_C_range) + MLP_C_min))(MLP_C_layer)

    MLP_m_min = low_m
    MLP_m_range = up_m - low_m

    MLP_m_layer = MLP_m_layer(filterLayer)
    MLP_scaled_m_layer = Lambda(lambda x: ((x * MLP_m_range) + MLP_m_min))(
        MLP_m_layer)

    dk_input_shape = filterdkLayer.get_shape()

    dkLayer = StressIntensityRange(input_shape=dk_input_shape,
                                   dtype=myDtype,
                                   trainable=False)
    dkLayer.build(input_shape=dk_input_shape)
    dkLayer.set_weights([np.asarray([F], dtype=dkLayer.dtype)])
    dkLayer = dkLayer(filterdkLayer)

    ldK_layer = Lambda(lambda x: tf.math.log(x) /
                       (tf.math.log(tf.constant(10.))))(dkLayer)

    dKm_layer = Multiply()([MLP_scaled_m_layer, ldK_layer])

    aux_layer = Add()([C_layer, dKm_layer])

    da_layer = Lambda(lambda x: 10**(x))(aux_layer)

    functionalModel = Model(inputs=[placeHolder], outputs=[da_layer])
    "-------------------------------------------------------------------------"
    CDMCellHybrid = CumulativeDamageCell(model=functionalModel,
                                         batch_input_shape=batch_input_shape,
                                         dtype=myDtype,
                                         initial_damage=a0RNN)

    CDMRNNhybrid = RNN(cell=CDMCellHybrid,
                       return_sequences=return_sequences,
                       return_state=False,
                       batch_input_shape=batch_input_shape,
                       unroll=unroll)

    model = Sequential()
    model.add(CDMRNNhybrid)
    model.compile(loss='mse',
                  optimizer=RMSprop(learning_rate=1e-6),
                  metrics=['mae'])
    return model