How to constrain Neural Network output weights to fixed values
4 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
i have the necessity to train a NN to predict a certain output y(t) given a dataset [x(t) w(t)]. where x and w are signals in time [x(1) x(2)...w(1) w(2)....]
I need the shape of the network to be:
y(k)=F(x(k))+G(x(k))*w(k)
Meaning that i give x and w as input to my network and the training procedure has to learn something like the equation before. F and G can be nonlinear but the relation between G and w has to be G(x)*w and this last product has to sum with F.
By playing with layers of NN i defined this structure in the image attached. My idea is to "fix" weights on the output layer to be 1 and w(k).
How can i do this in matlab? Is it possible to do this?
Thanks in advance
Best
Gianni![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/277526/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/277526/image.png)
0 个评论
回答(1 个)
Srivardhan Gadila
2020-3-21
You can access the layer weights as follows:
net.LW{i,j}
You can set any values to the above weights and set the net.layerWeights{i,j}.learn to 0 so that the weights won't be altered during the training & adaption. In this case setting a specific weight for a connection is not possible since the property net.layerWeights{i,j}.learn is defined for the entire connections between layers i and j.
net.layerWeights{i,j}.learn = 0
net.LW{i,j} = ones(size(net.LW{i,j})) % any weights of size(net.LW{i,j})
If your network architecture is defined and trained already:
Then you can set weight of a connection between nodes k & l of layers i & j as follows:
net.LW{i,j}(k,l) = 1
and then use the network.
The above things can be done to Input wieghts too.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!