Please read this paper for Tuesday, 15 April:
If you need background to understand the stomatogastric network, this will help:
Enjoy,
Heather
Interdisciplinary Neuroscience, Evolution, and Computer Science Discussion Group
Please read this paper for Tuesday, 15 April:
If you need background to understand the stomatogastric network, this will help:
Enjoy,
Heather
Last session we found that it would be nice to save a brief version of the agent’s brain as a text. I added a function to tAgent called “saveBrain” you can use it like this:
agent->saveBrain("filename.txt");
and it will save the brain as a text file which lists each gate and it’s input and output connections.
In order to explore more of the brain anatomy in a quantitative way I also added a function called “memNodes” it is defined as:
vector<double> memNodes(void);
and returns a vector of three doubles. The first is the number of nodes that are connected with themselves, something that intuitively looks like memory. The second number is the number of connections that go back and forth between two nodes like this: A->B and B->A. The third number is the number of all connections between all nodes. This one can be used to normalize the first two results which are raw counts.
Please find the new tAgent.h and tAgent.cpp here:tAgent
Cheers Arend
Hi all.
You can download a PDF of the Chittka and Niven paper from Lars Chittka’s website. Here’s the link:
http://chittkalab.sbcs.qmul.ac.uk/2009/ChittkaNivenCurrBiol09.pdf
Again, we’re going to discuss this paper at our meeting on Tuesday 8 April.
Best,
Heather
In todays lecture we implemented the basics of the judgement task. Here is the code for everyone to download:
JudgementTask
Unpack those files and replace your files in the project with these new ones and all should be good.
Cheers Arend
The last command I am going to talk about in this series is the command for. Together with the variables, while, and if it makes about 80% of all programming, the secret is only to put them together in a meaningful way. For is technically nothing else than a sophisticated while command. for allows you to execute a command a set couple of times:
int i; for(i=0;i<100;i++) printf("%i\n",i);
The above code does the following: In the first part of the for command it sets i=0 and then executes the next line (the printf) as long as i<100 - very similar to the while from last time, and technically they are the same. Lastly there is this i++ which is first of all a fancy way of saying i=i+1 but also this little thingy gets executed every time as well. There for the above code does exactly the same as:
int i; i=0; while(i<100){ printf("%i\n",i); i=i+1; }
It if just easier to write the for loop than the multiple lines the while requires.
Cheers Arend
The command “while” allows you to execute other commands until a certain criterion is met. It is very similar to if, because it also evaluates the truth of a statement, and while that truth is met, it executes the next command again and again and again, until the statement becomes false:
int i; i=0; while(i<100) i=i+1;
The above example might be simple but it illustrates a way to count to 100. Again like the if, in case you want to execute more than one command use {}:
int i; i=0; while(i<100){ i=i+1; printf("%i\n",i); }
The above code not only increments i a hundred times, it also prints it out.
Cheers Arend
What are all those numbers and variables good for when all you need is to make a decision? What I am going to write about is called “flow control” because the “flow” of the program to do one or the other thing is controlled, and one of the many ways of doing that is by using the command “if”. Technically “if” assesses the truth of a statement, and either does something or it doesn’t. To do so, if uses a couple of comparisons operators like bigger > or smaller <. To come up with a stupid example imagine you want to pay a bonus to your employee once more than say 100 donuts were sold:
if(donuts>100) payment=payment+bonus;
Simply put if the statement within the () is “true” the next line gets executed, otherwise skipped. If you need to make a couple of commands dependent on your if, use {} and everything within those {} (called scope) gets executed:
if(donuts>100){ payment=payment+bonus; printf("You received a bonus!"); }
The printf in there just puts text to the command line. There are two other important comparators besides < and > which are == (equal) and != (unequal). The thing that will drive you nuts is this double equal sign to indicate a comparison, opposed to the single equal sign which indicates that what is left of it is assigned to what is to the right.
One last thing is the “else”:
if(donuts>100){ payment=payment+bonus; printf("You received a bonus!"); } else { printf("Work harder!"); }
Which does nothing else than to allow you to execute something else in case the condition within the if is not met.
Cheers Arend
As promised, let me talk about fancier ways of making arrays, namely vectors. We just “learned” that you can create an array using [] and that you can use those [] to address a particular element in the array:
int a[10]; a[4]=5;
But what if I don’t know how large my array should be beforehand? That is why we have vectors. Check this out:
vector<int> a; a.resize(10); a[4]=5;
The above code creates a vector that will contain ints called a and afterwards we set it’s size to 10. Once that is done the variable a behaves exactly like a classic array of that size. Well not exactly because vector
vector<int> a; int i; a.clear(); // removes every element from the vector a.push_back(4); // adds the value 4 to the end of the vector i=a.size(); // .size() will tell you how long the vector is, in this case 1, so that now i has the value of 1
And to blow your mind, vectors can be nested to create multidimensional structures:
vector<vector<int> > a; // //code to initialize every thing properly //which I will not put here right now //Note the space in between the two right-angle brackets "> >" above. This is necessary*. // a[10][10]=4;
In case you wanted to make something like a checker board …
Cheers Arend
Next Tuesday we are going to code a little more, and I wanted to give you a simple intro into C++. However, C++ requires more than a simple intro, but just so that you can tag along with what is going on I am going to give a set of these briefings. This one is about variables.
Variables are used to store data in them … nothing more nothing less. But C++ is very narrow minded about what type of data each variable can store, you can not simply write everything into any variable – everything has to go where it belongs. That is why variables have types. The second thing C++ insists on is knowing beforehand that you want to use a particular variable, you can not simply say “store this value here!”, the “here” has to be defined well beforehand. That is why somewhere close to the top of your program you see things like this:
int i; float f; double d; char c;
The above piece of code does nothing else than telling the compiler it would like to use a couple of variables called i,f,d, and c. It also makes sure that these four variables have four different types int (for integers that are whole numbers -2, 0, 12231, …), float and double (which are floating point numbers like 0.00121, 123.2, …) where the only difference is the precision because doubles are “twice” as accurate than floats, and lastly a char (which is a character that stores letters like ‘a’,’t’, or the character ‘0’).
Whenever you want to assign a value to a variable you need the = sign. It will take whatever is to the right of it, evaluate it, and dump it in whatever is on the left side of the equal sign. But what does “evaluate” mean in this context? Simply put, it performs the math that you might potentially want to do. Check out the following piece of code which makes it more obvious I hope:
i=5; // now i has the value 5 stored in it i=(5+5)*(7-1); // now i has the value 60 stored in it, the 5 that it held before is gone i=i-30; // i is now 30, because the right hand side was evaluated first, and at that moment i was still 60
So far so good, now to somewhat more complex variables, namely arrays. Arrays or vectors were invented to allow variables to have an index and to make lists. Check out this piece of code:
int a[10]; a[1]=656; a[3]=0;
Instead of making a single variable a, which is supposed to be an int, the [] blocky brackets create as many of these a’s as stated within the brackets. In this case you get ten variables a, and in order to differentiate between them, you can use the [] again to tell them apart. a[0] is the first one, followed by a[1], and the last in the bunch is a[9] – and yes C++ starts counting at 0.
Last one: Instead of specifying elements in an array with a constant value like a[0] you can replace the 0 with another variable:
int a[10]; int i; i=9; a[i]=i;
This will set the value of a[9] to 9. I let this sink in for a moment. Next time I talk about fancier ways of making arrays.
Cheers Arend
Just in case, and so that we have another place to download, here is the code template package:
Cheers Arend