Main Content

dist

Euclidean distance weight function

Description

example

Z= dist(W,P)takes anS-by-Rweight matrix,W, and anR-by-Qmatrix ofQinput (column) vectors,P, and returns theS-by-Qmatrix of vector distances,Z.

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

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

dw= dist('dw',W,P,Z,FP)returns the derivative ofZwith respect toW.

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

D= dist(pos)takesN-by-Smatrix of neuron positions,pos和returns theS-by-Smatrix of distances,D.

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

Examples

collapse all

This example shows how to calculate the corresponding weighted inputZ, given a random weight matrixW和input vectorP.

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 anS-by-Rmatrix.

输入矩阵,作为指定R-by-Qmatrix ofQ输入(列)向量。

Layer dimension, specified as a scalar.

Input dimension, specified as a scalar.

Matrix of neuron positions, specified as anN-by-Smatrix.

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 anS-by-Qmatrix.

Weight size, returned as a row vector.

Derivative ofZwith respect toW, returned as a cell array.

Distances, returned as anS-by-Smatrix.

More About

collapse all

Network Use

You can create a standard network that usesdistby callingnewpnnornewgrnn.

To change a network so an input weight usesdist, setnet.inputWeights{i,j}.weightFcnto'dist'. For a layer weight, setnet.layerWeights{i,j}.weightFcnto'dist'.

To change a network so that a layer’s topology usesdist, setnet.layers{i}.distanceFcnto'dist'.

In either case, callsimto simulate the network withdist.

Seenewpnnornewgrnnfor simulation examples.

Algorithms

The Euclidean distancedbetween two vectorsXYis

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

Version History

Introduced before R2006a