具有非负权重的神经网络

数据挖掘 神经网络
2022-02-19 19:44:30

你能告诉我,有什么技术可以构建非负权重的神经网络吗?

2个回答

使用非负权重接近神经网络的一种可能方法是使用前馈神经网络我们可以使用具有非负权重约束的优化技术来构建神经网络,而不是正常的反向传播方法。

此处采用的修改后的Matlab 示例如下

load iris_dataset

% Number of neurons
n = 4;

% Number of attributes and number of classifications
[n_attr, ~]  = size(irisInputs);
[n_class, ~] = size(irisTargets);

% Initialize neural network
net = feedforwardnet(n);

% Configure the neural network for this dataset
net = configure(net, irisInputs, irisTargets); %view(net);

fun = @(w) mse_test(w, net, irisInputs, irisTargets);

% Add 'Display' option to display result of iterations
ps_opts = psoptimset ( 'CompletePoll', 'off', 'Display', 'iter', 'MaxIter', 100); %, 'TimeLimit', 120 );

% There is n_attr attributes in dataset, and there are n neurons so there 
% are total of n_attr*n input weights (uniform weight)
initial_il_weights = ones(1, n_attr*n)/(n_attr*n);
% There are n bias values, one for each neuron (random)
initial_il_bias    = rand(1, n);
% There is n_class output, so there are total of n_class*n output weights 
% (uniform weight)
initial_ol_weights = ones(1, n_class*n)/(n_class*n);
% There are n_class bias values, one for each output neuron (random)
initial_ol_bias    = rand(1, n_class);
% starting values
starting_values = [initial_il_weights, initial_il_bias, ...
                   initial_ol_weights, initial_ol_bias];

% alter the patternsearch function with the appropriate constraints, in your case we would change it so that the lower bounds of the weights are zero 
[x, fval, flag, output] = patternsearch(fun, starting_values, [], [],[],[], zeros(size(starting_values)), 1e10, ps_opts); 

其中mse_test.m函数如下:

function mse_calc = mse_test(x, net, inputs, targets)
net = setwb(net, x');
y = net(inputs);
[row col] = size(y);
mse_calc = sum(sum((y - targets).^2))/(row * col);
end

您可以轻松地采用现有的多层感知器实现并修改反向传播算法以防止权重变为负数。当然,您还需要确保仅使用非负值初始化权重。

但是您需要注意,您正在限制神经网络可以学习的决策面。因此,您应该考虑仅具有非负权重的神经网络是否可以为您的给定数据集提供可接受的解决方案。