forked from Sebastian-MR/ThinWire_MRIGradientCoilDesign
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTikhonovReg.py
More file actions
28 lines (21 loc) · 917 Bytes
/
TikhonovReg.py
File metadata and controls
28 lines (21 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# calculates Currents approximately satisfying equation
# TargetField = ElementFields*Currents using simple Tikhonov regularization
# with the unity regularization matrix. Regularization parameter lambda is
# scaled to the norm of ElementFields
import numpy as np
def TikhonovReg(ElementFields, TargetField, lambda_val):
"""
Tikhonov Regularization
Args:
ElementFields (ndarray): Element fields
TargetField (ndarray): Target field
lambda_val (float): Regularization parameter
Returns:
Currents (ndarray): Computed currents
"""
AtA = ElementFields.T @ ElementFields
G = lambda_val * np.linalg.norm(ElementFields) * np.eye(ElementFields.shape[1])
GtG = G.T @ G
Currents = np.linalg.pinv(AtA + GtG) @ ElementFields.T @ TargetField
#Currents = np.linalg.pinv(AtA + GtG) @ ElementFields.T @ TargetField
return Currents