iam-git / WellMet (public) (License: MIT) (since 2021-08-31) (hash sha1)
WellMet is pure Python framework for spatial structural reliability analysis. Or, more specifically, for "failure probability estimation and detection of failure surfaces by adaptive sequential decomposition of the design domain".
List of commits:
Subject Hash Author Date (UTC)
voronoi: add fantastic ConvexSolver 2853826e5ef1abc79d3ac2fb8289b13c45211a31 I am 2022-10-14 04:00:14
qt_gui.qt_plot: add (finally!) Numbers class 4cdc658c0fcc857c23c0e39e91e7a1ce5e1b30a1 I am 2022-10-13 06:23:46
qt_gui.qt_gui: show contacts in distance matrix. Based on ContactSolver for now 21bd6101888d9f06d7d6a7c6ba2732ff30fdd68d I am 2022-10-13 04:16:41
voronoi: ContactSolver is ready. Ale je to na nic. Pomalá, potvora 28e2442b0101eac2407ed4a69c6f757ffd579cf1 I am 2022-10-13 04:14:59
voronoi: add some preliminary lines of ContactSolver. WIP 6a203b278c9fa6de7da75c402c80f78d40164fdf I am 2022-10-12 23:38:59
voronoi: přídat pár těžkých smyček. WIP 7b0ffb602ae00ab2f12dc98d34c35ec20afa3cc4 I am 2022-10-12 00:13:36
add to repo voronoi module. WIP f43768c22d88fac7c7095be02d8c9b5620153976 I am 2022-10-11 03:29:49
convex_hull.Grick: malý puntičkářský fix v get_r() cfa07257b9ebadc21f2bd295d35978072fac19e9 I am 2022-10-10 07:14:26
qt_gui.qt_plot: add Grick to Ghull widget d90b9a87c3ef0989951a45b2a22346381ce16f02 I am 2022-10-10 03:17:24
convex_hull: implement Grick convex hull aproximation d09ca2e6aca41cfc67f3303eb97b97dd9c6f1fba I am 2022-10-10 03:15:52
qt_gui.qt_gui: distance matrix viewer is ready a532e5259c081a1aff193d3b61e0104c42b08f20 I am 2022-10-08 20:52:14
qt_gui.qt_gui: prepare distance matrix window 4eaea3305643c60c35f0b22421a7e57dbe7a7817 I am 2022-10-08 02:59:01
qt_gui.qt_graph_widgets: set up x limits for all graph widgets 413d114f6a4e4b45c6cd44959cc42588bb7c8008 I am 2022-10-07 22:54:46
qt_gui.qt_plot: set up equal aspect by default 11bfe09b3e96881ef6f7c8202a6723b6e8adc03a I am 2022-10-07 21:41:18
qt_gui.qt_gui: hide "connect/disconnect" button. It wasn't really supported d9f195fe0611d6cf9a8154f0175c6c9506d56247 I am 2022-10-07 21:33:07
qt_gui.qt_plot: fix zero r cirkle (off by one error) 681397de6d075b693897d5f64004c0eb481fd36f I am 2022-10-07 20:34:44
qt_gui: replace globally QtGui by QtWidgets 969a659ae31728e75f587f25f54bab1ae5d6bfff I am 2022-10-07 12:45:34
qt_gui: add radia in Gaussian space (GRaph) widget e3f5be57dcdc6bdd06cda0594ffd795ef5bc8ccc I am 2022-10-07 01:15:38
testcases.testcases_2d: fix natafm_plane pf 75006ccd448c9717c13659e8ceb68800fbda39a7 I am 2022-06-26 12:03:39
misc: add entropy formula 72736d485b4f0fa912a47a49f72954e1ec06c03f I am 2022-06-26 12:02:52
Commit 2853826e5ef1abc79d3ac2fb8289b13c45211a31 - voronoi: add fantastic ConvexSolver
Author: I am
Author date (UTC): 2022-10-14 04:00
Committer name: I am
Committer date (UTC): 2022-10-14 04:00
Parent(s): 4cdc658c0fcc857c23c0e39e91e7a1ce5e1b30a1
Signer:
Signing key:
Signing status: N
Tree: f8f425c78f493d501f7ed244d6d849de106da432
File Lines added Lines deleted
wellmet/voronoi.py 180 5
File wellmet/voronoi.py changed (mode: 100644) (index 7a39675..136400c)
... ... from . import sball
23 23
24 24
25 25
26
27
28
29 def is_line_convex(points, line_indices):
30 i, j = line_indices
31
32 X = points
33 __nsim, ndim = X.shape
34
35 basis = np.random.random((ndim, ndim))
36
37 #č QR rozklad jede po sloupcich
38 basis[:, 0] = X[j] - X[i]
39
40 for dim in range(1, ndim-1):
41 #č co jsem viděl, numpy matici Q normalizuje
42 #č a první sloupec zůstavá (skoro) tím samým, co byl před tím
43 basis[:, :dim+1], __ = np.linalg.qr(basis[:, :dim+1])
44
45 # get constrain
46 a = basis[:, dim]
47 #č nejak tuším, že v poslední dimenzi
48 #č znaménko normál musí být jednotné
49 a = a * -np.sign(a[-1])
50 b = X @ a
51 if np.max(b) - np.max(b[[i, j]]) < 1e-7:
52 return True
53 else:
54 idx = np.argmax(b)
55 basis[:, dim] = basis[:, 1]
56 basis[:, 1] = X[idx] - X[i]
57
58
59
60 for __ in range(ndim):
61 basis, __ = np.linalg.qr(basis)
62
63 # get constrain
64 a = basis[:, -1]
65 #č nejak tuším, že v poslední dimenzi
66 #č znaménko normál musí být jednotné
67 a = a * -np.sign(a[-1])
68 b = X @ a
69 if np.max(b) - np.max(b[[i, j]]) < 1e-7:
70 return True
71 else:
72 idx = np.argmax(b)
73 basis[:, 2:] = basis[:, 1:-1]
74 basis[:, 1] = X[idx] - X[i]
75
76 basis, __ = np.linalg.qr(basis)
77 a = basis[:, -1]
78 #č nejak tuším, že v poslední dimenzi
79 #č znaménko normál musí být jednotné
80 a = a * -np.sign(a[-1])
81 b = X @ a
82 return np.max(b) - np.max(b[[i, j]]) < 1e-7
83
84
85
86
87 class ConvexSolver:
88 """
89 č Hlavní pointa třídy:
90 č pokud dva body zvednuté na povrch convexního paraboloidu
91 č v prostoru ndim+1 (feature space, quadratic kernel)
92 č lze lineárně separovat (hyperrovinou) od ostatních bodů,
93 č znamená to, že v původním prostoru
94 č jejich Voroného buňky budou mít společnou stěnu (kontakt),
95 č neboli, což je totež, u Delone triangulace by měly společné simplexy
96
97 linprog:
98 minimize c @ x
99 such that:
100 A_ub @ x <= b_ub
101 A_eq @ x == b_eq
102 lb <= x <= ub
103
104 č rovnice hyperroviny
105 H = ax + b = a1x1 + a2x2 + ... + b = 0
106 č ačka a bčko jsou pro nás neznamé
107 č takže máme ndim+1 iksů do tamtoho lineárního solveru
108
109 č nebudeme puntičkařit a pro jednoduchost předepíšeme,
110 č nechť dva body zájmu leží přímo v hyperrovině
111 č (bude to hlasít existence rozhraní i v degenerovaných případech
112 č jako např. tří teček na jedné přímce. Mně to ale nevadí)
113 č Takže.
114
115 č pro linprog zadáme constrains Ax=b
116 A = [[ x_1i, x_2i, ..., x_ni, 1],
117 [ x_1j, x_2j, ..., x_nj, 1]]
118 b = [0, 0]
119
120
121 č Zbytek musí splňovat nerovnost, tj.
122 "Convex hull inequalities of the form Ax + b <= 0"
123
124 č Neboli Ax <= b v termínech linprog
125 č díky "menší nebo rovno"
126 č nemusíme plnou matici ani maskovat
127
128 č ačka hyperroviny zadavají jednotkový vektor normály,
129 č takže leží v mezích -1 < a < 1
130 č bčko lze omezit poloosou
131 """
132 def __init__(self, points):
133 nsim, ndim = points.shape
134
135 self.lifted_points = np.empty((nsim, ndim + 1))
136 self.lifted_points[:, :ndim] = points
137 # kind of datascience. feature space, quadratic kernel...
138 self.lifted_points[:, -1] = np.sum(np.square(points), axis=1)
139
140
141 def is_couple(self, couple_indices):
142 return is_line_convex(self.lifted_points, couple_indices)
143
144
145
146
147
148
26 149 class ContactSolver: class ContactSolver:
27 150 """ """
28 151 č Hlavní pointa třídy: č Hlavní pointa třídy:
 
