CMPSCI 383: Artificial Intelligence

Fall 2014 (archived)

A Simple Hill Climber

In class today we ended up working through a Java version of a simple hill climber for Assignment 02. Thanks to you all for helping me get it right(-ish). Any errors you spot are mine.

I was using the free Community Edition of the IntelliJ IDEA, which you might want to give a try if you haven’t before. PyCharm is a similar tool for Python from the same company.

You can download the code that we wrote here: simple-hillclimber.tar.gz. You are welcome to use it as the basis for your own solution.

I made a few minor changes after class:

  • I added some suggestions in comments about ways to add random restarts and stochastic searches. You won’t need to do all of them, and you might be able to think of others that will do better, or that will be easier to implement, or that are just more interesting to you.
  • I switched the sub-problem representation (that is, the sub-wall) from type Integer[] to type SubWall. It makes the program marginally more readable.
  • I limited the scope of the try/catch block to only enclose the relevant code.

Let me know if you particularly liked or disliked the use of class time for programming. I can’t do it every class, but I might do it occasionally if enough people found it useful and few enough found it useless. Alas that we have no discussion section, as that would be a great time for it.

Assignment 01 Graded

I finished grading Assignment 01 a few minutes ago. As noted, it was primarily done by an autograder on test cases, though I did have to do some manual work on many assignments. I will post the test cases after the last extension expires (or the person granted it hands in their work, whichever comes first).

Some notes:

  • My A* Solver, written in Java, finished all test cases in under the time limit. If you feel yours just missed the cutoff, email me and I’ll re-run it and give it longer.
  • I pasted the output of the autograder into the Moodle feedback area.
  • If I had to modify your code in any way to get it to compile or produce correct output, I imposed a one point penalty. This was noted in the feedback.

I’ll have more comments about grading and the grades later.

Questions About Heuristics

I’m catching up on the reading and I am a little confused about consistent heuristics for A*.

Graph search maintains an explored set, so I am not sure why there is the more strict requirement of consistency for it over the tree search requirement of admissibility?

Because without it, you might end up with two different values of f for the same node. If you don’t keep track, you might end up on a suboptimal path.

A* expands nodes on the basis of their f value. That means you might reach the same node more than once in your expansions of the frontier, with different f values each time. This can’t happen with a consistent heuristic, though if you’re willing to do the bookkeeping then you can still find optimal paths with an admissible but inconsistent heuristic, by tracking best f-values so far for all nodes visited, updating as you go.

Perhaps this is because consistency also seems like admissibility stated another way to me.

Oh no, it’s definitely different, and a stronger requirement.

I can’t imagine when a heuristic would be admissible without being consistent.

They are odd. You can construct them, but they’re almost always contrived — that is, they’re usually obviously created to be an example of such an odd thing, not because they’re an obvious, natural fit for the problem.

Can you please try to clarify the difference for me?

Admissible heuristics always exactly- or under-estimate the distance to the goal.

Consistent heuristics are bounded by being at most the cost to move to a neighbor, plus the estimated distance from that neighbor to the goal.

Unlike admissible heuristics, consistent heuristics are monotone, that is, the estimated path cost is monotonically decreasing along a path toward the goal (at each step, it decreases or remains the same). This is a stronger requirement than admissibility, which is only a per-node requirement. Put another way, consistent heuristics must obey the triangle inequality.

Speaking of contrived examples, one way to construct them is to specify that the heuristic is chosen at random from among two admissible heuristics. For example, imagine an 8-puzzle, where for every node, the search process chooses to use either Manhattan distance, or the number of misplaced tiles. Whichever is selected, the value is admissible. But along a given path, there’s no guarantee the value will monotonically decrease (as Manhattan distance is generally going to be higher than the number of misplaced tiles). This odd definition of a heuristic is admissible, but not consistent.

Is A* always complete, even if the heuristic is not admissible?

Generally yes. It is not always optimal in this case, but will be complete, assuming you do the incompleteness-associated bookkeeping. (With the exception of state spaces that are infinite: much like A* with an admissible heuristics can have trouble with infinite numbers of successors with underestimated values of f, you can run into trouble here. I’ll leave it to you to work out the details.)

Java 7 on the EdLab

Update: CSCF appears to have speedily resolved this problem. Plain old javac should now work. You can ignore the rest of this post.

For whatever reason, while the default JVM on the edlab is Java 7 compatible:

1
2
3
4
$ java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.1) (7u65-2.5.1-4ubuntu1~0.12.04.2)
OpenJDK Server VM (build 24.65-b04, mixed mode)

the default Java compiler is only Java 6:

1
2
$ javac -version
javac 1.6.0_32

I’ve asked CSCF to update the javac default, but in the meantime, you can use, for example,

1
/usr/lib/jvm/java-7-openjdk-i386/bin/javac Validator.java

to compile your code.

Assignment 00 Graded

Assignment 00 has been graded.

The assignment was worth three points in total.

I asked Patrick to grade strictly according to the rubric below. If you think he made a mistake you can check in with him. But generally, if you have concerns about the grading on assignments please complain to me, not him.

  • 1 point was awarded if you submitted a résumé as PDF file with a reasonable name.
    • -½ point if it was in the wrong format (.doc, etc.)
    • no points were granted if you didn’t submit anything matching the description above.
  • 1 point for each of the two functions of your Hello World program.
    • -½ point if the spacing for either/both is wrong, either newline(s) or extra inter-word spaces.
    • -½ point for other errors, e.g., both Hello and World should have been capitalized in the output; java HelloWorld Marc should have produced Hello Marc not Hello World Marc, etc.