# calculus.geometry package¶

## calculus.geometry.distances module¶

filename

sppas.src.calculus.geometry.distances.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

A collection of basic distance estimators.

Distance axioms:
• d(x,y) = 0 iff x = y

• d(x,y) = d(y,x)

• d(x,z) <= d(x,y) + d(y,z)

calculus.geometry.distances.chi_squared(x, y)[source]

Estimate the Chi-squared distance between two tuples.

Parameters
• x – a tuple of float values

• y – a tuple of float values

Returns

(float)

x and y must have the same length.

```>>> x = (1.0, 0.0)
>>> y = (0.0, 1.0)
>>> round(chi_squared(x, y), 3)
>>> 1.414
```
calculus.geometry.distances.euclidian(x, y)[source]

Estimate the Euclidian distance between two tuples.

Parameters
• x – a tuple of float values

• y – a tuple of float values

Returns

(float)

x and y must have the same length.

```>>> x = (1.0, 0.0)
>>> y = (0.0, 1.0)
>>> round(euclidian(x, y), 3)
>>> 1.414
```
calculus.geometry.distances.manathan(x, y)[source]

Estimate the Manathan distance between two tuples.

Parameters
• x – a tuple of float values

• y – a tuple of float values

Returns

(float)

x and y must have the same length.

```>>> x = (1.0, 0.0)
>>> y = (0.0, 1.0)
>>> manathan(x, y)
>>> 2.0
```
calculus.geometry.distances.minkowski(x, y, p=2)[source]

Estimate the Minkowski distance between two tuples.

Parameters
• x – a tuple of float values

• y – a tuple of float values

• p – power value (p=2 corresponds to the euclidian distance)

Returns

(float)

x and y must have the same length.

```>>> x = (1.0, 0.0)
>>> y = (0.0, 1.0)
>>> round(minkowski(x, y), 3)
>>> 1.414
```
calculus.geometry.distances.squared_euclidian(x, y)[source]

Estimate the Squared Euclidian distance between two tuples.

Parameters
• x – a tuple of float values

• y – a tuple of float values

Returns

(float)

x and y must have the same length.

```>>> x = (1.0, 0.0)
>>> y = (0.0, 1.0)
>>> squared_euclidian(x, y)
>>> 2.0
```

## calculus.geometry.linear_fct module¶

filename

sppas.src.calculus.stats.linear_fct.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Linear functions

A linear function from the real numbers to the real numbers is a function whose graph - in Cartesian coordinates with uniform scales, is a line in the plane.

The equation y = ax + b is referred to as the slope-intercept form of a linear equation.

calculus.geometry.linear_fct.intercept(p1, p2)[source]

Estimate the intercept between 2 points.

Parameters
• p1 – (tuple) first point as (x1, y1)

• p2 – (tuple) second point as (x2, y2)

Returns

float value

calculus.geometry.linear_fct.linear_fct(x, a, b)[source]

Return f(x) of the linear function f(x) = ax + b.

Parameters
• x – (float) X-coord

• a – (float) slope

• b – (float) intercept

calculus.geometry.linear_fct.linear_values(delta, p1, p2, rounded=6)[source]

Estimate the values between 2 points, step-by-step.

Two different points p1=(x1,y1) and p2=(x2,y2) determine a line. It is enough to substitute two different values for ‘x’ in the linear function and determine ‘y’ for each of these values.

a = y2 − y1 / x2 − x1 <= slope b = y1 - a * x1 <= intercept

Values for p1 and p2 are added into the result.

Parameters
• delta – (float) Step range between values.

• p1 – (tuple) first point as (x1, y1)

• p2 – (tuple) second point as (x2, y2)

• rounded – (int) round floats

Returns

list of float values, i.e. all the y, including the ones of p1 and p2

Raises

MemoryError could be raised if too many values have to be returned.

calculus.geometry.linear_fct.slope(p1, p2)[source]

Estimate the slope between 2 points.

Parameters
• p1 – (tuple) first point as (x1, y1)

• p2 – (tuple) second point as (x2, y2)

Returns

float value

calculus.geometry.linear_fct.slope_intercept(p1, p2)[source]

Return the slope and the intercept.

Parameters
• p1 – (tuple) first point as (x1, y1)

• p2 – (tuple) second point as (x2, y2)

Returns

tuple(slope,intercept)

calculus.geometry.linear_fct.ylinear_fct(y, a, b)[source]

Return x of the linear function y = ax + b.

Parameters
• y – (float) Y-coord

• a – (float) slope

• b – (float) intercept