FOR the past decade or so, generals commanding the world's most advanced armies have been able to rely on accurate forecasts of the outcomes of conventional battles. Given data on weather and terrain, and the combatants' numbers, weaponry, positions, training and level of morale, computer programs such as the Tactical Numerical Deterministic Model, designed by the Dupuy Institute in Washington, DC, can predict who will win, how quickly and with how many casualties.

Guerrilla warfare, however, is harder to model than open battle of this sort, and the civil insurrection that often precedes it is harder still. Which, from the generals' point of view, is a pity, because such conflict is the dominant form of strife these days. The reason for the difficulty is that the fuel of popular uprisings is not hardware, but social factors of a type that computer programmers find it difficult to capture in their algorithms. Analysing the emotional temperature of postings on Facebook and Twitter, or the telephone traffic between groups of villages, is always going to be a harder task than analysing physics-based data like a tank's firing range or an army's stocks of ammunition and fuel.

Harder, but not impossible. For in the war-games rooms and think-tanks of the rich world's military powers, bright minds are working on the problem of how to model insurrection and irregular warfare. Slowly but surely they are succeeding, and in the process they are helping politicians and armies to a better understanding of the nature of rebellion.

SCARE tactics

One of the best-known projects in this field is SCARE, the Spatio-Cultural Abductive Reasoning Engine, developed at the United States Military Academy at West Point by a team led by Major Paulo Shakarian, a computer-scientist-turned-soldier. SCARE operates at the most militarily conventional end of the irregular-conflict spectrum: the point where an army of guerrillas is already in being and is making life hard for a notionally better-armed army of regular troops. That, of course, has been the experience of American forces in Vietnam, Iraq and Afghanistan. Major Shakarian and his team have analysed the behaviour of guerrillas in both Iraq and Afghanistan, and think they understand it well enough to build reliable models.

Their crucial insight is the local nature of conflict in these countries. In particular, bombs directed at occupying forces are generally planted close to the place where they were made, and on the territory of the bombmaker's tribal kin or co-religionists. That is not a surprise, of course. Kin and co-religionists are the most reliable allies in wars where different guerrilla groups may not always see eye to eye about objectives, beyond the immediate one of driving out foreign troops. But it does give Major Shakarian and his team a convenient way in. Using the co-ordinates of previously bombed sites, data from topographical and street maps, and information on an area's ethnic, linguistic and confessional “human terrain”, SCARE is able to predict where guerrillas' munition dumps will be to within about 700 metres. That is not perfect, but it is close enough to be able to focus a search in a useful way.

Moreover, SCARE's focus should soon become more precise. Major Shakarian's latest trick is to include data on phone-traffic patterns in the calculations. An upgraded version of the program, employing this trick, will be created next month.

All of which is useful for dealing with a conflict once it has started. But it is better, if possible, to see what may happen before things get going. And for that, America's navy has a project called RiftLand.

RiftLand is being developed on the navy's behalf by Claudio Cioffi-Revilla, a professor of computational social science at George Mason University in Virginia. It is specific to the part of East Africa around the Great Rift Valley (hence the name). That this area includes Congo, Ethiopia, Rwanda, Somalia and Uganda, each of which has been the scene of present or recent civil strife, is no coincidence. But the ideas involved could be generalised to other parts of the world, with due alteration for local conditions.

Broadly, RiftLand works by chewing its way through a range of data collected by charities, academics and government agencies, and uses these to predict where groups of people will go and with whom they may clash in times of drought or armed conflict. Dr Cioffi-Revilla gives the example (though he will not name names specifically) of a tribe of nomadic herders known for sharing its notions of veterinary medicine with others. This tribe, the model predicts, will reckon it safer to cross the lands of groups who also rely on keeping their animals healthy. Another point is that tribes who own a radio or mobile phone will steer clear of roads after news reports of government atrocities against their kin. A third is that much of the movement of herdsmen can be predicted from satellite data on the condition of pasture lands, modified by knowledge of what Dr Cioffi-Revilla calls “the complex network of IOUs” between tribes: which are currently hostile to one another, and who owes whom favours.

Hostile sentiments

The sort of conflict dealt with by RiftLand—a war of all against all in countries where central government is light or non-existent—has been particularly characteristic of this part of Africa in recent years. Further north, where states are stronger, urban insurrection of the sort seen at the beginning of the Arab spring is a more common threat. Politicians faced with such uprisings may thus be interested in yet another piece of software, known as Condor, which has been developed by Peter Gloor of the Massachusetts Institute of Technology. Dr Gloor is certainly not in the business of saving the jobs of Middle-Eastern dictators. He is actually a consultant to the Christian Democratic Union, Germany's largest political party. But all politicians in power, whether democrats or dictators, share a distaste for demonstrations and protests on the streets.

