# Where orientation information is present in dipole fitting function

**URL:** <https://mne.discourse.group/t/where-orientation-information-is-present-in-dipole-fitting-function/5437>\
**Category:** Support & Discussions\
**Created:** [August 20, 2022, 9:33pm UTC](https://mne.discourse.group/t/where-orientation-information-is-present-in-dipole-fitting-function/5437 "2022-08-20T21:33:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rekha](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/rekha/32/1372_2.png) [@Rekha](https://mne.discourse.group/u/Rekha)\
**Post date:** [August 20, 2022, 9:33pm UTC](https://mne.discourse.group/t/where-orientation-information-is-present-in-dipole-fitting-function/5437/1 "2022-08-20T21:33:53Z")

</div>

I looked at the MNE dipole fitting function but couldn’t find the information where the orientation of dipole is changed iteratively. Can someone tell me in what line of the code the orientation of the dipole is changed with each iteration?

And also what exactly is a lead field matrix? Does it contain the Voltage/ fT signals information picked up by each sensor for all possible orientations of the sources in the source grid or does it contain information for only a unit source at a particularly defined orientation at given location in source?

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [August 21, 2022, 10:18am UTC](https://mne.discourse.group/t/where-orientation-information-is-present-in-dipole-fitting-function/5437/2 "2022-08-21T10:18:32Z")

</div>

> [@Rekha](#):
>
> Can someone tell me in what line of the code the orientation of the dipole is changed with each iteration?

I think it happens here:

> <https://github.com/mne-tools/mne-python/blob/56543eda8f8739cc9e36de0b6eb95f93d756a39b/mne/dipole.py#L832-L842>

This is what @agramfort described as well:

> [@For developer team: How is dipole fitting exactly performed?](https://mne.discourse.group/t/for-developer-team-how-is-dipole-fitting-exactly-performed/5433/2):
>
> hi, MNE optimizes the mean squared error between data and dipole model taking into account the noise covariance. You can see this as L2 norm on the whitened data (see eg Engemann et al. 2015 [https://www.semanticscholar.org/paper/Automated-model-selection-in-covariance-estimation-Engemann-Gramfort/34b659eeb98727fc37b7e60c0d652fcb20ccb870](https://www.semanticscholar.org/paper/Automated-model-selection-in-covariance-estimation-Engemann-Gramfort/34b659eeb98727fc37b7e60c0d652fcb20ccb870)) first it tries to find a good initial position of the dipole by only considering a discrete regular grid. Then it iterates and aims to refine the location o…

> [@Rekha](#):
>
> And also what exactly is a lead field matrix?

It’s the [forward model](https://mne.tools/stable/glossary.html#term-forward-solution), i.e. a matrix that defines how activity from each grid point in the source space will be represented at the sensor level. The matrix will have `n_channels` rows and `n_sources` columns, describing how source activity is linearly combined into sensor (channel) data.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [March 17, 2025, 3:54pm UTC](https://mne.discourse.group/t/where-orientation-information-is-present-in-dipole-fitting-function/5437/3 "2025-03-17T15:54:12Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
