Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Wednesday, December 10, 2008

Genetic Algorithms and Mona Lisa

Genetic Algorithms try to apply evolution mechanisms to find solutions to hard problems (typically, where no "proper" solution is known and where the search area is large).

Roger Alsing posted a couple of days ago an extremely cool article showing the convergence of 50 polygons to represent the Mona Lisa, using a random approach.

That was too cool to not try to implement it :)







The screenshot shows a rendering of the Mona Lisa using 50 polygons (16 points each), after 40818 total iterations, with 4577 elected states; the middle image is the original (i.e. the target) and the right image the difference between the current polygon-based image and the target (i.e. a representation of the fitness function).
Underneath was an earlier attempt using ovals instead of polygons.

Now, to be more exact, Roger Alsing's algo is more a hill climber algorithm or possibly a simulated annealing algorithm than a good example of a genetic algorithm; it should be interesting to actually implement a proper genetic algorithm approach (i.e. a population > 1) and see how the convergence rate compares... combining polygons and ovals might also result into interesting things.

Thursday, October 30, 2008

Factor

I just watched this talk:



It's a very nice presentation of the Factor language, a mix of Forth / Lisp / Smalltalk -- a higher level Forth. Interestingly, they do have Cocoa bindings...

Thursday, June 19, 2008

Gears presentation at the Google IO conference

The videos from Google IO are online, so if you wonder what I'm working on at Google, here is a nice presentation of Gears for Mobile, by Charles and Andrei:



Slides are also available

Friday, April 11, 2008

Iliad iRex note taking and hand-writing recognition

I recently bought an Iliad iRex, a pretty awesome eBook reader. Among the cool features, it's running linux, an sdk is available, and it's really easy to hack stuff for it (for instance I wrote a simple script for downloading the 24h edition of The Guardian). Also, as shown with the previous link, the community is quite active :)

Just a couple of words about the iliad itself... the hardware is pretty awesome, with wifi, ethernet, wacom tablet, usb, mmc card and compactflash, audio jack...
the e-ink display is quite amazing too -- 768x1024 makes it precise enough to be able to read A4 PDF without too much problem (a great thing to review lots of research papers, believe me !).

The software side on the other hand... is a bit disappointing. Don't get me wrong: it's good enough, and some aspects are pretty cool. But you really unlock the possibilities of the devices by getting the root access and adding applications developed by the community (notably, the PDF viewer hacked by the community is fantastic, with gestures, etc.). Which means it's fine if you are a geek and not afraid to hack your device, but more annoying for your average consumer :-/
The other disappointing aspect is the (comparatively) low battery life: about 12-15 hours depending on the model (mine is a v1, the v2 do better), which is mostly caused by the fact that no sleep mode is available. Other eBook readers perform much better on that metric. To be fair they don't have wifi nor a wacom tablet :D ... so it's really a matter of choice.

All in all, it's a bit of a shame as really the platform is very nice, and with a bit more effort on the software side, Iliad would have a killer product on their hands. Oh, and yes the e-ink display refresh rate is slow, but curiously it's not that annoying, and having its full library in such small factor is absolutely fantastic.

Anyway... one of the really, really cool feature of the iliad is the presence of a stylus (i.e. the iliad display sports a wacom tablet), which allows you to annotate PDFs, take notes, etc.

