# BrayCurtis Distance¶

The BrayCurtis Distance or Sorensen Distance is similar to the Manhattan Distance with normalization.

$\frac{\sum_{i=0}^{n}|{\bf x_i}-{\bf x'_i}|}{\sum_{i=0}^{n}|{\bf x_i}+{\bf x'_i}|}$

where $$\bf x$$ and $$\bf x'$$ are $$n$$ 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 CBrayCurtisDistance by passing it CDenseFeatures.

distance = BrayCurtisDistance(features_a, features_a)

distance = BrayCurtisDistance(features_a, features_a);

BrayCurtisDistance distance = new BrayCurtisDistance(features_a, features_a);

distance = Shogun::BrayCurtisDistance.new features_a, features_a

distance <- BrayCurtisDistance(features_a, features_a)

distance = shogun.BrayCurtisDistance(features_a, features_a)

BrayCurtisDistance distance = new BrayCurtisDistance(features_a, features_a);

auto distance = some<CBrayCurtisDistance>(features_a, features_a);


The 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 asymmetrical distance as follows: distance.init(features_a, features_b) distance_matrix_ab = distance.get_distance_matrix()  distance.init(features_a, features_b); distance_matrix_ab = distance.get_distance_matrix();  distance.init(features_a, features_b); DoubleMatrix distance_matrix_ab = distance.get_distance_matrix();  distance.init features_a, features_b distance_matrix_ab = distance.get_distance_matrix  distance$init(features_a, features_b)
distance_matrix_ab <- distance\$get_distance_matrix()

distance:init(features_a, features_b)
distance_matrix_ab = distance:get_distance_matrix()

distance.init(features_a, features_b);
double[,] distance_matrix_ab = distance.get_distance_matrix();

distance->init(features_a, features_b);
auto distance_matrix_ab = distance->get_distance_matrix();


## References¶

‘BrayCurtis Distance <http://people.revoledu.com/kardi/tutorial/Similarity/BrayCurtisDistance.html>’