|
1 | | -# 数值转换 |
| 1 | +# Conversion |
| 2 | +**Read this in other languages: [简体中文](./README.zh-CN.md)** |
2 | 3 |
|
3 | | -本包主要封装数值转换相关接口. |
| 4 | +This package mainly encapsulates interfaces related to numerical conversion. |
4 | 5 |
|
5 | | -## 结构体 |
| 6 | +## Structure |
6 | 7 |
|
7 | 8 | ```go |
8 | 9 | package conversion |
9 | 10 |
|
10 | 11 | type Calculator struct { |
11 | | - logBase float32 //对数计算的底数, 默认为自然数e |
| 12 | +logBase float32 //The base of logarithmic calculation, defaults to natural number e |
12 | 13 | } |
13 | 14 |
|
14 | 15 | ``` |
15 | 16 |
|
16 | | -可以调用 ```func NewCalculator(optionalParam ...float32) Calculator ``` 获取对象. 动态参数如果存在则设置为logBase, 若不存在则默认设置为自然数e. |
17 | | - |
18 | | -## 接口 |
19 | | - |
20 | | -1. **StandardizationInt32([]int32) ([]float32, error)** |
21 | | - ```text |
22 | | - 最大最小值标准化. |
23 | | - 将int32类型的一组数据处理过后数据均落在[0,1]区间内, 处理后输出不再是整数. |
24 | | - 计算公式为: normalized=(maxValue−minValue)/(value−minValue) |
25 | | - 注意: 无法对零范围(最大最小值相等)的数组进行规范化. |
26 | | - ``` |
27 | | -
|
28 | | -2. **StandardizationFloat32([]float32) ([]float32, error)** |
29 | | - ```text |
30 | | - 最大最小值标准化. |
31 | | - 将float32类型的一组数据处理过后数据均落在[0,1]区间内. |
32 | | - 计算公式为: normalized=(maxValue−minValue)/(value−minValue) |
33 | | - 注意: 无法对零范围(最大最小值相等)的数组进行规范化. |
34 | | - ``` |
35 | | -3. **ZScoreInt32([]int32) ([]float32, error)** |
36 | | - ```text |
37 | | - Z-Score标准化. |
38 | | - 计算公式为: Z=(X−μ)/σ |
39 | | - X 是原始数据, μ 是数据的平均值, σ 是数据的标准差 |
40 | | - 注意: 无法对零范围(最大最小值相等)的数组进行规范化. |
41 | | - ``` |
42 | | -4. **ZScoreFloat32([]float32) ([]float32, error)** |
43 | | - ```text |
44 | | - Z-Score标准化. |
45 | | - 计算公式为: Z=(X−μ)/σ |
46 | | - X 是原始数据, μ 是数据的平均值, σ 是数据的标准差 |
47 | | - 注意: 无法对零范围(最大最小值相等)的数组进行规范化. |
48 | | - ``` |
49 | | -5. **LogInt32([]int32) ([]float32, error)** |
50 | | - ```text |
51 | | - 计算对数. |
52 | | - 计算公式为: log(base, x), base默认为自然数e. |
53 | | - 注意: 需保证输入参数均为正数, 否则: |
54 | | - Log(+Inf) = +Inf |
55 | | - Log(0) = -Inf |
56 | | - Log(x < 0) = NaN |
57 | | - Log(NaN) = NaN |
58 | | - ``` |
59 | | -6. **LogFloat32([]float32) ([]float32, error)** |
60 | | - ```text |
61 | | - 计算对数. |
62 | | - 计算公式为: log(base, x), base默认为自然数e. |
63 | | - 注意: 需保证输入参数均为正数, 否则: |
64 | | - Log(+Inf) = +Inf |
65 | | - Log(0) = -Inf |
66 | | - Log(x < 0) = NaN |
67 | | - Log(NaN) = NaN |
68 | | - ``` |
69 | | -7. **SquareInt32([]int32) ([]float32, error)** |
70 | | - ```text |
71 | | - 计算平方根. |
72 | | - 计算公式为: √x |
73 | | - 注意: 需保证输入参数均为非负实数, 否则: |
74 | | - Sqrt(+Inf) = +Inf |
75 | | - Sqrt(±0) = ±0 |
76 | | - Sqrt(x < 0) = NaN |
77 | | - Sqrt(NaN) = NaN |
78 | | - ``` |
79 | | -8. **SquareFloat32([]float32) ([]float32, error)** |
80 | | - ```text |
81 | | - 计算平方根. |
82 | | - 计算公式为: √x |
83 | | - 注意: 需保证输入参数均为非负实数, 否则: |
84 | | - Sqrt(+Inf) = +Inf |
85 | | - Sqrt(±0) = ±0 |
86 | | - Sqrt(x < 0) = NaN |
87 | | - Sqrt(NaN) = NaN |
88 | | - ``` |
| 17 | +You can call ```func NewCalculator(optionalParam ...float32) Calculator ``` to get the object. If the dynamic parameter exists, it is set to logBase. If it does not exist, it is set to natural number e by default. |
| 18 | + |
| 19 | +## Interface |
| 20 | + |
| 21 | +### 1. StandardizationInt32([]int32) ([]float32, error) |
| 22 | + |
| 23 | +Maximum and minimum value standardization. |
| 24 | + |
| 25 | +After processing a set of int32 type data, the data all fall within the range of [0, 1]. After processing, the output is no longer an integer. |
| 26 | + |
| 27 | +The calculation formula is: |
| 28 | +$$normalized=(maxValue−minValue)/(value−minValue)$$ |
| 29 | + |
| 30 | +> [!IMPORTANT] |
| 31 | +> It is not possible to normalize an array with zero range (equal maximum and minimum values). |
| 32 | +
|
| 33 | +### 2. StandardizationFloat32([]float32) ([]float32, error) |
| 34 | + |
| 35 | +Maximum and minimum value normalization. |
| 36 | + |
| 37 | +After processing a set of float32 data, the data all fall within the interval [0, 1]. |
| 38 | + |
| 39 | +The calculation formula is: |
| 40 | +$$normalized=(maxValue−minValue)/(value−minValue)$$ |
| 41 | + |
| 42 | +> [!IMPORTANT] |
| 43 | +> It is not possible to normalize an array with zero range (equal maximum and minimum values). |
| 44 | +
|
| 45 | +### 3. ZScoreInt32([]int32) ([]float32, error) |
| 46 | + |
| 47 | +Z-Score standardization. |
| 48 | + |
| 49 | +The calculation formula is: |
| 50 | +$$Z=(X−\mu)/\sigma$$ |
| 51 | + |
| 52 | +$X$ is the original data, $\mu$ is the mean value of the data, and $\sigma$ is the standard deviation of the data. |
| 53 | + |
| 54 | +> [!IMPORTANT] |
| 55 | +> Cannot normalize an array with zero range (equal maximum and minimum values). |
| 56 | +
|
| 57 | +### 4. ZScoreFloat32([]float32) ([]float32, error) |
| 58 | + |
| 59 | +Z-Score normalization. |
| 60 | + |
| 61 | +The calculation formula is: |
| 62 | +$$Z=(X−\mu)/\sigma$$ |
| 63 | + |
| 64 | +$X$ is the original data, $\mu$ is the mean value of the data, and $\sigma$ is the standard deviation of the data. |
| 65 | + |
| 66 | +### 5. LogInt32([]int32) ([]float32, error) |
| 67 | +Calculate the logarithm. |
| 68 | +The calculation formula is: |
| 69 | +$$log(base, x)$$ |
| 70 | +> [!TIP] |
| 71 | +> base defaults to the natural number e |
| 72 | +
|
| 73 | +> [!IMPORTANT] |
| 74 | +> Make sure that all input parameters are positive, otherwise: |
| 75 | +> Log(+Inf) = +Inf |
| 76 | +> Log(0) = -Inf |
| 77 | +> Log(x < 0) = NaN |
| 78 | +> Log(NaN) = NaN |
| 79 | +
|
| 80 | +### 6. LogFloat32([]float32) ([]float32, error) |
| 81 | +Calculates logarithm. |
| 82 | +Calculation formula: |
| 83 | +$$log(base, x)$$ |
| 84 | +> [!TIP] |
| 85 | +> base defaults to natural number e |
| 86 | +
|
| 87 | +> [!IMPORTANT] |
| 88 | +> Input parameters must be positive, otherwise: |
| 89 | +> Log(+Inf) = +Inf |
| 90 | +> Log(0) = -Inf |
| 91 | +> Log(x < 0) = NaN |
| 92 | +> Log(NaN) = NaN |
| 93 | +
|
| 94 | +### 7. SquareInt32([]int32) ([]float32, error) |
| 95 | +Calculates square root. |
| 96 | + |
| 97 | +Calculation formula: |
| 98 | +$$\sqrt{x}$$ |
| 99 | + |
| 100 | +> [!IMPORTANT] |
| 101 | +> Input parameters must be non-negative real numbers, otherwise: |
| 102 | +> Sqrt(+Inf) = +Inf |
| 103 | +> Sqrt(±0) = ±0 |
| 104 | +> Sqrt(x < 0) = NaN |
| 105 | +> Sqrt(NaN) = NaN |
| 106 | +
|
| 107 | +### 8. SquareFloat32([]float32) ([]float32, error) |
| 108 | +Calculate the square root. |
| 109 | + |
| 110 | +The calculation formula is: |
| 111 | +$$\sqrt{x}$$ |
| 112 | + |
| 113 | +> [!IMPORTANT] |
| 114 | +> Ensure that all input parameters are non-negative real numbers, otherwise: |
| 115 | +> Sqrt(+Inf) = +Inf |
| 116 | +> Sqrt(±0) = ±0 |
| 117 | +> Sqrt(x < 0) = NaN |
| 118 | +> Sqrt(NaN) = NaN |
0 commit comments