Exemplo n.º 1
0
    if one_point_b1_inside_b2 or one_point_b2_inside_b1:
        return numpy.vstack((numpy.vstack(
            (b1[0], b2[0])).max(0), numpy.vstack((b1[1], b2[1])).min(0)))
    else:
        return None


fiberDelta = lambda f: numpy.sqrt(((f[1:] - f[:-1])**2).sum(1))


def _constant(x, val=0):
    """docstring for parabolic_fun"""
    return numpy.zeros(x.shape[:-1], dtype=float) + val


cov_thinPlate3D = _GP.covariance_function_bundle(
    'thinplate3d_mat', 'tractographyGP.bounded_thinPlate', {'r': 'r'})
cov_thinPlate2D = _GP.covariance_function_bundle(
    'thinplate2d_mat', 'tractographyGP.bounded_thinPlate', {'r': 'r'})


class fiberGP:

    _k = 0
    _precomputedVariance = None
    _precomputedMean = None
    _scaleFactor = 1
    _mean = None
    _cov = None
    _alpha = None
    _inv_cov = None
Exemplo n.º 2
0
# Clindmri import
from .bounded_thinplate import innerproduct_thinplate3d


# Define 'pymc' new covariance using 'covariance_function_bundles' method:
# Init method takes three arguments:
#     1- cov_fun_name: The name of the covariance function.
#     2- cov_fun_module: The name of the module in which the covariance
#        function can be found. This must be somewhere on your PYTHONPATH.
#     3- extra_cov_params: A dictionary whose keys are the extra parameters
#        the covariance function takes, and whose values are brief sentences
#        explaining the roles of those parameters. This dictionary will be used
#        to generate the docstring of the bundle.
cov_thinplate3d = gp.covariance_function_bundle(
    "thinplate3d_mat", "clindmri.tractography.bounded_thinplate",
    {"R": ("the radius of a shpere in R3 inside which the soultion is "
           "calculated.")})

# Lambda function to compute the fiber sampling deltas: if a determinist
# tractography with constant integration step has been used to produce the
# fiber, all the deltas are the same and are equal to the integration step.
fiber_deltas = lambda f: numpy.sqrt(((f[1:] - f[:-1]) ** 2).sum(1))


class FiberGP(object):
    """ Single fiber as a gaussian process (GP).

    The GP of a fiber ~ the blurred indicator function (BIF) of a fiber is
    characterized by the BIF for a smooth trajectory as a GP with covariance
    Cs (geometric) and by the anisotrpoic blurring of a smooth function as a
    GP with covariance Cd (diffusion).
  one_point_b1_inside_b2 = len(((b1>=b2[0])*(b1<=b2[1])).prod(1).nonzero()[0])>0
  one_point_b2_inside_b1 = len(((b2>=b1[0])*(b2<=b1[1])).prod(1).nonzero()[0])>0
  if one_point_b1_inside_b2 or one_point_b2_inside_b1:
    return numpy.vstack((numpy.vstack((b1[0],b2[0])).max(0),numpy.vstack((b1[1],b2[1])).min(0)))
  else:
    return None


fiberDelta = lambda f: numpy.sqrt(((f[1:]-f[:-1])**2).sum(1))

def _constant(x, val = 0):
    """docstring for parabolic_fun"""
    return numpy.zeros(x.shape[:-1],dtype=float) + val


cov_thinPlate3D = _GP.covariance_function_bundle( 'thinplate3d_mat', 'tractographyGP.bounded_thinPlate', {'r':'r'} )
cov_thinPlate2D = _GP.covariance_function_bundle( 'thinplate2d_mat', 'tractographyGP.bounded_thinPlate', {'r':'r'} )

class fiberGP:
  
  _k = 0
  _precomputedVariance = None
  _precomputedMean = None
  _scaleFactor = 1
  _mean = None
  _cov = None
  _alpha = None
  _inv_cov = None

  def __init__(self,fiber,  resolution=.5, rFactor=1,epsilonFactor=1,scaleFactor=1):