# Euclidean Distance¶

The Euclidean distance for real valued features is the square root of the sum of squared disparity between the corresponding feature dimensions of two data points.

\[d({\bf x},{\bf x'})= \sqrt{\sum_{i=0}^{d}|{\bf x_i}-{\bf x'_i}|^2}\]

where \(\bf x\) and \(\bf x'\) are \(d\) dimensional feature vectors.

## Example¶

Imagine we have files with data. We create CDenseFeatures (here 64 bit floats aka RealFeatures) as

```
features_a = RealFeatures(f_feats_a)
features_b = RealFeatures(f_feats_b)
```

```
features_a = RealFeatures(f_feats_a);
features_b = RealFeatures(f_feats_b);
```

```
RealFeatures features_a = new RealFeatures(f_feats_a);
RealFeatures features_b = new RealFeatures(f_feats_b);
```

```
features_a = Shogun::RealFeatures.new f_feats_a
features_b = Shogun::RealFeatures.new f_feats_b
```

```
features_a <- RealFeatures(f_feats_a)
features_b <- RealFeatures(f_feats_b)
```

```
features_a = shogun.RealFeatures(f_feats_a)
features_b = shogun.RealFeatures(f_feats_b)
```

```
RealFeatures features_a = new RealFeatures(f_feats_a);
RealFeatures features_b = new RealFeatures(f_feats_b);
```

```
auto features_a = some<CDenseFeatures<float64_t>>(f_feats_a);
auto features_b = some<CDenseFeatures<float64_t>>(f_feats_b);
```

We create an instance of CEuclideanDistance by passing it CDenseFeatures.

```
distance = EuclideanDistance(features_a, features_a)
```

```
distance = EuclideanDistance(features_a, features_a);
```

```
EuclideanDistance distance = new EuclideanDistance(features_a, features_a);
```

```
distance = Shogun::EuclideanDistance.new features_a, features_a
```

```
distance <- EuclideanDistance(features_a, features_a)
```

```
distance = shogun.EuclideanDistance(features_a, features_a)
```

```
EuclideanDistance distance = new EuclideanDistance(features_a, features_a);
```

```
auto distance = some<CEuclideanDistance>(features_a, features_a);
```

Distance matrix can be extracted as follows:

```
distance_matrix_aa = distance.get_distance_matrix()
```

```
distance_matrix_aa = distance.get_distance_matrix();
```

```
DoubleMatrix distance_matrix_aa = distance.get_distance_matrix();
```

```
distance_matrix_aa = distance.get_distance_matrix
```

```
distance_matrix_aa <- distance$get_distance_matrix()
```

```
distance_matrix_aa = distance:get_distance_matrix()
```

```
double[,] distance_matrix_aa = distance.get_distance_matrix();
```

```
auto distance_matrix_aa = distance->get_distance_matrix();
```

We can use the same instance with new CDenseFeatures to compute distance.

```
distance.init(features_a, features_b)
```

```
distance.init(features_a, features_b);
```

```
distance.init(features_a, features_b);
```

```
distance.init features_a, features_b
```

```
distance$init(features_a, features_b)
```

```
distance:init(features_a, features_b)
```

```
distance.init(features_a, features_b);
```

```
distance->init(features_a, features_b);
```

If desired, squared distance can be extracted like:

```
distance.set_disable_sqrt(True)
distance_matrix_ab = distance.get_distance_matrix()
```

```
distance.set_disable_sqrt(true);
distance_matrix_ab = distance.get_distance_matrix();
```

```
distance.set_disable_sqrt(true);
DoubleMatrix distance_matrix_ab = distance.get_distance_matrix();
```

```
distance.set_disable_sqrt true
distance_matrix_ab = distance.get_distance_matrix
```

```
distance$set_disable_sqrt(TRUE)
distance_matrix_ab <- distance$get_distance_matrix()
```

```
distance:set_disable_sqrt(True)
distance_matrix_ab = distance:get_distance_matrix()
```

```
distance.set_disable_sqrt(true);
double[,] distance_matrix_ab = distance.get_distance_matrix();
```

```
distance->set_disable_sqrt(true);
auto distance_matrix_ab = distance->get_distance_matrix();
```