Saturday, April 06, 2013

Matlab question marks and exclamation points

Random Matlab things I find cool or perplexing. Updated periodically. Some of the comments are very dense, basically just lines of code I will likely forget, but will want to remember at some point.

5/6/13
To check what mfile is currently running, enter mfilename (useful in debug mode).


4/6/13
1. Filtering an image stored in matrix M:
%build the filter to convolve with the image
imFilt=fspecial('gaussian',10,10);
%convolve them
smoothed=imfilter(M,imFilt,'symmetric','conv');
 
2. To change your gridlines to solid grey without changing the colors of the tick labels:
grid
%make gridlines solid
set(gca,'gridlinestyle','-'); 
%make them grey
set(gca,'Xcolor',[.8 .8 .8],'Ycolor',[.8 .8 .8])
%unfortunately, the above changes everything to grey

%copy the axes
c=copyobj(gca,gcf);
%redo them in black. 
set(c,'color','none','xcolor','k','xgrid','off', ...
    'ycolor','k','ygrid','off','Box','off');

8/24/12
If your Windows machine doesn't show the .mat file extension (and you have already unclicked 'Hide extensions for known file types' in your folder options menu) you can fix it within an open folder. First, select Tools->Folder Options->File Types-->New. A GUI to create a new extension will open: type MAT in the field. Then click 'Advanced' and select Matlab Data from the list. It will warn you that this is already associated with a different file type. Accept the change. Problem solved. I stole this simple solution here, and Matlab has a page about it here.

7/9/12
1. If you have a cell array that contains strings, and want to get a numeric array with 1's where a particular string occurs, and 0's otherwise, you can use the cellfun function coupled with strfind: 
>>out=~cellfun('isempty', strfind(cell_array,'string'));

2. Why doesn't the following yield a 1?
>>NaN==NaN


3/24/12
You can use plotyy to display data on different y axes in the same figure. While there isn't presently a scatteryy command (why?), you can try something like the following:
>>[ax,h1,h2]=plotyy(x1,y1,x2,y2);
>>set(h1,'LineStyle','o');

2/17/12
1. It would be cool if, on a documentation page for a function, it let you click on a 'function history' link that showed when the function was introduced, and the changes added with each version.

2. Check out the grpstats function. Enter your data, and the group assigned to each data point, and it calculates all sorts of statistics sorted by group (e.g., mean, standard error, standard deviation, etc). I had done this on my own, but their function is better than what I had.

3. Why isn't the following legal?
>>scatter(x,y,'Color',[a b c])
Why must we use CData (and not Color) for scatter plots?

Saturday, May 12, 2012

What is a p value?

For nonscientists reading scientific papers, one of the most daunting aspects is the constant mention of 'p-values.' What is a p-value? It is a number associated with a statistical test, and you need to just know two things to understand p-values enough to get you through a paper.

First, statistical tests look for differences between two things. That is, every statistical test tries to determine if one thing is different from something else. The things being compared vary greatly. Is this mean different than that mean? Is this distribution of people's heights different than that distribution? The null hypothesis is that the two things being compared are actually the same.

The second thing to understand is the p-value itself. The p-value is the probability of observing what you did if  there is no difference between the two things.That is, how likely are you to make the measurements you made if you assume the null hypothesis is true?

Two corollaries:
a. If the p-value is very high (e.g., 0.99), that means it is likely that the two quantities you are comparing are not in fact different, i.e., that the null hypothesis is true. E.g., the two means are the same, or the distribution of heights is the same.
b. If the p-value is very low (convention is below 0.05), this suggests that the two quantities you are comparing are different, i.e., that the null hypothesis is not true.E.g., the two means are different, or the distribution of heights is different.

------------------------

For the mavens:  technically the p-value is the probability of observing what you did, or a more extreme value, but that is a wrinkle that makes things too complicated for a dirty synopsis.

Friday, January 20, 2012

Filtering images in Matlab

Given image stored in matrix M:

%build the filter to convolve with the image
imFilt=fspecial('gaussian',10,10);
%convolve them
smoothed=imfilter(M,imFilt,'symmetric','conv');

