LaTeX for Premises

Concatenated Premises for Presentation \[ lim_{\epsilon \to 0} A - \epsilon \\ \min(\epsilon) \text{ when standard deviation in period is minimized: } \\ \min( \sqrt{ \frac{1}{n}\sum_{i = 1}^n \max_{\text{local}}V_T(t)_{i} - \max_{\text{local}}V_T(t)_{i+1} - \mu(\max_{\text{local}}V_T(t)_{i} - \max_{\text{local}}V_T(t)_{i+1}))^2})\\ \text{and when:} \\ lim_{coh \to 1}coh(B(t),P_{\gamma}(t)) \\ \text{ ie. coherence between }P_{\gamma}(t) \text{ and }B(t) \text{ is maximized} \\ \text{where:} \\ B(t) = \text{breath time-series} \text{ & } .2Hz \leq f(B(t)) \leq .35Hz\ (f = \text{frequency})\\ BPM_a = \text{Actual breaths in a minute} \\ BPM_r = \text{Number of breaths reported in a minute} \\ P_{\gamma}(t) = \text{gamma power time-series} \\ A = \text{attention: }\frac{60s - \frac{60s}{BPM_{a}} * \mid BPM_{r} - BPM_{a} \mid}{60s} \\ \text{attention standardized with reference to a consistent measure of time} \\ \text{ to account for differences in rate of breathing} \\ \epsilon =\text{Error} \\ \text{ie a perfect attention score is 100 \& }\epsilon \text{ is the error resulting from actual attention score} \\ V_T = \text{Breath tidal volume} \] Coherence Assumption \[ lim_{\epsilon \to 0 } A_{ext} - \epsilon \\ lim_{coh \to 1} coh(t) = coh(B(t),P_{\gamma}(t)) \\ A_{ext} = \text{exteroceptive attention: }\frac{60s - \frac{60s}{CC_{a} } * \mid CC_{r} - CC_{a} \mid}{60s} \\ \text{ where: } \\ CC_r = \text{reported color changes} \\ CC_a = \text{actual color changes} \\ f(B(t)) = .2Hz \leq f(B(t)) \leq .35Hz \\ \text{ attention standardized with reference to a consistent measure of time} \\ \epsilon = \text{Error, ie a perfect attention score is 100 }\epsilon \text{ is the error resulting from actual attention score} \\ \] Consistency of Period assumption \[ lim_{\epsilon \to 0} A - \epsilon \\ \min(\epsilon) \text{ when standard deviation in period is minimized: } \\ \min( \sqrt{ \frac{1}{n}\sum_{i = 1}^n \max_{\text{local}}V_T(t)_{i} - \max_{\text{local}}V_T(t)_{i+1} - \mu(\max_{\text{local}}V_T(t)_{i} - \max_{\text{local}}V_T(t)_{i+1}))^2})\\ \text{where:} \\ B(t) = \text{breath time-series} \text{ & } .2Hz \leq f(B(t)) \leq .35Hz\ (f = \text{frequency}) \\ V_T = \text{Breath tidal volume} \]

Loading and Cleaning Data

Analysis

Respiration

Respiratory smoothing

Respiratory Smoothing and Visualization

Respiratory Components

Simulate Respiratory Impulse

## ----------------------- Mon Apr 08 13:23:44 2019 ------------------------#
## TODO: Take the derivative of the respiratory signal to capture flow rate. From
## flow rate determine the breath impulse.
library(pspline)
out <- predict(pspline::sm.spline(Resp_sma$x, Resp_sma$y), Resp_sma$x, 1)[, 1]
kout <- ksmooth(Resp_sma$x, out, kernel = "normal")
ind <- out > qnorm(0.999, mean(out), sd(out))
out[100:15000] <- QuantTools::sma(out, 100)[100:15000]
out[1:99] <- kout$y[1:99]
ind <- out > qnorm(0.999, mean(out), sd(out))
out[ind] <- ksmooth(Resp_sma$x, out, kernel = "normal", bandwidth = 0.8)$y[ind]
Resp_sma$dydt <- out

# ----------------------- Mon Apr 08 16:37:10 2019 ------------------------# Is
# the breath impulse the integral of dy/dt?

pos.neg <- rle(Resp_sma$dydt > 0) %>% unclass() %>% as.data.frame() %>% mutate(end = cumsum(lengths), 
    start = c(1, lag(end)[-1] + 1)) %>% extract(c(1, 2, 4, 3))
Resp_sma <- lapply(apply(pos.neg[pos.neg$values == T, ], 1, function(r) {
    seq(r["start"], r["end"])
}), df = Resp_sma, function(ind, df) {
    df[ind, ]
}) %>% lapply(function(df) {
    df %>% mutate(cs = cumsum(dydt))
}) %>% do.call("rbind", .) %>% right_join(Resp_sma, by = c("x", "y", "dydt"))
Resp_sma$cs[is.na(Resp_sma$cs)] <- 0
Resp_sma$cs %<>% scale(center = 0) %>% .[, 1]

ggplot(Resp_sma, aes(x = x, y = y)) + geom_line() + geom_line(aes(y = dydt), color = HDA::ggColor(2)[1]) + 
    geom_line(aes(y = cs), color = HDA::ggColor(2)[2], size = 1) + theme_light() + 
    labs(title = "Respiratory Signal - 1st 60s", subtitle = latex2exp::TeX("Flow Rate $(\\frac{dB}{dt})$ in Red, Tidal Volume $(\\int \\frac{dB}{dt} > 0)$ in blue"), 
        caption = latex2exp::TeX("ksmooth(bw=.8) and sma(100) applied to $(\\frac{dy}{dt})$"), 
        x = "Time (s)", y = "Normalized Value") + theme(plot.title = element_text(hjust = 0.5), 
    plot.subtitle = element_text(hjust = 0.5)) + guides(color = guide_legend())

