Posts

Showing posts from July, 2017

Stocastic models and mathematics

I have been studying different models, and it seems I neglected stocastic models. This however are needed to analyse agent based models. My time for submission of proposal is running out, and it seem I will have to learn a bit about statistical modeling before I proceed in well informed manner. There seems to be network models but which i figured are similar to discrete time models. Similar to state based models. I think at the end as much as the computing modeling community want to stay away from the math, math is inescapable so to speak. Math fobia is not the solution to design of modeling, infact math is the utopia of all modeling. Mathematics represents resources, logical or algebraic intellectual tools that can be used across many fields. It is formal language that is meant to formalize our loose statements in science. Useful resource. I think its value derives in its hierachical development, logical consistency. but also its reasoning capability. I think the war between fun...

Amazing paper period.

https://arxiv.org/pdf/1006.0408.pdf

Modeling Part 1

I am back at modeling now. I am reading agent based modeling and individual based modeling by steven railback et.al. Thinking out loud, it gets me thinking about the different types of models. 1. deterministic 2. non deterministic and the subgategories goes like 1. deterministic 1.1 traditional mathematical models ( aggregate models) 2. non deterministic 2.1 statistical models ( sample models ) 2.2 individual based models( individual models ) The models differ in the way they treat their variables. With traditional mathematical models, the variables are aggregates of similar type, eg number of people, height, age, etc. These are what we call quantities, infact quantity is an aggregate of similar things. Traditional mathematics models things by first quantifying and then finding equations that represent the quantity as it changes in time. Normally this is represented using differential equations( it can be done using plain functions however, with a note that s...

99 lisp problems

Here is the solutions to 99 lisp problems so far. I am Problem 11. ;P01 (*) Find the last box of a list. ;Example: ;* (my-last '(a b c d)) ;(D) to my.last :list ifelse emptyp butfirst :list [output first :list] [output my.last butfirst :list] end to my.last2 :list output last :list end ;P02 (*) Find the last but one box of a list. ;Example: ;* (my-but-last '(a b c d)) ;(C D) to my.but.last :list ifelse emptyp butfirst butfirst :list [output :list] [output my.but.last butfirst :list] end ;P03 (*) Find the K'th element of a list. ;The first element in the list is number 1. ;Example: ;* (element-at '(a b c d e) 3) ;C to element.at :list :index ifelse emptyp :list [output :list] [ifelse equalp :index 1 [output first :list] [output element.at butfirst :list (:index - 1)]] end to element.at2 :list :index output item :index :list end ;P04 (*) Find the number of elements of a list. to number.of.elements :list ifelse emptyp :lis...

Logo

Logo is lisp without brackets and some syntax modifications: fput - cons first - car butfirst - cdr list - list sentence - append templates - lambda cond - cond ifelse - if

Debugging Part 4

