[Cs254f11] length of individual thoughts...

Lee Spector lspector at hampshire.edu
Fri Dec 2 12:20:55 EST 2011


Close.... or rather, I think it will work but slightly by accident.

I'm assuming that "sorted" here contains a sequence of [program error] pairs -- note that in some of my example code I had those pairs the other way around, so make sure you're treating them consistently! 

In any event, with that assumption (which is the only thing that makes sense given the rest of your code) your call to filter is producing a sequence of only those that have the same error as the first one (which will be the best). Then you're sorting those on the basis of which has the lowest codesize, but you're calling codesize on the whole pairs rather than on just the programs. Which I guess always comes to the same thing, since the error will just add 1 to everything uniformly. So it'll do the right thing but not quite in the right way (which you could do by calling codesize on just the programs).

Alternatively, and this is probably what I'd do, you could change the predicate used in the call to sort that gives a value to "sorted" it say that %1 should come before %2 if either %1 has a lower error OR if they have the same error by the program in %1 has a lower codesize.

 -Lee


On Dec 2, 2011, at 11:24 AM, Wm. Josiah Erikson wrote:

> So in the way I'm evolving things, I've often got a population full of individuals with similar error. Given Lee's
> 
> (let [sorted (sort #(< (second %1) (second %2)) population)]
> 
> would this function get the smallest individual that had the best error? :
> 
> (first (first (sort #(< (codesize %1) (codesize %2)) (filter #(= (second %) (second (first sorted))) sorted))))
> 
> (It seems to work)
> 
> Is there an easier way to do that? Is this even a good idea? I'm currently just using it as the final return value so that my final result is as easy to read as possible :)
> _______________________________________________
> Cs254f11 mailing list
> Cs254f11 at lists.hampshire.edu
> https://lists.hampshire.edu/mailman/listinfo/cs254f11

--
Lee Spector, Professor of Computer Science
Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspector at hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438



More information about the Cs254f11 mailing list