Updating Your Priors Effectively

I use that term (“update your priors”) quite frequently.  Almost as frequently, people don’t understand what in the world I mean.  Now you too can learn all about Bayes’s Theorem from the comfort of your own home, without too many scary equations.


Review You Can Use [tm]: Marvel vs. Capcom 3 (PS 3)

Editor’s note: There’s no money in the bank at Wrestlemania, and we aren’t ordering Wrestlemania this year, so no columns on that. Two more Reviews coming up — MLB 11: The Show and You Don’t Know Jack (PS 3).

There was a time, many years ago, when I loved fighting games. The year was 1995. The Indians were going to head to their first World Series in over forty years. I had recently become a teenager and played video games every hour I wasn’t sleeping or in school. Three years before that, I’d gotten my first GameBoy, and spent many an hour with Link’s Awakening, Kirby’s Dreamland, or what have you. That’s when I got Street Fighter II for GameBoy.

I loved the shit out of that game. I could beat anybody with anybody else on the hardest difficulty. I’d spend hours each day just playing this one game.

Flash forward to the present, 2011. My wife has a soft spot for fighting games (I don’t get it either), and when she saw Marvel vs Capcom 3 during a commercial on TV, she demanded we get it. Off we go to our local video game dealer and pick it up. Thus, this review.

The concept is quite simple. Galactus, of Fantastic Four fame, wants to eat a planet, as is his wont, and decides the Earth would make an excellent snack. The heroes and villains from Marvel Comics and various Capcom video games get together to stop him/steal his power. Commence explosions, fireballs, lasers, punching, kicking, etc.

Unlike your standard game, however, it isn’t three rounds of 1-on-1 action. Instead, you have a team of three vs. another team of three. You can call for an assist or tag out. One side wins when the other side loses all three competitors.

Most of the characters play very differently — some are great for every situation (Iron Man, Ryu, and Dante), whereas others are a little more challenging (Phoenix, Spider-Man). In addition to a standard library of moves — a dozen or so per character — you also get Hyper-Combos. A Hyper Combo is some ridiculously over-the-top sequence that scores plenty of hits, fueled by a combo bar, which you gain more of as the fight progresses. Get three of these bars and you can use all three fighters against one of the others — if you have five bars, the other guy is more or less dead. The other unique part of the game is X-Factor, where you can temporarily gain a huge increase in power and strength. The upshot is this — the weaker your teammates and you are, the more powerful X-Factor is. It can turn fights around in a heart beat.

There are offline and online modes. The offline modes include Arcade — you take a team of three through a series of randomly chosen fights, and whoever gets the last blow on Galactus, you see that ending — Shadow Mode — a free DLC adds randomly created teams based on online players’ skills, which is somewhat neat but a weird concept — and Versus mode, just you vs the CPU or a friend. There’s also a training mode and a mission mode where you have to perform a certain sequence of moves. Online modes include standard Versus matches.

Since there are 36 characters (prior to the insanely expensive DLC — 4.99 for one lousy character?!), you have 36 endings and a bunch of other stuff to unlock.

The controls are either very complex or very easy — the Simple Mode gives you one-button moves, at the expense of greatly limiting your move set. The normal mode maps three attack buttons (light, medium, heavy) and a chuck ’em up in the air button. Moves are a little harder to pull off, but you get complete flexibility. It’s a tradeoff.

The game looks and sounds fantastic. Deadpool is voiced by Uncharted star Nolan North, and it’s a fantastic characterization. The little quips are nice, but they get cycled through very quickly.

That’s the good news. Here’s the bad news. Single player is incredibly shallow. You can clear all the endings in a day or two, with enough time. You can always try new combos, but the game is fundamentally the same. Some of the most iconic characters you’d expect (a Capcom game without Mega Man?!?!) aren’t in M v C 3, so that Capcom can put in obscure characters that nobody’s ever heard of (although Arthur from Ghouls ‘n Goblins was an awesome addition) from games that only sold well in Japan. The missions are ridiculously stupid — unless you have incredible reflexes, you’ll never clear the missions for some of the characters, and the game is way too sensitive. There’s no happy medium between Simple and Normal mode — Simple is too easy, Normal is too hard without huge amounts of practice.