Monday, November 07, 2011

Prepping for SFN

Alone in Bryan Research Building. Surprised there aren't more people here furiously getting their posters ready...

Monday, July 25, 2011

Catterall's group cracks the (closed) sodium channel

I haven't read it yet, so have no comments, just wanted to get the abstract here so I don't forget to take a closer look.

Reference
Payandeh, Scheuer, Zheng, Catterall (2011) The crystal structure of a voltage-gated sodium channel. Nature 475: 353-358.
Pubmed link

Abstract
Voltage-gated sodium (NaV) channels initiate electrical signalling in excitable cells and are the molecular targets for drugs and disease mutations, but the structural basis for their voltage-dependent activation, ion selectivity and drug block is unknown. Here we report the crystal structure of a voltage-gated Na+ channel from Arcobacter butzleri (NavAb) captured in a closed-pore conformation with four activated voltage sensors at 2.7 Å resolution. The arginine gating charges make multiple hydrophilic interactions within the voltage sensor, including unanticipated hydrogen bonds to the protein backbone. Comparisons to previous open-pore potassium channel structures indicate that the voltage-sensor domains and the S4–S5 linkers dilate the central pore by pivoting together around a hinge at the base of the pore module. The NavAb selectivity filter is short, ~4.6 Å wide, and water filled, with four acidic side chains surrounding the narrowest part of the ion conduction pathway. This unique structure presents a high-field-strength anionic coordination site, which confers Na+ selectivity through partial dehydration via direct interaction with glutamate side chains. Fenestrations in the sides of the pore module are unexpectedly penetrated by fatty acyl chains that extend into the central cavity, and these portals are large enough for the entry of small, hydrophobic pore-blocking drugs. This structure provides the template for understanding electrical signalling in excitable cells and the actions of drugs used for pain, epilepsy and cardiac arrhythmia at the atomic level.

Thursday, June 03, 2010

Consciousness (15): Opening the time capsule

Table of Contents of posts on consciousness.
-------------------------------------

Below you'll find a series of quotations that highlight the topics we have been discussing in the last nine posts. I chose them for their exceptional eloquence, clarity, and influence. They are not in chronological order, but are roughly in ascending order of specificity of the claims. This will be the final post in this narrative arc.

The quotes
[V]ision is the process of discovering from images what is present in the world, and where it is.
     -David Marr (1982)
We may define visual perception as attributing objects to images.
     -Richard Gregory (2009)
Visual perception involves coordination between sensory sampling of the world and active interpretation of the sensory data. Human perception of objects and scenes is normally stable and robust, but it falters when one is presented with patterns that are inherently ambiguous or contradictory. Under such conditions, vision lapses into a chain of continually alternating percepts, whereby a viable visual interpretation dominates for a few seconds and is then replaced by a rival interpretation. This multistable vision, or ‘multistability’, is thought to result from destabilization of fundamental visual mechanisms, and has offered valuable insights into how sensory patterns are actively organized and interpreted in the brain…
     -Nikos Logothetis (2002)
[The Necker cube] has an interesting property. Look at it fairly steadily for a while, and the cube will invert, as if it were being viewed from another angle. After a time the percept switches back to the original one, and so on. In this case there are two equally plausible 3D interpretations of the image, and the brain is uncertain which it prefers. Notice that it only chooses one at a time, not some odd mixture of both of them…

The reason you normally see without ambiguity is that the brain combines the information provided by the many distinct features of the visual scene (aspects of shape, color, movement, etc) and settles on the most plausible interpretation of all these various visual clues taken together…[W]hat the brain has to build up is a many-leveled interpretation of the visual scene, usually in terms of objects and events and their meaning to us.
     -Francis Crick (1995)
We don’t directly experience what happens on our retinas, in our ears, on the surface of our skin. What we actually experience is a product of many processes of interpretation—editorial processes, in effect. They take in relatively raw and one-sided representations, and yield collated, revised, enhanced representations, and they take place in the stream of activity occurring in various parts of the brain. This much is recognized by virtually all theories of perception…
     -Dan Dennett (1991)