I started to experiment a bit with the note taking feature of the iliad; the idea is that you can open a PNG image in the notes folder, and a copy will automatically be made where you can write on it (the image is being used as a background, so it's trivial to have customized backgrounds). But I then wanted to generate a PDF from those notes (i.e. combining the scribbles+PNG).

Iliad do provide a windows application to do all that, but it's a windows app, not really useful for me... there is a nice java application written by the community that allows merging scribbles with the PDF as well. Alas, the java scribble merging application only seems to work for PDF scribble; I guess it would be trivial to modify the java app, but I had a look at the xml scribbling format, and I saw that the format was really simple.

So I quickly wrote myself a MacOSX viewer for the notes, using the png image as a background, letting me print notes easily or convert them to PDF.

But then... I suddenly remembered the Ink handwriting recognition engine.

This thing comes straight from the ill-fated Apple Newton PDA (such a loss!), but what is nice is that it is available and installed by default on OSX.

Turns out it's not too difficult to feed Ink a set of custom datapoints, and after some tweaking it doesn't work too bad apparently, as can be seen on the screenshot...





So far, this is only highly experimental code, and it'll probably take a bit more time to have a really usable application. Still, pretty cool!

Thursday, March 27, 2008

GNUstep Summer of Code 2008

For those who don't know yet... GNUstep is one of the organisation that Google has accepted for the Summer of Code program --- which means that if you are a student looking for something to do this summer, want to hack Objective-C code, help a cool free software project, learn a lot... and even be paid, well, you should apply ! sure beat your average summer job :)


...


Deadline for applications is next monday (31/03/2008), so hurry up !

update: the deadline has been pushed by a week, so if you thought you missed it, you still have a few days left to apply.

Thursday, March 06, 2008

Google Gears Mobile

One of the few annoying things when you work at Google is that you can't really talk with your outside friends about what you are doing... so it's rather nice when you finally release the project you worked on for the last few months and be able to point to it :)

So anyway... we released Google Gears for Mobile tuesday morning ! Here is the post from Charles Wiles announcing it, another one describing mobile gears, and one on the Desktop Gears blog. Plus you get fancy videos from Charles, Andrei and Dave talking about it.





A few words about Gears: it's an opensource project, adding a cool set of javascript APIs to internet browsers. Those APIs let your website use a database locally, cache pages, and execute javascript code in threads, basically blurring the line between webapps and native apps.

Biggest use so far is enabling sites to be used while not being connected to internet. Of course, disconnected mode and local storage make even more sense on a mobile device than for a laptop... add to that the fact that writing native applications for mobile devices is a pain, and gears-enabled "webapps" are suddenly very attracting, even if on winmo you have to go through some gymnastic around PocketIE "limitations". Oh, and this work for the moment on Windows Mobile 5 and 6, touchscreen and smartphone, and implements all the 0.2 APIs of the desktop gears.

And more is coming...

Sunday, September 23, 2007

Evolved Virtual Creatures

A pretty cool video showing evolved virtual creatures:



More infos here, with Karl Sims Siggraph's 1994 paper..

another video from Nicolas Lassabe



more on Lee Graham's page :


Wednesday, October 26, 2005

Subtext

Found on Martin Fowler's bliki, an interesting short summary of the OOPSLA'05 conference, along with interesting links. One of them is Subtext, a really cool language / programming environment (you perhaps already encounteered it, it was featured on slashdot some time ago...). Definitely something interesting -- check the demo (flash video) and the researcher's blog. Lots of good points / ideas about what should be a programming environment ;-)

I wonder if we could extend some ideas about ide to really dump the text editing, or at least relay a lot more on metamodels of the code.. Dynamic Aspects seems to head into that direction ;-)

Saturday, September 10, 2005

High Order Messaging

Marcel Weiher sent a mail on the objc mailing-list about a paper he wrote (with Stéphane Ducasse) on High Order Messaging. Basically, HOM is a message that takes another message as a parameter -- like in functional language you have High Order Functions that take a function as parameter.

Ok, nice name .. but why is it interesting ? Well, you have lots of cases where it's really neat :-) but the most known is to use it for iterations. Imagine you have an array containing objects, and you want to send to all of them a message. In Objective-C you'd do:


int i;
for (i=0; i<[myArray count]; i++)
{
id currentElem = [myArray objectAtIndex: i];
[currentElem aMessage];
}

You could also use an enumerator (NSEnumerator) but that doesn't really simplify things. What's the problem with that ? Well, you have code (the for loop..) that you don't really care about, that is actually always the same, you need to deal with each elements, etc. Basically, the programmer's intent is not immediately clear. And of course, the more code you have, the more you can encounteer bugs... So simplifying this pattern would be great. Well, with HOM you will do:

