ieeLabTools 0.1.0__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,172 @@
1
+ # Documentation
2
+
3
+ ## Quickstart / TL;DR
4
+
5
+ ```python
6
+ from ieeLabTools.core import Yvel
7
+ import sympy as sp
8
+ import numpy as np
9
+
10
+ #Example variables and function
11
+ U, I = sp.symbols("U I")
12
+ R = U/I
13
+ calc = Yvel(R)
14
+
15
+ U_vals = np.array([1,2,3,4,5,6])
16
+ I_vals = np.array([6,5,4,3,2,1])
17
+ U_err = U_vals*0.001
18
+ I_err = I_vals*0.05
19
+ #Convert to desirable input format: m x k array-like, where k is your number of variables and m is your number of measurement events.
20
+ values = np.column_stack([U_vals, I_vals])
21
+ sigmas = np.column_stack([U_err, I_err])
22
+
23
+ sigma_R = calc.numeric(values, sigmas)
24
+ ```
25
+
26
+ > ⚠ The current version uses the **non-covariant** general error propagation formula. Covariance-aware propagation is planned for a future release.
27
+
28
+ ## 1. YVEL: Yleinen virheen etenemisen lauseke
29
+ > YVEL = General error propagation equation in finnish.
30
+
31
+ The class Yvel implements the general error propagation equation in non-covariant form, and exposes 2 methods for working with it.
32
+
33
+ The mathematical expression for the YVEL in non-covariant from is:
34
+
35
+ $$
36
+ \sigma = \sqrt{ \sum_{i} \left( \frac{\partial f}{\partial x_{i}} \right) ^{2}\sigma_{i}^{2} }
37
+ $$
38
+
39
+ The **initializer expects a sympy object representing the function** referred to from now on as `f`.
40
+ An optional parameter for the initializer is a 1D array-like of the **variables as Sympy symbols** referred to as `var`.
41
+
42
+ For note, the covariant expression for the YVEL is:
43
+ $$
44
+ \sigma = \sqrt{ \sum_{i} \left( \frac{\partial f}{\partial x_{i}} \right) ^{2}\sigma_{i}^{2} +2 \sum_{i>j} \frac{\partial f}{\partial x_{i}} \frac{\partial f}{\partial x_{j}} \text{cov}(x_{i},x_{j}) }
45
+ $$
46
+
47
+ > Note: Adding a method to take covariance into account is planned for a future release.
48
+
49
+ ## Working principle:
50
+ After instantiation, the class immediately either assigns the given `var` or automatically detects variables from `f` using the `free_symbols()` method.
51
+
52
+ Then the class calculates the partial derivatives for each variable by looping over all entries in `var` and calling `sp.diff`.
53
+
54
+ Then a symbolic representation of the general error propagation equation is built as a Sympy object.
55
+ #### Example.
56
+
57
+ For a simplistic example, consider Ohm's law:
58
+ $$
59
+ R=\frac{U}{I}
60
+ $$
61
+ To find the deviation for $R$ using the ieeLabTools package, we will first build an instance of the Yvel class:
62
+ >Note: for correct usage, some degree of familiarity with numpy and sympy is required.
63
+
64
+ ```python
65
+ from ieeLabTools.core import Yvel
66
+ import sympy as sp
67
+
68
+ U , I = sp.symbols("U I") #Assign your symbols
69
+
70
+ R = U/I #Create the expression
71
+
72
+ instance = Yvel(R) #After this line the class has been instantiated.
73
+ ```
74
+
75
+ The Yvel class currently provides 2 methods for working with the error propagation function. The first of these is the simpler one: `symbolic()`
76
+
77
+ The `symbolic()` method simply returns the symbolic expression of the general error propagation equation for the `f` used to initialize it. As referenced earlier, this computation is implemented using `sympy`, for further details, consult the `sympy` documentation for `symbol(), diff(), lambdify() and free_symbols()` methods.
78
+
79
+ Example usage of the `symbolic()` method:
80
+ ```python
81
+ #continuing from earlier...
82
+
83
+ symbolic_expression = instance.symbolic()
84
+ #For the example function, you should see:
85
+ print(symbolic_expression)
86
+ #return this:
87
+ #sqrt(sigma_U**2/I**2 + U**2*sigma_I**2/I**4)
88
+ ```
89
+
90
+ The 2nd method exposed by the class is the `numeric()` method. This is the arguably more useful method, as it allows you to calculate the actual deviation numerically.
91
+
92
+ ### Working principle for `numeric()`
93
+
94
+ The `numeric()` method is intended to massively ease the computation of errors for functions with many variables each contributing values (and possibly errors), making the partial derivatives tedious to solve by hand.
95
+
96
+ To achieve this, I design the method with 2 principles in mind:
97
+
98
+ 1. Handle an arbitrary amount of variables and their errors, with 2 parameters.
99
+ 2. Do so in a clean, performant manner
100
+
101
+ The `numeric()` method expects the variables and arrays to be passed in a matrix (array-like) format, where for any number of variables $k$ and a measurement series of length $m$ for each variable, constituting an $m \times k$ 2D array-like.
102
+
103
+ A mathematical representation:
104
+
105
+ $$
106
+ \text{values}: m \times k \implies \begin{bmatrix}
107
+ x_{0} & x_{1} & x_{2} & x_{3} & \dots & x_{k} \\
108
+ val_{0} & val_{0} & val_{0} & val_{0} & \dots & val_{0} \\
109
+ val_{1} & val_{1} & val_{1} & val_{1} & \dots & val_{1} \\
110
+ val_{2} & val_{2} & val_{2} & val_{2} & \dots & val_{2} \\
111
+ val_{3} & val_{3} & val_{3} & val_{3} & \dots & val_{3} \\
112
+ \vdots & \vdots & \vdots & \vdots & \dots & \vdots \\
113
+ val_{m} & val_{m} & val_{m} & val_{m} & \dots & val_{m}
114
+ \end{bmatrix}
115
+ $$
116
+
117
+ $$
118
+ \text{deviations}: m \times k \implies \begin{bmatrix}
119
+ x_{0} & x_{1} & x_{2} & x_{3} & \dots & x_{k} \\
120
+ \sigma_{0} & \sigma_{0} & \sigma_{0} & \sigma_{0} & \dots & \sigma_{0} \\
121
+ \sigma_{1} & \sigma_{1} & \sigma_{1} & \sigma_{1} & \dots & \sigma_{1} \\
122
+ \sigma_{2} & \sigma_{2} & \sigma_{2} & \sigma_{2} & \dots & \sigma_{2} \\
123
+ \sigma_{3} & \sigma_{3} & \sigma_{3} & \sigma_{3} & \dots & \sigma_{3} \\
124
+ \vdots & \vdots & \vdots & \vdots & \dots & \vdots \\
125
+ \sigma_{m} & \sigma_{m} & \sigma_{m} & \sigma_{m} & \dots & \sigma_{m}
126
+ \end{bmatrix}
127
+ $$
128
+
129
+
130
+ > Note: The measurement series for all variables must be the same size
131
+ > Assumption: measurement events for all variables are equal
132
+
133
+ > Note: The series of deviations must be equal in length with its corresponding series of measurements, and each measurement series must have a corresponding deviation series.
134
+
135
+ > Note: For possible variables with 0 deviation, pass an array with all values being 0.
136
+
137
+ Internally, the method uses numpy for vectorized processing and does shape validation.
138
+
139
+ Example usage:
140
+ ```python
141
+ #lets assume the variables from earlier have some values and deviations:
142
+ import numpy as np
143
+
144
+ #Real measurement data from a lab-course:
145
+ U_values = np.array([
146
+ 0.131, 0.165, 0.204, 0.268, 0.361, 0.505,
147
+ 0.692, 0.958, 1.370, 1.997, 2.944, 4.33, 6.74])
148
+
149
+ I_values = np.array([10/1000]*13) #mA -> A
150
+
151
+ U_errors = np.array([0.000656, 0.000826, 0.001021, 0.001341, 0.001806, 0.002526, 0.003461, 0.004791, 0.006851, 0.009986, 0.014721, 0.021651, 0.033701])
152
+
153
+ I_errors = np.zeros([13]) #good example of 0 deviations handling
154
+
155
+ # Now in order to call the method, we must remember its required parameters and construct them out of our existing arrays.
156
+ values = np.column_stack([U_values, I_values])
157
+ sigmas = np.column_stack([U_errors, I_errors])
158
+ # This constructs a 13x2 matrix for both values and sigmas, in alignment with what the method parameters expect.
159
+
160
+
161
+ # Now to find the deviations for each value we call:
162
+ deviation = instance.numeric(values,sigmas)
163
+
164
+ #with the example data you should expect something like:
165
+ print(deviation)
166
+ # "[3.82262106e-04, 3.03397612e-04, 2.45338331e-04, 1.86706393e-04,
167
+ # 5.22029629e-05, 3.65016783e-05, 2.50400639e-05, 1.69848494e-05, 1.15478775e-05,
168
+ # 7.41861776e-06,]
169
+
170
+ ```
171
+
172
+
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ieeLabTools
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: General symbolic + numeric uncertainty propagation, weighted linear regression
5
5
  Project-URL: Homepage, https://github.com/ieepirzy/PhySiLight-Tools/tree/main/Packages/ieeLabTools
