executable-engineering 0.1.36__py3-none-any.whl → 0.1.39__py3-none-any.whl
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.
- executable_engineering/__init__.py +3 -1
- executable_engineering/linearsystems_module.py +61 -0
- executable_engineering/openrootfinder_module.py +18 -12
- {executable_engineering-0.1.36.dist-info → executable_engineering-0.1.39.dist-info}/METADATA +1 -1
- {executable_engineering-0.1.36.dist-info → executable_engineering-0.1.39.dist-info}/RECORD +8 -8
- {executable_engineering-0.1.36.dist-info → executable_engineering-0.1.39.dist-info}/WHEEL +0 -0
- {executable_engineering-0.1.36.dist-info → executable_engineering-0.1.39.dist-info}/licenses/LICENSE +0 -0
- {executable_engineering-0.1.36.dist-info → executable_engineering-0.1.39.dist-info}/top_level.txt +0 -0
|
@@ -5,9 +5,11 @@ from .closedoptimization_module import OptimizerClosed
|
|
|
5
5
|
from .openoptimization_module import OptimizerOpen
|
|
6
6
|
from .gradientoptimization_module import OptimizerGrad
|
|
7
7
|
from .numerical_error_module import python_internal_binary, decimal_to_binary
|
|
8
|
-
from .linearsystems_module import visual_solve_2d, visualize_conditioning, visualize_matrix_norms, jacobi_step, gauss_seidel_step, sor_step, visualize_convergence_2d, create_diagonally_dominant_matrix, iter_solve, steepest_descent, conjugate_gradient, IterationTracker
|
|
8
|
+
from .linearsystems_module import visual_solve_2d, visualize_conditioning, visualize_matrix_norms, jacobi_step, gauss_seidel_step, sor_step, visualize_convergence_2d, create_diagonally_dominant_matrix, iter_solve, steepest_descent, conjugate_gradient, IterationTracker, discretise_poisson, spai
|
|
9
9
|
|
|
10
10
|
__all__ = [
|
|
11
|
+
"discretise_poisson",
|
|
12
|
+
"spai",
|
|
11
13
|
"visual_solve_2d",
|
|
12
14
|
"visualize_conditioning",
|
|
13
15
|
"visualize_matrix_norms",
|
|
@@ -471,3 +471,64 @@ class IterationTracker:
|
|
|
471
471
|
if self.print_residual:
|
|
472
472
|
guess_str = np.array2string(x, precision=4, separator=', ', suppress_small=True)
|
|
473
473
|
print(f"Step {self.step}: Guess = {guess_str}, Residual = {res:.4e}")
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
def discretise_poisson(N, Q):
|
|
477
|
+
"""Generate the matrix and rhs associated with the discrete Poisson operator."""
|
|
478
|
+
import numpy as np
|
|
479
|
+
from scipy.sparse import coo_matrix
|
|
480
|
+
|
|
481
|
+
nelements = 5 * N**2 - 16 * N + 16
|
|
482
|
+
|
|
483
|
+
row_ind = np.empty(nelements, dtype=np.float64)
|
|
484
|
+
col_ind = np.empty(nelements, dtype=np.float64)
|
|
485
|
+
data = np.empty(nelements, dtype=np.float64)
|
|
486
|
+
|
|
487
|
+
f = np.empty(N * N, dtype=np.float64)
|
|
488
|
+
|
|
489
|
+
count = 0
|
|
490
|
+
for j in range(N):
|
|
491
|
+
for i in range(N):
|
|
492
|
+
if i == 0 or i == N - 1 or j == 0 or j == N - 1:
|
|
493
|
+
row_ind[count] = col_ind[count] = j * N + i
|
|
494
|
+
data[count] = 1
|
|
495
|
+
f[j * N + i] = 0
|
|
496
|
+
count += 1
|
|
497
|
+
|
|
498
|
+
else:
|
|
499
|
+
row_ind[count : count + 5] = j * N + i
|
|
500
|
+
col_ind[count] = j * N + i
|
|
501
|
+
col_ind[count + 1] = j * N + i + 1
|
|
502
|
+
col_ind[count + 2] = j * N + i - 1
|
|
503
|
+
col_ind[count + 3] = (j + 1) * N + i
|
|
504
|
+
col_ind[count + 4] = (j - 1) * N + i
|
|
505
|
+
|
|
506
|
+
data[count] = 4 * (N - 1)**2
|
|
507
|
+
data[count + 1 : count + 5] = - (N - 1)**2
|
|
508
|
+
f[j * N + i] = Q
|
|
509
|
+
|
|
510
|
+
count += 5
|
|
511
|
+
|
|
512
|
+
return coo_matrix((data, (row_ind, col_ind)), shape=(N**2, N**2)).tocsr(), f
|
|
513
|
+
|
|
514
|
+
def spai(A, m):
|
|
515
|
+
"""Perform m step of the SPAI iteration."""
|
|
516
|
+
import numpy as np
|
|
517
|
+
from scipy.sparse import identity
|
|
518
|
+
from scipy.sparse.linalg import onenormest
|
|
519
|
+
|
|
520
|
+
n = A.shape[0]
|
|
521
|
+
|
|
522
|
+
ident = identity(n, format='csr')
|
|
523
|
+
alpha = 2 / onenormest(A @ A.T)
|
|
524
|
+
M = alpha * A
|
|
525
|
+
|
|
526
|
+
for index in range(m):
|
|
527
|
+
C = A @ M
|
|
528
|
+
G = ident - C
|
|
529
|
+
AG = A @ G
|
|
530
|
+
trace = (G.T @ AG).diagonal().sum()
|
|
531
|
+
alpha = trace / np.linalg.norm(AG.data)**2
|
|
532
|
+
M = M + alpha * G
|
|
533
|
+
|
|
534
|
+
return M
|
|
@@ -138,20 +138,26 @@ class RootFinderOpen:
|
|
|
138
138
|
return HTML(anim.to_jshtml())
|
|
139
139
|
|
|
140
140
|
def show_toggle_open(self, interval_ms=750):
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
newton_anim_html = self._make_animation_open('Newton', interval_ms)
|
|
142
|
+
secant_anim_html = self._make_animation_open('Secant', interval_ms)
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
if newton_anim_html is None or secant_anim_html is None:
|
|
145
|
+
print("Cannot create animations. Check function definition or initial points (x0, x1).")
|
|
146
|
+
return
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
newton_out = widgets.Output()
|
|
149
|
+
secant_out = widgets.Output()
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
with newton_out:
|
|
152
|
+
display(newton_anim_html)
|
|
153
|
+
|
|
154
|
+
with secant_out:
|
|
155
|
+
display(secant_anim_html)
|
|
153
156
|
|
|
154
|
-
|
|
155
|
-
|
|
157
|
+
tab_container = widgets.Tab()
|
|
158
|
+
tab_container.children = [newton_out, secant_out]
|
|
156
159
|
|
|
157
|
-
|
|
160
|
+
tab_container.set_title(0, 'Newton')
|
|
161
|
+
tab_container.set_title(1, 'Secant')
|
|
162
|
+
|
|
163
|
+
display(tab_container)
|
{executable_engineering-0.1.36.dist-info → executable_engineering-0.1.39.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: executable_engineering
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.39
|
|
4
4
|
Summary: Demonstrative tools for the Executable Engineering textbook
|
|
5
5
|
Home-page: https://github.com/themintlab/ExecutableEngineering/tree/main/executable_engineering
|
|
6
6
|
Author: Michael Welland
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
executable_engineering/__init__.py,sha256=
|
|
1
|
+
executable_engineering/__init__.py,sha256=TbE18BDMSDAqyHnJI0XQXMIcM6bXQv8ebV3rWijyVP0,1656
|
|
2
2
|
executable_engineering/closedoptimization_module.py,sha256=i9KkdulyCZmriYKlx0CuUetjoMmxJm9ADWgStU3w85w,9273
|
|
3
3
|
executable_engineering/closedrootfinder_module.py,sha256=ozccVABOrTiqcdkkqwAWRNo04MsDC0Z_f_tfukl3q20,5706
|
|
4
4
|
executable_engineering/gradientoptimization_module.py,sha256=-2fErE9cemSEPeV9PlWOf4cF7Tr6DjilEw_NxvE-JYw,6601
|
|
5
|
-
executable_engineering/linearsystems_module.py,sha256=
|
|
5
|
+
executable_engineering/linearsystems_module.py,sha256=w6UkwZu80gUz5bAIWY47xJbwaEVzR9tCcIBkMsKjIRk,18356
|
|
6
6
|
executable_engineering/neuralnet_module.py,sha256=Hu9QFoMyODg4RCEpHmT9zTwzjcVFYM8ZLYtbB3CbrsA,10102
|
|
7
7
|
executable_engineering/numerical_error_module.py,sha256=wxfYP8u29c19I2D6MxpQV3zDMV0DpS1QUqFpp3f6eGE,1204
|
|
8
8
|
executable_engineering/openoptimization_module.py,sha256=OCPyrynkTo1It50RoT7irnL72aQn6FexE_R1SfFYxlg,8590
|
|
9
|
-
executable_engineering/openrootfinder_module.py,sha256=
|
|
10
|
-
executable_engineering-0.1.
|
|
11
|
-
executable_engineering-0.1.
|
|
12
|
-
executable_engineering-0.1.
|
|
13
|
-
executable_engineering-0.1.
|
|
14
|
-
executable_engineering-0.1.
|
|
9
|
+
executable_engineering/openrootfinder_module.py,sha256=R_lPtCQsIGLXV-j_uDpQepImOOgtgA7I6qnhUPwWLLc,5944
|
|
10
|
+
executable_engineering-0.1.39.dist-info/licenses/LICENSE,sha256=Tg4nrt8rFhgpkPbIA8SWoCR3MlGLw0NufB8AE6-TH_o,1074
|
|
11
|
+
executable_engineering-0.1.39.dist-info/METADATA,sha256=D3CtWo1BiOOo9yR8WeFNw-LBi94rd9flj-M2BxTqKC0,1648
|
|
12
|
+
executable_engineering-0.1.39.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
13
|
+
executable_engineering-0.1.39.dist-info/top_level.txt,sha256=0U5ATV5WGTLvN9rRSjQ54TyL-ztTyXaN3FzZ_QMq4HM,23
|
|
14
|
+
executable_engineering-0.1.39.dist-info/RECORD,,
|
|
File without changes
|
{executable_engineering-0.1.36.dist-info → executable_engineering-0.1.39.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{executable_engineering-0.1.36.dist-info → executable_engineering-0.1.39.dist-info}/top_level.txt
RENAMED
|
File without changes
|