
ย
Dear Students Student,๐๐โจ
To ensure a smooth process of submitting your assignment and guaranteeing that your hard work gets the recognition it deserves, I have prepared a brief guide to help you navigate the submission process for this particular assignment: Non-linear regressor in a microcontroller. Follow these steps to avoid last-minute hassles and ensure your assignment reaches the intended recipients without any glitches.
Note: Please consider that this session must be presented running on the microcontroller (Arduino-uno, MSP430, or other)
1. Main goal ๐โ๏ธ:
2. Nonlinear Relationship ๐งฎ๐:
(input, target)
->
(voltage, distance) for training your model.ย

ย
The next point must be covered to present your model successfully:
ย
3. Create the model using
TensorFlow
๐:
Dense layer is a fully connected neural network layer, meaning each neuron receives input from all neurons of the previous layer. This is a crucial component in creating neural networks, including those for nonlinear regression or classification tasks.
Sequential
model from
Keras
(which is part of TensorFlow) to stack layers. Here's an example of a simple neural network with two Dense layers for a nonlinear task; don't forget to change the
activation
parameter:import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Input
ย
l0 = Input(shape=(1,), name='l0')
l1 = Dense(units=20, activation='linear', name='l1') l2 = Dense(units=1, activation='linear', name='l2') model = Sequential([l0, l1, l2])
4. Prepared input data :

Where:
In Python, it can be implemented as follows
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler().fit(input)
inpScaler = scaler.transform(input) # data ready for ANN
5. Train the model ๐๐:
mean_squared_error
as the loss function and use the loss to determine if your model is ready. ย ย from tensorflow.keras.optimizers import Adam
modelo.compile(optimizer=Adam(0.1), loss='mean_squared_error')
historial = modelo.fit(celsius, fahrenheit, epochs=100, verbose=False)
plt.xlabel("# Epochs")
plt.ylabel("MSE")
plt.plot(historial.history["loss"], '.k')
plt.show()
6. Activation functions ๐๐:
In TensorFlow and Keras, you have several activation function options to choose from for your neural network layers. Each activation function serves a different purpose and is suitable for different kinds of tasks. Here's a list of some commonly used activation functions:
ReLU (Rectified Linear Unit):
Sigmoid:
Tanh (Hyperbolic Tangent):
Softmax:
Linear:
activation='linear'
7. Plot and compare ๐๐:
linspace
) and plot the results Vs. the real data.8. ANN implementation ๐ป0๏ธโฃ1๏ธโฃ:
ย
double relu(double x)
{
if(x>=0)
return x;
else if(x<0)
return 0;
}
ย
ย
Warm regards,
Gerardo Marx
Lecturer