Overall, it was kind of a disappointment. It looks great, plays great, and sounds great — for a few hours. For $60, I expect more. NBA Jam was shallow too, but it only cost $40. I’ve heard it’s great online, but I’m not an online gamer. If you’re an old-school fighting gamer, rent it before you buy it. I was at first really intrigued, but eventually traded it in for MLB. It’s a good concept, but not hugely rewarding for single player campaigns.


Breathtaking graphics and sound

— Unique concepts like X-Factor and the 3 vs 3 aspect

— Some strategy involved in choosing which three characters to play as


— Really, really shallow

— Some stupid choices for characters — Morrigan over Mega Man? She Hulk over Cyclops? No Fantastic Four?

— DLC is ridiculously expensive

More Tally Table Fun

I am a fan of tally tablesHere’s another case in which they can be very helpful.

Getting a portion of a string is rather easy with a tally table.  For example, if you get a record which looks like “Bob, Dole, Kansas, Senate, 1969, 1996” you can split that out into several different fields, helping you create a normalized table from which you can do other activities like querying house of Congress, length of term, and that kind of stuff.

--Create a tally table.  All Hail Jeff Moden!
 DROP TABLE dbo.Tally

SELECT TOP 11000 --equates to more than 30 years of dates
INTO dbo.Tally
FROM Master.dbo.SysColumns sc1,
 Master.dbo.SysColumns sc2



--Now use the tally table to extract the relevant information.
create table #CongressInformation
 Id int,
 String varchar(500)

insert into #CongressInformation values (1,'Bob,Dole,Kansas,Senate,1969,1996');
insert into #CongressInformation values(2,'Robert,Taft,Ohio,House,1920,1930');
insert into #CongressInformation values(3,'Robert,Taft,Ohio,Senate,1938,1953');

--Split out into different fields.  You can use these later to insert into a normalized table.
 ROW_NUMBER() over (partition by Id order by N),
 SUBSTRING(',' + p.String + ',', N+1, CHARINDEX(',', ',' + p.String + ',', N+1 ) - N-1)
 dbo.Tally t
 cross join #CongressInformation p
 N < LEN(',' + p.String + ',')
 AND SUBSTRING(',' + p.String + ',', N, 1) = ','

drop table #CongressInformation;

The Death Of The Union Towns

With the latest census, we can see the death of the old union towns.  After New Orleans (which had a natural catastrophe that we can point to for cause), the next seven largest declines in major cities all fall on the old union midwest towns.  Detroit and Cleveland have had little to offer for decades.  Cincinnati, Pittsburgh, and Toledo are seeing the old industrial centers move out and nothing to replace them with.  St. Louis and Chicago, meanwhile, also have seen major declines.  The next two cities on the list are Baltimore and Santa Ana.  Baltimore’s another old union town.

The common thread between so many of those cities is an old-timey union-style “I’ve got mine” attitude for the people who have jobs and control of the government handout machine, and the need to flee to get something at all for everyone else.

EPD: Haunted Houses

Chapter 12 of Extraordinary Popular Delusions and the Madness of Crowds pertains to haunted houses.  You hear the creaking of a shifting foundation, the whistling of wind through a gap in the shutters, and imagine the only logical conclusions:  ghosts!

We don’t really take haunted houses seriously anymore—the most common understanding of the concept includes sticking your hand in a bowl of cold spaghetti and other cheap thrills come Halloween time—but at the time of Mackay’s writing, the citizenry of Europe certainly did.  One of the advantages of belief in haunted houses, though, was that apparently you could get some nice properties on the cheap.  One of the author’s examples was in Aix-la-Chapelle, where people heard a regular knocking noise.  The proprietor eventually sold his house, unable to rid his house of ghosts via use of the logical methods (holy water, commandments by a priest, that kind of stuff).  The new owner heard the noise, discovered that it was a door with a busted latch.  When the wind came in through a broken pane of glass nearby, it would cause the door to slam, causing the noise (594-595).