... ... class ContactSolver:
75 198 A[:, :ndim] = points A[:, :ndim] = points
76 199 # kind of datascience. feature space, quadratic kernel... # kind of datascience. feature space, quadratic kernel...
77 200 #č dáme to trochu niž (ten "ndim"), abychom se vyhli triviálnímu řešení #č dáme to trochu niž (ten "ndim"), abychom se vyhli triviálnímu řešení
78 A[:, -2] = np.sum(np.square(points)-ndim, axis=1)
201 A[:, -2] = np.sum(np.square(points), axis=1)-1000
79 202 A[:, -1] = 1 A[:, -1] = 1
80 203
204 self.lifted_points = A[:, :ndim+1]
205
81 206 #č žšmaria, alokovat nuly.. #č žšmaria, alokovat nuly..
82 self.b_ub = np.zeros(nsim)
207 self.b_ub = np.atleast_1d(np.zeros(ndim-2))
83 208 self.c = np.zeros(ndim + 2) self.c = np.zeros(ndim + 2)
84 209 self.b_eq = self.c[:2] self.b_eq = self.c[:2]
85 210 self.bounds = [(-1, 1) for __ in range(ndim + 1)] self.bounds = [(-1, 1) for __ in range(ndim + 1)]
86 211 #č skoro-nulové b-čko může být legální #č skoro-nulové b-čko může být legální
87 212 #č ale musíme vyhnout triviálnímu řešení #č ale musíme vyhnout triviálnímu řešení
88 213 #č nevím co s tím #č nevím co s tím
89 self.bounds.append((None, -0.3))
214 self.bounds.append((None, -0.2))
215
216 def is_couple(self, couple_indices):
217 i, j = couple_indices
218
219 #č pro linprog zadáme constrains Ax=b
220 # A = [[ x_1i, x_2i, ..., x_ni, 1],
221 # [ x_1j, x_2j, ..., x_nj, 1]]
222 A_eq = self.A[[i, j]]
223
224 mask = np.ones(len(self.A), dtype=np.bool8)
225 mask[[i, j]] = False
226 A_ub = np.atleast_2d(self.A[mask])
227
228 result = linprog(self.c, A_ub=A_ub, b_ub=self.b_ub, A_eq=A_eq,\
229 b_eq=self.b_eq, bounds=self.bounds)
230
231 return result.success
232
233
234
235
90 236
91 237 def is_couple(self, couple_indices): def is_couple(self, couple_indices):
92 238 i, j = couple_indices i, j = couple_indices
 
