This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Euclidean distance weight function


Z = dist(W,P,FP)
dim = dist('size',S,R,FP)
dw = dist('dw',W,P,Z,FP)
D = dist(pos)
info = dist('code')


Weight functions apply weights to an input to get weighted inputs.

Z = dist(W,P,FP) takes these inputs,


S-by-R weight matrix


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


Struct of function parameters (optional, ignored)

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

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

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

dist is also a layer distance function which can be used to find the distances between neurons in a layer.

D = dist(pos) takes one argument,


N-by-S matrix of neuron positions

and returns the S-by-S matrix of distances.

info = dist('code') returns information about this function. The following codes are supported:


Name of derivative function


Full derivative = 1, linear derivative = 0


Input: reduced derivative = 2, full derivative = 1, linear derivative = 0


Full name


Returns names of function parameters


Returns default function parameters


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 = dist(W,P)

Here you define a random matrix of positions for 10 neurons arranged in three-dimensional space and find their distances.

pos = rand(3,10);
D = dist(pos)

Network Use

You can create a standard network that uses dist by calling newpnn or newgrnn.

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

To change a network so that a layer's topology uses dist, set net.layers{i}.distanceFcn to 'dist'.

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

See newpnn or newgrnn for simulation examples.

More About

collapse all


The Euclidean distance d between two vectors X and Y is

d = sum((x-y).^2).^0.5

Introduced before R2006a

Was this topic helpful?