TheJach.com

Jach's personal blog

(Largely containing a mind-dump to myselves: past, present, and future)
Current favorite quote: "Supposedly smart people are weirdly ignorant of Bayes' Rule." William B Vogt, 2010

Featured on reddit!

Cool, my FFP Machine paper got a reddit link: http://www.reddit.com/r/ECE/comments/k5yld/ffp_machine/

I didn't get that many hits from it, but still cool anyway. I didn't even notice until I looked at my analytics tonight, I guess that's a good thing. (I don't think my site would last in a real reddit crisis.) Eventually I'll get around to optimizing the site... Right now every page hits the DB, which is the main cause of downtime.

See Full Post and Comments

Clojure Tip: defstruct, deftype, defrecord

I'm currently learning Clojure, so I intend to document a few findings here that required at least a couple minutes of Googling around for me. The Clojure docs will tell you in the nitty-gritty the differences between defstruct, deftype, and defrecord, but I think an example of each is more beneficial. Also, some older examples of deftype are out of date! Trying to do things the obvious way, at least to me, resulted in a runtime error: "Expecting var, but Point is mapped to class user.Point". Anyway, enough babble, here's a working example of all three.


kevin@jachoonster ~/clojure-1.2.1 $ java -jar clojure.jar
Clojure 1.2.1
user=> (defstruct Point1 :x :y)
#'user/Point1
user=> (def p1 (struct-map Point1 :x 3 :y 4))
#'user/p1
user=> (println p1)
{:x 3, :y 4}
nil
user=> (println (:x p1))
3
nil
user=> (println (struct-map Point1 3 5))
{:x nil, :y nil, 3 5}
nil
user=>
user=> (deftype Point2 [x y]) ; actually creates a java class
user.Point2
user=> (def p2 (Point2. 8 9)) ; notice the '.'!
#'user/p2
user=> (println p2)
#<Point2 user.Point2@54083e1e>
nil
user=> (println (:x p2)) ; won't work
nil
nil
user=> (println (.x p2))
8
nil
user=>
user=> (defrecord Point3 [x y])
user.Point3
user=> (def p3 (Point3. 11 12))
#'user/p3
user=> (println p3)
#:user.Point3{:x 11, :y 12}
nil
user=> (println (:x p3)) ; works
11
nil
user=> (println (.y p3)) ; also works!
12
nil


For a handy flowchart for telling you which you should prefer (especially if you are wondering about proxy, gen-class, and reify), check out this page: http://cemerick.com/2011/07/05/flowchart-for-choosing-the-right-clojure-type-definition-form/. (The author wrote a book on Clojure.)

See Full Post and Comments

The best is the enemy of the better

Is the best your goal? Your standard? Is omniscience your goal? Your standard?

For many people, this is true, or at least they think it is. Children's television is a great way to observe a cornerstone of current thought in developmental psychology and how kids' futures may be determined by what influences them. It used to be "Everyone is special", sometimes with the added "in their own special way." Recently it has been "Just do your very best", sometimes with the added "and try try again!" I don't know the most modern phrase. There are two obvious sillinesses here: if everyone is "special", "special" loses its meaning and you might as well say everyone is Gorp. If you do your best, what makes you think trying again will produce any results if you're not improving?

The best is not my goal, nor omniscience itself, but appearances of both can provide some direction. If I had omniscience, I'd still look for something better. Where my philosophy lies is that I'm not seeking the best, merely the better. I'm not even sure there's a best. But hypothetical omniscience often serves as something I can point to showing that there is something better. Some place I can keep moving towards, cheaply, through learning.

See Full Post and Comments

Short guide to Lisp (syntax)

(Update: Go watch Rich Hickey's Clojure for Java Programmers for a superior introduction to Clojure's (a Lisp) syntax.) Lisp has been around for a long time. While some of its current magic capabilities are fairly recent, the basic syntax it uses has hardly changed at all over 50 years. To me this means it's endured because it's good and because it's simple and because it's powerful. I'll talk about those last two qualities here, maybe you'll end up also believing the syntax is good.