As promised here is the solution to P09. I must confess I cheated, I looked up the solution because I couldn't sleep. I kept thinking about the problem in my sleep. So I looked it up to have a peace of mind. The key is knowing the difference between dotted list and proper list in lisp. In logo we can use fput function to simulate cons. So to create a list of a list you had to do something like fput fput 5 [3 4 5] [[3 3 5] [4 5 6]]. Know how to do this properly was key to solving the problem. Lesson learnt: you may have to look up the solution sometimes to avoid wasting so much time in one problem. The key is learning even from solution so that you can solve other problem. Sometimes the key may be little ideas like fput usage above. ;P09 (**) Pack consecutive duplicates of list elements into sublists. ;If a list contains repeated elements they should be placed in separate sublists. ;Example: ;* (pack '(a a a a b c c a a d e e e e)) ;((A A A A) (B) (C C) (A A) (D) (E E E E)...

Debugging Part 3

I am debugging the following program, and I started realising the disadvatanges of blind debugging. I had solved the problem before. And I solved it through debugging. So now faced with the same problem I seem not to remember how I solved it. So here i is the disadvatanges of blind debugging. It is adhoc and prone to blind programming. The other way I like to say it, is it is "hacky". Not hack of breaking computers but that of prototyping something quickly without following principles. I am still in the process of solving the problem below. When I am done, I will let you know how I did it. ;P09 (**) Pack consecutive duplicates of list elements into sublists. ;If a list contains repeated elements they should be placed in separate sublists. ;Example: ;* (pack '(a a a a b c c a a d e e e e)) ;((A A A A) (B) (C C) (A A) (D) (E E E E)) to pack.run :list :item ifelse emptyp :list [output :list] [ifelse equalp first :list :item [output sentence first :list pa...

Debuging Part 2

After having debugged the program, the new program is shown below. I followed a programming pattern with the first program, but that pattern did not the follow the algorithm I had in mind. What I wanted to do was to print the first letter encountered in the list. the previous program printed the last letter. It is interested how debugging to bring that out. And I used the helper function called compress.2.run with two inputs to solve. The technique is worth remembering. I think this is related to another technique of scanning the list twice(ie simumlation of 2 for loops, more on that later). to compress.2.run :list :item ifelse emptyp :list [output :list] [ifelse equalp :item first :list [output compress.2.run butfirst :list :item] [output sentence first :list compress.2.run butfirst :list first :list]] end to compress.2 :list output compress.2.run :list [] end show compress.2 [a a a a b c c a a d d e e e e]

Debuging Part 1

I am debugging the following program below. It is working as expected but I still don't get it. I followed some programming pattern, and then magically it work. But I had to debug it to get what is really happenning. I inserted show statements(print) around the code to print out the the list as the program is running. Now i wanted to say a word about debugging skills for beginner programmers. this is a must have skills. Knowing where to insert your print statements and possibly using stop command is key. I like the vba debug invironment and i have realised I am more productive under vba than most platforms, thanks to the debugger. The debugger is really key. A nice idea like vba enviroment can help beginner programmers understand whats going on behind the hood. Insert those stop statements around the code and seeing what the program is doing while it it is running is really key. ;P08 (**) Eliminate consecutive duplicates of list elements. ;If a list contains repeated...

Recursion Part 3

I just read this by Brian Harvey, the author of berkeley Logo. I must confess that this is an eye opener of the ideas I had in my mind about the hierachy of computer abstractions. It turns out recursion is not abstract enough. Functions are more abstract. The idea is not the think what the machine is doing step by step but the have a vision of what you want to archive at top level. Functional programming as first announced by Backus in 1978 goes further than the recursion abstractions and uses APL ideas of dealing with arrays of data(or list) directly. Functions like map(called map-car in list), reduce, and filter are powerful tools in this functional approach. My next exercises will be to use recursion and try to convert the solutions into functional approach as much as I can. I think this is good exercise in general. Many times we ask novices to practice programming exercises but we don't emphasize these programming abstractions and approaches that can help beginners solve ma...

Switching from Lisp to Logo

I switched from learning lisp directly to learning a lisp dilect called logo. I need logo for my research hence this preference. To practice algorithms I am solving some problems from the following site( here ). So far I did 5 out of 99. I hope to do them all. I am using a logo compiler called liogoc. I just found out it does not have cond statement. Well, its not bad since I can use ifelse statement instead. ;P01 (*) Find the last box of a list. ;Example: ;* (my-last '(a b c d)) ;(D) to my.last :list ifelse emptyp butfirst :list [output first :list] [output my.last butfirst :list] end to my.last2 :list output last :list end ;P02 (*) Find the last but one box of a list. ;Example: ;* (my-but-last '(a b c d)) ;(C D) to my.but.last :list ifelse emptyp butfirst butfirst :list [output :list] [output my.but.last butfirst :list] end ;P03 (*) Find the K'th element of a list. ;The first element in the list is number 1. ;Example: ;* (element-at '(a b ...

Recursion Part 2

I am currently practicing lisp and recursion using the following site : https://www.informatimago.com/develop/lisp/l99/ . There 99 problems to be solved. I think I am on number 11. I almost got discouraged working on problem 9. The problem asks to group a list according to the numbers given. eg. (1 3 4 5 5 4 4 4 5 5) will give ((1) (3) (4) (5 5) (4 4 4) (5 5)). To tell the truth I worked on this whole day today, and I couldn't get the brackets right until I had to look it up. The issue was not understanding how to use (list) function. Key is to use (append) and (list (list 'a 'a)) to make a pairs or list of list. But on reflection about my solution this afternoon, I didn't like that it was hacky(not elegant). INfact the solutions on the site are also hacky. Using accumalators in my opinions, during recursive calls is a bit inelagant. He is my final solutions after parching out the inelagant parts. (defun group (l) (labels ((group-run (element group l) ;(forma...

Recursion Part 1

Recursion is art of making programs call themselves. It is my opinion, recursion is the main idea in computer programming. In fact early computer theorist where recursion theorist( eg. church, curry, ackermann,etc). Recursion theory inspired functional programming in the 70s. Functional programming is prefered by these mathematically oriented programmers not only by its elagence but by it suitability to be reasoned with mathematically. Lisp was invented by John Mccathy in 1958. It was also based in recursive theory paradigm. The language in my opinion possesess the beauty of the mathematics it inherited from. It has simple syntax(core language i mean). eg. only 5 primitive operations are defined: car,cdr,cons,eq, and null. Knowing these together with statements for creating functions(lamda or defun) and conditional statements(if, cond) one can derive everything else using the language. I am set to master lisp, not necessary to use as a language in my programming task, but you thi...

Back to programming competitons

I am coming back to programming competitions. and as preparation I am back at a study of recursion. I have bought books and read websites on this topics over the years. Only lately have I thought I made progress. Firstly I must thank God for getting to know lisp. And getting to understand its power. List makes you look at programs in a different way. I never knew a programming language could make a person see the programs different. Also the idea of list forces you to program using data. Very smart. And data is static. You generate output as the program progress. All you should be worried about the final list and the list you consume. It is highly recommended for anyone who wants to do serious programming. A key advantage of engaging in programming competitions is it will boost your programming skills. In my opinion, this is how far it can go. I don't think a good algorithms programmer automatically can make a good software developer. Development in my opinion is another skill,...