Saturday, November 6, 2010

Geometric proof of sum(1 to n)

Ah, geometric proofs, so graphic, so intuitive and clear, so fitting to the way our brain works. I remember that last year I spent some time doubting Pythagoras' proof of c2 = a2 x b2, it sent me on a survey for all existing proofs, many of the more graphical ones did not 'really' convince me, specially when they involved rotating or moving shapes and then made claims about them fitting somehow, Euclid's proof on wikipedia did a better job, one of it's 'less convincing' points being the triangle area lemma. When I look at it I am pretty sure it came out of intuition (like most good proofs) and then the 'formal' proof got put into pieces after having 'devised a plan for the solution' as George Polya would put it in his classic book: HOW to solve it.

Still, it made me like geometric proofs more than I used to -- and the reason I liked algebraic ones more, in retrospect is because of the history of my Math teachers -- and so I started scribbling... I came up with a couple of tiny nice geometric proofs.

The first one is proving that and that . The key idea is (like the start of Pythagoras' theorem) is to use area when multiplying numbers by each other, and then figuring out a relationship between the resulting shapes (in this case all rectangles) and writing it down:


Another, nicer proof is the one for the sum of 1 to n being equal to n(n+1)/2 :
There are many ways to proove this one, by induction per example, or geometrically as demonstrated in one of the discrete math video lectures I am using. However, the geometric proof used there involves having to rotate shapes and comparing them, I did not really like that, so I tried to come up with a clearer proof and I found out that it is possible, I have not seen a proof that did it exactly this way, so here it is:


The idea is that we know that the square in the figure has n x n 'dots' in it, we therefore know that cutting in half by the diagonal, we have dots. This 'almost' covers the total number of dots (the answer we are looking for) and might not even be an integer.
We can see that all the last dots are cut by the diagonal in half, and those halves are all what is missing to account for the missing rest, therefore, we add them.
We have n halves since we have n rows, so adding to , we get the final answer: . We did it without having to move shapes, rotate them or compare their lengths. And that is nice!



Thursday, October 21, 2010

So I tried 'Star Wars, the force unleashed II, Demo' on PS3 for half an hour.



Of course I was not being nice, did not play along and built all sorts of contraptions. But hey ... I was simply using 'the force' the way Vader taught me.

Follow the discussion here: http://forums.aigamedev.com/showthread.php?t=4516
.

Sunday, October 17, 2010

Know your induction, deduction and logical implication.

Induction:

Induction in colloquial English means 'educated guess', Mathematical induction however, is a kind of deductive reasoning, unlike plain 'induction'.

Deduction:

An argument is valid if it is impossible both for its premises to be true and its conclusion to be false. An argument can be valid even though the premises are false.

Deductive arguments are generally evaluated in terms of their validity and soundness, For a deductive argument to be considered sound the argument must not only be valid, but the premises must be true as well.

Logical implication:

Many writers draw a technical distinction between the form ``p implies q " and the form ``if p then q ". In this view, writing ``p implies q " asserts the existence of a certain relation between the logical value of p and the logical value of q while writing ``if p then q " simply forms a compound sentence whose logical value is a function of the logical values of p and q . Notice that a relation is a mathematical object while a sentence, whether open or closed, is a syntactic form that exists in the domain of signs.


How young students understand this: Students' understandings of logical implication

.

Friday, October 15, 2010

sqrt(prime) is irrational proof as an excuse for latex training


Proving that the square root of a prime number is a basic discrete math exercise, here is my proof (using my first latex document ever).
Final pdf:
http://jadnohra.net/release/sqrt_prime_irrational.pdf
Source tex file:
http://jadnohra.net/release/sqrt_prime_irrational.tex

.

Thursday, October 7, 2010

Integer remainder repetition

I was just trying to solve a discrete math problem, when I bumped into the following:
take 2 prime numbers A and B, when you starting taking multiples of A, the remainders of those multiples after division by B will change at every multiple, and within B repetitions, they would have produced all possible remainders, this is quite 'intuitive' if we take an example.
Let us take 11 and 7.
11 x 1 = 7 x 1 + 4
11 x 2 = 7 x 3 + 1
11 x 3 = 7 x 4 + 5
11 x 4 = 7 x 6 + 2
11 x 5 = 7 x 7 + 6
11 x 6 = 7 x 7 + 3
11 x 7 = 7 x 11 + 0

The sequence of remainder is quite interesting: 4,1,5,2,6,3,0.
I guess it is possible to derive an equation for it depending on the 2 numbers but for now let us try to prove that within 7 multiples of 11, all possible remainders are generated.

It is not very hard:

Sunday, September 26, 2010

Spot a 'Vulgar Mechanick', how many of them do you know?

"A Vulgar Mechanick can practice what he has been taught or seen done, but if he is in error, he knows not how to find it out and correct it; . . . Whereas he that is able to reason nimbly and judiciously about figure, force, and motion, is never at rest till he gets over every rub"

Isaac Newton wrote to Nathaniel Hawes on 25 May 1694.

Sunday, September 5, 2010

Free BVH viewer released.




I just released a small viewer for the Biovision BVH mocap file format.
It can be downloaded from this page: http://jadnohra.net/?page_id=58

I did not plan to write this viewer, but I suddenly found myself having all the code I need for it while writing code for my animation research projects.

The 'Bigeye' UI library


I already had developed the 'Bigeye' UI library. This was I think the 4th UI library I had ever written. For this one, I had a couple of goals in mind: Small, OpenGL based but without state management headaches, easy integration of 3D scenes using render to texture, good looking with shadows, mouse-over, gradients, ttf and svg, no complex auto-layout/resizing support, no need for editor or text definition (at least not for the first versions). It took a number of weeks for this to happen, but I am very pleased with the results.

ImageMagick

A key idea was to use the ImageMagick library which is basically, photoshop/gimp in your code.
It allowed me to create nice and detailed widgets without having to prerender them in an image editor.
Compiling and linking ImageMagick can be quite a headache, but after that is done, using it is a lot of fun. I spent quite some time reading 'how to make a nice button' tutorials and trying things out in gimp before deciding on a look, one of the main inspirations was the Zbrush user interface. Colorpic was also a useful ally in debugging the looks and colors of various widget screenshots that I wanted to reproduce.

RenderState Management

For the UI I wanted to keep things simple, but still self managing, I went for a render tree approach, with automatic dependency management which was important for the 3D scenes rendered to textures. That way, RenderToTexture widgets could simply declare their dependency on a different (3D) RenderTree than their current tree (the main UI tree), and the Renderer would automatically take care of ordering the trees. Inside a tree, parents would render before their children.
The rendering would happen in three stages, building the render tree, figuring out dependencies, and then rendering in the right order.

For render states, again a simple design with one hashed state containing all the options needed for all the UI widgets (e.g: enabling transparency, texture, etc...). Each UI element would set it's desired render state instance, and the rest would happen automatically. Of course this is not the most flexible or performant design as code needs to be added to the render state structure and it can grow big, and for options that are not in the render state (e.g: line width) care must be taken to set them every time they are needed, but for a tiny UI like this, it does the job perfectly.

Biovision .BVH file format

Of all mocap formats, .BVH is the simplest, but many free mocap resources in bvh format exist on the internet, specially the .BVH conversion of the CMU mocap database is great. I will probably add .c3d support when I feel need it.

The format is relatively well documented on the internet. The fact that it uses Euler angles is usually the biggest source of headaches as I gathered from forums. I also had to try a couple of things out before finding out what the right way is. This included looking a the blender importer source code and even having fun writing a feature-incomplete bvh exporter for blender. A precise answer to the question of how to create a rotation matrix from the angles is nowhere to be found, because of that even some bvh viewers (bioviewer) got it wrong.

BVH euler rotation order

one way to build the rotation matrix is to concatenate the matrices built from each angle in the order Y,X,Z. This is not entirely correct. The order should follow the one delcared in the bvh file itself, this means that if in the bvh file you see: "CHANNELS 3 Zrotation Xrotation Yrotation"
you concatenate with the order Y,X,Z but "CHANNELS 3 Xrotation Zrotation Yrotation" would require the order: Y,Z,X.
Since most files use the Y,X,Z order this bug can easily slip by.
Some of the CMU mocap files have a different order and look wrong in the viewers that got it wrong.

Of course, as usual, care must be taken about the coordinate systems and the order of matrix multiplications. Depending on you code, this might be different.

In a previous project of mine, I had a very elaborate runtime coordinate system conversion system, but this time I kept it simple and convert everything to an OpenGL compatible system when loading.

Code Dependencies

Everybody hates dependencies, but if you want to be productive, and pick the right ones, it is not so bad. In the past I avoided them like the plague, which was very educational, but this time around I am using the glm library (basically glsl on your pc) for math, strtk for strings (a great library which makes file parsing a ride in the park), glew for OpenGl extensions (which I need for rendering to texures using FBO), OpenGLUT and finally ImageMagick. I link all of them statically except for glew for now.

Viewer 'features'

The viewer loads bvh files using drag and drop and has the usual playback controls.
It analyzes the scale of the skeleton and the bounding box of the animation space, from that it decides on the best grid size, depth planes, camera position and camera movement speeds.
I implemented a simple 'turn table' camera controller (as inspired by Blender).
I also copied the way Blender renders Skeletons, without lighting for now.

If you download it and like it, let me know.
If you have any feature requests, let me know as well...

Sunday, July 18, 2010

Stanford bunny released.




I was cleaning up my hard disk at home and I found the 'packet ray tracing project that was supposed to become the base of a photon mapper' I posted about in the past:

Since I will have no time to take this anywhere anytime soon, I thought it might be a good idea to simply release the source code instead of backing it up into the dark corners of the web and a backup DVD.

The last version I am releasing dropped support for all primitives (e.g: spheres, quadrics) except for triangles and concentrated on triangles with SSE Packet tracing, BVH, and multi-core using OpenMP.

OpenMP is disabled in the delivered executable because my Visual Studio at home is the Express Edition and it does not include OpenMP.
SSE Packet tracing is also disabled because it does not support Lambert shading (I do not remember why though ... it's been a long time).
This means you will not see the 1 millions rays per sec I claim in one of the posts.

There is a number of build configurations and preprocessor options to play around with to enable / disable these options and other features.

In the executable, you can use numeric pad keys to rotate the camera and arrow keys to move the camera, when you do this, the program enters a low detail rendering mode until you release the keys. It is not great, but at least some kind of camera control is there.

The code depends on the 'WitchEngine' library (namespace 'WE' in code) which is the engine I had written for 'World of Football', but that is a LOT of code, so I spent 10 minutes only copying the code needed. It should therefore build with no problems, all you need is to point it to a DX9 SDK.




Monday, May 31, 2010

Homegrown math study group.

Tom Lahore and me, and I am sure many others, find that there are not enough practical problems forcing us non-PhD / non-academic to delve into math as much as we like. It is a chicken and egg problem and we have strongly felt during the last years that we should do something about it and never had the discipline to do it consistently and therefore usefully. We will give this another shot at http://sites.google.com/site/77neuronsprojectperelman/

We will start by using the Khan academy videos (1 to 2 videos per week) and discuss them during sundays possibly using some online conference tool and use the wiki to share our thoughts. The Site is public so feel free to do it with us. Will we fail and stop in a month? I don't know ... we hope the fact that we do it in a group and that we use very low commitment (1 to 2 videos per week) will help.

Saturday, May 22, 2010

That's what happens when you are researching human locomotion.

You find sentences like:
"Modern humans exhibit a much higher body fat content and reduced relative muscle mass than their ancestral counterparts, trends that are seen in domesticated animals generally (Allen and Mackey, 1982; O’Dea, 1991; Clutton-Brock, 1999)." (http://jeb.biologists.org/cgi/content/full/204/18/3235)

.

Saturday, April 10, 2010

More time = shorter letter

Yet another extremely valuable addition to my neuronal network. (Thanks to R.M)


How true!

Wednesday, January 20, 2010

Anything must be something, except for nothing ...


We all have encountered and enjoyed seemingly mind convoluting statements like:
"This statement is false" or "I am a liar", such statements are basically 'unprovable'.

I have been reading about this while investigating logic and it's roots, mathematics, number theory, Goedel .... Some older posts are related to this.

Recently I decided to write down one such sentence that comes pretty naturally whenever you start thinking about what 'something' is.

Here is the complete sentence:
"Anything (any 'thing') must be 'something', except for nothing, which is of course also 'something', but on a different level of thingness, which goes up and down into itself to infinity."

The sentence flows pretty naturally when you are making it up, you start with:
"Anything must be something"
But then your mind remembers that there is an exception to that so you add:
"Except for nothing"
Again your mind jumps in, it cannot accept the void, this 'nothing' also fits the mind's intuitive notion of 'something', in the end, we just mentioned it, so it must be something, and this is where the fun starts, so you add:
"Nothing is also some kind of 'something'"
But then you fell uncomfortable, now nothing is nothing and something at the same time, but let's simply go on trying to explain how we feel about that:
"But on a different level of thingness"
The mind is trying to say that this nothing on one level (of 'thingness') is 'something', yes, but not on that same level), but now we have two levels, we needed those to resolve the paradox of nothing, but that's a problem, because on that new level we can probably do the same, and we can also think that the lower level is an upper level for some other level which has a 'nothing'. So we add:
"which goes up and down into itself to infinity."

So here we have it, nothing, something, a paradox and infinity all at the same time, plus the inability to make logical sense out of even the simplest everyday construct.

If you have been reading some Set theory, Number theory, Russel, Hilbert, Whitehead, Turing and friends all this would seem all too familiar: nothing could be the more formal 'Empty Set {}' ... and it's a long ride after that. So this is my layman's version of what all these geniuses and many others spent years thinking about, if that makes you interested, I suggest you read the most excellent book: "Godel, Escher, Bach: An Eternal Golden Braid"

I also found it interesting that this multi-level hierarchy of rules that we make up to reflect on a lower system from a higher system (escaping to the meta level as some colleagues would say) is inherent in the way we think, it is even mentioned in a seemingly unrelated game design book "Theory of Fun" and also a recurrent topic in our AI related discussions.

Next I will be investigating in more detailed the 'Completeness' part of this whole topic coming from Goedel's famous "Incompleteness theorem" that seems to be touching the physical limits of our brain and melting them in the core. More specifically completeness relative to what? Logic itself? probably, but, but ....

.

Wednesday, December 30, 2009

The answer from above


While we game AI programmers noodle with our gross simplfications and regrettable /understandably unavoidable but also fun and challenging real-time performance constraints, we occasionally look up for any new answers from above, normally we are too busy to stay up to date, but it's the holidays and I am bored, I have no ps3 devkit here, nor a PC with a dev. environment to do some brainless coding... so I had to be brainful and start reading and so I stumbled upon this: "the currently available theories do not explain or engender anything resembling human-level general intelligence" what is meant here is theories coming from Information-processing psychology e.g: Cognitive Science and Cognitive Neuroscience. (source: http://www.cs.umd.edu/~nau/cmsc722/)

I wonder when such theories will start to be discovered and what kind of processing power we will have at the time and if they will good enough to allow the ones who will be peeking there at the time and spotting low hanging fruits to become famous applying them to video games (and other applications) being again, at the right time and place.

Sunday, November 29, 2009

Now that's bad performance code! once and for all....

Translating an idea into a piece of code is an over-constrained problem, just like many other problems.

To decide how to code something, make a list of all points you think are important for it (maintainability, performance, easy to read by me, easy to reuse by me, flexible, many other pieces will depend on it, multi-platform, multi-compiler, link fast, compile fast, short names for faster typing, easy to read/understand/reuse for my colleagues, easy to read/understand/reuse for my clients, cryptic to prove I am 'old school' and can write assembly and you should be scared of discussing it with me, totally abstract to prove I don't care about performance and want to make a point that premature optimization is the source of all evil, totally lean and mean to prove that non-premature optimization is the road to a lame duck... you name it! I don't care what you put in there, the list can be very long and can include anything you like), score the points in your list based on their utility for the piece of code to be written with the very welcome possibility of zero utility for some of them (makes it less constrained).

You cannot compare apples to oranges? (e.g: maintainability vs. performance) ? yes you can (Yes son, you can compare apples to oranges... )! on top of that, you have no choice...

Finally, code/make compromises to maximize the total score, that's all there is to it and being an over-constrained problem for anything none-trivial it won't be completely obvious.

But the problem is clear, no need to call a programming style 'too old school' or another one 'too abstract' or 'too object oriented'. The higher the total score, the better ... that's it.

Now if u do not have the necessary coding skills, you might generate code that has a total score that is not the maximum possible ... but that is another topic.

.

cool, now we can point to this instead of discussing it one more time ... saves more time for the 10,000 hours :)

http://www.youtube.com/watch?v=CtUuJo_DeyI

http://foodandretail.blogspot.com/2007/11/interlude-rule.html

http://www.youtube.com/watch?v=pIYUMwxKFzo

brought to by the AIGameDev IRC channel.

AI room + blackboard = geek art


I started out by wanting to draw a tree (the only thing I know how to 'draw' ... but then ... I had a Bob Ross happy accident)

PS3 game/FPS AI research

You gotta know your competition ... so I got me a PS3 and start taking notes while playing PS3 FPS's. As a side effect I am also enjoying Uncharted 2 MP.



Uncharted 2 Stats Card by JAKPRO.net - pinkfish00