Azzera filtri
Azzera filtri

Neural Networks with constrains

3 visualizzazioni (ultimi 30 giorni)
Yonny Muñoz Muñoz
Yonny Muñoz Muñoz il 25 Mag 2023
Risposto: Shubham il 1 Giu 2023
Hello,
I am using the NN toolbox to solve a problem target = F(variables) and It works really good. However, I need that every inputs into "variables" be positive. Is it possible to do it in Matlab?
Thank you very much
Yonny
  1 Commento
Yonny Muñoz Muñoz
Yonny Muñoz Muñoz il 25 Mag 2023
So, the thing is that "variables" are calculated by using the targets that the NN predicts, i.e. "variables" is a "post-processing" vector. It would be great to write into the NN code that those "variables" should be positive, so that once I calculate them with another postprocessing code they are all positive.

Accedi per commentare.

Risposte (1)

Shubham
Shubham il 1 Giu 2023
Hi Yonny,
Yes, it is possible to constrain the inputs to your neural network to be positive using the MATLAB NN Toolbox.
One way you can achieve this is by preprocessing your data before training the network. You can use MATLAB's mapminmax function to scale your input data to a range of [0, 1] and then multiply the scaled data by the maximum value of your input variables to ensure that all inputs are positive.
Here's an example code snippet that shows how you can apply this preprocessing step:
% Assume that your input data is stored in an n-by-m matrix X, where n is the number of samples and m is the number of variables.
% Scale the input data to [0, 1]
[X_scaled, PS] = mapminmax(X');
X_scaled = X_scaled';
% Multiply the scaled data by the maximum value of your input variables
max_vals = max(X);
X_pos = X_scaled .* repmat(max_vals, n, 1);
After preprocessing your data, you can use X_pos as the input to your neural network to ensure that all inputs are positive.
I hope this helps!

Categorie

Scopri di più su Measurements and Feature Extraction in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by