I will start with a related topic: mathematics. Not any particular usage of math, just the notation. The symbols. One of the hardest things for me in math has been memorizing symbols, especially this little guy: $$\nabla$$. Very subtle changes in the way you write stuff on paper can drastically change the meaning of something. In elementary school you're taught that $$\times$$ means the same as $$\cdot$$. Later you find out they're very different. I could give more symbol soup examples, but take a moment and just skim down the linked Wikipedia page.

There's a similar phenomenon in most programming languages. There are symbols and syntax for all sorts of weird things. In math you might say "let x = 4", in programming you might say "$x = 4;". Wouldn't it be nice if math, and programming, had a consistent syntax?

See Full Post and Comments

Anarchy vs. Sovereign Structures

There's a curious relationship between forms of government that employ states vs. those that don't. I'll try and touch simplistically on it, and go over a few thoughts.

The main issue at hand is authority, with a corollary being power. Abstractly, systems of Anarchy claim that structures where no individual person, or node, has authority over any other, should perform better at least on average than structures with a command network, i.e. authority. In Anarchy, power is distributed equally across everyone. In other structures, different nodes have different amounts of power, with the most stable structure being one where there's a clear ordering to the power. That is, one node has the majority of the power, and the rest follow from there with no equivalent nodes of useful size. (In a Monarchy, the peasants may all be more or less equal, but the individual power amounts and the sum total of the power in the group is negligible compared to the absolute authority of the Crown.)

When people dismiss Anarchy, they are arguing that either a) authority-less networks perform worse on average and so aren't useful, or b) such a network is unstable (some say impossible) and authority will manifest itself naturally one way or another (typically through mob violence). a) is purely a technical argument that I won't get into here, though briefly I'd mention that while there may be some cases where having a command system definitely helps, such as running corporations or militaries, I think it could be shown that those do not represent the majority of interesting cases. b) is more interesting.

See Full Post and Comments

Inferential Distances Again

I briefly touched upon this previously, but some actual examples in the form of fake dialog would be more useful. Before I get to that though, let me try and frame the problem abstractly. When you master a body of knowledge with long argument chains, you'll find that trying to convince someone of your conclusions, especially the non-intuitive ones, without them going through a similarly long argument chain, is near impossible if they haven't even started on a similar road you took. In the process of trying to explain why you believe your conclusion, you inevitably have to move down to a further level on the inferential chain and create a link from that level to your conclusions. At science conferences, a presenter might do this by starting off with a general set of facts the layman wouldn't be expected to know, but most people in the presenter's field should, and create a link from that point to his presentation's conclusion. A single step such as that has an inferential distance of 1, and has two levels. Now if the same presenter is trying to explain it to a layman, there may be any number of levels below the first that he started with his colleagues, and he now has to go through those first.

But it gets even worse, because the inferential chain is really a graph. There may be some "hierarchy" to it, as in you need to accept certain ideas on the graph before you can move to a different area of the graph with its own network of ideas, so you can consider it a chain with each link being a graph, but that's only valid for strongly hierarchical models.

Now imagine the difficulty that presenter might have trying to explain his conclusions to a layman. Many ideas, or "nodes", in the graph need to be visited and agreed upon or at least understood before he can move up an inferential level. If he's uncertain where the layman's initial knowledge lies, he'll most likely start at a level too high. And so the layman asked him to explain X, suddenly the presenter is explaining Y, Z, W... None of which the layman really understands, and the presenter only realizes this once he gets to W which is reinforced by Y, so he drops down a level to start explaining A, B, C...repeat. This is understandably confusing for the layman, and if the layman is predisposed to not liking the general thrust the presenter is heading for already, he may start shutting out everything. Then he'll accuse the presenter of constantly changing the subject and being dishonest when the presenter is just trying to bring the layman up to a level where understanding X in reasonable terms is even possible.

See Full Post and Comments

Python: map or list comprehensions?

This question seems to come up a lot when doing functional programming in Python. Should you use the more classical map/filter functions, or the Pythonic and usually more readable list/generator comprehensions? Do you do:


map(lambda x: x*x, xrange(11))

or

[x*x for x in xrange(11)]

?

(Note that map in Python3 is lazy and you would use range(), if you want laziness with comprehensions use parentheses instead of brackets to use generators.)

See Full Post and Comments