Skip to content
Snippets Groups Projects
Commit 96f6ee28 authored by Hossein Rafipoor's avatar Hossein Rafipoor
Browse files

added more functions to utils

parent 9453eb20
No related branches found
No related tags found
No related merge requests found
numpy
scipy
matplotlib
joblib
\ No newline at end of file
......@@ -15,7 +15,7 @@ test_requirements = ['pytest',]
setup(
author="Hossein Rafipoor, Michiel Cottaar, Saad Jbabdi",
author_email='hossein.rafipoor@ndcn.ox.ac.uk',
python_requires='>=3.6',
python_requires='>=3.7',
classifiers=[
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
......
......@@ -6,7 +6,7 @@ from dataclasses import dataclass
from . import utils
@dataclass
class hbm():
class hbm:
forward_model: Callable
param_names: List
param_priors: Mapping
......
......@@ -155,3 +155,27 @@ def generate_acq(n_b0=10, n_dir=64, b=(1, 2, 3)):
bvecs = np.concatenate([bvecs, fibonacci_sphere(n_dir)])
return bvals, bvecs
def grad(f, p, bounds, dp=1e-6):
dp = np.maximum(1e-10, abs(p * dp))
g = []
for i in range(len(p)):
pi = np.zeros(len(p))
pi[i] = dp[i]
u = p + pi
if u[i] > bounds[i][1]:
u[i] = bounds[i][1]
l = p - pi
if l[i] < bounds[i][0]:
l[i] = bounds[i][0]
g.append((f(u) - f(l)) / (u[i]-l[i]))
return np.stack(g, axis=0)
def hessian(f, p, bounds, dp=1e-6):
g = lambda p_: grad(f, p_, bounds, dp)
return grad(g, p, bounds, dp)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment