Sunday, December 12, 2010

Book Review: Head First HTML With CSS & XHTML by Elizabeth Freeman and Eric Freeman

Head First HTML with CSS & XHTML (Head First)Head First HTML with CSS & XHTML by Elisabeth Freeman

My rating: 5 of 5 stars

This member of the Head First series teaches in an engaging way with every lesson providing the context and the why, not only what and how, of using HTML and CSS.

I have written web pages before, and even worked through some on-line tutorials. But having some colleagues gently remind me that my web page needed to be updated and filled out provides an opportunity to learn how to do this right.

Head First HTML with CSS & XHTML does a better job then others. The style of teaching lends itself very well. Three case studies (even if contrived) weave their way throughout the book. And having three case studies allow every new concept to be introduced in a usable context. Each chapter had several different kinds of exercises. For all of us who learn in different ways.

I appreciated many sections where they take a break from teaching to explain why certain features of XHTML and CSS were the way they were. So you are not only learning a lot of syntax, but you are also learning why HTML and CSS are the way they are, and how to use them as tools as a coherent whole. Making it easier to remember and retain what they are teaching (almost like learning from first principles in addition to the tutorial they are giving).

Book page at O'Reilly

I review for the O'Reilly Blogger Review Program



View all my reviews

Tuesday, December 07, 2010

Book Review: Baghdad at Sunrise by Peter Mansoor

Baghdad at Sunrise: A Brigade Commander's War in Iraq (Yale Library of Military History)Baghdad at Sunrise: A Brigade Commander's War in Iraq by Peter R. Mansoor

My rating: 5 of 5 stars


This is the memoir of a field-grade officer's tour in Iraq as a Armored brigade commander in 2006. It covers a period where U.S. military doctrine was being debated and changed from active denial that the U.S. was facing an insurgency to fully engaged in counter-insurgency. In particular, as a brigade commander Mansoor was exposed to both decisions from higher up as well as the reality on the ground.

Mansoor demonstrates the capabilities of those in the military. As some recognize (esp. Col Gian Gentile USA), as a practical matter, many in the U.S. military were very aware of tenets of low-intensity warfare from experience in the Balkans, Africa, northern Iraq and around SW Asia and SE Asia. And regardless of what their political masters may say, many have learned that these have to be dealt with, and the U.S. has experience and doctrine to do so, if it is followed.

So the book becomes a memoir of what he faced, how he dealt with the Iraqi people he was there to protect as well as the insurgency he was fighting. And how he handled both as well as the political and military senior leadership of the time (who did not have on-the-ground experience in these same areas). I found it to be candid, and worth reading the thoughts of those who attempted to carry out their countries missions in the unknown of war.



View all my reviews

Monday, November 29, 2010

Fatherhood: One month in


Father and Son
Originally uploaded by LugerLA
One month. One thing we are agreed upon that a baby's state at the one month mark is not the fault of the parents (of course, assuming survival), which is why the one month point is traditionally the time you publicly celebrate. That being said, there are certain nice-to-have's at the one month point.

1. Baby is healthy (In a newborn there is only one measure. Gaining weight)
2. Baby crying is bounded.
3. Parents are doing better than walking zombies.

At this point, baby is doing a good job gaining weight, as we look at the strains in anything labeled 3 months. The official pronouncement from the pediatrician is "thriving"

He has quickly determined that there are other ways of getting attention other then crying. Although there are days that he tries that method quicker then others.

He is feeding on a three hour cycle. Most days. And some days it gets freaky (meaning you can set your clock on it). Of course there are some days (growth spurts. Too much energy) where he does not get anywhere close.

Some initial thoughts.

1. The runner's reminder, we are experiments of one, seems to apply here. I have a healthy disrespect for any expert who proclaims the One True Way to ____.

2. I've noticed that on Amazon.com, every baby book has readers who complain that the book is too belief in one true way. The majority of the books I have read are considerably more nuanced then their detractors (or most enthusiastic supporters) give credit for. Mind you, there is one book I consider an exception to this.

3. Baby feeds and eats and goes back to sleep a lot better when we get to him before he starts crying. It helps that he usually gives us other cues. But I don't easily take the advice that we should let the baby cry. At least not a newborn. (I don't think that newborns are deceptive. But I am aware that that time will come.)

4. We are given the understanding that a baby's personality changes over time, regardless of what the parents do. We'll take what we have as long as it lasts.

Wednesday, November 17, 2010

Conference notes: INFORMS 2010

I was in Austin, TX for the Institute for Operations Research and Management Sciences (INFORMS) annual conference. I had gone to this conference through grad school, and a few times since. This time was a little different.

There are many reasons to go to conferences. To keep up with your field. To follow recent developments. It is an efficient way of learning new developments (compared to only reading a paper). To present your work. But it is also a way to keep in touch with old friends (and if you are in a profession for any length of time, there should be friends at conferences). And in my case, the obvious conversation topics were:
"How old is he? Why are you here?" and "Pictures!"

As far as the professional side went, I had my talk. It went well. And a good chunk of the audience left right after my talk (I was the first talk of the session, so this meant that people were in the room for my talk, then they went to where they really wanted to be for the rest of the session time slot).

But what made the conference different was my talk was not important (ok, so maybe that has not changed). I was part of two talks at the conference, and this was the boring one. The interesting one was my student's. And that went well. Good audience reaction and commentary. And definite interest. Which bodes well when he does this again next year, with visions of graduating dancing in our heads. The goal for this conference was not about me, but all about him. Having him give a talk. And meet all the researchers who wrote the papers that he has been reading, poring over, and extending. To talk about what they have done and what he is doing now. Developing confidence that what he is working on is indeed something reasonably new, a contribution to the body of work, and something that can be of interest when it is done. It was a good feeling, watching my student interact with people I know (and many I did not). While talking to my own advisor, another, more senior researcher was commenting that it would be my advisors first 'grandchild'. I have to agree, talking about my student is a lot like what being proud of your own child is supposed to be like. So, in a sense, I have two thriving children, and one getting ready to take flight.

Sunday, October 17, 2010

Why I am Asian-American

All persons born or naturalized in the United States, and subject to the jurisdiction thereof, are citizens of the United States and of the State wherein they reside. No State shall make or enforce any law which shall abridge the privileges or immunities of citizens of the United States; nor shall any State deprive any person of life, liberty, or property, without due process of law; nor deny to any person within its jurisdiction the equal protection of the laws. - Amendment XIV, Section 1, United States Constitution

This is another badly worded post. I am asian as both parents are of asian descent. And I am American based on the Fourteenth Amendment of the Constitution as my parents were under the jurisdiction of the laws of the United States at the time of my birth. But it is also important to remember that nothing in the U.S. Constitution has to be the way it is. And like many aspects, this is one that has been challenged in the past, present, and will be in the future (Heritage Foundation brief about the granting of citizenship to those born while parents where in the U.S. under legal visas). And certainly, few countries follow this rule. Most countries define citizenship to follow from the parents. And few countries will allow the children of immigrants to be full citizens, with the rights to vote, hold office, and serve in its defense. In the United States at various point in time many groups were viewed with suspicion, and much resistance to viewing them as worthy of citizenship (obvious historical examples are Catholics, Irish, Italians, Germans, Chinese, Japanese, as well as Blacks, which prompted the amendment in the first place. A list of current examples is not much shorter.)

Where is my place in this? For several years, I have been on the board of a local asian american professional organization. (this causes amusement on people who knew me before I moved to Pittsburgh, as I am not the type who usually does such things.) As such, this is something other then asian (other groups are comprised of mostly asian immigrants), and not completely just another professional group (the Pittsburgh region distinctly lacks diversity compared to other urban areas of the United States.)

Other countries view the idea that the children of immigrants can be full citizens just as those who have been in the U.S. for several generations to be impossible. I suspect that most countries do not have provision for someone to desire full citizenship who did not have local ancestry by blood. The alternative is the view that purity of blood is paramount. An example was the view in the early days of the U.S. that one drop of blood was enough to make someone viewed as black, regardless of how much of his ancestry was white. In Germany, Chanceler Merkel has declared that multiculturalism has 'utterly failed'. France is in the process for making it easier to strip people of their citizenship.

Why should the U.S. not follow the path of Germany, France, or Japan? Why should the U.S. continue too put itself up as a place where those who have ambition and goals and drive can go and work to succede? Why should the U.S. be a place where the children of immigrants who work with their hands can gain the education to succede and thrive?

The U.S. has a myth of American Exceptionalism. But if the myth is true, then it must be because there is a characteristic of the U.S. that is exceptional. It is not the racial stock of its people, because that racial stock is found in the lands of its origin. It is not the ties to the land. Others in other places have just as strong ties to the same types of land that we have. It is not a natural industriousness of its people, many lands claim industriousness and even education better then the U.S. But none have told the world that there is a place for those who have ambition, drive and desire to create in the way the U.S. has over the decades. And none have been therefore attractive for those without social status, where the children of parents with no special status of title, social class or privilege can begin working on the street, in garages, with their hands and rise to become captains of industry or even a President. And because all these things are true, I believe in the myth of American Exceptionalism.

Does it have to be this way? No, it does not. There are many calls that say that those who 'do not look like us' should not have the privileges of a citizen. That it is not possible for people to change from the citizenship or religion of their parents. That people should not be able to rise in the world through effort, drive and education. That people who are different should not be allowed to serve in this countries defense or in public service.

Are there places like this? Yes. And they are dying, stagnant, fully aware that their best days are past and will not return. Realizing that they are in a spiral of destruction, feeding off the assets built in the past, and not renewing the future. And should America turn its back on the things that make it exceptional, I will mourn the end of America's greatness.

Sunday, September 26, 2010

PSO: Showing off talent

Yuja Wang Sonatas & Etudes


[This post was originally posted at Pittsburgh Symphony Blogs]

Before last week's opening Gala, Ann Pratchett and Renee Fleming hosted a interactive talk about their books. One question came up about the internet and Ann Pratchett criticized how commentators on websites have a tendency to give their reviews 'gladiator style', meaning thumbs up or thumbs down. What results are reviews that either excoriate the work reviewed as a pile of worthless garbage or the most incredible experience this side of heaven. But generally with no explanation or justification. And the result is only the form of interacting with the author and the creation without substance. It is a criticism that can be leveled at American society in general, valuing quick, snappy decisions based on instant impressions as sincere and authentic while being suspicious of anything that results from deep thought and study.

But these impressions turn out to be merely shallow and incomplete. I was talking over lunch this past week with a regional manager of a major shipping company who was lamenting the difficulty in identifying job applications with a particular ability. Things like grades are too one-dimensional, and the interview does not allow for depth. The only way she can evaluate the applicant, was to have them work for a year.

And so it is with the creative arts. It is a mistake to evaluate a work on one aspect, or an artist for a single work, or even work in a single environment. An evaluation needs to be across a range. And that is what made last weekend's concert rather enjoyable, it showcased a range across style in a single concert.

Michael Gandolfi's Garden of Cosmic Speculation opened up the concert. Prior to the piece, the composer spoke about it. The complete piece is actually 11 movements. But for performances the composer expects only a selection of the movements to be played, and any subset is appropriate. It becomes very much like going to a large garden or an art museum, there is no time to see the whole thing if you do it right, to experience it deeply you must go and select what parts of the museum to see, and leave the rest for another day. Musically, the four movements feel very different, almost like each was a separate work. And this provides an example of showing his range as a composer in a single work.

Having Yuja Wang play Rhapsody on a Theme of Paganini was a great choice. It is very easy to have Ms. Wang play pieces to show off technical brilliance. Certainly most publicity for her revolves around her ability to perform fast, technically demanding pieces. And many soloists use such pieces to showcase their skills. But Ms. Wang is capable of more. And in Rhapsody she was able to show this. There are the expected fast, loud and technical sections that demonstrates her command of the keyboard. But there are also flowing melodies, intricate delicate sections and textured nuance that show off not just mastery of a piece, but an understanding it to let it shine. And by not trying to dominate the piece, I am more impressed by this interpretation of it, and by Ms. Wang's artistry in addition to talent and skill.

Friday, September 24, 2010

Installing pyspatialite

Goal: To use spatial databases to perform operations such as centroid, nearest point, and distances to generate a table of distances along a road network from area to area, using the nearest node to the centroid of an area to represent the area.

Backup plan: Create a list of nearest node to centroid of areas. Use some code I have previously written in R to implement Dijkstra's algorithm.

Preferred method: Programmatically access Spatialite and perform all functions in spatialite.

Barrier: Most distributions of SQLite (including the sqlite3 library included in Python) do not enable loading of extentions.

Solution: Install Python module pyspatialite.

Installing pyspatialite is done through easy_install: sudo python setup.py install

The documentation mentions that you need geos and proj libraries installed. What it does not tell you is that you need the development versions (which include header files) of these libraries, as well as the Python headers. After installing the developmental files, then you can install pyspatialite.

Installing JAGS/rjags/R2jags

I got a new computer via a project. It is a Windows machine which is heavily administered, but they let me put Virtualbox on it, and naturally I have Ubuntu running on it so I can actually build the tools that let me do work. Times like this I am very glad I've been putting my installation notes for various packages on the blog since it saves me time searching all over the place (e.g. some gotchas on Eclipse and StatET (R-project))

For JAGS (Just Another Gibbs Sampler), there is an Ubuntu package of 1.0.2, but JAGS is at 2.0+. And the CRAN packages of rjags and R2jags are similarly behind. So I downloaded the source and installed them.

JAGS was simple. The usual combination of:

./configure

make


sudo make install


make installcheck


works as expected.

For rjags and R2jags I had to try a number of different configurations. I ended up with

sudo R --with-jags-modules=/usr/local/lib/JAGS/modules-2.1.0 CMD INSTALL rjags_2.1.0-10.tar.gz

sudo R --with-jags-modules=/usr/local/lib/JAGS/modules-2.1.0 CMD INSTALL R2jags_0.02-09.tar.gz

While I'm not entirely sure that sudo was necessary, prior to this I was getting in trouble with

Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared library '/home/louis/R/i486-pc-linux-gnu-library/2.10/rjags/libs/rjags.so':
libjags.so.2: cannot open shared object file: No such file or directory


So this did work. Source is Installing jags on 64-bit Debian by Roger Levy

Wednesday, September 22, 2010

Why I am a Red Cross Volunteer



At my University there has been a Red Cross Club for a few years. And our local American Red Cross chapter finally discovered them. So I was there today at their second meeting of the year to talk about the Red Cross and the VA and volunteering off campus. I spoke about the things we do as emergency services volunteers, responding to fires, floods, hurricanes, storms, and so forth. Of Health & Safety, teaching classes. Of Service to the Armed Forces, of having others in my unit who were deployed who got the calls that they should come home while there was time. I suppose that this audience probably were more interested in this talk then my students in class are.

I started volunteering for the Red Cross when I was in college. I was a volunteer EMT, and since I was learning CPR, I also became an instructor. Our EMS organization taught classes on campus to university staff and to students (it was how the organization raised funds). And I taught classes in the community as an instructor for the Red Cross chapter.

I left that behind when I graduated and started work. Work and grad school just squeezed that out of my life for a while. Then when I went back to grad school for a PhD I started volunteering again, this time in emergency services. My degree was in modeling operations. The Red Cross gave me the opportunity to take part in operations.

It is not just that the Red Cross conducts operations. It conducts them under some of the most difficult constraints for operations. In disaster response, we do not choose the time, place or scale, and we do not get to choose who responds. Those who plan and run the operation work with the resources and personnel available at the time and place. The current classical situation is a hurricane. And to work in that setting competently, with the chaos of an unknown and uncertain situation where the pressure of people whose lives are at stake is a stress and challenge only matched by combat against a willful and capable opponent.

What to tell these college undergraduates that perhaps volunteering with the Red Cross or with Veterans Affairs is worthy of their time? I had three areas for them.

1. This was good and meaningful tasks. Granted, there were other opportunities for good and meaningful things that they will be provided on a college campus. With the Red Cross and VA staff and volunteers where people who have done things. At both, everyone there has had the experience of being in high stress situations and having to act and make decisions. Whether it is a Red Cross volunteer who is the team lead at a house fire where the family has no where to go, no food and only the clothes on their back, or the nurse who has had a patient crash, they would be with people who have experienced life and can get things done.

2. The Red Cross and the VA trains their volunteers. For those who volunteer over years, they will be trained to do their tasks, but also about dealing with people and dealing with life in all its aspects, both the good and bad. To recognize what is important and what is not.

