Main Content


Negative distance weight function


Z = negdist(W,P)
dim = negdist('size',S,R,FP)
dw = negdist('dz_dw',W,P,Z,FP)


negdist is a weight function. Weight functions apply weights to an input to get weighted inputs.

Z = negdist(W,P) takes these inputs,


S-by-R weight matrix


R-by-Q matrix of Q input (column) vectors


Row cell array of function parameters (optional, ignored)

and returns the S-by-Q matrix of negative vector distances.

dim = negdist('size',S,R,FP) takes the layer dimension S, input dimension R, and function parameters, and returns the weight size [S-by-R].

dw = negdist('dz_dw',W,P,Z,FP) returns the derivative of Z with respect to W.


Here you define a random weight matrix W and input vector P and calculate the corresponding weighted input Z.

W = rand(4,3);
P = rand(3,1);
Z = negdist(W,P)

Network Use

You can create a standard network that uses negdist by calling competlayer or selforgmap.

To change a network so an input weight uses negdist, set net.inputWeights{i,j}.weightFcn to 'negdist'. For a layer weight, set net.layerWeights{i,j}.weightFcn to 'negdist'.

In either case, call sim to simulate the network with negdist.


negdist returns the negative Euclidean distance:

z = -sqrt(sum(w-p)^2)

Version History

Introduced before R2006a