# Calculate the cost function in SIFT

**URL:** <https://community.mrtrix.org/t/calculate-the-cost-function-in-sift/92>\
**Category:** Uncategorized\
**Created:** [February 29, 2016, 1:09pm UTC](https://community.mrtrix.org/t/calculate-the-cost-function-in-sift/92 "2016-02-29T13:09:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![liyuan\_yang](https://community.mrtrix.org/user_avatar/community.mrtrix.org/liyuan_yang/32/345_2.png) [@liyuan\_yang](https://community.mrtrix.org/u/liyuan_yang)\
**Post date:** [February 29, 2016, 1:09pm UTC](https://community.mrtrix.org/t/calculate-the-cost-function-in-sift/92/1 "2016-02-29T13:09:53Z")

</div>

Dear MRtrix3 team

I recently read the paper ‘‘SIFT: Spherical-deconvolution informed filtering of tractograms’’.  
I have a question about how to calculate the cost function.According to the equation  
 ![](https://community.mrtrix.org/uploads/default/original/1X/ddde69f4bf666f9d0d98841a6112d2e0a47ec04d.PNG)  
I’m not sure that the _u and TD_ are the values before removing the prospective streamline or after.  
Could I understand that using the lobes not traversed by the removal streamline (the equation 4) represent the all lobes (traversed and not traversed) for calculating the cost function (f) ?  
One more question about how to calculate \_the gradient per unit length for each streamlin\_e ,is it using the gradient of a streamline divide the streamline length ?

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [March 1, 2016, 4:01am UTC](https://community.mrtrix.org/t/calculate-the-cost-function-in-sift/92/2 "2016-03-01T04:01:37Z")

</div>

Hi again,

So that equation (neglecting my math error… 😒) is used to _estimate_ the change in cost function for _all_ lobes, given the change in _u_ only (`src/dwi/tractography/SIFT/sifter.cpp:422`).

For those lobes that _are_ traversed by the streamline, two things happen:

1. The contribution of that lobe to the partial derivative above is _removed_, by calculating the contribution to that term from that lobe alone and inverting it (`sifter.cpp:425,427`)
2. The difference in the cost function for the prospective removal of that streamline (i.e. both before and after) is calculated _precisely_, based on _both_ the change in _u_ _and_ the change in _TD_ (`sifter.cpp:426`). We could write this as (using `f()` to represent the cost function):  
`df = f (TD_without_track, u_without_track) - f (TD_with_track, u_with_track)`

Yes, the gradient per unit length is literally the gradient divided by the streamline length (`sifter.cpp:442`). Though the ‘length’ used for this scaling (which only affects the order of streamline removal) is actually the sum of (`streamline_length_in_voxel * processing_mask_value_in_voxel`); this should remove any biases in streamline removal order due to different streamlines having different processing mask values along their lengths.

Cheers  
Rob

---

<div class="post-metadata">

**Author:** ![liyuan\_yang](https://community.mrtrix.org/user_avatar/community.mrtrix.org/liyuan_yang/32/345_2.png) [@liyuan\_yang](https://community.mrtrix.org/u/liyuan_yang)\
**Post date:** [March 2, 2016, 3:20pm UTC](https://community.mrtrix.org/t/calculate-the-cost-function-in-sift/92/3 "2016-03-02T15:20:35Z")

</div>

Thanks for your reply !  
I’m a little understand the exact thought about calculating the f.  
One more question about\_ the contribution to cost function from each voxel in Fig.4 and Fig.5\_.In my view, I think it represents the percentage of the cost function, the sum of contribution from each voxel is 1.But according to color bar in Fig.4(0.05)and Fig.5(0.5) ![](https://community.mrtrix.org/uploads/default/original/1X/bdeb662646c541d07bab2a527262435d967bbc43.PNG)  
 ![](https://community.mrtrix.org/uploads/default/original/1X/b2a110dd0bdc619713f4fb2f2da85c116520d1c1.PNG)  
it appears wrong…  
So what is the contribution ?

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [March 3, 2016, 12:31am UTC](https://community.mrtrix.org/t/calculate-the-cost-function-in-sift/92/4 "2016-03-03T00:31:28Z")

</div>

There aren’t any percentages involved here. The simplest figure to understand is the top one. In each individual voxel (that is within one of the two bundles), there is a single FOD lobe. For each, we can solve Equation 3, _just for that one lobe_ (i.e. there are no sums across voxels or lobes):  
`f = PM. (u.TD - FOD)^2`  
This is the value that determines the colour within each voxel.  
The total cost function is then the _sum_ of these values _across the entire image_.

For the lower image, the only difference is that there may now be multiple lobes in a single voxel. In this case therefore, for each voxel, the _sum_ of the contributions to _f_ from all lobes within that voxel is calculated, and this is the value that determines the colour of that voxel in the image.

We certainly don’t want the sum of all contributions to equal 1: this would remove the information regarding whether one tractogram configuration is a better fit to the data than another. Remember that the cost function _f_ yields a _single scalar value_ across the entire image volume; these figures are simply demonstrating the spatial regions within the image volume that are contributing the greatest amount toward this value.

---

<div class="post-metadata">

**Author:** ![liyuan\_yang](https://community.mrtrix.org/user_avatar/community.mrtrix.org/liyuan_yang/32/345_2.png) [@liyuan\_yang](https://community.mrtrix.org/u/liyuan_yang)\
**Post date:** [March 6, 2016, 11:00am UTC](https://community.mrtrix.org/t/calculate-the-cost-function-in-sift/92/5 "2016-03-06T11:00:39Z")

</div>

Dear rsmith  
Thank you for your patience to answer my questions！  
I recently read the paper “The effects of SIFT on the reproducibility and biological accuracy of the structural connectome”  
Just one simple question, how do I understand the meaning of _‘up to a global scaling factor’_?  
I’m sorry to bother you so many times:sweat:

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [March 7, 2016, 2:21am UTC](https://community.mrtrix.org/t/calculate-the-cost-function-in-sift/92/6 "2016-03-07T02:21:22Z")

</div>

So there’s a couple of meanings behind using that term (used repeatedly to cover ourselves).

Firstly, we make the argument that the total intra-cellular cross-sectional area between two regions is a reasonable measure for the structural connectivity between them. Ideally we’d have a gamut of measures such as axon count, diameter distributions, myelination etc.; but intra-cellular cross-sectional area is something we can quantify reasonably well.

Ideally we would provide this measure in units of mm^2, ie. an actual physical cross-sectional area. However because the AFD measure itself is only _proportional_ to fibre volume and is not a volume _fraction_, and is affected by T2 differences, we cannot use the physical size of the image voxels to convert this into a physically-dimensioned measure. Therefore we are stuck with something that is _proportional_ to cross-sectional area; there’s a hidden global scaling factor to convert from our measure (streamline count) to an actual cross-sectional area, but we don’t know what it is.

The other ramification of this effect is that although we can compare the relative connection densities of different pathways in the one reconstruction (provided we perform B1 bias field correction), we cannot trivially compare connection densities directly _between subjects_. It’s fairly common practise to just use the same number of streamlines in each subject and then compare like with like, but there are a few hidden assumptions when using this approach that many may not be aware of.

---

<div class="post-metadata">

**Author:** ![liyuan\_yang](https://community.mrtrix.org/user_avatar/community.mrtrix.org/liyuan_yang/32/345_2.png) [@liyuan\_yang](https://community.mrtrix.org/u/liyuan_yang)\
**Post date:** [March 16, 2016, 2:10am UTC](https://community.mrtrix.org/t/calculate-the-cost-function-in-sift/92/7 "2016-03-16T02:10:34Z")

</div>

Dear rsmith  
Thank you very much !  
I recently read the paper '‘SIFT2: Enabling dense quantitative assessment of brain white matter connectivity  
using streamlines tractography’'  
I have a question about why making a combination of whole-brain and targeted seeding. Using SIFT2 ,“_the very dense sampling of the plausible pathways emanating from the structure of interest is retained_” Is there deeply meaning or other purpose?

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [March 16, 2016, 5:04am UTC](https://community.mrtrix.org/t/calculate-the-cost-function-in-sift/92/8 "2016-03-16T05:04:22Z")

</div>

When people perform targeted tracking, it’s often because they want to generate a large number of streamlines for a particular pathway; to make sure that the spatial extent of the pathway is well-defined in the reconstruction, and that the pathway is evident from the bulk streamline behaviour rather than counting individual streamlines. You could equivalently generate a whole-brain tractogram, and then extract those streamlines corresponding to your pathway of interest; but the reconstruction density of that pathway may then be not adequate.

For instance: Say you’re interested in the density of a very small pathway. You generate a whole-brain tractogram, apply SIFT (greatly reducing the number of tracks), then select only those in your pathway of interest (also greatly reducing the number of tracks). If the final number of streamlines in your pathway is too small, then you may be susceptible to erroneous conclusions: either due to the spatial extent and termination points of the pathway being ill-defined (because the remaining streamlines are few and far between), or the streamline count being so small that the random nature of the tracking process makes your results highly variable.

This trick is simply a way of combining the quantitative properties attainable using SIFT/SIFT2, with the high targeted reconstruction density of targeted tracking. If you have a particular pathway of interest, you can reconstruct it with a very high density (to make sure that you are not missing any features of that pathway), and combine that data with a whole-brain tractogram (to obtain the quantitative properties). To get a comparable result using exclusively whole-brain tracking, you would either run the risk of your pathway of interest being too sparsely reconstructed, or have to generate a _massive_ number of whole-brain streamlines to ensure that this doesn’t happen.

---

<div class="post-metadata">

**Author:** ![liyuan\_yang](https://community.mrtrix.org/user_avatar/community.mrtrix.org/liyuan_yang/32/345_2.png) [@liyuan\_yang](https://community.mrtrix.org/u/liyuan_yang)\
**Post date:** [March 28, 2016, 12:02pm UTC](https://community.mrtrix.org/t/calculate-the-cost-function-in-sift/92/9 "2016-03-28T12:02:12Z")

</div>

I’m a little confused about the ‘_dynamic seeding_’.  
_‘Each time an FOD lobe is selected at random for potential seeding……… Once an FOD lobe has been selected for streamline seeding, a random position within that voxel is determined’_  
In my view, firstly, I should select an FOD lobe for potential seeding, but how to select one FOD lobe? Is the FOD in the center of the voxel?  
If an FOD lobe has been chosen, then choosing a random position within that voxel? As for the chosen FOD lobe，it just determines the roughly initial seeding direction?

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [March 30, 2016, 12:31am UTC](https://community.mrtrix.org/t/calculate-the-cost-function-in-sift/92/10 "2016-03-30T00:31:49Z")

</div>

The selection of FOD lobes for seeding is done based on the FOD lobes within your seed mask image. That mask will contain some number of FOD lobes. A lobe is selected entirely at random, and a decision is then made as to whether or not it is appropriate to seed a streamline from that lobe (if it is not, another lobe is selected at random, and the process repeats). So you as a user do not need to select an FOD lobe for seeding: this is done intrinsically by the dynamic seeding algorithm.

The position within the voxel from which to propagate the streamline is also determined automatically by the seeding algorithm. It’s preferable to not seed all streamlines from the very centre of a voxel, as this would introduce a bias into the coverage of streamlines emanating from that voxel.

The FOD lobe used to determine the streamline seed position will also provide a fibre direction. However, the tracking algorithm must then initialize correctly based on this seed direction: precisely what occurs here will depend on whether a probabilistic or deterministic tracking algorithm is used.