Condor works by sifting through data from Twitter, Facebook and other social media, and using them to predict how a public protest will evolve. It does so by performing what Dr Gloor calls “sentiment analysis” on the data.

Sentiment analysis first classifies protesters by their clout. An influential Twitter user, for instance, is one who has many followers but follows few people himself. His tweets are typically upbeat (containing words or phrases such as “great”, “fun”, “funny”, “good time”, “hilarious movie”, “you'll love” and so forth), are rapidly retweeted, and appear to sway others. In a nod to the methods developed by Google, Dr Gloor refers to this process as “PageRanking for people”.

Having thus ranked protesters, Condor then follows those at the top of the list to see how their output changes. Dr Gloor has found that, in Western countries at least, non-violent protest movements begin to burn out when the upbeat tweets turn negative, with “not”, “never”, “lame”, “I hate”, “idiot” and so on becoming more frequent. Abundant complaints about idiots in the government or in an ideologically opposed group are a good signal of a movement's decline. Complaints about idiots in one's own movement or such infelicities as the theft of beer by a fellow demonstrator suggest the whole thing is almost over.

Condor, then, is good at forecasting the course of existing protests. Even better, from the politicians' point of view, would be to predict such protests before they occur. Not surprisingly, several groups of researchers are trying to do this too.

Aptima, a firm based in Woburn, Massachusetts, is one. Its program, called E-MEME (Epidemiological Modelling of the Evolution of MEssages) uses sentiment analysis to see how opinions and states of mind flow across entire populations, not just activists. It employs data from online news sources, blogs and Twitter, and attempts to rank the “susceptibility” of certain parts of the populace to specific ideas. According to Robert McCormack, the project's chief technologist, E-MEME can determine things as different as which places in Egypt contain people who will care a lot about a border incident with Israel, and which parts of a country most need water in times of drought. The Worldwide Integrated Crisis Early Warning System (W-ICEWS) project, led by Lockheed Martin, a large American defence contractor, goes even further. According to Lieutenant-Colonel Melinda Morgan of the office of the secretary of defence, in Washington, who is the government's liaison officer for the project, it can crunch great quantities of data from digital news media, blogs and other websites, and also intelligence and diplomatic reports. It then uses all this to forecast—months in advance—riots, rebellions, coups, economic crises, government crackdowns and international wars. Colonel Morgan calls this process “social radar”. Conflict forecasters are even joining the open-source bandwagon, in an attempt to improve their software. Last August IARPA, an American-government technology-development agency for the intelligence services, started the Open Source Indicators programme. This finances developers of software that can “beat the news”: forecasting political crises and mass violence in a reliable way. The programme's manager, Jason Matheny, is now considering the proposals that have come in so far. These range from tracking Wikipedia edits to monitoring traffic with roadside cameras. The only proposals Mr Matheny will not consider are those designed to forecast conflict in America itself (the CIA is not supposed to spy on people in the United States), and those that rely on monitoring particular individuals, whether in America or elsewhere. Guerrillas in the midst

Rather than just foretelling the future, however, the best technology should concentrate on shaping it. W-ICEWS offers a bit of that. It has a “what if” capability, which allows users to change the inputs and see how things might develop differently given different events in the real world. But Venkatramana Subrahmanian of the University of Maryland proposes something more specific. The Temporal-Probabilistic Rule System, a program his team has developed using $600,000 of American-army money, looks at 770 social and political indicators and uses them to predict attacks by Lashkar-e-Taiba, a guerrilla group based in Pakistan-administered Kashmir. If it works, this process might be applied, using a different set of indicators, to other groups of rebels.

The crucial point about Dr Subrahmanian's model is that it not only predicts attacks, it also suggests how they might be countered. Dr Subrahmanian is understandably cagey about the details, but he does give one example: if an attack requires complex co-ordination between group members, the software might recommend “stoking paranoia” by forging false communications between them.

On April 2nd President Barack Obama announced a $10m bounty on Lashkar-e-Taiba's leader, Hafiz Saeed. It would indeed mark the coming of age of civil-strife software if that bounty, or another like it, were one day claimed on behalf of a group of programmers half a world away.