Main Content

dist

Euclidean distance weight function

Description

example

Z = dist(W,P) takes an S-by-R weight matrix, W, and an R-by-Q matrix of Q input (column) vectors, P, and returns the S-by-Q matrix of vector distances, Z.

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

dim = dist('size',S,R,FP) takes the layer dimension S, input dimension R, and function parameters, FP, 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 N-by-S matrix of neuron positions, pos and returns the S-by-S matrix of distances, D.

Examples

collapse all

This example shows how to calculate the corresponding weighted input Z, given a random weight matrix W and input vector P.

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)

Input Arguments

collapse all

Weight matrix, specified as an S-by-R matrix.

Input matrix, specified as an R-by-Q matrix of Q input (column) vectors.

Layer dimension, specified as a scalar.

Input dimension, specified as a scalar.

Matrix of neuron positions, specified as an N-by-S matrix.

Output Arguments

collapse all

Vector distances, returned as an S-by-Q matrix.

Weight size, returned as a row vector.

Derivative of Z with respect to W, returned as a cell array.

Distances, returned as an S-by-S matrix.

More About

collapse all

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.

Algorithms

The Euclidean distance d between two vectors X and Y is

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

Version History

Introduced before R2006a