6
- Project-URL: Documentation, https://github.com/ieepirzy/PhySiLight-Tools/tree/main/Packages/ieeLabTools/README.md
6
+ Project-URL: Documentation, https://github.com/ieepirzy/PhySiLight-Tools/tree/main/Packages/ieeLabTools/Documentation.md
7
7
  Project-URL: Source, https://github.com/ieepirzy/PhySiLight-Tools/tree/main/Packages/ieeLabTools/ieeLabTools/core.py
8
8
  Author-email: Ilari Pirkkalainen <iladevv0@gmail.com>
9
9
  License: MIT
@@ -48,4 +48,6 @@ This library is part of the **PhySiLight-Tools** ecosystem.
48
48
  pip install ieeLabTools
49
49
  ```
50
50
 
51
+ >🧪 This package was originally developed to automate general uncertainty propagation for physics lab courses, reducing >manual symbolic differentiation and repetitive numeric error calculation.
52
+
51
53
  Part of the PhySiLight-Tools physics utilities collection.
@@ -29,4 +29,6 @@ This library is part of the **PhySiLight-Tools** ecosystem.
29
29
  pip install ieeLabTools
30
30
  ```
31
31
 
32
+ >🧪 This package was originally developed to automate general uncertainty propagation for physics lab courses, reducing >manual symbolic differentiation and repetitive numeric error calculation.
33
+
32
34
  Part of the PhySiLight-Tools physics utilities collection.