The mental activities that lead us to infer that in front of us at a certain place there is a certain object of a certain character, are generally not conscious activities, but unconscious ones. In their result they are equivalent to a conclusion, to the extent that the observed action on our senses enables us to form an idea as to the possible cause of this action; although, as a matter of fact, it is invariably simply the nervous stimulations that are perceived directly, that is, the actions, but never the external objects themselves. But what seems to differentiate them from a conclusion, in the ordinary sense of that word, is that a conclusion is an act of conscious thought… Still it may be permissible to speak of the mental acts of ordinary perception as unconscious conclusions, thereby making a distinction of some sort between them and the common so-called conscious conclusions.
     -Hermann von Helmholtz (1866)
Perception consists of interpreting two-dimensional retinal images of a three-dimensional world. The process of projecting a three-dimensional scene onto a two-dimensional retina necessarily discards information about the three-dimensional structure of the scene. This makes it impossible, in principle, to deduce all of the three-dimensional structure of a scene…However, even though such problems cannot be solved by deduction, acceptable solutions can be found using statistical inference.
     -JV Stone (2009)
Our visual experience evidently is the product of highly sophisticated and deeply entrenched inferential principles that operate at a level of our visual system that is quite inaccessible to conscious introspection or voluntary control. We do not first experience a two-dimensional image and then consciously calculate or infer the external three-dimensional scene that is most likely, given that image. The first thing we experience is the three-dimensional world—as our visual system has already inferred it for us on the basis of the two-dimensional input. Hermann von Helmholtz, the great nineteenth century scientist who more than any other single individual laid the foundations for our present understanding of visual and auditory perception, expressed this by characterizing perception as “unconscious inference.”
     -Roger Shepard (1991)
[T]he brains’ representations are hypotheses, predictive like the hypotheses of science. Like science, perception bets from available evidence on what is likely to be true…For perception, there is always guessing and going beyond available evidence. On this view, the closest we ever come to the object world is by somewhat uncertain hypotheses, selected from present evidence and enriched by knowledge from the past. Some of this knowledge is inherited—learned by the statistical processes of natural selection and stored by the genetic code. The rest is brain-learning from individual experience, especially important for humans.
     -Richard Gregory (2009)
It is the business of the brain to represent the outside world. Perceiving is not just sensing but rather an effect of sensory input on the representational system. An ambiguous figure provides the viewer with an input for which there are two or more possible representations that are quite different and about equally good, by whatever criteria the perceptual system employs. When alternative representations or descriptions of the input are equally good, the perceptual system will sometimes adopt one and sometimes another. In other words, the perception is multistable.
     -Fred Attneave (1971)
We have suggested that the biological usefulness of visual consciousness in humans is to produce the best current interpretation of the visual scene in the light of past experience, either of ourselves or of our ancestors (embodied in our genes), and to make this interpretation directly available, for a sufficient time, to the parts of the brain that contemplate and plan voluntary motor output, of one sort or another, including speech.
     -Francis Crick and Christof Koch (1998)

References
Attneave, F (1971) Multistability in perception. Sci Am. 6: 63-71.

Crick, Francis (1995) The Astonishing Hypothesis: The Scientific Search for the Soul. Scribner.

Crick, F, and Koch, K (1998) Cerebral Cortex, 8:97-107.

Dennett, D (1991) Consciousness Explained. Back Bay Books.

Gregory, RL (2009) Seeing Through Illusions. Oxford University Press.

Helmholtz, H. von 1866 Concerning the perceptions in general. In Treatise on physiological optics, vol. III, 3rd edn (translated by J. P. C. Southall 1925 Opt. Soc. Am. Section 26, reprinted New York: Dover, 1962).

Leopold, Wilke, Maier, and Logothetis (2002) Stable perception of visually ambiguous patterns. Nature Neuroscience 5: 605-609.

Marr, D (1982) Vision. WH Freeman, NY.

Shepard, RN (1991) Mind Sights, W.H.Freeman & Co Ltd.