3. I also told them that I was a professor. And that this semester, there is a group in my department whose senior design project is with the local Red Cross Chapter. Because the Red Cross and the VA are not just another charity or hospital, but they are organizations that reach out into their communities and interact with them in complex ways. And because of this someone with a little curiosity will quickly see there are many questions to be asked, ways of handling difficult issues to develop, and resource limitations that need to be dealt with. So I told them that I would like to see members of this club who volunteer with the Red Cross and the VA over the course of their college years to be doing senior projects, senior thesis and class papers based what they observed and did with the Red Cross and VA. So they can take what they are learning and put it in context with real problems effecting real people.

This fall, the first Pitt students have started volunteering at the VA under the Red Cross Veterans Affairs Voluntary Services partnership, after going through orientations in spring. This year, they are being introduced to the Red Cross and VA at the beginning of the year before they have settled into their routines. And these students will see a part of life greater then what they would get if they did not leave their campus.

Monday, September 20, 2010

Renee Fleming: The Inner Voice

This post was originally posted at the Pittsburgh Symphony Orchestra Blogs

The day before the opening Gala, Renee Fleming and Ann Pratchett had a book discussion at the O’Reilly Theater. It was an enjoyable conversation with two artists. They spoke of limits, of family, of talent. But what stood out, was they spoke that creating art is work.

Fleming commented that one thing that she dislikes is the belief that music is a gift, that one day someone opens her mouth and sings, then she is discovered, and then she goes to the Met. (Metropolitan Opera). Ann also has instances where people ask if she works. Because they are faced with the belief that talent is innate, it only needs to be found. But for both of them, this is not true. And it is not true in general.