[[myArray do] aMessage];

Better, no ?

Conceptually, the message "do" takes another message as parameter -- it's a HOM. Here it actually bounces the message to all the elements of the array -- therefore, encapsulating the iteration pattern.

Technically, it's a rather cool usage of the Objective-C runtime -- no need to change anything to your compiler :-) -- the HOM message actually returns a Trampoline object that will get the message send to it via forwardInvocation. Read the paper for a good description.

So, using HOM is great for encapsulating the iteration pattern, ok. But after all, we have the makeObjectsPerformSelector.. so why using HOM ?.. Well, the difference is that YOU can create new HOMs, and you are not limited to the iteration pattern :-)

Another good example from the paper.. You have a delegate object you need to send a message to. You'll have the following code:

if ( [delegate respondsToSelector: @selector(windowDidClose:) ]
{
[delegate windowDidClose: self];
}

Again, this is a frequent pattern. Moreover, it's prone to errors -- the selector in the test needs to be equal to the message you send.. An HOM equivalent will be:

[[delegate ifResponds] windowDidClose: self];

Elegant, no ?

Just to finish.. some other examples from the paper:

Starting a method in a thread is done like that in OpenStep:

[NSThread detachNewThreadSelector: @selector(doSomething)
toTarget: receiver withObject: nil];

The HOM equivalent:

[[object async] doSomething];

Or say you want to send a message with a delay.. In OpenStep:

[receiver performSelector: @selector(doSomething)
withObject: nil afterDelay: 1.0];

With HOM:

[[object afterDelay: 1.0] doSomething];


I remember reading about HOM on Marcel's site before this paper, but this paper is an excellent presentation of the idea and do a great job highlighting the possibilities -- another useful mechanism to add to your toolbox to capture patterns :-)

Many HOM implementations exists (in addition to Marcel's original, MPWFoundation), that you can check on that page

Monday, August 29, 2005

VERY interesting videos

Following a link from the Squeak-dev mailing list... I watched theses two videos (a presentation in two parts) by Alan Kay, circa 87 ... They are brilliant, and extremely interesting. Definitely something to view !

Part 1

Part 2

(ps: Squeak is an incredible environment, and Seaside is a fantastic web app framework running in Squeak... worth your time..)

addendum: Interesting PDF about PARC's work ...

addendum 2: another interesting video, an interview of alan kay.

Thursday, July 14, 2005

Newton...

Received the wifi card and memory card, so I was able to connect the newton to my local network :-)

After some tweaking, I have NTK (the newton dev environment) running under Classic and connected to the newton using the wifi card :-)



Just started to play with NTK and NewtonScript, but it's quite cool. By far not as cool as IB/Gorm ;-) but NewtonScript is a rather nice language, and NTK seems ok, though not fantastic... got a very basic app running here, where what you write on the newton is displayed on the above textfield when you click on the button (very dull, but it's just to test things ;-)

Not sure what I'll do on it... perhaps a simple calc application where you'd write the numbers / operations and have a "paper trail" ? or perhaps simply a battleship game (there are two already, but they don't use the whole screen, and anyway it's just to play a bit more with NTK/NewtonScript ...). I should also try the xmlrpc lib, it could be cool to use the newton to connect to my visualization system at uni ;-)

I tried VNC on the newton too, both as client and server, and it's extremely cool.. even if it's very slow :-)

Sunday, June 26, 2005

STPalette 1.2

I uploaded STPalette 1.2, you can find it here: http://www.roard.com/gnustep/STPalette-1.2.tgz

The archive contains libStepTalkView, the StepTalkPalette, and CalculatorExample containing the sourcecode and the gorm file of the Calculator done in the flash demo...

Thursday, June 23, 2005

It works :-)

After fixing a couple of bugs, I was able to code a simple calculator entirely in Gorm :-)



I need to finish properly the NSMethodSignature encoding, but after that I'll probably make a release.

integration in Gorm..