Of course, this wasn’t the only way to take advantage of popular forms of madness.  In one case, a number of monks were able to move into a French palace by convincing the king that it was haunted.  The only thing they didn’t tell the king was that they were the ones doing the haunting…  (596-597).

Unique Date Ranges: A Tally Table Solution

I am a huge fan of tally tables.  When I was a developer, I didn’t really understand the concept—it’s a table of numbers, so what?—but now that I do SQL Server full-time, I have picked up on some great uses for the concept and ways of improving my code quality and performance.

I am also working on building a data warehouse for my organization.  Unfortunately, as anybody with experience in data warehousing can imagine, there is some bad data:  duplicate records, bad keys, end dates before begin dates, that kind of stuff.  In this particular case, I had a combination #1 and #3 to deal with.  The source application now has checks to make sure that these types of problems don’t occur in the future, but there were some old records submitted by organizations which were incorrect.  I can’t have somebody change the source data because much of it is 8-10 years old and some of these organizations aren’t even around any longer, so I get to deal with it however I can.

Here is a basic setup which should give an idea of the scope of the problem.

create table #Data
 Id int identity(1,1),
 Person int,
 BeginValue int,
 EndValue int

insert into #Data(Person, BeginValue, EndValue) values(1, 1, 5);
insert into #Data(Person, BeginValue, EndValue) values(1, 2, 7);
insert into #Data(Person, BeginValue, EndValue) values(1, 2, 2);
insert into #Data(Person, BeginValue, EndValue) values(1, 2, 14);
insert into #Data(Person, BeginValue, EndValue) values(1, 9, 13);
insert into #Data(Person, BeginValue, EndValue) values(1, 14, 17);
insert into #Data(Person, BeginValue, EndValue) values(1, 16, 20);
insert into #Data(Person, BeginValue, EndValue) values(1, 20, 20);
insert into #Data(Person, BeginValue, EndValue) values(2, 1, 5);
insert into #Data(Person, BeginValue, EndValue) values(2, 6, 8);
insert into #Data(Person, BeginValue, EndValue) values(2, 9, 15);
insert into #Data(Person, BeginValue, EndValue) values(2, 15, 15);
insert into #Data(Person, BeginValue, EndValue) values(2, 16, 20);
insert into #Data(Person, BeginValue, EndValue) values(2, 21, 25);
insert into #Data(Person, BeginValue, EndValue) values(3, 1, 5);
insert into #Data(Person, BeginValue, EndValue) values(4, 2, 2);
insert into #Data(Person, BeginValue, EndValue) values(5, 1, 5);
insert into #Data(Person, BeginValue, EndValue) values(5, 6, 10);
insert into #Data(Person, BeginValue, EndValue) values(6, 1, 5);

select * from #Data;

Looking at the data, you can see all of the problems that I mentioned.  What I want is a listing of unique ranges and the first record in that range.  It would like a bit like so:

Desired results:
 Id    Person  BeginValue  EndValue
 1     1         1           5
 2     1         6           7
 4     1         8          14
 6     1        15          17
 7     1        18          20
 9     2         1           5
 10    2         6           8
 11    2         9          15
 13    2        16          20
 14    2        21          25
 15    3         1           5
 16    4         2           2
 17    5         1           5
 18    5         6          10
 19    6         1           5

At first, I was trying all kinds of convoluted joins, recursive CTEs, and other mechanisms which were slow and error-prone.  Then I hit on a very elegant solution:

with records as
      FirstId as Id,
      MIN(N) as NewBeginValue,
      max(N) as NewEndValue
          MIN(d.Id) as FirstId
          #Data d
          inner join sp_tally t
             on t.N between d.BeginValue and d.EndValue
       group by
     ) arrangements
   group by
select *
   #Data d
   inner join records r on d.Id = r.Id
order by

In this simple query, joining to a tally table (sp_tally), I was able to return precisely the desired results.

Unfortunately, this particular query breaks down over a very large load.  I’m still looking for an elegant solution which works for millions of records; what I ended up doing was finding the set of records which overlap and doing this processing only on them, and then performing a UNION ALL with the remaining records.  Because the problematic records are close to 1-2% of the total, this gets around the scaling problem.

