How to set weights of data sample for neural net training

조회 수: 25 (최근 30일)
Peter Krammer
Peter Krammer 2021년 10월 5일
답변: Srivardhan Gadila 2021년 10월 8일
Hello, I am trying to train the simple shallow neural net.
However, individual data records (samples / input vectors / instances) have different importance (weight), in my task.
Traditional code (from Matlab example) for neural network training is something like this :
x = [0 1 2 3 4 5 6 7 8]; % input attribute
t = [0 0.84 0.91 0.14 -0.77 -0.96 -0.28 0.66 0.99]; % target attribute
net = feedforwardnet(10);
net = train(net,x,t);
y2 = net(x)
but I want to set also weights (importance) of individual instances, like this
w = [1 1 1 1 1 0.2 1 1 4 0.1];
(most of instances have normal importance (value 1), 0.1 and 0.2 are less important, and 4 is very important)
And I want to use this weights w in training proces.
It should work (theoreticaly) by multiplying the learning rate coefficient by the weight of the actual instance.
LearningRate for specific instance = network learning rate * instance weight ;
In Weka (programmed in Java), It could be set with method Instance.setWeight(), like this :
for (int i = 0; i < data.numInstances(); i++) {
data.instance(i).setWeight(w[i]);
}
and, in next training process, these weights are used automatically.
Could you give me some hint, or inspiration, how to achieve this goal in Matlab (training with instance weights) ?
What are you suggest ?
Of course, I could call the Weka library from Matlab. However, Weka contain only limited types of neural networks.
Thank you.

답변 (1개)

Srivardhan Gadila
Srivardhan Gadila 2021년 10월 8일
Refer to Weight and Bias Values to know on how to acess the weights & bias values and also understand the structure.
net = configure(net,x,t);
Then set the custom weights as follows:
net.LW{2,1} % Accessing the existing weights
CW = 100*ones(1,10) % Replace this with your weights
net.LW{2,1} = CW
Then you can train the network with the updated weights. In addtion refer to Neural Network Object Properties & Neural Network Subobject Properties to understand more about the different properties of shallow nerual networks in MATLAB.

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by