I have now a reasonably-working StepTalkClass implementing inheritance -- you can inherits from other StepTalkClass instances or from a normal ObjC class (well, only the methods.. the ivars aren't inherited..). I also started a new inspector in Gorm for managing a StepTalkClass, where you can add ivars and methods, and if you modify a variable in your method the variable correctly changes (eh, useful no ? ;-)

On the other hand, the object model is rather simple -- I don't have classes and instances, I just define ivars and methods. But for a first version that will be enough for most of the needs (you don't really use lots of instances in general for dealing with the UI..), although I think I will implements a class/instance system anyway (I have a StepTalkRuntime that keep tracks of the created classes..)

I have a slight problem at the moment, calling directly a "script method" in a StepTalkClass works, but for some reasons it doesn't in Gorm, so I need to investigate... it's a bit odd as I inform Gorm of the methods, and I can link a button to a method; I implement respondsToSelector: in StepTalkClass, but somehow I don't even get the message... well I'll see that this evening.

I had some problems with NSMethodSignature, by default the StepTalkClass methods returned an object and took only objects as parameters; so it was easy to build the signature (I actually used a convenient method available in STObjCRuntime). But for actions in gorm, the methodsignature must apparently have a void return value.. so I need to allow signature creation with different return values. Setting the signature by hand make it works though, so it won't be difficult. The other problem is that I can't seem to be able to return an int (not an object) from a script method, even if the NSMethodSignature is correct: I end up with a vacall error when I set the return value of the NSInvocation... I need to find a way, else it will be difficult to create for example NSTableView delegates ! :-)

Anyway, I hope that i'll be able to fix the remaining bugs soon and make a release. At least with it you will be able to create for example a calculator completely in Gorm (as in http://www.levenez.com/NeXTSTEP/IB_ex2.html). I think I'll make a flash video to show how it works :-)

Friday, June 17, 2005

StepTalkClass !

Well, after messing a bit, I have now the following code working:


@implementation Transcript
+ (void) show: (NSString*) str
{
NSLog (@"<Transcript> %@", str);
}
@end

...

StepTalkClass* myClass = [[StepTalkClass alloc] init];

[myClass setName: @"NewClass"];

[myClass addIVar: @"Transcript"];
[myClass setTranscript: [Transcript class]];

[myClass addMethod: @"display: str"
withContent: @"Transcript show: str."];
[myClass display: @"Hello World!"];

...

<Transcript> Hello World!

...


:-)

Basically, it means I have objects written using StepTalk, integrated in the ObjC runtime. So what it really means is that we'll be able to develop complete applications in StepTalk, directly in Gorm :-)

Well, I still need to do a bit of work -- I need to hook that into the StepTalk palette, and add a reasonably good class browser in Gorm for theses "Steptalk classes", but it shouldn't be to complex.

I will probably have a Smalltalk-like browser, and in the future I'll try to implement some of the ideas described here...

Also, as the metamodel is easily modifiable (obviously :), it's possible to implement interesting things... first, I need to implement single inheritance, categories, class methods, class variables to the current simple model...

StepTalk "objects"

As I said previously, what I want now is "real" objects in Steptalk, not just scripts. Basically, to abuse the runtime thinking classes really exist as objective-c classes, while in fact they will be a special class containing dictionaries for its ivars and its methods, and that will execute theses methods (mere NSString containing a script) via Steptalk.

It's not done yet... but I have a basic behavior done: I can add a class to the GormClassManager, add a method to it, and connect a button to this virtual method. And that works -- clicking one button connected to the standard execute: method does something, clicking on a second button connected to the virtual method does something else :-)

So, well, it's not ready yet, but things looks good :-)

Wednesday, June 15, 2005

STPalette 1.1

I worked a bit on the steptalk palette today, and I added some nice improvements...

steptalk palette sshot


  • You can create script outlets on the fly -- no need to use the object1,object2,...object9 limitation.. :-)

  • I added a non-ui object that you can instanciate as any object

  • The StepTalkView is still there, but more like a button containing a script. And actually by default its target/action is itself, so when you click on it, you execute the script. To change the default image, just dragn'drop another on it :-)

  • added a connection inspector to only show the script outlets



