This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prior1 = function(n=1) { | |
runif(n,min=0.0,max=2.0) | |
} | |
prior2 = function(n=1) { | |
15 | |
} | |
sampleprior = function(n=1){ | |
return(replicate(n,rbeta(n=1,shape1=prior1(),shape2=prior2()))) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Multithreading is the most straightforward type of parallel processing supported by Julia | |
# https://docs.julialang.org/en/v1/manual/multi-threading/#man-multithreading | |
# If your parallel computing problem doesn't involve shared memory state | |
# then this is probably the way to go | |
Nthreads = Threads.nthreads(); | |
Ncalcs = Nthreads * 5 | |
# Let's distribute Ncalcs operations across Nthreads threads | |
# We can have a look at which thread carries out each operation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simulating two schemes for irregular sampling from regular timeseries | |
deltasim = 0.1 | |
deltarec = 1/3 | |
tmax = 10.0 | |
simtimes = seq(0,tmax,0.1) | |
rectargets = seq(0,tmax,deltarec) | |
recindex = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import seaborn as sns | |
tips = sns.load_dataset("tips") | |
print(sns.__version__) | |
print(tips.head()) | |
ax=sns.swarmplot(x="day", y="total_bill", hue="sex", data=tips,split=True) | |
sns.barplot(x="day", y="total_bill", hue="sex", data=tips,capsize=0.1,errwidth=1.25,alpha=0.25,ci=None) | |
xcentres=[0,1,2,3] | |
delt=0.2 | |
xneg=[x-delt for x in xcentres] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flength = function(fname) length(readLines(fname)) | |
for(droot in c("agent","gillespie")){ | |
dirname = paste0(droot,"_csv_files") | |
fnames = file.path(dirname,list.files(dirname,pattern="*.csv")) | |
nfiles = length(fnames) | |
ntimes = flength(fnames[1])-1 | |
times = 0:(ntimes-1) # You might want to change this to get the right units |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Warren et al. (2020) https://doi.org/10.1038/s41598-020-70885-3 | |
op = par(mfrow=c(2,2)) | |
# Healthy control subjects (all proteins) | |
# C01, C02, C03 | |
plot(function(x) dbeta(x,1,75),from=0,to=1.0,xlab="pi",ylab="Density",lwd=2, main="Controls") | |
abline(v=c(0,1),col="red",lwd=3) | |
# Note that we would expect RC defect to manifest in old age, so, in principle, | |
# this prior could change with age of patient at biopsy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to separate plotting from CPU intensive analysis | |
plotfuns = list() | |
Npts = 1000 | |
Nsims = 12 | |
# Visualising a 1D random walk, for example | |
makewalk = function(Npts){ | |
# Do some like real heavy computing man | |
deltas = sample(c(-1,1),Npts,replace=TRUE) | |
walk = cumsum(deltas) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(MASS) | |
xdat = rnorm(1000) | |
ydat = rnorm(1000) | |
# https://stackoverflow.com/questions/16225530/contours-of-percentiles-on-level-plot | |
dens = kde2d(xdat, ydat, n=200); ## estimate the z counts | |
prob = c(0.95, 0.5) | |
dx = diff(dens$x[1:2]) | |
dy = diff(dens$y[1:2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N=10000 | |
noise = rnorm(N,mean=0,sd=0.5) | |
random_walk=cumsum(noise) | |
ylim = range(random_walk) | |
op = par(mfrow=c(1,2)) | |
plot(noise,type="l",ylim=ylim,xlab="time",cex.lab=1.75,cex.axis=1.75) | |
plot(random_walk,type="l",ylim=ylim,xlab="time",cex.lab=1.75,cex.axis=1.75) | |
par(op) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make some synthetic data, like patient with v-shaped 2Dmito scatterplot | |
N = 500 | |
mu_x = 5 | |
sd_x = 2.5 | |
intercept = 0.1 | |
slope_normal = 1.0 | |
slope_deficient = 0.0 | |
sd_err = 1.0 | |
x_normal = rnorm(N/2,mu_x,sd_x) |