def _pred_sig(self, theta, phi, beta, lambda1, lambda2):
        """
        The predicted signal for a particular setting of the parameters
        """

        Q = np.array([[lambda1, 0, 0],
                      [0, lambda2, 0],
                      [0, 0, lambda2]])

        # If for some reason this is not symmetrical, then something is wrong
        # (in all likelihood, this means that the optimization process is
        # trying out some crazy value, such as nan). In that case, abort and
        # return a nan:
        if not np.allclose(Q.T, Q):
            return np.nan
        
        response_function = ozt.Tensor(Q,
                                        self.bvecs[:,self.b_idx],
                                        self.bvals[:,self.b_idx])
                                        
        # Convert theta and phi to cartesian coordinates:
        x,y,z = geo.sphere2cart(1, theta, phi)
        bvec = [x,y,z]
        evals, evecs = response_function.decompose

        rot_tensor = ozt.tensor_from_eigs(
            evecs * ozu.calculate_rotation(bvec, evecs[0]),
            evals, self.bvecs[:,self.b_idx], self.bvals[:,self.b_idx])

        iso_sig = np.exp(-self.bvals[self.b_idx][0] * lambda1)
        tensor_sig =  rot_tensor.predicted_signal(1)

        return beta * iso_sig + (1-beta) * tensor_sig
Esempio n. 2
0
    def _pred_sig(self, theta, phi, beta, lambda1, lambda2):
        """
        The predicted signal for a particular setting of the parameters
        """

        Q = np.array([[lambda1, 0, 0], [0, lambda2, 0], [0, 0, lambda2]])

        # If for some reason this is not symmetrical, then something is wrong
        # (in all likelihood, this means that the optimization process is
        # trying out some crazy value, such as nan). In that case, abort and
        # return a nan:
        if not np.allclose(Q.T, Q):
            return np.nan

        response_function = ozt.Tensor(Q, self.bvecs[:, self.b_idx],
                                       self.bvals[:, self.b_idx])

        # Convert theta and phi to cartesian coordinates:
        x, y, z = geo.sphere2cart(1, theta, phi)
        bvec = [x, y, z]
        evals, evecs = response_function.decompose

        rot_tensor = ozt.tensor_from_eigs(
            evecs * ozu.calculate_rotation(bvec, evecs[0]), evals,
            self.bvecs[:, self.b_idx], self.bvals[:, self.b_idx])

        iso_sig = np.exp(-self.bvals[self.b_idx][0] * lambda1)
        tensor_sig = rot_tensor.predicted_signal(1)

        return beta * iso_sig + (1 - beta) * tensor_sig
Esempio n. 3
0
def test_Tensor_decompose():
    """
    Test the eigen-vector/value decomposition of the tensor:
    """
    q = np.array([
        [1.5, 0, 0],
        [0, 0.5, 0],  # This needs to be slightly higher, so that
        # there is no ambiguity about the order of the
        # evals
        [0, 0, 0.5]
    ])

    # And the bvecs are unit vectors:
    bvecs = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    bvals = [1, 1, 1]

    T1 = mtt.Tensor(q, bvecs, bvals)
    vals, vecs = T1.decompose

    npt.assert_equal(vecs, np.eye(3))
    npt.assert_equal(vals, np.diag(q))

    T2 = mtt.tensor_from_eigs(vecs, vals, bvecs, bvals)

    npt.assert_equal(T2.Q, q)
Esempio n. 4
0
 def _tensor_helper(self, theta, phi):
     """
         This code is used in all three error functions, so we write it out
         only once here
         """
     # Convert to cartesian coordinates:
     x, y, z = geo.sphere2cart(1, theta, phi)
     bvec = [x, y, z]
     # decompose is an auto-attr of the tensor object, so is only run once
     # and then cached:
     evals, evecs = self.response_function.decompose
     rot = ozu.calculate_rotation(bvec, evecs[0])
     rot_evecs = evecs * rot
     rot_tensor = ozt.tensor_from_eigs(rot_evecs, evals,
                                       self.bvecs[:, self.b_idx],
                                       self.bvals[self.b_idx])
     return rot_tensor
Esempio n. 5
0
 def _tensor_helper(self, theta, phi):
         """
         This code is used in all three error functions, so we write it out
         only once here
         """
         # Convert to cartesian coordinates:
         x,y,z = geo.sphere2cart(1, theta, phi)
         bvec = [x,y,z]
         # decompose is an auto-attr of the tensor object, so is only run once
         # and then cached:
         evals, evecs = self.response_function.decompose
         rot = ozu.calculate_rotation(bvec, evecs[0])
         rot_evecs = evecs * rot
         rot_tensor = ozt.tensor_from_eigs(rot_evecs,
                                           evals,
                                           self.bvecs[:,self.b_idx],
                                           self.bvals[:,self.b_idx])
         return rot_tensor
Esempio n. 6
0
def test_Tensor_decompose():
    """
    Test the eigen-vector/value decomposition of the tensor:
    """
    q = np.array([[1.5,0,0], 
                  [0,0.5,0],  # This needs to be slightly higher, so that
                               # there is no ambiguity about the order of the
                               # evals 
                  [0,0,0.5]])

    # And the bvecs are unit vectors: 
    bvecs = np.array([[1,0,0],[0,1,0],[0,0,1]])
    bvals = [1,1,1]

    T1 = mtt.Tensor(q, bvecs, bvals)
    vals, vecs = T1.decompose

    npt.assert_equal(vecs , np.eye(3))
    npt.assert_equal(vals, np.diag(q))

    T2 = mtt.tensor_from_eigs(vecs, vals, bvecs, bvals)

    npt.assert_equal(T2.Q,q)