So basically now, it's more useable imho :-) and starts to be quite nice.

Check the readme files for more infos. You can download it from here: http://www.roard.com/gnustep/STPalette-1.1.tgz

enjoy :)

StepTalk Palette 1.0 released :-)

Well, I had the time this evening to create a small libStepTalkView library (containing... the StepTalkView widget...) and correct a few things, so I thought it was good enough for a release ! For once I'm trying to do "release early, release often". Although I'm not sure about the latter... ;-)

Anyway, the whole package (libStepTalkView and StepTalkPalette) is here: http://www.roard.com/gnustep/STPalette-1.0.tgz

What's wrong at the moment ? well, it seems the StepTalkView class is not properly exported somehow, so you need to reload manually the class in Gorm (Classes->load class, load StepTalkView.h from libStepTalkView) before drag'n dropping a StepTalkView -- I guess that's probably easy to fix. Else it seems to work..

What I'd like to do now is to create outlets/actions on the fly (well, actually, tell Gorm about them) -- if I can do that, then I can create an object that will let you dynamically create "StepTalk objects" -- add instance variables, methods, etc. Each "methods" will contains a script, executed on the fly, and each instance variables will be passed to the scripts. Not completely sure about methods parameters, but I'll probably find a nice way to deal with them...

Anyway, if I can do that (and that seem doable..), then you could really program entirely in Gorm :-)

(although it probably won't be very fast, for sure... but for prototyping that would be quite useful I think, and if you need perfs, you can create an ObjC object!).

Have fun, and contact me if you have ideas :-)

Tuesday, June 14, 2005

Steptalk palette :-)

Making a StepTalk palette was quite simple, as it turned out...



Now I just need to build a proper framework and add a non-view StepTalk object in addition to the current one... :-)

Monday, June 13, 2005

Steptalk integration ..

Now that I have something mostly working on the "stack" side .. what would be neat is to have a way of adding some little code snippets directly in Gorm and link them to actions; it's not meant to replace ObjC coding, but in my "hypercard"-like idea, it's ok -- you'll use small scripts to do some of the things, and if you want really complex stuff you can use objc objects. Well I guess people could abuse the script system, but hey..

So, the obvious way to add scripting is to use Steptalk, Stefan Urbanek's script engine for GNUstep. Furthermore, Steptalk isn't tied to a specific language (actually it can support a smalltalk-like language and scheme, and we could have something else like ruby in the future...).

I had a look to F-Script but I was disappointed by its IB palette.. basically it's not really useable for what I want ;-) -- even if I didn't want to use it, I was wondering how the palette was working, as I thought it permitted what I want... in fact, it kinda does, but by setting manually the targets/actions of objects in the script .. bah :-) -- I want something more easy to use.

Well, I compiled Steptalk on OSX to play a bit with it, and I'm trying to think about how the palette could work to provide an environment as easy to use as possible... F-Script palette's idea of defining a bunch of outlets (object1, object2, .. object9) on the F-Script view where you link objects to have them accessible from the script is a bit crude, but for a start it will do the work. Though I think it should be possible to create a custom editor/connector that will let you add outlets on the fly, which would be a better way. Need to ask greg about that :-)

So the idea is to create a Steptalk palette that will contain a "Steptalk object" (which will contains a steptalk environment and
a text containing the script). You will be able to connect outlets to this object (and theses outlets will then be accessible from the script), and also use it as a target (so you could connect a button to it, when the button is clicked it will execute the content of the script). That won't be a perfect system and not as transparent as visual basic / hypercard (eg, click on the button, you get a window with the corresponding code executed onClick), but that would be a start. This "Steptalk object" won't be a view, but we could have a simple view so you could put the script on your windows (this view won't show when the program is running...).

Something that could be interesting too is to use custom widgets that already contains a steptalk object, with their target/action set to it. For example, the Stack could (and probably should) contains such an object. Same for the cards. And we could have a custom button containing a steptalk object too, which will then permit the "I click on the button and the code appears" scenario...