Neural Networks with constrains

조회 수: 7 (최근 30일)
Yonny Muñoz Muñoz
Yonny Muñoz Muñoz 2023년 5월 25일
답변: Shubham 2023년 6월 1일
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
Yonny Muñoz Muñoz
Yonny Muñoz Muñoz 2023년 5월 25일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Shubham
Shubham 2023년 6월 1일
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!

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by