... ... class ContactSolver:
96 242 # [ x_1j, x_2j, ..., x_nj, 1]] # [ x_1j, x_2j, ..., x_nj, 1]]
97 243 A_eq = self.A[[i, j]] A_eq = self.A[[i, j]]
98 244
99 #č nevím, zda omezení (bounds) zrychlí, nebo zpomalí běh řešiče
100 result = linprog(self.c, A_ub=self.A, b_ub=self.b_ub, A_eq=A_eq,\
245
246 mask = np.ones(len(self.A), dtype=np.bool8)
247 mask[[i, j]] = False
248 A_ub = np.atleast_2d(self.A[mask])
249
250 result = linprog(self.c, A_ub=A_ub, b_ub=self.b_ub, A_eq=A_eq,\
101 251 b_eq=self.b_eq, bounds=self.bounds) b_eq=self.b_eq, bounds=self.bounds)
102 252
103 253 return result.success return result.success
254
255
256 # def solve(self, A_eq, couple_indices, constrains=[]):
257 # i, j = couple_indices
258 #
259 # A_ub = np.atleast_2d(constrains)
260 # b_ub = np.atleast_1d(self.b_ub[:len(constrains)])
261 #
262 # result = linprog(self.c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq,\
263 # b_eq=self.b_eq, bounds=self.bounds)
264 #
265 # if len(constrains) < len(self.b_ub):
266 #
267 #
268 #
269 # else:
270 # return result.success
271
272
273 def get_constrain(hyperplane):
274 X = self.lifted_points
275 a = hyperplane[:-1]
276 b = X @ a
277 return np.argmax(b)
278
104 279
105 280
106 281
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/iam-git/WellMet

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/iam-git/WellMet

Clone this repository using git:
git clone git://git.rocketgit.com/user/iam-git/WellMet

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main