Model

from mcot.dippi.model import Model
class mcot.dippi.model.Model(scanner, T2=False, dual_phase=False, only_phase=False, with_intercept=False, susc_by_motion=True)[source]

Model to fit to the DIPPI data

__init__(scanner, T2=False, dual_phase=False, only_phase=False, with_intercept=False, susc_by_motion=True)[source]

Creates a new DIPPI model

Parameters
  • T2 – if True fit R2 and R2* instead of fitting each amplitude independently

  • dual_phase – if True fit unmyelinated and myelinated axons as separate compartments

  • only_phase – Ignore the biophysical model and just fit the phase difference between readouts for every dyad

  • with_intercept – Adds a phase offset at t_phase=0 to the DIPPI model

  • susc_by_motion – Adds susceptibility gradient as a function of head orientation as confound

Inheritance diagram

digraph inheritanceb59b405e28 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "mcot.dippi.model.Model" [URL="#mcot.dippi.model.Model",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Model to fit to the DIPPI data"]; }

Methods

cost(parameters, data[, only_mag])

Squared offset between the model signal and observed data

derivative(name[, only_mag])

Computes the derivative with respect to a given parameter

func_args(parameters[, to_vary])

Fills in the arguments for the numpy functions from self.:meth:funcs

get_cost(parameters, data, tofit[, only_mag])

Returns a set of functions that allows for efficient evalution of the model during model optimisation

get_equations([only_mag])

get_func([derivatives, only_mag])

Return the model equations as numpy functions

signal(parameters[, only_mag, split_fibres])

Computes the signal given a set of parameters

cost

Model.cost(parameters: mcot.dippi.model.Parameters, data, only_mag=False)[source]

Squared offset between the model signal and observed data

Parameters
  • parameters – set of model parameters

  • data – input data (list with for each shell the complex signal during first and second readout)

  • only_mag – if True only consider the magnitude rather than the complex signal

Returns

total cost across all shells and readouts

derivative

Model.derivative(name, only_mag=True)[source]

Computes the derivative with respect to a given parameter

This function uses cacheing

Parameters

name – name of one of the parameters

Returns

sympy equations with derivative as a list with the equation for each shell and both readouts

func_args

Model.func_args(parameters: mcot.dippi.model.Parameters, to_vary=())[source]

Fills in the arguments for the numpy functions from self.:meth:funcs

Parameters
  • parameters – current best estimate of the parameters

  • to_vary – names of the parameters that should not be filled in yet (None placeholder)

Returns

nested lists with model parameters (they are the same for the first and second readout)

  1. outer list loops over shells

  2. middle list loops over fibre orientations (length of 2)

  3. inner list loops over individual parameters in the order of self.parameter_names

get_cost

Model.get_cost(parameters: mcot.dippi.model.Parameters, data, tofit, only_mag=False)[source]

Returns a set of functions that allows for efficient evalution of the model during model optimisation

Used internally by singla_fit() and model_fit.

Parameters
  • parameters – initial set of parameters

  • data – input data (list with for each shell the complex signal during first and second readout)

  • tofit – sequence with parameter names to fit

  • only_mag – if True only fit the mangitude rather than the complex signal

Returns

A tuple with:

  • function that given an array with current parameter values returns the cost and its derivatives

  • function that turns array of best-fit parameter values back into a Parameter object

  • array with initial parameter values

get_equations

Model.get_equations(only_mag=False)[source]

get_func

Model.get_func(derivatives=(), only_mag=False)[source]

Return the model equations as numpy functions

Parameters
  • derivatives – list of the derivatives of interest

  • only_mag – if True only compute the magnitude rather than the complex signal

Returns

for each shell return a tuple with functions for the first and second readout signal (or its derivatives)

signal

Model.signal(parameters: mcot.dippi.model.Parameters, only_mag=False, split_fibres=False)[source]

Computes the signal given a set of parameters

Parameters
  • parameters – set of model parameters

  • only_mag – if True return the magnitude rather than the complex signal

  • split_fibres – if True return the signal for each fibre population individually

Returns

a list with for each shell the signal during the first and second readout