# Set a specific weight for a connection in neural networks

43 views (last 30 days)
Abdelwahab Afifi on 9 Jan 2020
Commented: LukasJ on 7 Sep 2020
I have already build my neural network. I wanna set a specific weight for the conection from layer i to layer j
foe example ...set weights from the inputs to the outputs = 1
How can i do this in MATLAB ?
X=Calculations('comp2real' , PA_in); % convert nx1 complex vector to nx2 real vector
T=Calculations('comp2real' , PA_out);
%% Network structure
net = feedforwardnet(20);
% net.numInputs=2
% net.layers{2}.size=2;
net.biasConnect=[1;0];
% net.inputWeights{2,1}.weight=1;
net.inputWeights{2,1}.learn=0;
net.layers{1}.transferFcn = 'poslin';
% net.inputConnect=[1 1;1 1]
net.inputConnect=[1;1];
[net tr] = train(net,X,T);
plotperform(tr)
view(net)
wb=getwb(net);
Param_num=length(wb)
Evaluation
Y = net(X);
perf = perform(net,T,Y)
Adam Danz on 9 Jan 2020
Have you tried to search for the answer to this question? Google has returned some useful examples and starting points to solving this. Searching the matlab documentation directly is also helpful. Without providing more context, how you created the neural network, etc; we're shooting in the dark. I'd be interested in hearing what solutions you've found and where we can help implement them.

Srivardhan Gadila on 24 Jan 2020
Please refer to the following Weight and Bias Values, Input Weights, Layer Weights
If by "I have already build my neural network" you imply that
1. The network architecture is defined and has to be trained:
Then 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})
2. The 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.
LukasJ on 7 Sep 2020
I think my Issue with the updating of the weights could be related.
Thanks in advance and best regards,
Lukas

### Community Treasure Hunt

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

Start Hunting!

Translated by