Category Archives: Programming

More artificial intuition ideas…

A post I just made on Slashdot in the context of an article about improving computer “Go” opponents:

Intuition is something a successful AI (and a successful human Go player) will require, and while we can model it on a computer, most people haven’t thought of doing so. Most systems are either based on symbolic logic, statistics, or reinforcement learning, all of which rely on deductive A->B style rules. You can build an intelligent system on that sort of reasoning, but not ONLY on that sort of reasoning (besides, that’s not the way that humans normally think either).

I suspect that what we need is something more akin to “clustering” of concepts, in which retrieval of one concept invokes others that are nearby in “thought-space”. The system should then try to merge the clusters of different concepts it thinks of, resulting in the sort of fusion of ideas that characterizes intuition (in other words, the clusters are constantly growing). Since there is such a thing as statistical clustering, that may form a good foundation. Couple it with deductive logic and you should actually get a very powerful system.

I also suspect that some of the recent manifold learning techniques, particularly those involving kernel PCA, may play a part, as they replicate the concept of abstraction, another component of intuition, fairly well using statistics. Unfortunately, they tend to be computationally intense.

There are many steps that would need to be involved, none of them trivial, but no one said AI was easy:

1. Sense data.
2. Collect that data in a manageable form (categorize it using an ontology, maybe?)
3. Retrieve the x most recently accessed clusters pertaining to other properties of the concept you are reasoning about, as well as the cluster corresponding to the property being reasoned about itself (remembering everything is intractable, so the agent will primarily consider what it has been “mulling over” recently). For example, if we are trying to figure out whether a strawberry is a fruit, we would need to pull in clusters corresponding to “red things” and “seeded things” as well as the cluster corresponding to “fruits”.
4. Once a decision is made, grow the clusters. For example, if we decide that strawberries are fruits, we would look at other properties of strawberries and extend the “fruit” cluster to other things that have these properties. We might end up with the nonsymbolic equivalent of “all red objects with seeds are fruit” from doing that.

What I’ve described is an attempt to model what Jung calls “extroverted intuition” – intuition concerned with external concepts. Attempting to model introverted intuition – intuition concerned with internal models and ideas – is much harder, as it would require clustering the properties of the model itself, forming a “relation between relations” – a way that ideas are connected in the agent’s mental model.

But that’s for general AI, which I’m still not completely we’re ready for anyway. If you just want a stronger Go player, wait just a bit longer and it’ll be brute forced.

ActionScript 3 is a travesty

What was Adobe thinking? Not even Java requires jumping through this many hoops!
A pity, because ActionScript 2.0 was actually quite a nice language.

I experimented with it a bit for the new site I was developing for my music. I waded through all of the tedious conversions, getting rid of things like SetInterval in favor of the Timer class, loading movies using the Loader class instead of a direct method, finding lots of things taken out, lots of names changed, but basically the same capabilities packaged in a more structured yet klutzier form.

Then I tried to unload a movieclip.

You can’t do it. Flash WILL NOT LET GO of the object, even after you call one of the removeChild methods. And since the object in question is an ActionScript 2 music player and (surprise surprise) you can’t interoperate with ActionScript 2 movies, I’m stuck in a situation where I can’t change the file that is playing and I can’t remove and reload the component.

Alone, this is a bad issue, but after hours of struggling with the language’s weird idiosyncrasies, I’m ready to go back to AS2 and forget about learning AS3 until some of the issues are fixed.

Update: I finally solved this problem using LocalConnection. Yes, I needed to use what is essentially a light form of IPC to solve this problem.

LanceRates is out!

I’ve just launched LanceRates.com, a website designed specifically to answer the question “How much should I charge?” in relation to freelance work. Users can post or look up market rates for any sort of freelance job, and the site integrates some rather advanced analysis techniques, including several machine learning algorithms, to give visitors an unprecedented level of information.

And just in case it still isn’t enough, we make the raw data available. All for free.

Why does everyone depend on me?

It’s so incredibly tiring to know that the moment you take a break is the moment no fewer than three people will be on your case asking you where their work is.

I need to stop freelancing, but I still want to keep my programming skills razor-sharp. Perhaps working on more of my own coding projects is the answer.

From AJAX to an event-driven model.

Websites are becoming more application-like, with many using AJAX to make requests of the server and PHP or some other server-side language to process those requests. This seems to be getting closed to the event-driven programming model used in Visual Studio and various windowing frameworks.