Stone, JV, Kerrigan, IS, and Porrill, J (2009) Where is the light? Bayesian perceptual priors for lighting direction. Proc R Soc B 276: 1797-1804.

-------------------------------------
Table of Contents of posts on consciousness.

Friday, May 28, 2010

Consciousness (14): Interpretation Mechanics

Number fourteen in my series of posts on consciousness. Table of Contents is here.
-------------------------------------

The perception-as-interpretation view, summarized in the previous post, is useful as an informal ordinary-language hypothesis about consciousness. However, it is obviously a long shot from a final literal scientific theory. While it seems to be a useful way of speaking, I think we should look at it as an interesting suggestion, or perhaps even an inspiration that will lead us toward a more specific and fleshed-out theory.

There is a diverse range of theories that turn out to be special cases of the perception-as-interpretation hypothesis. These theories describe the interpretation-building mechanism alternatively as neuronal ‘model building’, ‘emulation,’ ‘virtual reality construction,’ ‘simulation of a world’, or ‘unconscious inference.’ Each specific theory carries slightly different assumptions about how the brain constructs experience, but most of them share two or more of the general features of the interpretation view delineated in previous posts.

Among psychologists, the most influential of these views is that the brain uses an unconscious inference procedure to construct a hypothesis about the source of a retinal projection. Because this theory of perception is so interesting, influential, and useful, I’ll describe it in a little bit of detail before stepping back to speak more generally about all of these theories.

Marty the Brain Scientist
To help us understand this theory, let’s imagine a tiny scientist, Marty, who lives and works in your brain (Figure 1). His sole occupation, every moment, is to monitor the movies playing on your retinae, and to build a hypothesis about their source in the world. Our conscious experience is identical to the specific hypotheses that Marty generates. For instance, if Marty’s best hypothesis about the source of the stimuli is that there is a red ball three feet to your left, that is precisely what you will see. Marty is fairly motivated to generate hypotheses accurately and quickly: after all, if you die, he dies. The more accurate his hypotheses, the better you will be able to interact with the world.

Figure 1: Marty the brain scientist.


Retinal movies are Marty’s primary source of evidence. He uses such evidence, along with various assumptions and background knowledge about how the world works, to generate hypotheses about the source of the observed projections (that is, he makes an inference about the source of the stimuli). We are only conscious of the outputs of Marty’s vocation, not any details of his inference-generating procedures. Hence the hypothesis that perception is unconscious inference.

Hypothesis formation is a special case of inference. It is a type of inference that doesn't enjoy the level of certainty granted to deductive inferences (as you’d find in mathematical proofs). Rather, when we form a hypothesis we are often throwing out our best hunch, an educated guess based on limited evidence and previous assumptions about the way the world works. Philosophers sometimes call this type of inference an ‘inference to the best explanation’ or ‘abductive inference.’

For instance, say the evidence we wish to explain includes late-night scratching sounds in the cupboard and small fecal nuggets deposited in the pantry. We could use such evidence, and our general understanding of how the world works (mice are nocturnal, etc), to construct a hypothesis that would best explain the evidence. In this case, we would likely hypothesize that there are mice living in our kitchen. Perhaps Marty settles on his hypotheses about visual stimuli using a similar process of abductive reasoning.

Obviously, Marty is merely a useful fiction. Nobody thinks there is literally a little man in your head viewing your retinal movies. Advocates of this theory believe that we will ultimately be able to give a more literal story that describes how brains construct hypotheses based on information coming in from the retinae. In the meantime, I should spell out why the unconscious inference theory appeals to psychologists.

