or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

classification.mdclustering.mddatasets.mdevaluation.mdfeature-engineering.mdfile-io.mdindex.mdmath-utils.mdpattern-mining.mdplotting.mdpreprocessing.mdregression.mdtext-processing.mdutilities.md

math-utils.mddocs/

0

# Mathematical Utilities

1

2

Mathematical functions and utilities commonly used in machine learning computations and statistical analysis.

3

4

## Capabilities

5

6

### Combinatorics

7

8

Functions for calculating combinations and permutations.

9

10

```python { .api }

11

def num_combinations(n, r):

12

"""

13

Calculate number of combinations (n choose r).

14

15

Parameters:

16

- n: int, total number of items

17

- r: int, number of items to choose

18

19

Returns:

20

- combinations: int, number of combinations

21

"""

22

23

def num_permutations(n, r):

24

"""

25

Calculate number of permutations.

26

27

Parameters:

28

- n: int, total number of items

29

- r: int, number of items to arrange

30

31

Returns:

32

- permutations: int, number of permutations

33

"""

34

35

def factorial(n):

36

"""

37

Calculate factorial of integer.

38

39

Parameters:

40

- n: int, input number

41

42

Returns:

43

- factorial: int, n! factorial

44

"""

45

```

46

47

### Vector Space Operations

48

49

Linear algebra operations for vector spaces.

50

51

```python { .api }

52

def vectorspace_orthonormalization(ary):

53

"""

54

Orthonormalize vectors using Gram-Schmidt process.

55

56

Parameters:

57

- ary: array-like, matrix of vectors (columns are vectors)

58

59

Returns:

60

- orthonormal_vectors: array, orthonormalized vectors

61

"""

62

63

def vectorspace_dimensionality(ary):

64

"""

65

Compute dimensionality of vector space.

66

67

Parameters:

68

- ary: array-like, matrix of vectors

69

70

Returns:

71

- dimensionality: int, vector space dimensionality

72

"""

73

```

74

75

## Usage Examples

76

77

```python

78

from mlxtend.math import num_combinations, num_permutations, factorial

79

from mlxtend.math import vectorspace_orthonormalization, vectorspace_dimensionality

80

import numpy as np

81

82

# Combinatorics examples

83

print(f"C(10,3) = {num_combinations(10, 3)}") # 120

84

print(f"P(10,3) = {num_permutations(10, 3)}") # 720

85

print(f"5! = {factorial(5)}") # 120

86

87

# Vector space operations

88

vectors = np.random.randn(4, 3) # 4-dimensional vectors, 3 vectors

89

orthonormal = vectorspace_orthonormalization(vectors)

90

dim = vectorspace_dimensionality(vectors)

91

print(f"Original vectors shape: {vectors.shape}")

92

print(f"Vector space dimensionality: {dim}")

93

```