diff --git a/projects/disclaimer.tex b/projects/disclaimer.tex index 6397967..e328d05 100644 --- a/projects/disclaimer.tex +++ b/projects/disclaimer.tex @@ -8,8 +8,8 @@ \vspace{1ex} The {\bf code} and the {\bf presentation} should be uploaded to - ILIAS at latest on Thursday, November 5th, 13:00h. The - presentations start on Thursday 13:00h. Please hand in your + ILIAS at latest on Thursday, February XXXXth, 13:00h. The + presentations start on XXXXXXX. Please hand in your presentation as a pdf file. Bundle everything (the pdf and the code) into a {\em single} zip-file. @@ -22,7 +22,7 @@ {\em figures} that you use in your slides. The figures should follow the guidelines for proper plotting as discussed in the course. The code should be properly commented - and comprehensible by third persons (use proper and consistent + and comprehensible by a third persons (use proper and consistent variable and function names). \vspace{1ex} \textbf{Please write your name and matriculation diff --git a/projects/project_input_resistance/Makefile b/projects/project_input_resistance/Makefile new file mode 100644 index 0000000..3befd71 --- /dev/null +++ b/projects/project_input_resistance/Makefile @@ -0,0 +1,10 @@ +latex: + pdflatex *.tex > /dev/null + pdflatex *.tex > /dev/null + +clean: + rm -rf *.log *.aux *.out auto + rm -f `basename *.tex .tex`.pdf + +zip: latex + zip `basename *.tex .tex`.zip *.pdf *.dat *.mat diff --git a/projects/project_photoreceptor/Makefile b/projects/project_photoreceptor/Makefile new file mode 100644 index 0000000..2cd51bd --- /dev/null +++ b/projects/project_photoreceptor/Makefile @@ -0,0 +1,10 @@ +latex: + pdflatex *.tex > /dev/null + pdflatex *.tex > /dev/null + +clean: + rm -rf *.log *.aux *.out auto + rm -f `basename *.tex .tex`.pdf + +zip: latex + zip `basename *.tex .tex`.zip *.pdf *.dat *.mat diff --git a/projects/project_photoreceptor/photoreceptor.tex b/projects/project_photoreceptor/photoreceptor.tex new file mode 100644 index 0000000..9bcf78d --- /dev/null +++ b/projects/project_photoreceptor/photoreceptor.tex @@ -0,0 +1,65 @@ +\documentclass[addpoints,11pt]{exam} +\usepackage{url} +\usepackage{color} +\usepackage{hyperref} + +\pagestyle{headandfoot} +\runningheadrule +\firstpageheadrule +\firstpageheader{Scientific Computing}{Project Assignment}{WS 2016/17} +%\runningheader{Homework 01}{Page \thepage\ of \numpages}{23. October 2014} +\firstpagefooter{}{}{{\bf Supervisor:} Jan Grewe} +\runningfooter{}{}{} +\pointsinmargin +\bracketedpoints + +%\printanswers +%\shadedsolutions + + +\begin{document} +%%%%%%%%%%%%%%%%%%%%% Submission instructions %%%%%%%%%%%%%%%%%%%%%%%%% +\sffamily +% \begin{flushright} +% \gradetable[h][questions] +% \end{flushright} + +\begin{center} + \input{../disclaimer.tex} +\end{center} + +%%%%%%%%%%%%%% Questions %%%%%%%%%%%%%%%%%%%%%%%%% +\section*{Analysis of insect photoreceptor data.} +In this project you will analyse data from intracellular recordings of +a fly R\.1--6 photoreceptor. The membrane potential of the +photoreceptor was recorded while the cell was stimulated with a +light stimulus. + +\begin{questions} + \question{} The accompanying dataset (photoreceptor\_data.zip) + contains seven mat files. Each of these holds the data from one + stimulus intensity. In each file are three variables. (i) + \textit{voltage} a matrix with the recorded membrane potential from + 10 consecutive trials, (ii) \textit{time} a matrix with the + time-axis for each trial, and (iii) \textit{trace\_meta} a structure + that stores several metadata. This is the place where you find the + \emph{amplitude}, that is the voltage that drives the light + stimulus, i.e. the light-intensity. + + \begin{parts} + \part{} Create a plot of the raw data. Plot the average response as + a function of time. This plot should also show the + across-trial variability.\\[0.5ex] + \part{} You will notice that the responses have three main parts, a + pre-stimulus phase, the phase in which the light was on, and + finally a post-stimulus phase. Create an characteristic curve that + plots the response strength as a function of the stimulus + intensity for the ``onset'' and the ``steady state'' + phases.\\[0.5ex] + \part{} The light switches on at time zero. Estimate the delay between stimulus.\\[0.5ex] + \part{} You may also decide to analyze the post-stimulus response in some + more detail. + \end{parts} +\end{questions} + +\end{document} diff --git a/projects/project_photoreceptor/photoreceptor_data.zip b/projects/project_photoreceptor/photoreceptor_data.zip new file mode 100644 index 0000000..2bf1127 Binary files /dev/null and b/projects/project_photoreceptor/photoreceptor_data.zip differ diff --git a/projects/project_random_walk/Makefile b/projects/project_random_walk/Makefile new file mode 100644 index 0000000..dad25ce --- /dev/null +++ b/projects/project_random_walk/Makefile @@ -0,0 +1,10 @@ +latex: + pdflatex *.tex > /dev/null + pdflatex *.tex > /dev/null + +clean: + rm -rf *.log *.aux *.zip *.out auto + rm -f `basename *.tex .tex`.pdf + +zip: latex + zip `basename *.tex .tex`.zip *.pdf *.dat *.mat diff --git a/projects/project_random_walk/random_walk.py b/projects/project_random_walk/random_walk.py new file mode 100644 index 0000000..3334e28 --- /dev/null +++ b/projects/project_random_walk/random_walk.py @@ -0,0 +1,116 @@ +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.mlab as mlab +import scipy.io as scio +from IPython import embed + + +def create_food_blotch(size_x=51, size_y=51, noise=0.01, threshold=0.008): + x = np.arange(-np.round(size_x/2), np.round(size_x/2)+1) + y = np.arange(-np.round(size_y/2), np.round(size_y/2)+1) + X, Y = np.meshgrid(x, y) + Z = mlab.bivariate_normal(X, Y, sigmax=10, sigmay=10) + food = (np.random.rand(size_x, size_y) * noise) + Z + return food + + +def create_world(width=100, height=100, d=0.1, food_sources=100, noise=0.01): + my_world = np.zeros((int(width/d), int(height/d))) + print("placing food sources ...") + for i in range(food_sources): + x = np.random.randint(0, width/d) + y = np.random.randint(0, height/d) + food = create_food_blotch(noise=noise) + if (x + food.shape[1]) > my_world.shape[1]: + x -= food.shape[1] + if (y + food.shape[0]) > my_world.shape[0]: + y -= food.shape[0] + my_world[y:y+food.shape[0], x:x+food.shape[1]] += food + return my_world + + +def get_step(): + options = [-1, 1] + step = np.asarray([options[np.random.randint(0, 2)], options[np.random.randint(0, 2)]]) + return step + + +def is_valid_step(pos, step, max_x, max_y): + new_pos = pos + step + if (new_pos[0] < max_y) & (new_pos[1] < max_x) & (new_pos[0] >= 0) & (new_pos[1] >= 0): + return True + return False + + +def do_valid_step(pos, max_x, max_y): + valid = False + while not valid: + step = get_step() + valid = is_valid_step(pos, step, max_x, max_y) + new_pos = pos + step + return new_pos, step + + +def random_walk(world, steps=10000): + x_positions = np.zeros(steps) + y_positions = np.zeros(steps) + start_x = np.random.randint(0, world.shape[1]) + start_y = np.random.randint(0, world.shape[0]) + eaten_food = 0 + new_pos = np.asarray([start_y, start_x]) + for i in range(steps): + new_pos, step = do_valid_step(new_pos, world.shape[1], world.shape[0]) + x_positions[i] = new_pos[1] + y_positions[i] = new_pos[0] + eaten_food += world[new_pos[0], new_pos[1]] + world[new_pos[0], new_pos[1]] = 0.0 + return x_positions, y_positions, eaten_food + + +def not_so_random_walk(world, steps=10000): + x_positions = np.zeros(steps) + y_positions = np.zeros(steps) + start_x = np.random.randint(0, world.shape[1]) + start_y = np.random.randint(0, world.shape[0]) + previous_food = 0.0 + current_food = 0.0 + eaten_food = 0 + pos = np.asarray([start_y, start_x]) + step = None + for i in range(steps): + gradient = current_food - previous_food + if (gradient <= 0) or ((step is not None) and \ + (not is_valid_step(pos, step, world.shape[1], world.shape[0]))): + pos, step = do_valid_step(pos, world.shape[1], world.shape[0]) + else: + pos += step + x_positions[i] = pos[1] + y_positions[i] = pos[0] + previous_food = current_food + current_food = world[pos[0], pos[1]] + eaten_food += current_food + world[pos[0], pos[1]] -= current_food + return x_positions, y_positions, eaten_food + + +if __name__ == '__main__': + print("create world... ") + world = create_world(noise=0.0, food_sources=50) + trials = 10 + gain_random = np.zeros(trials) + gain_nsr = np.zeros(trials) + print("run") + for i in range(trials): + x, y, gain_random[i] = random_walk(world.copy(), 100000) + x2, y2, gain_nsr[i] = not_so_random_walk(world.copy(), 100000) + + print("random walk yields: %.2f +- %.2f food per 100000 steps" % (np.mean(gain_random), + np.std(gain_random))) + print("not so random walk yields: %.2f +- %.2f food per 100000 steps" % (np.mean(gain_nsr), + np.std(gain_nsr))) + + scio.savemat('random_world.mat', {'world': world}) + plt.imshow(world) + plt.scatter(x[::2], y[::2], s=0.5, color='red') + plt.scatter(x2[::2], y2[::2], s=0.5, color='green') + plt.show() diff --git a/projects/project_random_walk/random_walk.tex b/projects/project_random_walk/random_walk.tex new file mode 100644 index 0000000..e0f906a --- /dev/null +++ b/projects/project_random_walk/random_walk.tex @@ -0,0 +1,68 @@ +\documentclass[addpoints,11pt]{exam} +\usepackage{url} +\usepackage{color} +\usepackage{hyperref} + +\pagestyle{headandfoot} +\runningheadrule +\firstpageheadrule +\firstpageheader{Scientific Computing}{Project Assignment}{WS 2016/17} +%\runningheader{Homework 01}{Page \thepage\ of \numpages}{23. October 2014} +\firstpagefooter{}{}{{\bf Supervisor:} Jan Grewe} +\runningfooter{}{}{} +\pointsinmargin +\bracketedpoints + +%\printanswers +%\shadedsolutions + + +\begin{document} +%%%%%%%%%%%%%%%%%%%%% Submission instructions %%%%%%%%%%%%%%%%%%%%%%%%% +\sffamily +% \begin{flushright} +% \gradetable[h][questions] +% \end{flushright} + +\begin{center} + \input{../disclaimer.tex} +\end{center} + +%%%%%%%%%%%%%% Questions %%%%%%%%%%%%%%%%%%%%%%%%% +\section*{Random walk with memory.} + +Some animals perform a random walk when searching for food. In some +cases this random walk is not completely random. In fact, sometimes +there is some memory involved. Whenever there is a positive gradient +in food gain between successive steps the animal will continue in the +very same direction as before. When the next step leads to a decrease +in food gain the animal switches back to a random walk. + + +\begin{questions} + \question{} The accompanying dataset (random\_world.mat) contains a + single variable stored. This is the world (10000\,m$^2$ area with + 10\,cm spatial resolution) in which there are randomly distributed + food sources (Gaussian blotches of food). + + \begin{parts} + \part{} Create a plot of the world.\\[0.5ex] + \part{} Create a model animal that performs a pure random walk. The + agent can walk in eight different directions (the cardinal and + diagonal directions) with a stepsize of 10\,cm + (approximately). Let the agent start at a random location in the + world and count how much food it eats in 10000 steps (eaten food + disappears from the world, of course). If the agent bumps into the + borders of the world choose a different direction.\\[0.5ex] + \part{} Plot a typical example walk. (You can also make an animation + with MATLAB)\\[0.5ex] + \part{} Same as above, but create a model animal that has some memory, + i.e. the direction is kept constant as long as there is a positive + gradient in the food gain. Otherwise a random walk is performed\\[0.5ex] + \part{} Plot a typical example walk also for this agent.\\[0.5ex] + \part{} Compare the performance of the two agents. Create appropriate + plots and apply statistical methods. + \end{parts} +\end{questions} + +\end{document} diff --git a/projects/project_random_walk/random_world.mat b/projects/project_random_walk/random_world.mat new file mode 100644 index 0000000..72b4ec9 Binary files /dev/null and b/projects/project_random_walk/random_world.mat differ