Ejemplo n.º 1
0
    def makeInputsAndOutputs(self, voxelsInEachDim, uniquebVals, numbVecs):
        bVals, bVecs = generatebValsAndbVecs(uniquebVals, numbVecs)

        gtab = gradient_table(bVals,
                              bVecs,
                              big_delta=self.bigDelta,
                              small_delta=self.smallDelta)

        inputs = generateSyntheticInputs(
            voxelsInEachDim,
            gtab,
            qMagnitudeTransform=self.qMagnitudeTransform)

        outputs = generateSyntheticOutputsFromMultiTensorModel(
            voxelsInEachDim, gtab, self.tensorEigenvalues, snr=None)
        return inputs, outputs
Ejemplo n.º 2
0
    def test_generateSyntheticInputs(self, mock_generateCoordinates):
        qMagnitudes = np.array([0, 5])
        bvecs = np.array([[0, 0, 0], [0, 0, 1]])
        mock_gtab = mock.MagicMock(qvals=qMagnitudes, bvecs=bvecs)
        (nx, ny, nz) = (1, 1, 2)
        expectedCoordinates = np.array([[0, 0, 0], [0, 0, 1]])
        expectedResult = np.vstack(
            (np.r_[expectedCoordinates[0, :], qMagnitudes[0],
                   bvecs[0, :]], np.r_[expectedCoordinates[0, :],
                                       qMagnitudes[1], bvecs[1, :]],
             np.r_[expectedCoordinates[1, :], qMagnitudes[0],
                   bvecs[0, :]], np.r_[expectedCoordinates[1, :],
                                       qMagnitudes[1], bvecs[1, :]]))

        mock_generateCoordinates.return_value = expectedCoordinates
        syntheticInputs = generateSyntheticInputs((nx, ny, nz), mock_gtab)
        npt.assert_array_equal(syntheticInputs, expectedResult)
Ejemplo n.º 3
0
 def generateSpatiallyCorrelatedData(self,
                                     n=100,
                                     lengthScale=1.,
                                     scaling=1.,
                                     noiseVariance=0.01):
     voxelsInEachDim = (n, 1, 1)
     bVals = np.array([0])
     bVecs = np.array([[1, 0, 0]])
     gtab = gradient_table(bVals,
                           bVecs,
                           big_delta=self.bigDelta,
                           small_delta=self.smallDelta)
     inputs = generateSyntheticInputs(voxelsInEachDim, gtab)
     xCoordinate = inputs[:, 0]
     distances = np.abs(xCoordinate[:, np.newaxis] -
                        xCoordinate[np.newaxis, :])
     spatialCovariance = (np.exp(-scaling * (distances / lengthScale)**2) +
                          noiseVariance * np.eye(n))
     outputs = scaling * np.random.multivariate_normal(
         np.zeros(n, ), spatialCovariance)
     outputs = outputs[:, np.newaxis]
     return inputs, outputs
Ejemplo n.º 4
0
    def test_dataGeneration(self):
        voxelsInEachDim = (2, 3, 4)
        bvals = np.concatenate([[0], 1500 * np.ones(6), 3000 * np.ones(6)])
        sq2 = np.sqrt(2) / 2
        setOfbvecs = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1], [sq2, sq2, 0],
                               [sq2, 0, sq2], [0, sq2, sq2]])
        bvecs = np.vstack([np.array([[0, 0, 0]]), setOfbvecs, setOfbvecs])
        gtab = gradient_table(bvals,
                              bvecs,
                              big_delta=self.bigDelta,
                              small_delta=self.smallDelta)

        inputs = generateSyntheticInputs(voxelsInEachDim, gtab)
        outputsLatent = generateSyntheticOutputsFromMultiTensorModel(
            voxelsInEachDim, gtab, self.tensorEigenvalues, snr=None)
        self.assertTrue(
            np.min(outputsLatent) >= 0 and np.max(outputsLatent) <= 1)

        totalNumberOfSamples = np.prod(voxelsInEachDim) * len(bvals)
        npt.assert_array_equal(inputs.shape, (totalNumberOfSamples, 7),
                               'Input shapes don\'t match')
        npt.assert_array_equal(outputsLatent.shape, (totalNumberOfSamples, 1),
                               'Output shapes don\'t match')