sha256
stringlengths
64
64
language
stringclasses
28 values
size
int32
1
491k
lines
int32
1
23.2k
content
stringlengths
1
200k
b5ec4338c4778c7766bbe1ddb28a0c59e4b53698af9dcac96b9ab2973dbf6de1
Julia
3,255
76
using DelayDiffEq using DifferentialEquations using BenchmarkTools using MRIgeneralizedBloch using MRIgeneralizedBloch: apply_hamiltonian_gbloch!, hamiltonian_linear using Test ## set variables α = (.01:.01:1) * π TRF = 500e-6 # s ω1 = α ./ TRF # rad/s m0s = 0.1 m0f = 1-m0s R1f = 0.3 # 1/s R1s = 2.0 # 1/s R2f = 1 / 50...
fa18922acb29e750d1e5c5a21088f7f7cbda64d70872a883ee762ca209922971
Julia
3,316
123
using ArgParse,Distributions,Random,CSV,RCall,DrWatson using LinearAlgebra,BayesianNetworkRegression,DataFrames include("sim_utils.jl") function parse_CL_args() args = ArgParseSettings() @add_arg_table! args begin "--seed", "-s" help = "random seed to use for simulations" arg_type = Int ...
d0b4d97722ffc502343be7338347879179b0d37142685bd0cf1b5eee7677cdc1
Julia
3,483
90
using DelayDiffEq using DifferentialEquations using Test using FiniteDifferences using MRIgeneralizedBloch using MRIgeneralizedBloch: apply_hamiltonian_gbloch_superlorentzian! ## set parameters ω1 = π / 500e-6 ω0 = 200.0 B1 = 1 m0s = 0.15 R1f = 0.3 R1s = 2 R2f = 1 / 65e-3 T2s = 10e-6 Rex = 30 TRF = 500e-6 M0 = 0....
b6c02fe01000a9a983f6b165011999db53370bebea06796636d1facda99e9378
Julia
3,487
112
## using MRIgeneralizedBloch using DifferentialEquations using StaticArrays using Test R2slT = precompute_R2sl() ## choose random parameters Npulse = 500 α = abs.(π/2 * sin.(π/2 * ((0:Npulse-1) / Npulse) .+ π/2)) TRF = 300e-6 .+ 200e-6 * cos.(π * (1:Npulse) / Npulse) α[1] = π TRF[1] = 500e-6 ω1 = α ./ TRF isInversionP...
da9930c9b3016489dc47836c891d7ade16cbbe2743f9dd569723487e4622772b
Julia
3,618
92
using MRIgeneralizedBloch using Test using FiniteDifferences using DelayDiffEq using DifferentialEquations using SpecialFunctions using QuadGK ## set parameters TRF = 500e-6 α = π NSideLobes = 1 f_ω1 = (t) -> sinc(2(NSideLobes+1) * t/TRF - (NSideLobes+1)) * α / (sinint((NSideLobes+1)π) * TRF/π / (NSideLobes+1)) @test...
5e535a6b0bb335dea09cd3aa233017e421a371d8e0d42ec6888e71fb5d4743cc
Julia
3,827
95
using DelayDiffEq using DifferentialEquations using SpecialFunctions using QuadGK using FiniteDifferences using Test using MRIgeneralizedBloch ## set parameters TRF = 10.24e-3 γ = 267.522e6 # rad/s/T ω₁ᵐᵃˣ = 13e-6 * γ # rad/s μ = 5 # rad β = 674.1 # 1/s f_ω1 = (t) -> ω₁ᵐᵃˣ .* sech.(β * (t - TRF/2)) # rad/s f_ω0 = (t)...
e59bb0cf7676294ea8d2f3461afb6e0f18d5ffd54cce77a597a17fef8b06047c
Julia
3,882
157
""" greens_lorentzian(κ) Evaluate the Green's function corresponding to a Lorentzian lineshape at `κ = (t-τ)/T2s`. # Examples ```jldoctest julia> t = 100e-6; julia> τ = 0; julia> T2s = 10e-6; julia> greens_lorentzian((t-τ)/T2s) 4.5399929762484854e-5 ``` """ greens_lorentzian(κ) = exp(-κ) lineshape_lorentzian(...
c4446829e6f3fe9603b1c3be4d0abccf34f382aa8e8262fd71e3107c9dc434a7
Julia
3,887
158
""" greens_lorentzian(κ) Evaluate the Green's function corresponding to a Lorentzian lineshape at `κ = (t-τ)/T2s`. # Examples ```jldoctest julia> t = 100e-6; julia> τ = 0; julia> T2s = 10e-6; julia> greens_lorentzian((t-τ)/T2s) 4.5399929762484854e-5 ``` """ greens_lorentzian(κ) = exp(-κ) lineshape_lorentzian(...
5910495880c071d20ce2ad023fa0e3452053b7a53ed35eb9af552aa14a0f0b7d
Julia
3,892
133
# fit the em model in this model dict to data, using experiment parmas # if parallel, make sure you already loaded toolbox and cores, etc. function fit_model_em(this_model,data, to_save_folder; full = false, parallel = false, emtol = 1e-3, maxiter = 100, run_loo = false, save_res = true, return_res = false) #...
161d7feae21bfdc5774ac4d76e03399c2e008c34e3a37e7eed2f69bc04a60479
Julia
3,924
70
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
a585f74a0cc2646aca169e5a7881312dae00f0e73e8ef76331aa7151cb63e97d
Julia
3,972
93
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
2e995c9472fd3b86bde253f8d02c5116d0d6d578274ccc164180258e355312ce
Julia
4,041
93
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
fa02bd0f8720012e8bc2f1b71b92e063cc10cc3bf52efa31ed0cd52b1fa3138d
Julia
4,342
152
""" create_lower_tri(vec,V) Create a lower triangluar matrix from a vector of the form [12, ... 1V,23,...(V-1)V] in the form [11 0............] [12 22 0.........] [13 23 33 0.......] [.................] [1V .....(V-1)V VV] # Arguments - `vector`: vector containing ...
2fbc9060caac80c657b66d4f428fa8f8b89c45df28f6e1c00dbf4a012612b58c
Julia
4,348
147
# julia EM model fitting, Nathaniel Daw 8/2019 ###### setup parallel = false # Run on multiple CPUs. If you are having trouble, set parallel = false: easier to debug full = false # Maintain full covariance matrix (vs a diagional one) a the group level emtol = 1e-3 # stopping condition (relative change) for EM ...
fddc1dfc1cea9a875597ee82bb6c5d04b1fab1de27bc313a4971cf314f7b9436
Julia
4,394
90
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
0428f7a73f056fd59b1c5a3eb9fa69f50e5fe0feb166b0615f17e71213761b2c
Julia
4,427
138
## using MRIgeneralizedBloch using DelayDiffEq using DifferentialEquations using SpecialFunctions using QuadGK using Test ## Pulse parameters α = 0.8π TRF = 100e-6 # define other parameters B1 = 0.87 m0s = 0.2 m0f = 1 - m0s R1f = 0.5 R1s = 3 R2f = 13 T2s = 12e-6 R2s = 1 / T2s Rex = 17 # random initial m0 ms = 0.5m0s...
4b87b61b156d217aca4dd9b25f06e42941eeddeb7f1afe8ed2c41189cb60c807
Julia
4,431
120
## using MRIgeneralizedBloch using DifferentialEquations using StaticArrays using Test using FiniteDifferences R2slT = precompute_R2sl() ## choose random parameters Npulse = 500 α = abs.(π/2 * sin.(π/2 * ((0:Npulse-1) / Npulse) .+ π/2)) TRF = 300e-6 .+ 200e-6 * cos.(π * (1:Npulse) / Npulse) α[1] = π TRF[1] = 500e-6 ω1...
53bb3c6891e57a607aa8c2f14791f64a42a5922f0138a5f5b78e7d773c4afe54
Julia
4,598
125
## Initial tests for BayesianNetworkRegression.jl on toy data ## global seed rng = Xoshiro(1234) X = [[0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0], [0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0], [0, 0, 1,...
41111215d41172326f4c7a88ab182d4c00a7ade3b6f74e3077c372bb0ad6c687
Julia
4,624
139
## using MRIgeneralizedBloch using DifferentialEquations using SpecialFunctions using QuadGK using Test ## Pulse parameters α = 0.8π TRF = 100e-6 # define other parameters B1 = 0.87 m0s = 0.2 m0f = 1 - m0s R1f = 0.5 R1s = 3 R2f = 13 T2s = 12e-6 R2s = 1 / T2s Rx = 17 # random initial m0 ms = m0s * rand() mf = (1 - m0...
ce5c8dcebb32e568f8b14f2e0164746d772f6ab9acdddf4a6b7c857d48ab3897
Julia
4,800
99
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
b91555f8f383c0123c686f15441c60d4a02e2dbb6f050300cb6ecbba153a9480
Julia
5,000
164
using DifferentialEquations using Test using MRIgeneralizedBloch using MRIgeneralizedBloch: hamiltonian_linear, propagator_linear_inversion_pulse ## max_error = 1e-5 ## set parameters α = π ω1 = α / 500e-6 ω0 = 200.0 B1 = 1.0 m0s = 0.15 R1f = 0.3 R2f = 1 / 65e-3 R1s = 2 T2s = 10e-6 Rx = 30.0 TRF = 500e-6 N = Inf #...
6c0745876e3acaa32ad1c11998327c764bd161075e42737a29d35fd660d89a73
Julia
5,029
222
# julia EM model fitting, Nathaniel Daw 8/2019 # example likelihood functions function qlik(params,data) # basic rescorla wagner learning beta = params[1] lr = 0.5 + 0.5 * erf(params[2] / sqrt(2)) # It is important that we specify the type of Q below, as corresponding to the type # of the input parameters # Thi...
bb6a6a71fbd0a5eae0cd31c93118e3c3dd8056755cc6af68b5208e6c8c74d2c8
Julia
5,051
114
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
55d95ae2f781cfa2da52a4aa427515a36725d120382703339828bd51dd005cce
Julia
5,068
114
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
8c7387f59237c31af32d62be0608e3b3b31d946a4f18384e36db555a44cb2e2b
Julia
5,106
176
########################################################################### ## THIS IMPLEMENTATION OF SAMPLING FROM THE GeneralizedInverseGaussian ## ## DISTRIBUTION IS TRANSLATED INTO JULIA DIRECTLY FROM ## ## Josef Leydold and Wolfgang Hormann's GIGrvg PACKAGE FOR R ## ################...
0b0e58a9defb47c35b6c8034b8fcf41c8a7759132a0889636ba9099d0f752ba1
Julia
5,135
114
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
00aa79b582e5b78629c9c004d387596ad32bf62addbc762145bee3348a3864bf
Julia
5,150
151
using MRIgeneralizedBloch using Test using LinearAlgebra using StaticArrays using FiniteDifferences R2slT = precompute_R2sl() function calc_CRB(ω1, TRF, w, grad_moment) _, gradients = simulate_linearapprox(ω1 .* TRF, TRF, TR, ω0, B1, 1, m0s, R1f, R2f, Rex, R1s, T2s, R2slT; grad_list, grad_moment) F = real.(gra...
c8d47e01f660d16c19fd0c78da9861de4e927ad7e472b2636c6d465822afb2b1
Julia
5,237
134
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/NLLS.ipynb) # # Non-Linear Least Square Fitting # This section gives a brief overview of the interface to fit the generalized Bloch model to [hybrid-state free precession](https://www.nature.com/articles/s42005-019-0174-0) data. We us...
35064c05bb687064ebe4c447fc7904e0e996c6bc459e545c9f019e829ccbd1a0
Julia
5,390
135
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/NLLS.ipynb) # # Non-Linear Least Square Fitting # This section gives a brief overview of the interface to fit the generalized Bloch model to [hybrid-state free precession](https://www.nature.com/articles/s42005-019-0174-0) data. We us...
6dcdbef76947bd32326465bf9ec87d7de3a016c5524673415ede9ac26966d5c8
Julia
5,435
206
using DataFrames,CSV unreal_psrf = DataFrame() real_psrf = DataFrame() normed_psrf = DataFrame() for flnm in readdir("results/simulation/local/unrealistic-results") if !occursin("psrf",flnm) continue end mu = flnm[last(findfirst("mu=",flnm))+1:last(findfirst("mu=",flnm))+3] pi_ = flnm[last(fin...
991a7da0f31a36b6d409a6c82b1aa65aad522d8f1d1d44b15c6884c7c6b972b3
Julia
5,672
155
using DifferentialEquations using Test using MRIgeneralizedBloch using MRIgeneralizedBloch: hamiltonian_linear, propagator_linear_crushed_pulse using FiniteDifferences ## max_error = 1e-5 ## set parameters α = π ω1 = α / 500e-6 ω0 = 200.0 B1 = 1.0 M0 = 0.85 m0s = 0.15 R1f = 0.3 R2f = 1 / 65e-3 R1s = 2. T2s = 10e-6 R...
440bc216752ee0d63f8db0694378eb74211f6322b83cf109bb99de0f472a0850
Julia
5,673
136
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
b2e7b427bc45247d12bfbebc4b4ae235c85684a32cd8759a493fa8d2e74b1e2e
Julia
5,733
145
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
5f8c7f4fdc5d255f86b363c60ce7564fcd63be79ab136936fdf3c4176f309d32
Julia
5,840
141
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
163aac555536bfc5475207e4f6395faebb41ac3c4471fc3cf4085cdde6f7a0ec
Julia
6,070
130
function d_hamiltonian_linear_dω1(B1, T, dR2sdω1) H = @SMatrix [ 0 0 B1 0 0 0; 0 0 0 0 0 0; -B1 0 0 0 0 0; 0 0 0 -dR2sdω1 B1 0; 0 0 0 -B1 0 0; 0 0 0 0 0 0] return H * T end functio...
596d8f05f09c0d86db910492e575a672a2b2848c424e330629c5531e280b9b5a
Julia
6,369
122
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
bfd2e1b2accecd1a0e24e3111c8e833aec701863cca0c27c032b5898335f05f7
Julia
6,418
109
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/tutorial_pulsetrain.ipynb) # # Balanced Hybrid-State Free Precession Pulse Sequence # This section explains the interface for calculating the spin evolution during a train of RF pulses, assuming balanced gradient moments (cf. [Hybrid-...
2c586b0d4d4626407f2047ed913bd08979a6e7d2fbaabe8578cd8d3d68b27323
Julia
6,422
181
## using MRIgeneralizedBloch using DifferentialEquations using SpecialFunctions using QuadGK using LinearAlgebra using Test ## Pulse parameters α = 5π TRF = 10.24e-3 # define other parameters B1 = 0.87 m0s = 0.2 m0f = 1 - m0s R1f = 0.5 R1s = 3 R2f = 13 T2s = 12e-6 R2s = 1 / T2s Rx = 17 # random initial m0 ms = m0s *...
3f9e02920c83b07a2be45cbb167e3955d4579a7479a626b77ea8faf1e1fa222c
Julia
6,605
238
### This file generates the "true" results used in init-tests.jl, toy-generate-samples-test.jl, and test1-generate-samples-test.jl import InteractiveUtils: versioninfo using BayesianNetworkRegression,Test,LinearAlgebra,Distributions using CSV,DataFrames,StaticArrays,TypedTables,Random,Distributed,JLD2 ## Initial tes...
2e87221a8ebe062a20ed9babd8977f77f7bc6e90e2263ecbf16a66516ce7f84c
Julia
6,606
109
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/tutorial_pulsetrain.ipynb) # # Balanced Hybrid-State Free Precession Pulse Sequence # This section explains the interface for calculating the spin evolution during a train of RF pulses, assuming balanced gradient moments (cf. [Hybrid-...
123459aedaa7c3b6940c07c1f87ca8384a7996fcdf3cad49c84bd45e6f0011ea
Julia
6,671
147
""" precompute_R2sl([;TRF_min=100e-6, TRF_max=500e-6, T2s_min=5e-6, T2s_max=21e-6, ω1_max=π/TRF_max, B1_max=1.5, greens=greens_superlorentzian]) Pre-compute and interpolate the linearized `R2sl(TRF, α, B1, T2s)` and its derivatives `dR2sldB1(TRF, α, B1, T2s)`, `R2sldT2s(TRF, α, B1, T2s)` etc. in the range specifie...
411ede89241df7ffbf06cb3841ea308bb79df5ab0bcf858db8ceddb8dad920d4
Julia
6,673
182
## using MRIgeneralizedBloch using DelayDiffEq using DifferentialEquations using SpecialFunctions using QuadGK using LinearAlgebra using Test ## Pulse parameters α = 5π TRF = 10.24e-3 # define other parameters B1 = 0.87 m0s = 0.2 m0f = 1 - m0s R1f = 0.5 R1s = 3 R2f = 13 T2s = 12e-6 R2s = 1 / T2s Rex = 17 # random in...
cfdc7dbe087e043f04d5a21fd829c2cfe047ff876d2bfbd13bf73efb3490ac62
Julia
6,678
222
using CSV using DataFrames using DataFramesMeta using CategoricalArrays using Gadfly using Statistics using Distributions using SpecialFunctions using StatsFuns using Optim using ForwardDiff using Cairo using Fontconfig cd("/Users/evanrussek/foraging/") # basic real data clearning, etc, functions... include("/Users/e...
e3da435c19d7b5f3b50889869335957ee0bb5c4213d0d4cbaed1e71a9ff3e1ba
Julia
6,840
147
""" R2slInterpolants Struct holding interpolated R2sl and its partial derivatives. Returned by [`precompute_R2sl`](@ref). All fields are callable as `f(TRF, α, B1, T2s)`. # Fields - `R2sl`: R2sl(TRF, α, B1, T2s) - `dR2sl_dT2s`: ∂R2sl/∂T2s - `dR2sl_dB1`: ∂R2sl/∂B1 - `dR2sl_dω1`: ∂R2sl/∂ω1 - `dR...
2d34ba7ad844332eb36d383aff65d570a69e0a7ace3a7fcdc85537536c3234ef
Julia
6,993
172
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
801c96eda0cfb9fd0e947fb6bda2664c7ca6d7769b88ff4250c869583cd5f0f8
Julia
7,034
143
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/Analyze_NMR_PreSat_Data.ipynb) # # Continuous Wave Saturation Experiments # The following code analyzes data from a steady-state experiment similar to the original work of [Henkelman et al](https://doi.org/10.1002/mrm.1910290607). In ...
b9e660e7e7bbc72878ac7c9417e3312afa9582164df18c3a1cb7d11d8007e18a
Julia
7,041
143
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/Analyze_NMR_PreSat_Data.ipynb) # # Continuous Wave Saturation Experiments # The following code analyzes data from a steady-state experiment similar to the original work of [Henkelman et al](https://doi.org/10.1002/mrm.1910290607). In ...
f26c59a66c056264ffa61f4ccd3c2408178472b6317f1bf7243a159e33ae83c1
Julia
7,045
174
include("ImpedanceAnalyzer_Functions.jl") function MagPhaseBoxDotImpedanceStats_AgainstKnown(ZMagVec::Vector,ZPhaseVec::Vector,KnownImpedance::Complex,newPlot,labelVal,CVal) plt = []; ZMagNormalized = ZMagVec ./ abs(KnownImpedance) KnownRealVec = repeat([real(KnownImpedance)], Int(length(ZMagVec))) ...
763adb7618af5fd0b28431cf6f841ed757d60f9a79bee2828660e8fd0166a195
Julia
7,086
117
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
a9b1833dea59cfd1aa3f3ba49ef2cb2b56c82ed2d34f8af501153033abcae554
Julia
7,280
181
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
e99b3f3576ac93f5e829f235a49686968342b2b89377cb2eebb566c3161ff9c4
Julia
7,505
243
using Base: String, Int64, simd_outer_range using ArgParse,Distributions,Random,CSV,RCall,DrWatson using LinearAlgebra,BayesianNetworkRegression,DataFrames,PhyloNetworks include("sim_utils.jl") function parse_CL_args() args = ArgParseSettings() @add_arg_table! args begin "--seed", "-s" help = "rand...
b2b2a46499e3241a36f909bb6c411176d234a64115f97408cfcd7a37105850a3
Julia
7,667
209
# Old tests; need to include them as files into runtests.jl; one by one. import InteractiveUtils: versioninfo using BayesianNetworkRegression,Test,LinearAlgebra,Distributions using CSV,DataFrames,StaticArrays,TypedTables,Random,Distributed seed = 2358 η = 1.01 ζ = 1.0 ι = 1.0 R = 7 aΔ = 1.0 bΔ = 1.0 ν = 10 @test...
188a7c2166932147555c3e0a503c324d16c2cd0aa809e6bc68142c6b97188864
Julia
8,028
135
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
4dcf1a006aeddfc0d1f1dad52e70aba84bba566f579b18798799650a2063acf0
Julia
8,228
292
using DrWatson @quickactivate using LinearAlgebra using CSV,ArgParse using Random, DataFrames, StatsBase, InvertedIndices, ProgressMeter, Distributions using StaticArrays,TypedTables using BayesianNetworkRegression,DrWatson,MCMCDiagnosticTools,JLD2,Distributed,DrWatson MIN_GEN = 10000 #10000 #20000 MAX_GEN = 200000 #...
077afd24004a5f2111074878d9e300696dea7ed1d8b8ccb0b18da76722304700
Julia
8,270
165
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/Linear_Approximation.ipynb) # # Linear Approximation # The following code demonstrates the linear approximation of the generalized Bloch model and replicates Figs. 7 and 8 in the paper. # For this analysis we need the following packa...
e6d7b8094c4b30032d8e9ed6e75d18b792ce6d0f373008b72f8edb3cef910541
Julia
8,374
166
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/Linear_Approximation.ipynb) # # Linear Approximation # The following code demonstrates the linear approximation of the generalized Bloch model and replicates Figs. 7 and 8 in the paper. # For this analysis we need the following packa...
f94cca995181aa42a0e8f11367239bd3852d2f76c1e805ac909e9cb9df5c2020
Julia
8,399
149
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/OCT.ipynb) # # Optimal Control # This section provides a brief introduction to the package's interface for sequence optimization. We use the [Cramer-Rao bound](https://en.wikipedia.org/wiki/Cramér–Rao_bound) (CRB) to assess a sequence...
88dcba4366c9024eac03040aef86c2e10398a0ac931f2203e188af143ad26cc7
Julia
8,557
183
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
89c5c2f632712eb818d7af841f67051645be0c8b0a00aeb8fac95d378995d34e
Julia
8,755
150
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/OCT.ipynb) # # Optimal Control # This section provides a brief introduction to the package's interface for sequence optimization. We use the [Cramer-Rao bound](https://en.wikipedia.org/wiki/Cramér–Rao_bound) (CRB) to assess a sequence...
da44fb49a1b0a1fee6f684c22ee3c742ac7bc150f3761a18de62c710177b9704
Julia
8,813
258
using DifferentialEquations using Test using MRIgeneralizedBloch using MRIgeneralizedBloch: apply_hamiltonian_freeprecession!, apply_hamiltonian_gbloch! ## max_error = 5e-2 ## set parameters ω0 = 200.0 m0s = 0.15 R1f = 0.3 R2f = 1 / 65e-3 R1s = 2 T2s = 10e-6 Rx = 30.0 TE = 3.5e-3 mfun(p, t; idxs=nothing) = typeof(idx...
af969a438ec5c8245509fc0dafca7a1f5788f772e08ff036e89b405a97e314f0
Julia
8,849
220
## """ hamiltonian_linear(ω1, B1, ω0, T, M0, m0s, R1f, R2f, Rex, R1s, R2s[, dR2sdT2s, dR2sdB1, grad_type]) Calculate the hamiltonian of the linear approximation of the generalized Bloch model. If no gradient is supplied, it returns a 6x6 (static) matrix with the dimensions (in this order) `[xf, yf, zf, xs, zs, 1]...
a3524177c544cc28ef454e2f32b537b27ab427db5bda6f69c1c0087477d5281d
Julia
8,983
210
""" qM = fit_gBloch(data, α, TRF, TR; reM0 = (-Inf, 1, Inf), imM0 = (-Inf, 0, Inf), m0s = ( 0, 0.2, 1), R1f = ( 0, 0.3, Inf), R2f = ( 0, 15, Inf), Rx = ( 0, 20, Inf), R1s = ( 0, 3, Inf), T2s = (8e-6,1e-5,12e-6), ...
d4ea977b71c4a712977faa3862f878372c17c5baa19b0bf779ba738888dfda52
Julia
9,039
270
using CSV,ArgParse using Random, DataFrames, StatsBase, InvertedIndices, ProgressMeter, Distributions using StaticArrays,TypedTables #using BayesianNetworkRegression,DrWatson,MCMCDiagnosticTools,JLD2,Distributed using DrWatson,MCMCDiagnosticTools,JLD2,Distributed include("../../BayesianNetworkRegression.jl/src/Bayesia...
c930043429394e277be60bce643d44a17600955fb709889ea02c63f9f921effe
Julia
9,336
278
using LinearAlgebra using CSV,ArgParse using Random, DataFrames, StatsBase, InvertedIndices, ProgressMeter, Distributions using StaticArrays,TypedTables using BayesianNetworkRegression,DrWatson,MCMCDiagnosticTools,JLD2,Distributed addprocs(3,exeflags=["--optimize=0","--math-mode=ieee","--check-bounds=yes"]) @everyw...
ecd1ad5fbeb997a3733ed6c13333522c516717fe7938f2b2e0c0092ee7146891
Julia
9,377
275
using LinearAlgebra using CSV,ArgParse using Random, DataFrames, StatsBase, InvertedIndices, ProgressMeter, Distributions using StaticArrays,TypedTables using BayesianNetworkRegression,DrWatson,MCMCDiagnosticTools,JLD2 #include("../BayesianNetworkRegression.jl/src/gelmandiag.jl") function parse_CL_args() args = ...
baeff3dfface4ba95d3d7640faeade463b03ba90427d3c92348e4ba9813d78f2
Julia
9,518
177
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/Simulation_ContinuousWave.ipynb) # # Continuous Wave Simulation # The following code replicates the continuous wave simulation of Fig. 2 and is slightly more comprehensive in the sense that all discussed models are simulated. # For ...
4d1d5b367fbfa21c1e536d2db3f6c3beea289174f23b5713b4a2bb03a8be5c9b
Julia
9,613
178
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/Simulation_ContinuousWave.ipynb) # # Continuous Wave Simulation # The following code replicates the continuous wave simulation of Fig. 2 and is slightly more comprehensive in the sense that all discussed models are simulated. # For t...
d52ce76c5cdeb8d189c7db13af15ec68a3d3c0e812fff52cadee10991c6c9438
Julia
9,676
247
using Pkg Pkg.develop(PackageSpec(path=pwd())) Pkg.instantiate() using Symbolics using Symbolics: SConst using MRIgeneralizedBloch ## @variables ω1, B1, ω0, T, M0, m0s, R1f, R2f, Rex, R1s, R1a, T2s, R2s, dR2sdT2s, dR2sdB1, grad_type @variables TRF, dR2sdB1, dR2sdω1, dR2sdTRF, dR2sdT2sdω1, dR2sdB1dω1, dR2sdT2sdTRF, dR2...
128770cee826453c56c070575cd666d481cf0dc97dc593dadd833c86999a71ec
Julia
9,793
288
using CSV,ArgParse using Random, DataFrames, StatsBase, InvertedIndices, ProgressMeter, Distributions using StaticArrays,TypedTables #using BayesianNetworkRegression,DrWatson,MCMCDiagnosticTools,JLD2,Distributed using DrWatson,MCMCDiagnosticTools,JLD2,Distributed include("../../BayesianNetworkRegression.jl/src/Bayesia...
791552c6ba146bca4ec89a355dbf34289a791be2ac22a5667f3038fa999812ef
Julia
9,793
288
using CSV,ArgParse using Random, DataFrames, StatsBase, InvertedIndices, ProgressMeter, Distributions using StaticArrays,TypedTables #using BayesianNetworkRegression,DrWatson,MCMCDiagnosticTools,JLD2,Distributed using DrWatson,MCMCDiagnosticTools,JLD2,Distributed include("../../BayesianNetworkRegression.jl/src/Bayesia...
62eb68533736d3308f753ed818e63597a29b5c5139c3b3bd5dfc10998e203c53
Julia
9,808
285
using DifferentialEquations using SpecialFunctions using QuadGK using Test using MRIgeneralizedBloch ## set parameters max_error = 5e-2 TRF = 500e-6 α = π # f_ω1(t) = α / 500e-6 NSideLobes = 1 f_ω1(t) = sinc(2(NSideLobes+1) * t/TRF - (NSideLobes+1)) * α / (sinint((NSideLobes+1)π) * TRF/π / (NSideLobes+1)) @test quad...
72c96deee26d5496af294de2c017e17b2ebdba2bceacec608f80273f43ffc0ba
Julia
9,825
281
using DifferentialEquations using SpecialFunctions using QuadGK using Test using MRIgeneralizedBloch ## set parameters max_error = 5e-2 TRF = 10.24e-3 γ = 267.522e6 # rad/s/T ω₁ᵐᵃˣ = 13e-6 * γ # rad/s μ = 5 # rad β = 674.1 # 1/s f_ω1(t) = ω₁ᵐᵃˣ .* sech.(β * (t - TRF/2)) # rad/s f_ω0(t) = -μ * β * tanh.(β * (t - TRF/...
0abd9513fc3bbd9f525e8d7b894444c91c67508008f01922df02c2242776546a
Julia
9,931
327
using DifferentialEquations using Test using MRIgeneralizedBloch using MRIgeneralizedBloch: apply_hamiltonian_graham_superlorentzian!, apply_hamiltonian_linear! ## max_error = 5e-2 ## set parameters ω1 = π / 500e-6 ω0 = 200.0 B1 = 1.0 m0s = 0.15 R1f = 0.3 R1s = 2.0 R2f = 1 / 65e-3 T2s = 10e-6 Rx = 30.0 TRF = 500e-6 ...
8b98f0d72553b0f8d3bf35741067ae7c5f0826b9b9bc093a9d3db8c7b353f3e8
Julia
10,204
407
using ArgParse,RCall,TickTock using BayesianNetworkRegression,StatsBase,DataFrames include("../old-src/plot_output.jl") function parse_CL_args() args = ArgParseSettings() @add_arg_table! args begin "--nburn", "-b" help="Number of burn-in Gibbs samples to take" arg_type = Int defaul...
ad28089dcc76db47fc239ddf47f81aba29d4ef97a9d570f9a443744273dd0144
Julia
10,323
353
# julia EM model fitting, Nathaniel Daw 8/2019 #### basic fitting routine function em(data,subs,X,betas,sigma::Vector,likfun; emtol=1e-4, parallel=false, startx = [], maxiter=100, quiet=false, full=false) if full return em(data,subs,X,betas,Matrix(Diagonal(sigma)),likfun; emtol=emtol, parallel=parallel, startx = s...
3050761e83f2ae1b7d43a78c2bcc9839c298e3c3e8f917921fbdc5ede42bd140
Julia
10,433
312
using LinearAlgebra using CSV,ArgParse using Random, DataFrames, StatsBase, InvertedIndices, ProgressMeter, Distributions using StaticArrays,TypedTables #using BayesianNetworkRegression,DrWatson,MCMCDiagnosticTools,JLD2,Distributed using DrWatson,MCMCDiagnosticTools,JLD2,Distributed include("../../BayesianNetworkRegr...
59832604bc161541613ebe124773e284ebdd4b375e1a4081f284efe9d0492f0a
Julia
10,437
312
using LinearAlgebra using CSV,ArgParse using Random, DataFrames, StatsBase, InvertedIndices, ProgressMeter, Distributions using StaticArrays,TypedTables #using BayesianNetworkRegression,DrWatson,MCMCDiagnosticTools,JLD2,Distributed using DrWatson,MCMCDiagnosticTools,JLD2,Distributed include("../../BayesianNetworkRegr...
b78b2b2864ede41e8121fe34571ad2334bed43acbd42f24d75c24d3fedd6a7df
Julia
10,652
321
using LinearAlgebra using CSV,ArgParse using Random, DataFrames, StatsBase, InvertedIndices, ProgressMeter, Distributions using StaticArrays,TypedTables #using BayesianNetworkRegression,DrWatson,MCMCDiagnosticTools,JLD2,Distributed using DrWatson,MCMCDiagnosticTools,JLD2,Distributed include("../../BayesianNetworkRegr...
19bd3754c31050628c73a5f67a4c78fb3e9709f1133845a46b63e0da2c633dac
Julia
10,746
400
using DifferentialEquations using Test using MRIgeneralizedBloch using MRIgeneralizedBloch: apply_hamiltonian_gbloch_superlorentzian! ## max_error = 5e-2 ## set parameters ω1 = π / 500e-6 ω0 = 200.0 B1 = 1.0 m0s = 0.15 R1f = 0.3 R1s = 2.0 R2f = 1 / 65e-3 T2s = 10e-6 Rx = 30.0 TRF = 500e-6 mfun(p, t; idxs = nothin...
2fe3c885be968f806e1a32c751996e173fa2c62950dfbfc0f445ff611bc1a198
Julia
10,929
192
############################################################################ # main call function ############################################################################ """ calculatesignal_linearapprox(α, TRF, TR, ω0, B1, m0s, R1f, R2f, Rx, R1s, T2s, R2slT[; grad_list=[undef], rfphase_increment=[π], m0=:perio...
3b61626d061aa687ead0225ebf1c72beb2ac18c63996ccc1befb7339e40a8e72
Julia
11,220
228
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/Simulation_Pulse.ipynb) # # RF-Pulse Simulation # The following code replicates the RF-pulse simulation of Fig. 3 and plots the ``z^s``-magnetization at the end of respective pulse. # For these simulations we need the following packa...
8c81f2c39b11e5884af0c8326deb5d3a910611926db3f87d08a50bd43d684157
Julia
11,434
229
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/Simulation_Pulse.ipynb) # # RF-Pulse Simulation # The following code replicates the RF-pulse simulation of Fig. 3 and plots the ``z^s``-magnetization at the end of respective pulse. # For these simulations we need the following packa...
9f0f9fe8a0b08e41533ddaefdeac9b0f4b0c4490a117a5234aa0381e17813c3e
Julia
11,821
310
using LinearAlgebra using CSV,ArgParse using Random, DataFrames, StatsBase, InvertedIndices, ProgressMeter, Distributions using StaticArrays,TypedTables #using BayesianNetworkRegression,DrWatson,MCMCDiagnosticTools,JLD2,Distributed using DrWatson,MCMCDiagnosticTools,JLD2,Distributed include("../../BayesianNetworkRegr...
db76222ba12b3afbe316139add3877a4db444bbd9c7d2c7510e45e194ed3579a
Julia
12,205
301
#################################################################### # Bounded ω1 and TRF #################################################################### """ ω1, TRF = get_bounded_omega1_TRF(x) Transform a vector of length `2Npulses` with values in the range `[-Inf, Inf]` into two vectors of length `Npulses`,...
76cb47b13c521ee0564c661e5ed175714068a94d60bbabc11d04e10887643927
Julia
12,319
275
""" qM = fit_gBloch(data, α, TRF, TR; reM0 = (-Inf, 1, Inf), imM0 = (-Inf, 0, Inf), m0s = ( 0, 0.2, 1), R1f = ( 0, 0.3, Inf), R2f = ( 0, 15, Inf), Rex = ( 0, 20, Inf), R1s = ( 0, 3, Inf), T2s = (8e-6,1e-5,12e-6), ...
ab3d0aab38f0a1a6a11d69cac3f8b8e194fae69c0e7cc64ea37bd5b77166a2d8
Julia
12,379
210
############################################################################ # main call function ############################################################################ """ simulate_linearapprox(α, TRF, TR, ω0, B1, M0, m0s, R1f, R2f, Rex, R1s, T2s, R2slT[; grad_list=nothing, rfphase_increment=π, m0=:periodic,...
562dc7c96312ebdb1071630de58a69627bb6d3404d724571f7c82d39ca23ddb1
Julia
12,618
377
#################################################################### # Bounded ω1 and TRF #################################################################### """ ω1, TRF = get_bounded_ω1_TRF(x; ω1_min = 0, ω1_max = 2e3π, TRF_min = 100e-6, TRF_max = 500e-6) Transform a vector of length `2Npulses` with values in th...
829e4f6d13166f758bf102f839b3cc5b4156f71aade4f0c8ee5b13d8a1ead2aa
Julia
13,172
426
using SpecialFunctions # for erf using StatsFuns using DataFrames using DataFramesMeta using Distributions ##################################################### ##################################################### # HELPER FUNCTIONS TO COMPUTE LIKELIHOOD ######### #################################################...
073e81fac43f276dc73b919c457b41432c86daafb203a803397e99027e4d34e7
Julia
13,239
271
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
96aa778e92baa805ff629cc13f60e883d49f036183997e05efa797691eeeb6fb
Julia
13,251
271
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
a5ea5533d980811034793c17ae41d2a0c1193d5e8ea066f9822553cc0b7b8249
Julia
13,265
376
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Distributions using Plots using LazySets, Polyhedra #For convex hull using Dates #For current time with Dates.now() include("BrainParameters.jl") using ..Main.BrainParameters include("BrainInitialConditions.jl") #load initial conditions usi...
5f75076ef04c617a0f704f4ee2b6aaf7008753d03650de2a40c33bb69deda6b5
Julia
13,482
274
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
fae007494f65ded1c1e6fbd3b8c5b078d320717098230e221f27de96dd77f3db
Julia
13,803
429
### want to use this to do the UWS and the Probability Sampling... include("$project_folder/model_fitting/likfuns2.jl") using Distributions using StatsFuns function binomial_pdf(n,N, p) #print(n) return binomial(N, n)*(p^n)*(1-p)^(N-n) end function ordered_probit_pmf(k, n_in, c_in, beta_in) # printl...
b3dc9dd3c0027b198bc3125899e648d57e4aa5ae44928e1c47e45170ba24e10b
Julia
13,833
289
cd(dirname(@__FILE__)) #to go to the directory where this file is saved using Plots using Dates #For current time with Dates.now() using CSV #To read data files using DataFrames #To read csv data files #Load parameters and functions of the brain model include("BrainParameters.jl") #load parameter values using ..Main....
95c8326bbbc2ad8ef11a629bb877578c20f694e2c80d0c525f3e907ca1af70a4
Julia
14,771
196
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/tutorial_singlepulse.ipynb) # # Simulation of a Single RF Pulse # The core of generalized Bloch model is implemented in the function [`apply_hamiltonian_gbloch!(∂m∂t, m, mfun, p, t)`](@ref), which calculates the derivative `∂m/∂t` fo...
3cfd538fa5820a159014990bacd3a1ae2ed66b1b0494160d886dbee18a405171
Julia
14,938
197
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/build_literate/tutorial_singlepulse.ipynb) # # Simulation of a Single RF Pulse # The core of generalized Bloch model is implemented in the function [`apply_hamiltonian_gbloch!(∂m∂t, m, mfun, p, t)`](@ref), which calculates the derivative `∂m/∂t` fo...
1b6703f45a796c917774fe307996c304f61d8734a9dbc8cd8e82ebf289644a4a
Julia
14,972
352
""" CRB, grad_ω1, grad_TRF = CRB_gradient_OCT(ω1, TRF, TR, ω0, B1, m0s, R1f, R2f, Rx, R1s, T2s, R2slT, grad_list, weights; isInversionPulse = [true; falses(length(ω1)-1)]) Calculate the Cramer-Rao bound of a pulse sequence along with the derivatives wrt. `ω1` and `TRF`. # Arguments - `ω1::Vector{Real}`: Control v...
442ac8c5b5ea422aea288c86a3f56f930a75f55233f76cf9be6df6770ff4047d
Julia
15,331
300
""" simulate_gbloch_ide(α, TRF, TR, ω0, B1, M0, m0s, R1f, R2f, Rex, R1s, T2s[; grad_list=nothing, Ncyc=2, output=:complexsignal]) Calculate the signal or magnetization evolution with the full generalized Bloch model assuming a super-Lorentzian lineshape (slow). The simulation assumes a sequence of rectangular RF-...
faf4bd43df63ee3828f491efd645144004d1eac37b4a488f566e27ef5b897c15
Julia
16,438
306
""" calculatesignal_gbloch_ide(α, TRF, TR, ω0, B1, m0s, R1f, R2f, Rx, R1s, T2s[; grad_list, Ncyc=2, output=:complexsignal]) Calculate the signal or magnetization evolution with the full generalized Bloch model assuming a super-Lorentzian lineshape (slow). The simulation assumes a sequence of rectangular RF-pulses...
6a8aeccd6b7e4a4831d4162f2808b5fe0858bb93c9af387b0050f8f42e51d411
Julia
19,826
162
function hamiltonian_linear(ω1, B1, ω0, T, M0, m0s, R1f, R2f, Rex, R1s, R2s, dR2sdT2s, dR2sdB1, grad_type::grad_M0) @inbounds begin begin begin SMatrix{11, 11}((*)((*)(-1, R2f), T), (*)(T, ω0), (*)((*)((*)(-1, B1), T), ω1), 0, 0, 0, 0, 0, 0, 0, 0, (*)((*)(-1, T), ω0)...