Ultimately, what I hope this will converge on is a truly event-driven model, where events triggered on the client are mapped directly to server-side functions that perform processing and return their results directly back to the client-side. Rather than explicitly sending out an AJAX request and catching a response in a callback, this would then use simple functional notation and the backend processing would happen behind-the-scenes, similar to how RPC works (come to think of it, that’s sort of how “web services” worked too, but I guess those are just glorified RPC when it comes down to it). It would be as simple as Qt’s “signals” and “slots”.

Bug in C#

Apparently Microsoft has no easily accessible place to report bugs in their programming languages, so I’m posting it here and hopefully someone who can fix it will eventually read it (and maybe even put an easy-to-find link up to report bugs on MSDN?)

If it’s not a bug with .NET itself, perhaps someone can tell me what I’m doing wrote here, C# newbie that I still am.

I have a DataGridView bound to an ArrayList of objects of the following class:

public class SeriesPoint : IComparable {
    private double _price;
    public DateTime? Timestamp;

    public double Price {
        get { return _price; }
        set { _price = value; }
    }

    public string Date {
        get { return Timestamp.ToString(); }
        set { Timestamp = DateTime.Parse(value); }
    }

    public SeriesPoint() { _price = 0; Timestamp = null; }
    public SeriesPoint(double p, DateTime? d) { _price = p; Timestamp = d; }

    //These are compared only based on date.
    public static bool operator<(SeriesPoint lhs, SeriesPoint rhs) { return lhs.Timestamp < rhs.Timestamp; }
    public static bool operator>(SeriesPoint lhs, SeriesPoint rhs) { return lhs.Timestamp > rhs.Timestamp; }

    //Equivalent in C++: return rhs.timestamp == timestamp;
    public override bool Equals(object obj) {
        if (obj == null || !(obj is SeriesPoint)) return false;
        if (obj == (Object) this) return true;

        return ((SeriesPoint) obj).Timestamp.Equals(Timestamp);
    }

    //Nothing special about how it's hashed.
    public override int GetHashCode() {
        return base.GetHashCode();
    }

    public int CompareTo(object other) {
        //Nulls to the beginning.
        if (this == null && other != null) return -1;
        if (this != null && other == null) return 1;

        if (this < (SeriesPoint) other) return -1;
        if (this > (SeriesPoint) other) return 1;
        return 0;
    }
}

And I run the following to attempt to find the last null value in a sorted list:

int lastnull = sortedpoints.LastIndexOf(new SeriesPoint(0.00, null));

This actually works, but when the function exits and control presumably returns to the main loop, the program suddenly crashes with the following exception in Application.Run() (not even running on the same thread as my code!):

“An unhandled exception of type ‘System.InvalidOperationException’ occurred in System.Windows.Forms.dll

Additional information: Operation is not valid due to the current state of the object.”

I checked all of my code, put try blocks around things, made sure nothing was throwing when it shouldn’t be, removed functions, rewrote functions, reordered functions, checked boundary conditions… nothing. My code is running fine and returning correct results. .NET is then crashing. I have no idea why, but the data binding is definitely a possibility.

I suppose my best course of action is to remove the Equals() method (this fixes the problem) and rewrite my code without it.

Type safety in newer programming languages

Am I the only one who finds newer programming languages, such as Java and C#, to take strong typing to a very undesireable extreme? It seems like a reaction to most programmers not being able to get type safety right in C++, but it ends up making the code look awful, obscuring its function, and requiring a lot of extra work to explicitly cast things around. Especially when working with arrays, it oftentimes requires creating entirely new loops dedicated solely to the purpose of casting. This is stupid in many different ways. ConvertAll sort of helps, but it’s clunky and doesn’t work for collections. Also, why does the cast operator have lower precedence than the dot operator? I would think the other usage would be more common.

In Perl, which I now consider my favorite language (because it doesn’t presume to impose seemingly arbitrary restrictions on the programmer), you can join an array of doubles into a string in one line of code. You can do it in two in C++, which isn’t bad, since the stream operators have overloads for numeric types. Try it in C# or Java and you’ll need at least four or five lines.

I think I prefer the flexibility of weak typing despite the added risk. It’s a pity that “hot” languages are all following the “programming with mittens” paradigm right now.

"Best Practices"

Most people who use the phrase “Best Practices” probably don’t know what they are. I haven’t really found anyone using these terms who can explain why these practices are truly “best”, and in the realm of software engineering (not so much for web dev.), the code of people who endorse them tends to be awful. They can sometimes spit out why one model is better than another particular model, because they’ve memorized the dogma, but present them with a completely new paradigm and ask them to compare it and they cannot. It seems like they’re substituting process for talent.