Peter Orszag recently wrote two pieces in the New York Times about talent and effort. His observation that is shared by many others who have examined this (Michael Syed “Bounce”, Carol Dwed “mindset”, and others is that innate talent only gets so far, that to reach world class levels in a complex field takes practice. 10,000 hours of practice. It holds in music, mathematics, many sports, and chess. It shows in the dedication of young men and women in their teens who get up with the rising sun to practice, whether it is on the athletic field the weight room or in the studio. The students working their way through problems and proofs. My friends in martial arts working on their kata. Soldiers and FBI agents working through battle drills in the desert.

Fleming said at one point that when learning a part, it is not enough to know the words and the music, then you need to learn the meaning. And then, when you know what it means and you know it well, you are able to do more then follow the score and you are able to interpret or try new techniques to make it your own. The same is in other fields. Through practice the athlete learns the limits of her body and strength. The chess or go player can recognize patterns on the board and see the progression of the game. The soldier knows his role on his team and the overall intent of his commander even when he is unable to communicate with them. The mathematician or scientist or engineer can look at a problem and recognize what the form of the solutions or results will be even before she begins the work. Authors and writers can see how a turn of phrase can change the tone of a work. All this comes not from some gift of birth, but time and effort in practice and study, purposeful and directed effort.

The thing is, somehow one has to be convinced this is worth the effort. If you are good, you will be around people who are even better. And you will be working on things beyond your ability. And here you have a choice. You can decide you are good enough and stop. You can give up because it is too hard. Or you can look ahead and decide that it is worth the effort and pain of work to master your art. And the rewards? While Renee Fleming stated that her goal when growing up was to be good at something and it did not have to be music, I am glad that it was.

Sunday, September 19, 2010

Why I enjoy classical/concert music

Fingers on keys

This is, obviously, a badly titled post. Because 'enjoy' is not the proper word. Not that there is anything wrong with merely enjoying something. I believe that there is a place in life for things that can be enjoyed as they are. But I don't think that 'enjoy' or 'appreciate' conveys how I experience concert music. There is a cliche that those with mathematical backgrounds should enjoy classical music because music, like math, deals with patterns. But that does not get you very far. By the end of chapter 2 of his Critical and Historical Essays (lectures on music at Columbia University), Edward MacDowell shows examples of what happens when you take mathematics as the means of analysis of music, and each historical case of cultures that try it leads to dead ends.

When I was in high school, the smart kids, the ones in the honors program, took Art Appreciation. I was not one of those kids. To this day, I say I know almost nothing about art/music history or theory. My experience with music was playing in the high school marching and symphonic bands. While I was good enough to be first chair my senior year, and being part of the Chicago All-Catholic Band, our ambitions were suitably limited (the bandmaster considered part of his job to be dissuading students from the profession.) The goal there was an appreciation of music, and perhaps a life-long hobby (e.g. community ensembles or playing in private). This is where I was when I lived around Washington DC, where I took advantage of a wealth of performances in public spaces (museums, parks, public buildings, university) and the occasional concert. And I continued my practice from when I was an undergraduate of going to performances of friends who were in music programs at the local universities.

In graduate school this began to transform. I had friends in the music program, but now I was at a school with a decent music program, where students there had aspirations of professional careers in classical music. I was going to recitals, concerts, and programs where my friends were performing on a regular basis. And, since I was taking my time in a Ph.D. program, I could follow them throughout their time in school, and I could watch how they developed both in performances and sitting in on practice time. (I had one friend comment that having me in the room while she was practicing was like a studio session. My wife thanks everyone for the training as she is the current beneficiary of all of those sessions.) Over time I stopped merely hearing the music to listening for the interpretation. Instead of appreciating the music being played, I could observe how an ensemble interact with each other and it became a conversation between people, not only the genius of the composer putting notes on a page.

What do I gain? Like all of the other fine arts, classical music is an abstract way of asking what it means to experience being human. At times composers use it to respond to a historical context. Most composers chose to create a tension by using a format to constrain themselves as they desired to emote or to present a story. (I tend to not get many of the more free form moderns). And I take it as a privilege to observe the result.

I am looking forward to another season of blogging for the Pittsburgh Symphony Orchestra. I have always maintained that my blog is not a concert review. The Post-Gazette has someone who does that as well as people associated with the schools of music and conservatories. Many with backgrounds in the humanities can discuss what a piece means. And I know little about the mechanics or history or philosophy of music. What I can do is pay attention to the concert and react to it. At a book discussion prior to last weeks opening gala, Renee Fleming stated that her performances where a collaboration between the creator (composer) and the performer. But she is missing an actor. Aaron Copeland stated that art is a collaboration between the composer, the interpreter, and the listener. Copeland tells the listener his job is to be aware of the personalities and functions of the composer and interpreter, to distinguish between them. And it is not sufficient (or maybe not even necessary) to be educated and trained, but the listener must love music. And not just particular styles or forms or schools of music, but across a wide range. And then react to it. Otherwise the efforts of composer and interpreter do not have meaning. I do my part.

A cello

Tuesday, September 14, 2010

Creating spatial data files

At my school, there is a class on Geographic Information Systems (GIS). When you complete the class, you now know how to analyze data using ArcGIS. But you do not know how to create the data files you used. And you do not know how to do anything that ESRI did not include in ArcGIS. As a researcher, I find that unacceptable. This year, there is a senior project team including someone who has taken this class doing a project with the local chapter of the Red Cross that will involve using spatial data. But since they cannot create a spatial file, I will create the data sets that they will use to populate their models. If I am going to do something, I may as well learn something along the way. Those somethings are Spatialite and Google Maps API for geocoding.

Step 1. Given a list of addresses, find their latitude and longitude. The official way to do this is to get the TIGER line files of street maps. These encode each block by name and the end points of addresses for each block along with their geospatial coordinates. Then you can interpolate. The more pragmatic way of doing this is to find someone who has already processed the TIGER line files and created an API or other interface to work with them. There are many that will then create Keyhole Markup Language (KML) files as output, and I have used one before.

The way I will do it is to use the Google Maps API. There is a Python package called googlemaps that will find lat/long given a properly formulated address. (note: long is a keyword in Python, so we use lng for longitude)

from googlemaps import GoogleMaps
def getlatlong(gmaps, streetaddress, city, state, zipcode):
address = streetaddress + " "+ city + ", "+ state +" "+ zipcode
lat, lng = gmaps.address_to_latlng(address)
return lat, lng
# get api_key from http://code.google.com/apis/maps/signup.html
api_key = "APIKEY"
gmaps = GoogleMaps(api_key)
. . .
lat, lng = getlatlong(gmaps, streetaddress, city, state, zipcode)

Step 2. Create an Spatialite database. Spatialite is the SQLite database with extensions for Simple Features for SQL, i.e. a relational database that allows for queries on geometric objects. The other options are Oracle Spatial, DB2 Spatial, PostGIS and MS Server with spatial extensions. There are also spatial extensions to MySQL, but they do not meet the SFSQL standard, and they are simplistically implemented (which would lead to many errors if you actually needed correct answers instead of approximations.) Of these, Spatialite does not require an administrator and contains its data in a single file, both of which simplify their use. To use Spatialite, the PROJ and GEOS libraries should already be on your machine. (see Spatialite installation instructions)

To create a database, use spatialite the same way as you would have used sqlite. But after creating the database, load init_spatialite.sql This SQL file loads some required tables. Sometimes, Spatialite will create the tables on its own, but sometimes not (especially if the database was originally an SQLite database).

Next, load the data (using any of a variety of different methods for SQLite databases.) Given address data, determine lat/long and enter each of them into their own fields. (you probably have to create these fields after importing the address data.

Step 3. Create the geometric representation of the data. What makes data spatial is the connection of a geometric representation of the data and the information about the spatial object. Before you do this, it would help to look at other datasets you are using. Spatial data is usually distributed as ESRI Shapefiles. Each Shapefile is actually a collection of files that include the polygons of the geographic objects, the data associated with those polygons, and a projection that describes how to make a representation of a surface of a sphere into the two dimensions of the computer screen (or piece of paper). The projection of a shapefile is usually found in a *.prj file in the same directory as the *.shp file. Most GIS viewers allow you to look at the shapefile properties from within the GIS viewer. The value needed is an SRID, usually a 4-digit number (sometimes 5). From here, a set of spatial queries are run from within Spatialite to add the geometry to the database. See prior post on loading lat/long data in Spatialite. When these spatial functions/queries are run, Spatialite will perform a series of operations that use the information in tables loaded by the init_spatialite.sql to generate the geometry representation or convert representations between projections. At this point, the data is now spatially enabled.

Step 4. View/Export. At this point, only a few GIS viewers can use Spatialite databased directly. One is QGIS. So after performing any wanted spatial queries or other operations you should export the data to another format, such as Shapefiles. The OGR/GDAL tools of the Geospatial Data Abstraction Library are able to do this. Within Spatialite you can use the .dumpshp function to create a shapefile.

The format of .dumpshp is
.dumpshp table Geometry sitelocations CP1252 POINT
table is the TABLE to be exported. I think this could have been a VIEW as well. Geometry is the name of the field within the table that has the geometric representation. Note that Spatialite stores this as a BLOB object. sitelocations is the name of the shapefile to be created. CP1252 is the name of a character set. Presumably there are others, but I have been using CP1252 for now. POINT is the spatial data type. Other types include LINESTRING, POLYGON, and MULTIPOINT.

What would be very useful right now is if I could automate steps 3 and 4 so I could run them from within Python instead of doing them inside Spatialite. However, this only works if SQLite was compiled with the ability to load extensions. Most distributers do not do so. One workaround is to install the pysqlite2 extension and compile it so that it can load extensions (as opposed to using the sqlite3 extension that is included in Python).

Sunday, September 12, 2010

Why I run

(and hike and camp and . . .)

"Short cut this way" - spectator sign at 2004 Chicago Marathon
"No short cuts" - 2004 Chicago Marathoners cry on seeing the sign

There are lots of reasons to promote running. Fitness. Competition. Glory. Euphoria. Myself, after 20 years of running I'm not going to turn heads by my fitness. The only races where I've gotten prizes are races where noone serious shows up (don't laugh, it has happened. The funny thing, I was teasing the eventual winner about it before the race). And I don't get euphoria from just running any more (ok, maybe if there is a real good hill. Note: my idea of a real good hill is one that a car cannot drive up.)

But what I do get is connect to reality. My profession is one of abstraction. How to make an abstraction of our world so we can understand it better. But, as I had to explain to one of my students, when you are faced with an actual instance, there is no need for abstraction. In running, hiking, camping the road, trail, hill, stream, field is present with you, and you have to deal with it as it is. Heat, water, cold, ice, rain, snow, hazards, obstacles, are things you face. The constraints of fuel, food, water and the limits of your body, skill, knowledge and training have to be considered before you start, and their effects have to be dealt with. Preparation matters, and you pay a price if you skimp. There are real hazards. I've written journal entries for the purpose of informing whoever discovered them. I've given reports that a trail was hazardous and should have been closed.

I think we live in a society that likes to ignore reality, preferring to view perception as more important. And they can use power derived from fait, moral righteousness or power to enforce their views. But that does not count when it is you, your fitness, skill, training and nature. And I like having one part of my life where that is unambiguously true.


J, J and I at the finish

Monday, September 06, 2010

Loading Lat/Long data into Spatialite

The task: Load spreadsheets with Longitude and Latitude data into a spatial format. Preferably in a way that can be done by people who are not good programmers but can follow directions to use command line tools.

Initial data: Spreadsheets with addresses and Longitude and Latitude. Note: this can be created using the Google Maps API accessed through various programming interfaces.

Tools: Spatialite and SQLite Manager (Firefox plug-in)

Steps:
  1. Save spreadsheet as a comma separated format
  2. Import into SQLite using SQLite Manager plug in
  3. Open Spatialite using command line interface.
  4. Add the geometry to the table using: SELECT AddGeometryColumn('addresstable', 'the_geom', 4326, 'POINT', 2);
  5. Note that 'addresstable' is the table within the database that contains the long/lat data. 'the_geom' will be the new field that contains the spatial data. 4326 represents the SRID for the projection to be used (in this case WGS 84). 'POINT' is the spatial data type. 2 indicates this is in a 2-D space.
  6. Calculate and insert the spatial data using: UPDATE 'addresstable' SET the_geom = GeomFromText('POINT('||Longitude||' '||Latitude||')', 4326);
  7. Longitude and Latitude are the field names containing the longitude and latitude data in the table. The names do not matter. But they order does. And they are separated by a single space.
  8. Method is taken from PostGIS in Action by Obe and Hsu. Spatialite function names are similar to PostGIS function names. In many (but not all) cases, the 'ST_' is removed from the beginning of the function name. Note that for the exceptions, the Spatialite documentation references two function names, one without 'ST_' and one with.

Sunday, September 05, 2010

Why I am a photographer

I have had a wide range of hobbies, as does most people over the course of their lives. And like most, many have gone by the wayside. I think one aspect of maturity in a hobby or an activity is that you are no longer merely an actor performing techniques, but you either guide others (through teaching or through organizing a community) or you are pushing yourself in the practice of the art. In photography, this observation comes through in the form of commentary on digital cameras, especially digital SLRs. One big criticism is that the advertising around cameras fosters a view that being a good photographer was only a matter of a big (and expensive) camera and big (and expensive) lenses, completely neglecting the elements of skill and practice and understanding of light.

Art Institute

Cellist at play

I started photography with a manual SLR. Center-weighted meter, manual focus, manual aperture, manual shutter speed. After that was a point and shoot. An Olympus Epic known for its good 35mm f/2.8 lens and being a hockey puck (indestructible). It was a few years before I even bought my first auto focus/auto exposure camera. Continuing my ways, my favorite camera was a manual focus, manual exposure rangefinder (i.e. what cameras were like before SLR was invented). This was characterized by fast (wide aperture) prime (non-zoom) lenses and frequent use of black & white film. Also known as "this is how Cartier-Breeson and Capa did it"

Louisa and Sheena talking by the eternal flame

There's soup in the pot



Part of being good is taking time to learn the fundamentals. Learning the ways of light and shadow. The limits of the sensor (film or digital). How to see relationships in a scene. How to see a relationship unfold so you can be ready at the decisive moment.

Hello great-grandson


Mynas over the Chao Phraya River

My investment in equipment pales in comparison to the investment in study and practice, and I like to think that it shows.

For my involvement in the arts, photography is my only practice of it. So to improve means to find ways of improving your skill. And one of the classical ways of developing creativity is to put in place boundaries that force creativity in other ways. Thus my preference for using prime lenses and black & white. It becomes the frame in which I develop. And the expectation is that when I do use color and zoom lenses, the skills and ability to see that is developed carry over.

Schenley Bridge over Panther Hollow

Three glasses at Cafe Havana

Sunbeams in Todd Nature Reserve

Like many things, I have adapted as the technology behind photography has changed. My rangefinder is now rarely used, since the chromonegative film I had always used is no longer available. I now have a digital SLR and a set of zooms. But the manual focus primes are still what I take most of the time and that goes well with one of the smallest APS digital SLRs on the market. Most of my photography is not intended to push my abilities, but to record the events of life.

Lawrence and S talking music


Sunset

Thursday, September 02, 2010

Why I read

Ruined by Reading: A Life in BooksRuined by Reading: A Life in Books by Lynne Sharon Schwartz

My rating: 2 of 5 stars

View all my reviews

I recently went to my first meeting of a book club. The last one I was with slowly faded away, as such enterprises do. For the new one, this was its second meeting of its existence. Which is a milestone. If nothing else it means that one group of strangers did not repulse each other away and they thought it was worth meeting again. It does seem odd that less than two months before a baby arrives I am meeting new people. But I was not alone, as one guy there is a new father as well. The book we read this month was fairly unremarkable. But its subject is the place reading has played in the life of the author. Most of the book focuses on the author as a young girl. And for an author to examine the place of reading in her life is a bit of navel gazing.

So, why read? There are many arguments not to. I know many people who state that they do not read fiction, only non-fiction, viewing all fiction as fantasy and a waste of time. Various books get branded as out of bounds or satanic. Of course, many of these same people invest time in video games, shopping, and other arguably non-productive hobbies and pursuits which I do not. I also can say, as my wife would put it, I have actually done a lot of these things in real life, so living vicariously through reading is not strictly necessary.

What reading provides is a way of making my world larger. I joke that the reason I listen to people telling stories and lessons learned is that I want to hear others talk about how things went wrong. Because I am a very creative person and I want to make mistakes that are unique. Mark Twain in "Taming the bicycle" discusses learning through one's experiences only as misleading, since you don't know if what aspect of your experience provided the right lesson.

Fiction does the same. What good fiction should do (and I hold movies to the same standard) is develop a world, and provide situations for its characters to engage in the three major conflicts: man against nature, man against man and man against self. Given the setting (I always give authors and writers great leeway in how they make their setting, since real life is pretty varied as well), do the choices and consequences of the characters make sense. (again, realizing the wide range of responses people in the real world use, there is a certain amount of range available here too.) Every (good) book adds to my world, and provides a base that I take with me in engaging my world, in all of its messiness and occasional perversity. And ways of describing my experiences to others (I write a lot of after action reports and meeting notes)

Is it worth reading and talking about it with other people? Like many things, reading is a skill. There is a benefit to testing your ability to observe and synthesize with other people who also had the same experience (reading the same book). It is a given that everyone will take away different things from a book (which is not to say that the takeaway needs to be anything profound or deep), but you should at least recognize each others observations of action, character, and motivations.

But the main reason I read is that it makes my world larger. And richer. And we look forward to our son doing the same.

Monday, August 30, 2010

Why I am a researcher

I was asked yesterday about the value of a Ph.D. It is a fair question. When I was in graduate school, occasionally a first year student would say something to the effect that he was in grad school because he wanted to make money. We all informed him that he assuredly had the skills to do very well, with an MBA (equivalent) from the excellent business school down the block at our university. And that he would make more money for considerably effort then the road that he was starting on. I did not start my professional life as an academic, so this is a question that in a sense has an answer.

After I finished college I went to D.C. to a policy school for a professional master's degree and to work. (because all Master's in policy students usually work while in school). Over the next four years I worked for a legislature, a non-profit, a government agency and at a government contractor. I did this as a quantitative analyst and as a logistician. And it was fun. I worked on environmental studies and projects that were at the cutting edge of applied economics and modeling. There is work I did that I could see in the news over a decade later as they came to fruition or the issues they addressed began to be considered by commercial enterprises. I had few projects that were routine. There was always the sense that you were developing something new, and while there may be ways to do that, what you would find along the way was not always obvious in foresight.

But I also realized that the only reason I was working on these projects was because of my boss(es) along the way. And this is not what work would always be like. Looking ahead, I realize that there were really two ways to have a career doing new things like this. One was to work for twenty years and establish yourself at the top of your field (like my last boss). The other was to get a Ph.D.

And this was the value of the Ph.D. Not the knowledge gained along the way, but the opportunities to work on things that were new and hard. At one meeting with non-researchers I've explained I do not want to be working on problems unless someone else has examined it and failed to find a resolution. And at this time, I can say I have this. Will this continue? As a non-tenure track academic I have a good place working on difficult applied problems, where there are both technical and social issues that need to be solved (as I've commented to one doctor, if the social issue is what is preventing the situation from being resolved, it is an issue that needs to be solved.) Is there a place long term for this? One of the criticism of academia is that it focuses on problems that are theoretically hard rather then hard in practice, even when the reason it is hard in practice is because of the lack of development in theory. In Operations Research, there is pride in working on hard problems, but the definition of hard is based on the technical difficulty of the math, while I tend to use the definition that smart and talented people have tried and failed as my benchmark. Whether there is a place for that remains to be seen.

Monday, August 23, 2010

Why I ____

I remember an article and conversations some time ago asking the question which is harder: Marriage or Motherhood? Replacing 'Motherhood' with 'Parenting', I think both of us have the conclusion that given how easy Marriage has been, we are going to come on the 'Parenting is harder' side of the argument. Even though we are not among those people who knew each other for many years, joining lives was not a big adjustment, partly because our lives were (and are) in the midst of ongoing changes so it was more of merging of two moving highways then big changes. And we both have well exercised sharp elbows. At least neither of us ever picked up the habit of hiding sharp elbows until the worst possible time. (or hiding them at all)

People who rhapsodize over marriage or parenting have tended to make both sound very unattractive. Both criticize those who have not yet joined them as selfish (I sometimes wonder if my friends who criticize their unmarried peers as selfish but do not have kids hear the criticism that those who are married without kids are being selfish.) Both describe the life post-marriage/parenthood as a dying of self and life and the parts of life that are interesting. And the wonderful alternative presented is often something unappetizing. A life without flavor. We've been glad that this has not come to pass in marriage, but parenting looks a little more problematic. To use vocabulary one mother used, working with the things that come in marriage involved skills and attitudes that were already part of our operating systems. We're not sure that Parenting is. One person who was ready to provide wisdom asked us the question "Are you ready? Most people are not sure they know how to raise a child before their first" Our answer was "Of course not! We're pretty sure that after our first child we still won't know how to raise a child."

The other problematic side is the reality that some aspects of our lives will fall away or change markedly. We are fortunate that we have many examples of people who did not disappear off the face of the earth when they had children, and so we think there is hope.

But, as I tell my graduate students and the post-docs I work with, the reason I write such detailed messages is because I have no memory. And while I still have a nice record of photographs, I do not live life through a viewfinder (and I never will). So to remember, I have to write it down. And so I won't loose it, I am putting my faith in Google (and maybe a printout) as a place of record. So begins a series of notes on the various aspects of my life now. And in a few years, I may look back on it fondly (or not) as we bring a child into this world and all that is before us.

Friday, August 20, 2010

WinBUGS and JAGS differences

One of my graduate students and I have been working on input modeling in a setting where the amount of historical data can range from a lot to almost no (i.e. 0, 1, 2) occurrences. So both of us have been learning Bayesian methods and developing means to work with our setting. Part of this involves working with the standard tools and building blocks for Bayesian methods, in particular Monte Carlo Markov Chains (MCMC). To implement these methods, you can program your own, or use some standard modeling frameworks. Some of these frameworks are essentially programming libraries. But the primary ones are Bayesian inference Using Gibbs Sampling (BUGS) derivatives. There are two families: WinBUGS/OpenBUGS and JAGS.

WinBUGS is the direct successor to BUGS, with OpenBUGS being the open source next generation. BUGS is both a software package as well as a model specification language for MCMC models. One issue with WinBUGS/OpenBUGS is that it is written in Component Pascal. WinBUGS depended on the BlackBox component builder, which is only available in MS Windows (as does OpenBUGS, but OpenBUGS is essentially the open source next generation of WinBUGS once it is done). JAGS is an opensource implementation of the BUGS model specification and command language and is written in C++ on top of some open source libraries. JAGS exists specifically because of the inability to port WinBUGS. A review of the literature shows that WinBUGS/JAGS/various other libraries, all have areas of strength and weakness. Research groups working extensively with Bayesian methods use all of the them at various times.

But, this is our first project. So one thing we did was to examine three frameworks while we were learning Bayesian methods. I primarily used JAGS, one graduate student worked with WinBUGS, a third graduate student (the strongest programmer) used MCMCpack (an R package).

Our intent was to use either WinBUGS or JAGS when we actually implemented our methods on real data, so the question was which to use. Some obvious differences that came up.

  1. When running using R, the RWinBUGS interface opens the WinBUGS application to run BUGS model. We anticipate having to run this on ~50 separate data sets a day as part of our methodologies. This time of interface is unstable (both theoretically, and practically as my student's computer ends up hanging a lot)
  2. WinBUGS is a lot more particular about the BUGS model specification. Or, since the WinBUGS people are the ones who developed the BUGS model specification, it is probably better to say that JAGS is much more forgiving. Some gotchas that came up included:
  • When specifying distributions, parameters in WinBUGS could not be expressions. Only single variables. I.e. something like (num1*num2) is not allowed. So we have to perform all computations, then specify the distribution separately. JAGS allows passing an expression as a parameter.
  • WinBUGS does not have an exponent operator (either '^' or '**') JAGS does. Since one parameter that is important and common is 1/variance, this is very useful when the data is expressed in terms of standard deviation. We have to use expressions like (num1*num1) all over the place.
  • JAGS from R is seamless (R2jags, rjags). You call JAGS, and it returns without opening any IDEs. You can see the JAGS output in the terminal, but JAGS runs in command line, then is done. No IDE left to close. (R2jags was designed to work the same way as RWinBUGS, but I think it is much more elegant)
  • The JAGS documentation includes some more differences, but we have not hit those yet.
So, for this project, given that we have a certain amount of risk based on the fact that we are figuring out Bayesian methods and MCMC along the way, we're going to go with JAGS as our engine. Someday we'll get better at using WinBUGS/OpenBUGS and MCMCpack, but not today.

Thursday, August 05, 2010

Book review: The Visual Display of Quantitative Information by Edward Tufte

Edward R. Tufte: The Visual Display of Quantitative Information by Edward R. Tufte

My rating: 4 of 5 stars


The book goes through many examples of displaying information visually. And it does so through a historical context, reminding us that the issues that are faced and the many ways to (mis)-represent them have been around for centuries.

What I'm reminded of is that statistics and data analysis is not just about methods, but they are means of communication. And like all methods of communication, they can be made less clear whenever you have something other than clear communication as the goal.

Many of the techniques discussed in the creation of various plots and charts are artifacts of when printing graphics was done by ink and pen, and difficult to reproduce. But the book's focus is not on the techniques of making these visual displays, but on the principles in designing efficient displays.

I use a number of data analysis packages and packages, Excel, R, Python, etc. After reading this it makes me look at these other packages and their options differently, wanting to evaluate the choices there designers made. It also makes me look at charts and graphs on internet sites, newspapers and magazines differently. I imagine the author would consider that to be a success.

View all my reviews >>