summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2014-05-16 01:44:16 -0400
committerbnewbold <bnewbold@robocracy.org>2014-05-16 01:44:16 -0400
commitb602a0ce3526c0d5f5fd6c681d6a70101a492d89 (patch)
tree72b08b798a8edf8eef7b61433dedf8c1a650368c
parent7624d4ded7ee62cc1c08b42b65ecdfbf0bce0cc3 (diff)
downloaddmmsb2014-b602a0ce3526c0d5f5fd6c681d6a70101a492d89.zip
dmmsb2014-b602a0ce3526c0d5f5fd6c681d6a70101a492d89.tar.gz
hw01 assignment and julia notes
-rw-r--r--assignments/hw01/flash4.jpgbin0 -> 369783 bytes
-rw-r--r--assignments/hw01/notes.txt8
-rw-r--r--assignments/hw01/question1.jl40
-rw-r--r--assignments/hw01/question2_to_8.jl87
-rw-r--r--assignments/hw01/sampledata2.matbin0 -> 4916 bytes
-rw-r--r--julia/misc.jl27
6 files changed, 162 insertions, 0 deletions
diff --git a/assignments/hw01/flash4.jpg b/assignments/hw01/flash4.jpg
new file mode 100644
index 0000000..5865a58
--- /dev/null
+++ b/assignments/hw01/flash4.jpg
Binary files differ
diff --git a/assignments/hw01/notes.txt b/assignments/hw01/notes.txt
new file mode 100644
index 0000000..c2f0795
--- /dev/null
+++ b/assignments/hw01/notes.txt
@@ -0,0 +1,8 @@
+
+
+### Question 1: 3rd (big spike, little bump)
+
+### Question 2: 2nd ("There are more patients who are older than 50...")
+
+### Question >3: (see question2_to_8.jl)
+
diff --git a/assignments/hw01/question1.jl b/assignments/hw01/question1.jl
new file mode 100644
index 0000000..32be340
--- /dev/null
+++ b/assignments/hw01/question1.jl
@@ -0,0 +1,40 @@
+
+using ImageView, Images
+img = imread("flash4.jpg")
+img.data = img.data'
+#display(img, pixelspacing = [1,1])
+
+# flash is 220 to 280 in the x-axis
+# flash_data = img.data[220:280,:]
+flash_avg = Float64[mean(img.data[r, 220:280]) for r = 1:size(img.data,1)]
+noflash_avg = Float64[mean(img.data[r, 300:400]) for r = 1:size(img.data,1)]
+
+# using Winston
+# plot(flash_avg)
+# plot(noflash_avg)
+
+# WRONG: background_F = Float64[mean(img.data[70:100, :])]
+background_avg = Float64[mean(img.data[r, 70:100]) for r = 1:size(img.data,1)]
+
+flash_avg ./= background_avg
+noflash_avg ./= background_avg
+
+function unitify(r, Ca2_baseline, K_D)
+ return r * K_D / ((K_D/Ca2_baseline) - r + 1)
+end
+
+Ca2_baseline = 100
+K_D = 700
+
+#Ca2_baseline = 150
+#K_D = 1000
+
+dT = 1.53
+t = dT * [0:length(flash_avg)]
+figure()
+hold(true)
+plot(t, Float64[unitify(v, Ca2_baseline, K_D) for v = flash_avg[:]], color="red")
+plot(t, Float64[unitify(v, Ca2_baseline, K_D) for v = noflash_avg[:]], color="blue")
+ylabel("[ca](nM)")
+xlabel("Time (ms)")
+
diff --git a/assignments/hw01/question2_to_8.jl b/assignments/hw01/question2_to_8.jl
new file mode 100644
index 0000000..3cf9dc9
--- /dev/null
+++ b/assignments/hw01/question2_to_8.jl
@@ -0,0 +1,87 @@
+
+using MAT
+
+all_vars= matread("sampledata2.mat")
+d = all_vars["data"]
+
+# ----------------------- Q2
+length(filter(x -> x > 5, d[:, 2])) / length(d[:, 2])
+# 0.19, so first statement is false
+
+length(filter(x -> x > 50, d[:, 1]))
+# 56x over 50
+
+length(filter(x -> x < 20, d[:, 1]))
+# 4x under 20
+# second statement is true
+
+length(filter(x -> x < 5, d[:, 2]))
+# 243
+length(filter(x -> x > 6, d[:, 2]))
+# 34
+# third statement is false
+
+length(filter(x -> x > 0.5, d[:, 3])) / length(d[:, 3])
+# 0.5233333333333333
+# last statement is false
+
+# ----------------------- Q3
+
+using Winston
+
+# TODO: this foldl business is ugly
+with_cancer = foldl(vcat, filter(x -> x[3] > 0.5, [d[row, :] for row = 1:size(d,1)]))
+without_cancer = foldl(vcat, filter(x -> x[3] < 0.5, [d[row, :] for row = 1:size(d,1)]))
+
+figure()
+p = FramedPlot()
+add(p, Histogram(hist(with_cancer[:, 1], 15:10:75)..., color="red"))
+
+# 1 NO (this is "without")
+# 2 yes
+# 3 NO
+# 4 NO
+
+# ----------------------- Q4
+
+add(p, Histogram(hist(without_cancer[:, 1], 15:10:75)..., color="green"))
+# 1 YES
+
+# ----------------------- Q5
+
+function fractional(f, d)
+ return length(filter(f, d)) / length(d)
+end
+
+fractional(x -> x>55, without_cancer[:, 1])
+#0.013986013986013986
+
+fractional(x -> x<25, without_cancer[:, 1])
+#0.08391608391608392
+# FALSE
+
+fractional(x -> x<35, without_cancer[:, 1])
+# FALSE
+
+fractional(x -> x<30, with_cancer[:, 1]) / fractional(x -> x>60, with_cancer[:, 1])
+# TRUE!
+
+fractional(x -> x>45, with_cancer[:, 1])
+# FALSE
+
+# ----------------------- Q6
+
+fractional(x -> x>35, with_cancer[:, 1])
+# 0.802547770700637
+
+# ----------------------- Q7
+
+fractional(x -> x<25, d[:, 1])
+# 0.06
+
+# ----------------------- Q8
+
+drinkers = foldl(vcat, filter(x -> x[2] > 3, [d[row, :] for row = 1:size(d,1)]))
+fractional(x -> x >0.5, drinkers[:, 3])
+# 0.6459627329192547
+
diff --git a/assignments/hw01/sampledata2.mat b/assignments/hw01/sampledata2.mat
new file mode 100644
index 0000000..86317df
--- /dev/null
+++ b/assignments/hw01/sampledata2.mat
Binary files differ
diff --git a/julia/misc.jl b/julia/misc.jl
new file mode 100644
index 0000000..5d98e0b
--- /dev/null
+++ b/julia/misc.jl
@@ -0,0 +1,27 @@
+### Julia image manipulation
+
+Pkg.update()
+Pkg.add("Images")
+Pkg.add("ImageView")
+
+using ImageView, Images
+img = imread("my_photo.jpg")
+# eg, rotate via a matrix transform
+img.data = img.data'
+display(img, pixelspacing = [1,1])
+
+### Julia .mat loating
+
+Pkg.update()
+Pkg.add("MAT")
+using MAT
+file = matopen("matfile.mat")
+read(file, "varname")
+close(file)
+
+file = matopen("matfile.mat", "w")
+write(file, "varname", variable)
+close(file)
+
+vars = matread("matfile.mat")
+