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.
Neural Networks with constrains
조회 수: 7 (최근 30일)
이전 댓글 표시
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개)
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!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!