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.

info = dist(code) returns information about this function. For more information, see the code argument description.

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.

Information you want to retrieve from the function, specified as one of the following:

  • 'name' returns the name of this function.

  • 'deriv' returns the name of the derivative function

  • 'fullderiv' returns 1 for full derivative and 0 for linear derivative.

  • 'pfullderiv' returns 2 for reduced derivative, 1 for full derivative, and 0 for linear derivative.

  • 'fpnames' returns the names of the function parameters.

  • 'fpdefaults' returns the default function parameters.

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
Introduced before R2006a