def __init__(self, mesh=None, el_pos=None, parser="fmmu", algo="jac", p=0.20, lamb=0.001): """ initialize """ if algo == "jac": solver = jac.JAC(mesh, el_pos, perm=1.0, parser=parser) solver.setup(p=p, lamb=lamb, method="kotre") else: # default: 'bp' solver = bp.BP(mesh, el_pos, parser="fmmu", step=1) solver.setup(weight="simple") self.solver = solver
def get_MAP(self,lamb_decay=1.,lamb_min=1e-5,maxiter=20,verbose=True,**kwargs): map=jac.JAC(self.mesh_obj,self.el_pos,self.ex_mat,self.step,perm=1.0,parser='std') map.setup(p=kwargs.pop('p',0.25),lamb=kwargs.pop('lamb',self.lamb),method=kwargs.pop('method','lm')) ds=map.gn(self.obs,lamb_decay=lamb_decay,lamb_min=lamb_min,maxiter=maxiter,verbose=verbose,**kwargs) return ds
tri, np.real(perm), shading="flat", cmap=plt.cm.viridis) fig.colorbar(im) ax.axis("equal") ax.set_title(r"$\Delta$ Conductivities") plt.show() """ 2. calculate simulated data """ el_dist, step = 1, 1 ex_mat = eit_scan_lines(n_el, el_dist) fwd = Forward(mesh_obj, el_pos) f1 = fwd.solve_eit(ex_mat, step, perm=mesh_new["perm"], parser="std") """ 3. solve_eit using gaussian-newton (with regularization) """ # number of stimulation lines/patterns eit = jac.JAC(mesh_obj, el_pos, ex_mat, step, perm=1.0, parser="std") eit.setup(p=0.25, lamb=1.0, method="lm") # lamb = lamb * lamb_decay ds = eit.gn(f1.v, lamb_decay=0.1, lamb_min=1e-5, maxiter=20, verbose=True) # plot fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor( pts[:, 0], pts[:, 1], tri, np.real(ds), shading="flat", alpha=1.0, cmap=plt.cm.viridis, )
fig.colorbar(im) ax.axis('tight') ax.set_title(r'$\Delta$ Permitivity') """ 2. calculate simulated data using stack ex_mat """ el_dist, step = 7, 1 n_el = len(el_pos) ex_mat1 = eit_scan_lines(n_el, el_dist) ex_mat2 = eit_scan_lines(n_el, 1) ex_mat = np.vstack([ex_mat1, ex_mat2]) # forward solver fwd = Forward(ms, el_pos) f0 = fwd.solve(ex_mat, step, perm=ms['alpha']) f1 = fwd.solve(ex_mat, step, perm=ms1['alpha']) """ 3. solving using dynamic EIT """ # number of stimulation lines/patterns eit = jac.JAC(ms, el_pos, ex_mat=ex_mat, step=step, parser='std') eit.setup(p=0.40, lamb=1e-3, method='kotre') ds = eit.solve(f1.v, f0.v) """ 4. plot """ fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor(no2xy[:, 0], no2xy[:, 1], el2no, np.real(ds), shading='flat', alpha=0.90, cmap=plt.cm.viridis) fig.colorbar(im) ax.axis('tight') ax.set_title(r'$\Delta$ Permitivity Reconstructed') # plt.savefig('quasi-demo-eit.pdf')
# calculate simulated data fwd = Forward(mesh_obj, el_pos) f0 = fwd.solve_eit(ex_mat, step=step, perm=mesh_obj["perm"]) f1 = fwd.solve_eit(ex_mat, step=step, perm=mesh_new["perm"]) """ 3. JAC solver """ # Note: if the jac and the real-problem are generated using the same mesh, # then, data normalization in solve are not needed. # However, when you generate jac from a known mesh, but in real-problem # (mostly) the shape and the electrode positions are not exactly the same # as in mesh generating the jac, then data must be normalized. eit = jac.JAC( mesh_obj, el_pos, ex_mat=ex_mat, step=step, perm=1.0, parser="fmmu", ) eit.setup(p=0.5, lamb=0.01, method="kotre") ds = eit.solve(f1.v, f0.v, normalize=True) ds_n = sim2pts(pts, tri, np.real(ds)) # plot ground truth fig, ax = plt.subplots(figsize=(6, 4)) delta_perm = mesh_new["perm"] - mesh_obj["perm"] im = ax.tripcolor(x, y, tri, np.real(delta_perm), shading="flat") fig.colorbar(im) ax.set_aspect("equal") # plot EIT reconstruction
ax.set_aspect("equal") ax.set_title(r"$\Delta$ Permittivity") """ 2. calculate simulated data using stack ex_mat """ el_dist, step = 7, 1 n_el = len(el_pos) ex_mat1 = eit_scan_lines(n_el, el_dist) ex_mat2 = eit_scan_lines(n_el, 1) ex_mat = np.vstack([ex_mat1, ex_mat2]) # forward solver fwd = Forward(mesh_obj, el_pos) f0 = fwd.solve_eit(ex_mat, step, perm=mesh_obj["perm"]) f1 = fwd.solve_eit(ex_mat, step, perm=mesh_new["perm"]) """ 3. solving using dynamic EIT """ # number of stimulation lines/patterns eit = jac.JAC(mesh_obj, el_pos, ex_mat=ex_mat, step=step, parser="std") eit.setup(p=0.40, lamb=1e-3, method="kotre") ds = eit.solve(f1.v, f0.v, normalize=False) """ 4. plot """ fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor( pts[:, 0], pts[:, 1], tri, np.real(ds), shading="flat", alpha=0.90, cmap=plt.cm.viridis, ) fig.colorbar(im) ax.set_aspect("equal")
# in python, index start from 0 ex_line = ex_mat[2].ravel() # change alpha anomaly = [{'x': 0.40, 'y': 0.40, 'z': 0.0, 'd': 0.30, 'perm': 100.0}] mesh_new = mesh.set_perm(mesh_obj, anomaly=anomaly, background=1.0) tri_perm = mesh_new['perm'] node_perm = sim2pts(pts, tri, np.real(tri_perm)) # solving once using fem # f, _ = fwd.solve(ex_line, tri_perm) # f = np.real(f) # calculate simulated data f0 = fwd.solve_eit(ex_mat, step=step, perm=mesh_obj['perm']) f1 = fwd.solve_eit(ex_mat, step=step, perm=mesh_new['perm']) """ 3. JAC solver """ # number of stimulation lines/patterns eit = jac.JAC(mesh_obj, el_pos, ex_mat=ex_mat, step=step, perm=1., parser='std') eit.setup(p=0.50, lamb=1e-3, method='kotre') ds = eit.solve(f1.v, f0.v, normalize=False) node_ds = sim2pts(pts, tri, np.real(ds)) # mplot.tetplot(p, t, edge_color=(0.2, 0.2, 1.0, 1.0), alpha=0.01) mplot.tetplot(pts, tri, vertex_color=node_ds, alpha=1.0)
el2no, np.real(alpha), shading='flat', cmap=plt.cm.viridis) fig.colorbar(im) ax.axis('equal') ax.set_title(r'$\Delta$ Conductivities') plt.show() """ 2. calculate simulated data """ el_dist, step = 1, 1 ex_mat = eit_scan_lines(n_el, el_dist) fwd = Forward(ms, el_pos) f1 = fwd.solve(ex_mat, step, perm=ms1['alpha'], parser='std') """ 3. solve using gaussian-newton """ # number of stimulation lines/patterns eit = jac.JAC(ms, el_pos, ex_mat, step, perm=1.0, parser='std') eit.setup(p=0.25, lamb=1.0, method='lm') ds = eit.gn(f1.v, lamb_decay=0.1, lamb_min=1e-4, maxiter=20, verbose=True) # plot fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor(no2xy[:, 0], no2xy[:, 1], el2no, np.real(ds), shading='flat', alpha=1.0, cmap=plt.cm.viridis) fig.colorbar(im) ax.axis('equal') ax.set_title('Conductivities Reconstructed')
""" 2. FEM simulation """ el_dist, step = 8, 1 ex_mat = eit_scan_lines(16, el_dist) # calculate simulated data fwd = Forward(mesh_obj, el_pos) f0 = fwd.solve_eit(ex_mat, step=step, perm=mesh_obj['perm']) f1 = fwd.solve_eit(ex_mat, step=step, perm=mesh_new['perm']) """ 3. JAC solver """ # Note: if the jac and the real-problem are generated using the same mesh, # then, jac_normalized in JAC and data normalization in solve are not needed. # However, when you generate jac from a known mesh, but in real-problem # (mostly) the shape and the electrode positions are not exactly the same # as in mesh generating the jac, then JAC and data must be normalized. eit = jac.JAC(mesh_obj, el_pos, ex_mat=ex_mat, step=step, perm=1., parser='std', jac_normalized=False) eit.setup(p=0.5, lamb=0.01, method='kotre') ds = eit.solve(f1.v, f0.v, normalize=True) ds_n = sim2pts(pts, tri, np.real(ds)) # plot ground truth fig, ax = plt.subplots(figsize=(6, 4)) delta_perm = mesh_new['perm'] - mesh_obj['perm'] im = ax.tripcolor(x, y, tri, np.real(delta_perm), shading='flat') fig.colorbar(im) ax.set_aspect('equal') # plot EIT reconstruction fig, ax = plt.subplots(figsize=(6, 4)) im = ax.tripcolor(x, y, tri, ds_n, shading='flat') for i, e in enumerate(el_pos):
# calculate simulated data fwd = Forward(mesh_obj, el_pos) f0 = fwd.solve_eit(ex_mat, step=step, perm=mesh_obj["perm"]) f1 = fwd.solve_eit(ex_mat, step=step, perm=mesh_new["perm"]) """ 3. JAC solver """ # Note: if the jac and the real-problem are generated using the same mesh, # then, jac_normalized in JAC and data normalization in solve are not needed. # However, when you generate jac from a known mesh, but in real-problem # (mostly) the shape and the electrode positions are not exactly the same # as in mesh generating the jac, then JAC and data must be normalized. eit = jac.JAC( mesh_obj, el_pos, ex_mat=ex_mat, step=step, perm=1.0, parser="std", jac_normalized=False, ) eit.setup(p=0.5, lamb=0.01, method="kotre") ds = eit.solve(f1.v, f0.v, normalize=True) ds_n = sim2pts(pts, tri, np.real(ds)) # plot ground truth fig, ax = plt.subplots(figsize=(6, 4)) delta_perm = mesh_new["perm"] - mesh_obj["perm"] im = ax.tripcolor(x, y, tri, np.real(delta_perm), shading="flat") fig.colorbar(im) ax.set_aspect("equal")