regdiff 3.6.1__tar.gz → 3.6.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.
- {regdiff-3.6.1 → regdiff-3.6.2}/PKG-INFO +1 -1
- {regdiff-3.6.1 → regdiff-3.6.2}/pyproject.toml +1 -1
- {regdiff-3.6.1 → regdiff-3.6.2}/pyproject.toml.orig +1 -1
- regdiff-3.6.2/src/regdiff/__init__.py +1 -0
- {regdiff-3.6.1 → regdiff-3.6.2}/src/regdiff/regdiff.py +6 -16
- regdiff-3.6.1/src/regdiff/__init__.py +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .regdiff import matrix_anti_diff, matrix_diff, reg_diff # noqa: F401
|
|
@@ -4,16 +4,6 @@ import scipy as sp
|
|
|
4
4
|
|
|
5
5
|
# NOTE - all matrix/vector operations are called using np.matvel/np.subtract, etc. Only scalars should multiply ndarrays.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
def finite_diff(x):
|
|
9
|
-
"""take the finite difference of the input vector. Performs no validation.
|
|
10
|
-
:param np.ndarray(x): data to take the finite difference of -- 1-dimensional array of length n
|
|
11
|
-
|
|
12
|
-
:return: diff(x) -- 1 dimensional array of length n-1
|
|
13
|
-
"""
|
|
14
|
-
return np.subtract(x[1:], x[:-1])
|
|
15
|
-
|
|
16
|
-
|
|
17
7
|
def matrix_diff(n, dx=1.0):
|
|
18
8
|
"""return the matrix representations of the first-order central finite first difference, first-order central second
|
|
19
9
|
finite difference, and simple finite difference for a specified size and delta x increment.
|
|
@@ -149,11 +139,11 @@ def reg_diff(
|
|
|
149
139
|
if diag:
|
|
150
140
|
u_cost = [
|
|
151
141
|
npl.norm(np.subtract(sp.integrate.cumulative_trapezoid(u), data_comp))
|
|
152
|
-
+ alpha * npl.norm(
|
|
142
|
+
+ alpha * npl.norm(np.diff(u), ord=1)
|
|
153
143
|
]
|
|
154
144
|
prev_cost = None
|
|
155
145
|
for iter in range(max_iter):
|
|
156
|
-
c = np.reciprocal(np.sqrt(np.power(
|
|
146
|
+
c = np.reciprocal(np.sqrt(np.power(np.diff(u), 2) + ep))
|
|
157
147
|
En = np.diag(c)
|
|
158
148
|
Ln = np.matmul(np.matmul(d_tp, En), d)
|
|
159
149
|
gn = np.add(np.subtract(np.matvec(a_tp_a, u), a_tp_b), alpha * np.matvec(Ln, u))
|
|
@@ -162,7 +152,7 @@ def reg_diff(
|
|
|
162
152
|
u = np.subtract(u, s)
|
|
163
153
|
cost_n = npl.norm(
|
|
164
154
|
np.subtract(sp.integrate.cumulative_trapezoid(u), data_comp)
|
|
165
|
-
) + alpha * npl.norm(
|
|
155
|
+
) + alpha * npl.norm(np.diff(u), ord=1)
|
|
166
156
|
if diag:
|
|
167
157
|
print(
|
|
168
158
|
f"u, iteration {iter + 1}: cost: {cost_n}, relative change: {npl.norm(s) / npl.norm(u)}"
|
|
@@ -196,11 +186,11 @@ def reg_diff(
|
|
|
196
186
|
data_comp,
|
|
197
187
|
)
|
|
198
188
|
)
|
|
199
|
-
+ alpha2 * npl.norm(
|
|
189
|
+
+ alpha2 * npl.norm(np.diff(v), ord=1)
|
|
200
190
|
]
|
|
201
191
|
prev_cost = None
|
|
202
192
|
for iter in range(max_iter):
|
|
203
|
-
c = np.reciprocal(np.sqrt(np.power(
|
|
193
|
+
c = np.reciprocal(np.sqrt(np.power(np.diff(v), 2) + ep))
|
|
204
194
|
En = np.diag(c)
|
|
205
195
|
Ln = np.matmul(np.matmul(d_tp, En), d)
|
|
206
196
|
gn = np.add(
|
|
@@ -216,7 +206,7 @@ def reg_diff(
|
|
|
216
206
|
),
|
|
217
207
|
data_comp,
|
|
218
208
|
)
|
|
219
|
-
) + alpha2 * npl.norm(
|
|
209
|
+
) + alpha2 * npl.norm(np.diff(v), ord=1)
|
|
220
210
|
if diag:
|
|
221
211
|
print(
|
|
222
212
|
f"v, iteration {iter + 1}: cost: {cost_n}, relative change: {npl.norm(s) / npl.norm(v)}"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .regdiff import finite_diff, matrix_anti_diff, matrix_diff, reg_diff # noqa: F401
|