Exemplo n.º 1
0
def create_model(a, b, batch_input_shape, da0RNN, ndex, myDtype, return_sequences = False, unroll = False):

    batch_adjusted_shape = (batch_input_shape[0], batch_input_shape[1], batch_input_shape[2]+1)
    dLSelction = inputsSelection(batch_adjusted_shape, ndex)

    n = batch_input_shape[0]
    da_input_shape = (n,2)
    
    daLayer = SNCurve(input_shape = da_input_shape, dtype = myDtype)
    daLayer.build(input_shape = da_input_shape)
    daLayer.set_weights([np.asarray([a,b], dtype = daLayer.dtype)])
    daLayer.trainable = False

    PINN = tf.keras.Sequential()
    PINN.add(dLSelction)
    PINN.add(daLayer)
    "-------------------------------------------------------------------------"
    CDMCell = CumulativeDamageCell(model = PINN,
                                       batch_input_shape = batch_input_shape,
                                       dtype = myDtype,
                                       initial_damage = da0RNN)

    CDMRNN = tf.keras.layers.RNN(cell = CDMCell,
                                       return_sequences = return_sequences,
                                       return_state = False,
                                       batch_input_shape = batch_input_shape,
                                       unroll = unroll)
    "-------------------------------------------------------------------------"
    model = tf.keras.Sequential()
    model.add(CDMRNN)

    model.compile(loss='mse', optimizer=tf.keras.optimizers.RMSprop(1e-12), metrics=['mae'])
    
    return model
Exemplo n.º 2
0
def create_physics_model(F,
                         C,
                         m,
                         batch_input_shape,
                         a0RNN,
                         myDtype,
                         return_sequences=False,
                         unroll=False):
    dk_input_shape = tensor_shape.TensorShape([2])

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

    da_input_shape = tensor_shape.TensorShape([None, 1])
    daLayer = ParisLaw(input_shape=da_input_shape, dtype=myDtype)
    daLayer.build(input_shape=da_input_shape)
    daLayer.set_weights([np.asarray([C, m], dtype=daLayer.dtype)])
    daLayer.trainable = False

    PINNhybrid = tf.keras.Sequential()
    PINNhybrid.add(dkLayer)
    PINNhybrid.add(daLayer)

    "-------------------------------------------------------------------------"
    CDMCellHybrid = CumulativeDamageCell(model=PINNhybrid,
                                         batch_input_shape=batch_input_shape,
                                         dtype=myDtype,
                                         initial_damage=a0RNN)

    CDMRNNhybrid = tf.keras.layers.RNN(cell=CDMCellHybrid,
                                       return_sequences=return_sequences,
                                       return_state=False,
                                       batch_input_shape=batch_input_shape,
                                       unroll=unroll)

    model = tf.keras.Sequential()
    model.add(CDMRNNhybrid)
    model.compile(loss='mse',
                  optimizer=tf.keras.optimizers.RMSprop(1e-12),
                  metrics=['mae'])

    return model
    def create_model(inspectionArray,
                     greaseMLP,
                     d0RNN,
                     batch_input_shape,
                     lowBounds_delgrs,
                     upBounds_delgrs,
                     myDtype,
                     return_sequences=False,
                     unroll=False):

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

        MLPOutputs = greaseMLP(placeHolder)

        scaledMLPOutputs = Lambda(lambda x, lowBounds_delgrs=lowBounds_delgrs,
                                  upBounds_delgrs=upBounds_delgrs: x *
                                  (upBounds_delgrs - lowBounds_delgrs
                                   ) + lowBounds_delgrs)(MLPOutputs)

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

        "-------------------------------------------------------------------------"
        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=maskedLoss,
                      optimizer=RMSprop(5e-4),
                      metrics=[maskedLoss])
        return model
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
Exemplo n.º 6
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