@@ -0,0 +1,3 @@
1
+ from .core import Yvel, weightedLinregress, ortDistanceRegress
2
+
3
+ __all__ = ["Yvel", "weightedLinregress","ortDistanceRegress"]
@@ -120,11 +120,8 @@ class weightedLinregress():
120
120
  Wxx = np.sum(w * self.x * self.x)
121
121
  Wxy = np.sum(w * self.x * self.y)
122
122
 
123
-
124
-
125
123
  D = W * Wxx - Wx**2
126
124
 
127
-
128
125
  slope = (W * Wxy - Wx * Wy) / D
129
126
  intercept = (Wxx * Wy - Wx * Wxy) / D
130
127
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ieeLabTools"
3
- version = "0.1.0"
3
+ version = "0.1.2"
4
4
  description = "General symbolic + numeric uncertainty propagation, weighted linear regression"
5
5
  authors = [
6
6
  { name = "Ilari Pirkkalainen", email = "iladevv0@gmail.com" }
@@ -22,7 +22,7 @@ classifiers = [
22
22
 
23
23
  [project.urls]
24
24
  Homepage = "https://github.com/ieepirzy/PhySiLight-Tools/tree/main/Packages/ieeLabTools"
25
- Documentation = "https://github.com/ieepirzy/PhySiLight-Tools/tree/main/Packages/ieeLabTools/README.md"
25
+ Documentation = "https://github.com/ieepirzy/PhySiLight-Tools/tree/main/Packages/ieeLabTools/Documentation.md"
26
26
  Source = "https://github.com/ieepirzy/PhySiLight-Tools/tree/main/Packages/ieeLabTools/ieeLabTools/core.py"
27
27
 
28
28
  [build-system]
@@ -1,3 +0,0 @@
1
- from .core import Yvel, WeightedLinearRegression
2
-
3
- __all__ = ["Yvel", "WeightedLinearRegression"]