Skip to content

Commit

Permalink
modfy some files since change to windows platform
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredcai committed Jul 4, 2019
1 parent 18f1a35 commit fa8e2df
Show file tree
Hide file tree
Showing 21 changed files with 540 additions and 14 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
58 changes: 58 additions & 0 deletions Week-3/notes/4-guest-lecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Guest lecture on Retina -- Dr. Fred Rieke
```
Retina cell --- where visual processing begins.
Photo-receptors are transduced and converted into electrical responses.
The rand photo-receptors are receptive to dim light.
The cone photo-receptors helps in extending higher visual levels.
The signals produced in the rand and cone segments are processed by serveral layers of cells within the retina before passing to the optic nerve of the brain.
The few photons are coming-in are being absorbed within a pool of several 100s upto 1000s of rods generate electrical signals which are not only reliably detective with the retina, but it sends to brain with reliable perception.
```
![](http://geekresearchlab.net/coursera/neuro/retina-g-1.jpg)
```
So, what are we looking for is,
The threshold of retaining the non-linearity of signals on rods from the photons, where it ejects noise from the remaining rods.
It's the case where in the nervous systems over the aspects of convergence of many inputs on downstream cell and those small subset of inputs where all those outputs are generating noise.
```
![](http://geekresearchlab.net/coursera/neuro/retina-g-2.jpg)
```
Advantages:
```
```
1. Access to rod signal and noise properties,
where it measure the response of the rods of single photons.
We can measure the noise of the rod responses and
We can summarize it by constructing the distributions that capture the probability of the given rod generates the amplitude responses,
where we can plot it as the probability versus the amplitude.
For those in black curve, the rod failed to absorb the photon that's being generating noise.
For those in red curve, the rod absorbs the photon that's being generated as single photons.
This helps in giving a theoritical prediction of how to make selection of signals and noise.
```
![](http://geekresearchlab.net/coursera/neuro/retina-g-3.jpg)
```
2. Circuitry points
-- The circuitry points are likely the location at synapse between rods and rod bipolar cells.
-- Rod bipolar cell seems to receive multiple inputs.
Combination of multiple inputs in a linear manner.
```
```
3. Direct recording
-- Majority of rod single photon responses were rejected.
```
![](http://geekresearchlab.net/coursera/neuro/retina-g-4.jpg)
```
The plots above were kinda misleading...
```
```
Here is an improved way of representing the distribution.
```
![](http://geekresearchlab.net/coursera/neuro/retina-g-5.jpg)
```
Now, the question is,
What will happen to the visual threshold (like 1 in 1000 rods absorb the photons)?
The second chart shows it (in the above diagram).
The maximum amplitude is gained from the rod associating with the noise and then, associating with signal.
This helps in predicting the position of non-linearity.
```
<br>
![](http://geekresearchlab.net/coursera/neuro/retina-g-6.jpg)
6 changes: 3 additions & 3 deletions Week-4/Quiz/Information-Theory&Neural-Coding.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ This exercise is based on a set of artificial "experiments" that we've run on fo

In the first set of experiments, we probed each neuron with a range of air velocity stimuli of uniform intensity and differing direction. We recorded the firing rate of each of the neurons in response to each of the stimulus values. Each of these recordings lasted 10 seconds and we repeated this process 100 times for each neuron-stimulus combination.

We've supplied you with a .mat file for each of the neurons that contains the recorded firing rates (in Hz). These are named neuron1neuron1, neuron2neuron2, neuron3neuron3, and neuron4neuron4. The stimulus, that is, the direction of the air velocity, is in the vector named stimstim.
We've supplied you with a .mat file for each of the neurons that contains the recorded firing rates (in Hz). These are named neuron1, neuron2, neuron3, and neuron4. The stimulus, that is, the direction of the air velocity, is in the vector named stimstim.

The matrices contain the results of running a set of experiments in which we probed the synthetic neuron with the stimuli in stim. Each column of a neuron matrix contains the firing rate of that neuron (in Hz) in response to the corresponding stimulus value in stimstim. That is, n\text{th}nth column of neuron1neuron1 contains the 100 trials in which we applied the stimulus of value stim(n) to neuron1neuron1.
The matrices contain the results of running a set of experiments in which we probed the synthetic neuron with the stimuli in stim. Each column of a neuron matrix contains the firing rate of that neuron (in Hz) in response to the corresponding stimulus value in stimstim. That is, nth column of neuron1 contains the 100 trials in which we applied the stimulus of value stim(n) to neuron1.

Plot the tuning curve-- the mean firing rate of the neuron as a function of the stimulus-- for each of the neurons.

Expand Down Expand Up @@ -170,7 +170,7 @@ In order to realize why this might be helpful, consider the fact that, for a con
Ansewer:
Neuron 3.

## 9.
## 9. What is the direction, in degrees, of the population vector?

Continued from Question 7:

Expand Down
31 changes: 31 additions & 0 deletions Week-4/Quiz/Programming/Python/pop3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pickle

import numpy as np


def load_data(path):
with open(path, 'rb') as f:
data = pickle.load(f)
return data


# question 9
data = load_data("pop_coding_3.4.pickle")

c = [data['c1'], data['c2'], data['c3'], data['c4']]
r = [data['r1'], data['r2'], data['r3'], data['r4']]

data = load_data("tuning_3.4.pickle")

stim = data['stim']
n = [data['neuron1'], data['neuron2'], data['neuron3'], data['neuron4']]

n_max = [np.max(np.mean(ni, axis=0)) for ni in n]

arg = np.divide([rr.mean() for rr in r], n_max)

popultion = np.multiply(c, arg.T)
popultion = popultion.sum(axis=1)
angle = np.arctan(-popultion[0] / popultion[1])
answer = 180 - angle * 180.0 / np.pi
print(answer)
59 changes: 59 additions & 0 deletions Week-4/Quiz/Programming/Python/pop_vector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
Finally, we ran an additional set of experiments in which we exposed each of the
neurons to a single stimulus of unknown direction for 10 trials of 10 seconds
each. We have placed the results of this experiment in the following file:
pop_coding contains four vectors named r1, r2, r3, and r4 that contain the
responses (firing rate in Hz) of the four neurons to this mystery stimulus.
It also contains four vectors named c1, c2, c3, and c4. These are the basis
vectors corresponding to neuron 1, neuron 2, neuron 3, and neuron 4.
Decode the neural responses and recover the mystery stimulus vector by computing
the population vector for these neurons. You should use the maximum average
firing rate (over any of the stimulus values in 'tuning.mat') for a neuron as
the value of rmax for that neuron. That is, rmax should be the maximum value in
the tuning curve for that neuron.
What is the direction, in degrees, of the population vector? You should round
your answer to the nearest degree. Your answer should contain the value only (no
units!) and should be between 0∘ and 360∘. If your calculations give a negative
number or a number greater than or equal to 360, convert it to a number in the
proper range (you may use the mod function to do this).
You may need to convert your resulting vector from Cartesian coordinates to
polar coordinates to find the angle. You may use the atan() function in MATLAB
to do this. Note that the the convention we're using defines 0∘ to point in the
direction of the positive y-axis and 90∘ to point in the direction of the
positive x-axis (i.e., 0 degrees is north, 90 degrees is east).
"""

import numpy as np
import pickle

FILENAME = 'pop_coding_3.4.pickle'

with open(FILENAME, 'rb') as f:
data = pickle.load(f)

c = [data['c1'], data['c2'], data['c3'], data['c4']]
r = [data['r1'], data['r2'], data['r3'], data['r4']]

basis_vector = []
for rr, cc in zip(r, c):
# Calculate the weighted basis vector
nr = rr / rr.max()
mean_vector = np.outer(nr, cc).mean(axis=0)

# Normalize the vector
mean_vector /= np.sqrt(np.inner(mean_vector, mean_vector))

basis_vector.append(mean_vector)

print('Weighted basis vectors: %s' % basis_vector)

# Only take the first two, because the rest are nan
pop_vector = np.nansum(basis_vector, axis=0)
pop_vector /= np.sqrt(np.inner(pop_vector, pop_vector))

print('Population Vector (X, Y): %s' % pop_vector)
print('Population vector in polar coordinates: %f' % np.arctan(pop_vector[1]/pop_vector[0]))
84 changes: 84 additions & 0 deletions Week-4/Quiz/Programming/Python/tuning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""
Created on Wed Apr 22 15:15:16 2015
Quiz 2 code.
This exercise is based on a set of artificial "experiments" that we've run on
four simulated neurons that emulate the behavior found in the cercal organs of a
cricket. Please note that all the supplied data is synthetic. Any resemblance to
a real cricket is purely coincidental.
In the first set of experiments, we probed each neuron with a range of air
velocity stimuli of uniform intensity and differing direction. We recorded the
firing rate of each of the neurons in response to each of the stimulus values.
Each of these recordings lasted 10 seconds and we repeated this process 100
times for each neuron-stimulus combination.
We've supplied you with a .mat file for each of the neurons that contains the
recorded firing rates (in Hz). These are named neuron1, neuron2, neuron3, and
neuron4. The stimulus, that is, the direction of the air velocity, is in the
vector named stim.
Plot the tuning curve-- the mean firing rate of the neuron as a function of the
stimulus-- for each of the neurons.
"""

from __future__ import division
import numpy as np
import matplotlib.pyplot as plt

import pickle

FILENAME = 'tuning_3.4.pickle'

with open(FILENAME, 'rb') as f:
data = pickle.load(f)

stim = data['stim']
neurons = ['neuron1', 'neuron2', 'neuron3', 'neuron4']

f, ax = plt.subplots(len(neurons), 1, sharex=True, sharey=True)
for i, n in enumerate(neurons):
ax[i].plot(stim, data[n].mean(axis=0))
ax[i].set_title(n)

plt.xlabel('Air direction [degree]')
plt.ylabel('Spike Rate [Hz]')
f.subplots_adjust(hspace=0.5)
plt.show()


"""
We have reason to suspect that one of the neurons is not like the others. Three
of the neurons are Poisson neurons (they are accurately modeling using a Poisson
process), but we believe that the remaining one might not be.
Which of the neurons (if any) is NOT Poisson?
Hint: Think carefully about what it means for a neuron to be Poisson. You may
find it useful to review the last lecture of week 2. Note that we give you the
firing rate of each of the neurons, not the spike count. You may find it useful
to convert the firing rates to spike counts in order to test for "Poisson-ness",
however this is not necessary.
In order to realize why this might be helpful, consider the fact that, for a
constant a and a random variable X, 𝔼[aX]=a𝔼[X] but Var(aX)=a2Var(X). What might
this imply about the Poisson statistics (like the Fano factor) when we convert
the spike counts (the raw output of the Poisson spike generator) into a firing
rate (what we gave you)?
"""

a = 10.0 # 10Hz
# As mentioned in the hint above
# a E[X] = a**2 Var(X) -> E[x] = a Var(X)
# So test for diversions from the similarity
f, ax = plt.subplots(len(neurons), 1, sharex=True, sharey=True)
for i, n in enumerate(neurons):
y = data[n].mean(axis=0) - a * data[n].var(axis=0)
ax[i].plot(stim, y)
ax[i].set_title(n)

plt.xlabel('Air direction [degree]')
plt.ylabel('E[X] - 10.0 * Var(X)')
f.subplots_adjust(hspace=0.5)
plt.show()

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pickle
import numpy as np

import matplotlib.pyplot as plt
data_path = "tuning_3.4.pickle"
import numpy as np


def load_data(path):
Expand All @@ -10,6 +10,7 @@ def load_data(path):
return data


data_path = "tuning_3.4.pickle"
data = load_data(data_path)
print(f"data.key:{data.keys()}")
# ['neuron4', 'stim', 'neuron3', 'neuron2', 'neuron1']
Expand All @@ -22,7 +23,7 @@ def load_data(path):
ave_n1 = np.average(n1, axis=0)
ave_n2 = np.average(n2, axis=0)
ave_n3 = np.average(n3, axis=0)
ave_n4 = np.average(n4,axis=0)
ave_n4 = np.average(n4, axis=0)

# Question 7
plt.figure(1)
Expand All @@ -42,5 +43,16 @@ def load_data(path):
plt.title("n4")
plt.plot(stim, ave_n4)

# plt.legend()
# question 8
delta1 = 10 * np.var(n1, axis=0) - np.average(n1, axis=0)
delta2 = 10 * np.var(n2, axis=0) - np.average(n2, axis=0)
delta3 = 10 * np.var(n3, axis=0) - np.average(n3, axis=0)
delta4 = 10 * np.var(n4, axis=0) - np.average(n4, axis=0)

plt.figure(2)
plt.plot(stim, delta1, label="n1")
plt.plot(stim, delta2, label="n2")
plt.plot(stim, delta3, label="n3")
plt.plot(stim, delta4, label="n4")
plt.legend()
plt.show()
Loading

0 comments on commit fa8e2df

Please sign in to comment.