The Economic System of Vicky II and its relevance to today

I was playing Vicky 2 the other day as Ukraine (released from the Russian Empire) and had a chance to build a country’s economy from the ground up. Here are some thoughts I gathered from the experience.

There are four major economic policies you can choose from, depending on your political party (Ukraine has an absolute monarchy, so I in effect choose the party. Later it turns into a Prussian-style constitutional monarchy, in that there’s a vote, but they just vote for the ruling party — I’ve only ever had them change my party once). They are:

1) Laissez-Faire — self explanatory. You can build railroads and military structures, that’s it. The Capitalists do everything else, according to the AI.

2) Interventionism — The Capis still do all the building of factories, but you can subsidize key factories, if you need to, and close or destroy factories. You’ve only got eight factories per state (a collection of provinces), so this is useful at times.

3) State Capitalism — You, the player, can do whatever you want, build factories, close them, etc. Capis can still build stuff too. There is a penalty to production overall, however, and you have a floor for tax rates.

4) Planned Economy — No private enterprise whatsoever. All the Capis have to find new jobs.

Now, every political party has other issues too — the game generates them, so sometimes there’s a great party and sometimes there isn’t. Other issues include citizenship, tariff policy, the military, and the totally meaningless religious policy. People vote by issue for the lower house and ideology for the upper house — even absolute monarchies have a functioning upper house, but they normally gravitate where ever you tell them to gravitate, unless you have some kind of voting. Thus, while the Liberal Party supports Laissez-Faire, it’s also Pacifist, which means huge penalties to defense spending, so it’s bad for war time. Each country has different mixes — even the Liberals (Republicans) in my USA game were at least Pro-Military (no limits on defense spending, but you don’t get the bonuses for declaring war you do with Jingoism).

On a strictly economic level, though, Laissez-Faire is the best system, with one caveat — the Capitalists are very stupid sometimes. Here’s an example. In the middle of the 19th century, canned food stops being a growth industry. Canned food is necessary primarily for armies, but eventually so many countries build canned food factories that the price is ridiculously low. So they tend to go bankrupt all the time. Now, my capitalists, geniuses that they are, see that they’re going bankrupt and go, “Oh no! Not the Canned Food factory! Let’s build another one!” instead of choosing something more profitable, like a Liquor Distillery. Now, ordinarily, since Capis fund everything themselves, I wouldn’t care, but it means huge amounts of unemployment and they rarely destroy factories, so the old ones just sit there. Eventually, they’ll learn, but with a small country, it’s not useful to have huge numbers of unemployed people while the Capitalists keep building worthless factories. The other problem is that they’re usually behind the tech curve — if you just discover telephones for example, it takes them a while to build telephone factories, which are always hugely profitable. They’ll keep building more low tech factories, though, even though they still tend to be profitable in the short term.

So, L-F isn’t always perfect. Interventionism is a good substitute — the ability to subsidize one factory while the capitalist builds another one means no unemployment, then I close the unprofitable factory (or let the free market do it — if it can survive without subsidies, that works). However, they’ll still keep building moronic factories from time to time. That’s when I go State Capitalist, build my own damn factories (really, let’s build the fuel refinery in Kiev? You know, instead of a place with oil, like Dubai, which I conquered?), and then switch back to L-F when the year is up. I never bother with Planned Economy — even when you have no capitalists, State Capitalism is still better. I’m sure there’s some hidden benefit (for gameplay purposes), but I don’t see it.

Now, I would argue the modern US would be Interventionist on this scale. The only reason to support subsidies in Vicky 2 is for critical defense industries in case you’re blockaded (so you want one canned food factory, one ammunition factory, etc.) or to thwart the mind-bogglingly stupid capitalist AI at times. L-F is the superior choice in all other instances. In other words, let unprofitable industries fail. That’s what I was getting at.

Note: This isn’t perfect, because one thing the US does a lot of is subsidize agriculture. Farms and mines, in Vicky 2 called RGOs (Resource Gathering Operations), can never be subsidized.