import numpy as np
# Get sample data of inputs and output
inputs = []
outputs = []
for i in range(100):
input1 = np.random.uniform(-1, 1)
input2 = np.random.uniform(-1, 1)
input3 = np.random.uniform(-1, 1)
output = hidden_model_function(input1, input2, input3)
inputs.append([input1, input2, input3])
outputs.append(output)
# Convert to numpy arrays
inputs = np.array(inputs)
outputs = np.array(outputs)
# Define model
model = Sequential()
model.add(Dense(3, input_dim=3, activation='linear'))
model.add(Dense(1, activation='linear'))
# Compile model
model.compile(loss='mean_squared_error', optimizer='adam')
# Train model
model.fit(inputs, outputs, epochs=1000, batch_size=32)
# Extract weights and biases
w1, b1 = model.layers[0].get_weights()
w2, b2 = model.layers[1].get_weights()
# Reverse engineered model function
def reverse_engineered_model(x1, x2, x3):
return (w1[0]*x1 + w1[1]*x2 + w1[2]*x3 + b1) * w2 + b2
This code generates sample input/output data from the hidden model, trains a neural network model to fit that data, and then extracts the weights and biases to define a reverse engineered model function.