The appeal of the theory
There are three main reasons for the theory’s appeal (aside from its impressive intellectual pedigree since Helmholtz (1866)). For one, the theory would explain how certain illusions are generated. For instance, recall Shepard’s Monsters (Figure 2) from post eleven. Shepard explains the illusion as follows:
[T]he linear perspective of the subterranean tunnel (along with other depth cues, such as the relative heights of the projections of the two monsters on our retinas) supports the automatic perceptual inference that one of the two monsters is farther back in depth. The two monsters, nevertheless being exactly the same size in the drawing, subtend the same visual angle at the eye [i.e., their projections occupy the same surface area on the retinae]. The visual system therefore makes the additional inference that in order to subtend the same visual angle, the monster that is farther back in depth must also be larger.
Notice how the idea of inference-making is built into multiple layers of Shepard’s explanation of the illusion. The brain makes inferences about which monster is further away, and then uses this information to make further inferences about which monster is larger, which explains why one monster looks bigger than the other. Note the claim isn’t that the brain only uses inferences in cases of illusions (how would the brain know if it were seeing an illusion or not?), but that illusions help reveal the underlying inferential machinery of normal perception.

Figure 2: Terra Subterranea, or Shepard’s Monsters


A second appeal is that the theory finds a mathematical home in probability theory and statistics. The brain lives in an uncertain world, and even the brain’s own responses to identical stimuli are not the same every single time (that is, the brain itself is a “noisy” processor). In mathematics, the principles of sound inference in such uncertain contexts are provided by statistics. Couching theories of brain function in the language of probability and statistics allows psychologists to state their theories with more rigor than can be done in ordinary language. Perhaps most importantly, such theories allow them to generate quantitative predictions that can be tested against the data.

Figure 3: The eye lives between a noisy brain and an uncertain world.


The third appeal applies to the ‘unconscious’ side of the ‘unconscious inference’ thesis. That is, it seems pretty clear that the processes which generate our perceptual experiences are not consciously accessible to us (as discussed in post ten and post thirteen).

Hopefully this gloss on the unconscious inference theory of perception was half as fair as it was brief. At this point I don’t want to push too hard against it (for instance, you would be right to ask what it means for the brain to perform an inference). Rather, my goal was to showcase the most prominent species of the perception-as-interpretation thesis. More than one-hundred years after Helmholtz initially suggested the hypothesis that perception is unconscious inference, Fodor and Pylyshyn were able to describe the theory, without much overstatement, as the ‘Establishment theory' of perception.

Representations within interpretations
Enough with unconscious inferences: what about all the other theories I mentioned above, such as the view that the brain builds a ‘simulation’ of the world? I am going to avoid jumping down the historical rabbit hole of comparing/contrasting the often subtle differences in this panoply of psychological-level theories of perception. Rather, it will be more productive to extract a common denominator shared by all of these theories, something all of the advocates would agree upon. If such a common factor turns out to be useful and correct, then great. If not, then we will have eliminated an entire class of models of perception with one parsimonious swing of the blade. This seems much easier than starting by contrasting every such theory pair in detail.

The one theoretical commitment shared by all these theories of perception is that the brain constructs representations of the world, and the contents of such neuronal representations are the contents of experience. Our first priority will be to analyze this idea of neuronal ‘representation’: what the heck does it mean, and how far can it take us in our quest to understand visual experiences?

While I won’t analyze the notion yet, the notion of a ‘representation’ should be intuitively familiar to most of us. Three squiggly lines on a map represent water. A photograph of someone represents the person. I’ve already sneaked in the claim that the brain constructs a ‘portrait’ of the world: a portrait of something is one type of representation. The claim we will evaluate is that one component of the brain’s interpretation of a stimulus is an internal representation of the world constructed partly based on that stimulus.

Before heading into brains, however, in the next post I will finish this chapter by posting a broad range of quotations from the literature on the topics we have explored in the last eight posts. This will help us to see how these ideas of interpretation, simulation, representation, etc are used in practice.

References
Fodor, JA, and Pylyshyn ZW (1981) How direct is visual perception? Cognition 9: 139-196.

Helmholtz, H. von 1866 Concerning the perceptions in general. In Treatise on physiological optics, vol. III, 3rd edn (translated by J. P. C. Southall 1925 Opt. Soc. Am. Section 26, reprinted New York: Dover, 1962).

Shepard, RN (1991) Mind Sights, W.H.Freeman & Co Ltd.

-------------------------------------
Table of Contents of my posts on consciousness.