Translate Respiratory signal to Frequency Domain

Frequencies of smoothed breath signal at Specific Intervals

Time (s) Frequency (Hz)
0 0.00035
15 0.00030
30 0.00030
45 0.00035
60 0.00035
## png 
##   2

Spectrograph of smoothed breath signal

EEG

Simulation with Respiration

Model EEG based on Respiratory Impulse

ggsave("../Images/Hippocampus.png", type = "cairo", width = 16/1.5, height = 9/1.5, 
    units = "in")
# ----------------------- Wed Apr 10 13:37:36 2019 ------------------------# OB
pos.neg <- rle(sign(Resp_sma$cs)) %>% unclass() %>% as.data.frame() %>% mutate(end = cumsum(lengths), 
    start = c(1, lag(end)[-1] + 1)) %>% extract(c(1, 2, 4, 3))
Resp_sma <- lapply(apply(pos.neg[pos.neg$values == 1, ], 1, function(r) {
    seq(r["start"], r["end"])
}), df = Resp_sma, function(ind, df) {
    df[ind, ]
}) %>% lapply(function(df) {
    df %>% mutate(thrs = qnorm(0.8, mean(cs), sd(cs)))
}) %>% do.call("rbind", .) %>% right_join(Resp_sma, by = c("x", "y", "dydt", "cs"))
Resp_EEG <- left_join(Fp1 %>% mutate_at(vars(Time), funs(round(., 3))), Resp_sma %>% 
    mutate_at(vars(x), funs(round(., 3))), by = c(Time = "x"))
Resp_EEG$thrs[is.na(Resp_EEG$thrs)] <- 0
OBEEG <- function(cs, thrs, Fp1) {
    if (cs > thrs) {
        out <- Fp1 * cs
    } else {
        out <- Fp1
    }
    return(out)
}
Resp_EEG %<>% rowwise %>% mutate(OB = OBEEG(cs, thrs, Fp1))
OB_gg <- Resp_EEG %>% rename(`Tidal Volume` = cs) %>% reshape2::melt(., measure.vars = c("Tidal Volume", 
    "OB")) %>% rename(Signal = variable) %>% ggplot(mapping = aes(x = Time, y = value, 
    color = Signal)) + geom_line() + geom_line() + labs(title = "Expected Olfactory Bulb EEG Signal", 
    subtitle = "OB = EEG * Tidal Volume when TV > 80%", caption = "OB EEG signal \n multiplicative (EEG * Breath volume @ 80% local quantile threshold)", 
    x = "Time (s)", y = "Amplitude") + scale_color_manual(values = c(OB = HDA::ggColor(2)[1], 
    `Tidal Volume` = HDA::ggColor(2)[2])) + theme(plot.title = element_text(hjust = 0.5), 
    plot.subtitle = element_text(hjust = 0.5))

plotly::ggplotly(OB_gg)

Computing Coherence

Hippocampal Coherence

Coherence between smoothed breathing signal and synthesized hippocampus signal

## png 
##   2
Mean coherence of synthesized hippocampus signal at respiratory frequency: 0.98
## png 
##   2

Olfactory Bulb Coherence

Coherence between smoothed breathing signal and synthesized olfactory bulb signal

## png 
##   2
Mean coherence of synthesized hippocampus signal at respiratory frequency: 0.649
## png 
##   2

Coherence with Fp1 Signal

Coherence between smoothed breathing signal and Raw Fp1 signal

## png 
##   2
Mean coherence of Fp1 Gamma1 power over time signal at respiratory frequency: 0.242
## png 
##   2

Modeling Neurons

Hodgkin-Huxley model in R

\[\begin{align} I_{ext} &= C_m \frac{dV_m}{dt} + I_{ion}\\ & = C_m \frac{dV_m}{dt} + g_{Na} m^3 h(V-E_{Na}) + g_K n^4 (V - E_K) + g_L (V - E_L) \end{align}\] \[\begin{align} C \frac{dV}{dt} & = I - g_{Na} m^3 h(V-E_{Na}) - g_K n^4 (V - E_K) -g_L (V - E_L)\\ \frac{dm}{dt} & = a_m(V) (1 - m) - b_m(V)m\\ \frac{dh}{dt} & = a_h(V)(1 - h) - b_h(V)h\\ \frac{dn}{dt} & = a_n(V) (1 - n) - b_n(V)n\\ a_m(V) & = 0.1(V+40)/(1 - \exp(-(V+40)/10))\\ b_m(V) & = 4 \exp(-(V + 65)/18)\\ a_h(V) & = 0.07 \exp(-(V+65)/20)\\ b_h(V) & = 1/(1 + \exp(- (V + 35)/10))\\ a_n(V) & = 0.01 (V + 55)/(1 - \exp(-(V+55)/10))\\ b_n(V) & = 0.125 \exp(-(V + 65)/80) \end{align}\] Model Hodgkin-Huxley Neuron

## png 
##   2

Input Stimulus

## png 
##   2

Sensitivity Analysis

Sensitivity Analysis with Sodium

## png 
##   2
## png 
##   2
## png 
##   2

Sensitivity Analysis with Sodium Conductance

## png 
##   2