# Social Dynamics of Terabithia

In the land of Terabithia, king Jesse and princess May Belle have taken over the duty to rule the kingdom. The people of the kingdom are divided into five tribes at the time of their inauguration. These are liberal people, willing to accept and share new ideas and fashion available in each tribe. Jesse has appointed Abul (the court mathematician) to figure out how and at what rate his newly introduced fashion of wearing a Lungi will spread throughout his kingdom. He has also decided to divide his country into different districts based on different styles of wearing lungi.

Now, there are several factors for Abul to consider here. Some of the tribes have accepted Lungi as their choice of official dress code. However, they have different styles of wearing those. Tribe 1 likes wearing it with no shirts on, tribe 2 refused to accept it as their fashion, tribe 3 wears lungi with a kurta, tribe 4 prefers this style

and so on. The fashion designers in each tribe have made appealing designs to impress and encourage people from other tribes to accept their fashion. Abul needs to figure out and forecast the possibility of each tribe’s fashion surviving and/or flourishing over the whole kingdom.

Problem Statement

In sociology, economics, business planning etc, researchers and analysts are always concerned about how competing cultures, languages, fashion etc survive over a period of time. Some cultural trends are short lived, some defeat the existing trends and completely take over. It is impossible to predict what individuals think about each trend, but it is in our reach to predict what the mass trend will be once a steady state is reached.

Individuals have different philosophies. In general we update our idea of fashion and culture based on movies, TV, books, what others around us do etc. Some of us are trend starters. Others follow them. Many times it is not one person, it is a group of people following a trend that motivates others to follow. In the formal terminology of social science and social dynamics, there are three stages of a cultural trend change before it reaches a steady state.

1. Emergence: A new cultural center emerges in a population. Someone or a group of people start using a new colloquial word, begin wearing a new kind of jeans or may be start listening/propagating a new genre of metal songs to others.
2. Broadcast: This new trend is “shown off” to others occasionally. The trend starters use their newly coined colloquial word too often in public, wear the newly designed clothes in parties or release albums and organize concerts to promote the new genre of metal with some frequency.
3. Following and Competition: Others decide whether they will accept or reject the new trend. If someone decides to accept, occasionally he/she also becomes one of the broadcasters. If there are several competing trends available, then a decision is made based on factors like the current number of people following the trend and how long this trend has been followed or simply personal taste.

Every trend usually dies after some time. This can be months, years or even decades. Our general tendency is to accept the newest trend.

In the field of Social Dynamics, agent based modeling has been used by many mathematicians to study the behavior of such chaotic systems. It is usually hard to find closed form solutions of any mathematical model describing such a complex process, so discrete time Monte Carlo simulations or rule based cellular automata systems have been used to predict mass behavior in a society.

To help Abul, we modify and suggest some improvements to a model proposed in this paper and add some more functionality to study the culture of Terabithian people.

Monte Carlo Model

The Monte Carlo simulation is performed on a lattice of size $L \times L$, containing $L^{2}$ agents who interact with their neighbors. A fashion is defined as $I(s,a)$, where s is the cultural center and broadcaster site, and a is the age of the fashion.

The model assumes that newly arrived fashions are likely to be accepted more. A fashion $I(s_{i},a_{i})$ for a particular agent i can change its preference to another fashion from site $s_{j}$ if $a_{j}. Keeping this in mind, the proposed algorithm to take a timestep from t to t + 1 over the whole lattice is

1. Emergence step: With a very small probability $p_{new}$, a new cultural center emerges. $I_{i}(t)=I(i,0)$.
2. Broadcast step: With a probability $p_{repeat}$, the cultural centers restrengthen themselves to affect their neighbors. $I(i,a_{i,t})=I(i,0)$.
3. Spread step: Each site i randomly chooses one of its nearest neighbors j (with equal probability) by whom it will be affected. If $a_{j}, then the current fashion at i is changed to the fashion followed by j. $I(s_{i},a_{i})=I(s_{j},a_{j})$. Otherwise nothing changes for i.
4. All ages in each lattice site is increased by 1.

Modifications

1. The original model proposes choosing a site randomly as an emerging cultural center. This limits Abul to concentrate on one tribe only. In other words, the model does not consider competition between several *existing* fashions. We propose to change this scheme and assume each tribe acts as their own ambassador. Thus we assign a cultural center to each tribe as an initial condition and all of them are broadcasters of their own fashion.
2. The paper considers geographic impacts such as closed boundary at the borders of a country. We extend this by considering geographic factors that can slow down the exchange of information, e.g. rivers and seas that divides countries and regions. To include this, we introduce another random variable $p_{cross}$ that determines the probability of information crossing over the given obstacle. With this probability, we exchange information only between the two sides along the obstacle in step 3.
3. Finally, we also propose changing the global $p_{new}$ and $p_{repeat}$ to local competing groups by converting these variables to arrays. This better captures the reality because different groups of people may have different tendencies to interact with others. It is too simple to assume that every competing group has the same level of interaction and motivation to spread their own culture.

Back to Terabithian Tribes

Mathematica was used to program this Monte Carlo simulation. We study the general model and our modifications one by one.

Terabithia is an infinite kingdom, it is a torus. That is, if you leave the kingdom from one side, you will enter through the other side. There is no escape from lungi or Jesse’s rules. We simulate this by assigning a periodic boundary condition on our lattice when choosing neighbors for a particular site.

For one of our examples though, we will use a closed boundary condition.

We model the kingdom by a $50 \times 50$ lattice , each site represents a group of people (presumably a family or a house). We choose the nearest four neighbors with whom each site will interact.

(a)

(b)

Figure 1. (a) Tribe colors. (b) Initial distribution of different groups.

Figure 1 shows an initial random distribution of different groups of people who follow different tribes, colored according to 1(a).

We would like to run the original paper model first. We choose 500 iterations for the simulation. Estimating that only one active interaction (an interaction with a broadcaster that changes someone’s mind to start following a new fashion) occurs in a day, this would mean the simulation is the result after 500 days.

Figure 2. Steady state reached after 500 iterations (days).

Figure 2 shows how fashions of different tribes have clustered over 500 days. Tribe 4 is less dominant for this particular number of iterations. The important point is that trends have emerged over different regions, it is not a random distribution of fashion anymore, as in 1(b).

Since we have imposed a periodic boundary condition, note how the clusters have continuity (wraps around) at the horizontal and vertical ends of the lattice.

We have helped Abul solve the initial problem. He can show this simulation to the king and inform him about possible clustering and number of people following particular fashions in this competing culture war after different number of days. However, there are more modifications on the way.

Rivers and Borders in Terabithia

Often we have borders among regions that stop people from interacting with each other. There are rivers and seas that distance people out (assuming no internet, like in the ancient days) and slow down the exchange of information and culture. Abul wants to incorporate these factors in the model. We help him by changing our neighborhood selection algorithm to include a set of cells in our lattice that stop information exchange.

(a)

(b)

Figure 3. (a) A different tribe is included among the cells (off-white cells creating a rectangle) which act as information barrier (a physical border, in a sense). (b) The two separate regions evolve independently, as expected.

Notice in figure 3 that some cultural trends have disappeared, they could not survive for 500 days. However, it is possible that they can come back if we ran the simulation for more iterations.

(a)

(b)

Figure 4. (a) A river that splits the kingdom into two equal regions. However, a slight probability of information exchange is allowed across the two river sides. Closed boundary conditions are used. (b) Result after 500 iterations.

Figure 4 shows our modification of the original algorithm to include slow information exchange among two regions. 4(b) shows what we would expect. The same cultures have emerged around the river sides since they have some interaction. Note the consistency of the clusters on both sides. However, they are dominated by the trends that are stronger in the larger regions. Closed boundary conditions were used for this example.

Individual Probabilities for Tribes

As promised, we now help Abul make the model more realistic by assigning individual $p_{new}$ and $p_{repeat}$ variables to each tribe. The algorithm needs to changed slightly for doing this.

Figure 5. Biased and higher probabilities assigned to tribe #5, which is why it cultural trend dominates over the others.

This is much better because it gives us the capability to include real world information in the model. Although the probability distributions for each of these random variables are decided here by us, in reality we can conduct surveys and build realistic discrete distributions from which we can run a much reliable simulation of the future events.

Conclusion

With the proposed modifications, we can expect that the model is useful in a real world setting to predict future outcomes for competing cultural trends in a society. The best way to integrate all the modifications is to create an MCMC (Markov Chain Monte Carlo) sampler to estimate parameters for the joint distribution function for $p_{new}$ and $p_{repeat}$ from real world data.

The resulting parameters will be used in the above simulation and we may get some useful results if we cleverly choose a good neighborhood coverage for each lattice site (e.g. considering information exchanged over internet among distant sites).

Finally, Abul can present these results to the king and expect to get a promotion in return. Math saves the day, once more.

# Analyzing Tagore’s Literature (Part 2)

In part 1, I employed Bose-Einstein distribution to find out how the “temperature” of Tagore’s writing varies across different novels. In part 2, I delve into Zipf’s power law and similarity metrics used to compare high dimensional vectors in order to analyze the lexical wealth and similarity across different novels and short stories written by the legend.

Zipf’s Law

In fractal theory, Zipf’s power law on linguistics is a tried and accepted heuristic to compare large texts [1]. This power law statistics, derived from the behavior of certain kind of fractals, can be used in many other disciplines too. In simple terms, Zipf’s law is stated as: N = Ak^(-$\phi$).

Taking logs on both sides: log(N) = log(A) – $\phi$ * log(k)

we get a linear equation. Here, N is the total number of words in a corpus, k is the ratio of the number of distinct words n to N. A is a constant amplitude and phi is a phase value that is unique for a given author. Using simple regression analysis, it is possible to find a characteristic phi for any author. The law merely dictates a simple fact: as the text size increases, the number of distinct words decreases. At what rate this happens is a question that is related to the expertise of a writer in maintaining variability of words and sentence structures over the course of his novels.

Demonstration

The following table shows n, N and k values for the same set of novels in part 1.

The following table shows the same data for a collection of short stories.

Note the higher values of k for the short stories. This could be mainly due to the smaller size of the text.

Figure 1. (Left) Data points in the Log(k)-Log(N) plane, and a linear fit equation showing the characteristic gradient $\phi$. (Right) Same experiment done on the short stories.

Figure 2. The linear fit equations for novels and stories on the same plot (red – stories, blue – novels). Clearly it demonstrates that the rate at which Tagore’s lexical wealth k falls is higher for novels. This could be due to the difference in the text size though.

Heap’s Law

Heap’s law is similar to Zipf’s law. It’s a power law that describes how the number of unique elements in a set of randomly chosen elements grow as the size of the set increases. In our case, we would expect to see that the number of unique words increase as we increase the size of the text.

Figure 3. (Left) Heap’s law demonstrated for novels (log(n) vs. log(N) plot), (right) for short stories.

Figure 4. The two linear fit equations on the same plot (red – short stories, blue – novels). This demonstrates that although the number of distinct words used in short stories prevail for a short size of text, ultimately the novels take over as the size of the text increases. This may indicate a better effort on Tagore’s side to polish and revise his novels to amplify the lexical wealth, whereas, statistically, this may be less true for his short stories.

Similarity Measure

The variability of distinct words across a set of novels or short stories can be captured by feature vectors – essentially rows of numbers in a document-term matrix. Comparing these high dimensional vectors to infer the similarity between short stories and novels of Tagore might be useful. Here, I use two schemes to compare these high dimensional vectors. One is the cosine of the angle between two vectors, and the other is the L2-norm of the difference between two vectors. These schemes project the high dimensional vectors to scalar values that can be easily compared. Histograms from all possible pair combinations are produced to analyze how similar or different are the span of the words used in short stories or novels.

Figure 5. (Left) Histograms from L2-normed difference scheme, (right) from cosine scheme. Red – short stories, blue – novels. Note the bimodal distribution for both novels and stories, except the cosine heuristic for short stories. It seems there are two principal modes of similarity among all novels and stories. Although this could be just a statistical property of texts that I am not aware of.

Note the width of novels histograms in both cases; they are wider than those of stories’. For the cosine scheme the novels histogram has a mode that’s closer to 1.0, whereas the average peak for stories histogram is farther from 1.0. These two observations mean that similar words and sentence structure recur themselves throughout novels, more than short stories. This is consistent with the inferences drawn in part 1 and Zipf’s and Heap’s laws for Tagore’s work.

Comparing Upendrakishor Raychowdhury’s Work

One last thing I try here is to see how these measures can be used to compare different authors’ works. Although my aim was to compare Kazi Najrul Islam with Tagore, unfortunately I could not find any of his work in text form. Instead, I found Upendrakishor Raychowdhury’s short stories collection and decided to compare the lexical wealth between the two authors’ stories collection. It should be noted that lexical wealth is only one of the (measurable) heuristics to compare authors. Most of the comparisons in the field of literature are qualitative and depend on the taste of readers and critics. Nonetheless, the lexical wealth does say a lot about the author’s expertise in not being monotonous.

The following table shows UR’s short stories that I have collected, along with their k values.

Figure 6. (Left) Zipf’s law linear fit for UR’s short stories. (Right) Zipf’s law linear fits for both UR’s (red) and Tagore’s (blue) short stories. Although it seems that UR has an upper hand with Tagore (smaller falloff rate as we increase the lexical wealth k), it would be dubious to claim that UR is better at not being monotonous. It’s quite risky to draw conclusions based on such a small margin, lack of adequate data is another issue. I could say something clearly if I had a collection of hundreds of stories from both writers. 🙂

Conclusion

In part 1 I found out that a possible characteristic falloff of the lexical wealth may exist for Tagore’s writings. The experiments here in part 2 restate a celebrated fact in linguistics: every author has a natural limit after which his writings give way to being monotonous in terms of repeating words and sentence structures. Rabindranath Tagore was not so different from the group of his contemporary writers. It will be interesting to see how his works compare with other contemporary works when/if I get enough data. 🙂

[1] L. L. Goncalves, L. B. Goncalves, Fractal power law in literary English, Physica A 360 (2006) 557 – 575.

# Analyzing Tagore’s Literature (Part 1)

Rabindranath Tagore, the Nobel Laureate for literature in 1913, has been one of my favorite authors of all time. In my series of summer weekend projects, among other things, I have collected some novels and short stories written by this author in unicode text format and analyzed the behavior of their lexical growth, hoping to find specific patterns in his writing. Part 1 of this investigation employs one of the DFR (Divergence From Randomness) models, namely the Bose-Einstein statistics that was originally derived by Satyendranath Bose (a physicist at the University of Dhaka) in 1924 as one of the emerging quantum ensemble models that was later backed up by Einstein in 1925.

Bose-Einstein Distribution

Bose-Einstein distribution has recently found its application outside the realm of describing the energy level occupation of bosons. Such applications include describing the statistics of low frequency words in a large text corpus [1]. It’s always interesting to investigate how a mathematical model describing a physical phenomenon can be  used as an analogy to another problem. Here, words are analogous to boson particles, which have the characteristic that they are indistinguishable from each other. Unlike Fermions, for example, there is no limit to the number of bosons that can occupy a quantum state. This property of bosons makes the related statistics suitable for analyzing words that have the same occurrence frequency in the corpus. An important aspect of using such analogy is temperature. What does it mean for a piece of text to have “temperature”? As demonstrated in [1] and here, it can describe and distinguish between different authors or different novels written by the same author. It may also describe how the lexical wealth of a piece of writing evolves as we read through it.

The Model

The Bose-Einstein distribution describes the occupation of bosons at specific energy levels. An energy level is specified by j = 1, 2, …, n. The level j = 1 corresponds to the Bose-Einstein condensate. Here, as an analogy of this condensate, the authors of [1] call the initial energy state hapax legomena. This Greek term originates from Biblical studies, it translates to “[something] said [only] once”. That is, words that occur only once will be put in the first energy level. Words with frequency 2 will occupy the level j = 2, and so on. The occupation of an energy level j is given as:

$N_{j}=\frac{1}{z^{-1}e^{\epsilon_{j}/T}-1}$

z is the absolute activity, or fugacity, epsilon is the energy of the jth level and T is the temperature. The power energy spectrum for epsilon is given by

$\epsilon_{j}=(j-1)^{\alpha}$

where $\alpha$ is a constant that can be determined by fitting. z is determined from the first energy level using

$N_{hapax}=\frac{z}{1-z}$

and with the new definition of the power spectrum the B-E distribution now looks like

$N_{j}=\frac{1}{z^{-1}e^{\frac{(j-1)^{\alpha}}{T}}-1}$

The parameters $\alpha$ and T are to be simultaneously determined by fitting the data present in the occupation matrix (a matrix that contains the occupation distribution for each level j) using a nonlinear regression.

Algorithm

A document-term matrix is created from the set of novels or stories that are to be analyzed. Then for each energy level j, the number of distinct words that have a frequency equal to j is found and saved in the occupation matrix. Now, each row in the matrix has the occupation levels distribution. By fitting the parameters for each row of data, we obtain T for the low frequency words (lower energy levels). In the case of texts, the B-E distribution does not turn out to capture the statistics of the higher energy levels quite well.

In order to see how T evolves with N (the number of words) in a novel, I divide the particular novel corpus into cumulatively increasing chunks of texts and do the above for each chunk.

Mathematica is the choice of programming language for all of these operations. 🙂

Results and Analysis

I have run the programs on a set of eight novels: Bou Thakuranir Haat, Chokher Bali, Ghore Baire, Gora, Noukadubi, Projapotir Nirbondho, Rajorshi and Shesher Kobita. All the novels and other short stories are collected from [2].

Figure 1. (a) Occupation matrix for all novels, colors represent the magnitude of occupation in each cell. Note the variability of words frequency for each novel. Novel #4 (Gora) is the largest in this set. It exhibits quite a variable frequency compared to others. (b) Occupation vs. j log-log plot for Bou Thakuranir Haat for the first 1000 energy levels. The blue line is the fit found for the first 20 energy levels (low frequency words).

Chokher Bali: This novel contains ~70000 words. The occupation matrix and the characteristic temperature curve is shown below.

Figure 2. (a) Occupation matrix for Chokher Bali. As the number of chunks increases, we find some amount of variability. (b) Temperature vs. N graph, the points are joined together with broken lines, not a fit. Note the rise of temperature until the middle of the novel and a gradual decrease as the size of the text increases.

Gora: This one is the largest in my collection, ~180000 words.

Figure 3. (a) Occupation matrix for Gora. Note that a lot of variability shows up as we increase the size of the text. There is a certain visible pyramid-like pattern. This regularity may indicate recurring usage of word sets over the course of the novel. (b) Temperature as the size of the text grows.

Noukadubi: This is one of the shorter novels, containing ~40000 words.

Figure 4. (a) Occupation matrix for Noukadubi. A similar pyramid structure is notable. (b) T vs. N graph.

Temperature Evolution Comparison

The novels usually have a rise in temperature for up to ~30000 words or so, then we see that they fall off. What does it mean in terms of the physical analog?

The figure on the left shows all the temperatures on the same plot, and on the right are a set of exponential fits for the first 25000 words. Since they resemble a Boltzmann-like distribution, I could have done a fit using that equation. Oh well! 🙂

Conclusion

I wonder if the peak in temperature at around 30000 words mark is a characteristic of Tagore’s writing (critical/transition temperature?). Note that temperature here refers to the net amount of variability of different frequencies for low frequency, i.e. rare words. Different authors have different styles of writing. One may sit and finish a large piece in one go and never come back to it. However, many authors do come back to the same piece again to hone the variability of words.

In literature, lexical wealth is a measure of the author’s ability to use different set of words. Every author has a natural limit though, rare words that describe particular events must cycle around in the novel. The results here could be the first step in showing that Rabindranath Tagore’s large piece of writings usually maintain a fairly distinct word frequency structure until around an approximately fixed word limit (~30000 to 50000), then it breaks and gives way – the rare words and sentence structures start repeating and cycling more often as the size of a novel increases. This claim, however, should be viewed with doubt as more experiments are needed to confirm this. This in general should be true for any author, but finding a characteristic falloff for Tagore is quite interesting.

Part 2 of my analysis uses power laws derived in fractal theory and similarity measures used in high dimensional data analysis to find out more about the lexical wealth of Tagore’s writings.

[1] Application of a quantum ensemble model to linguistic analysis, A. Rovenchak, S. Buk, Physica A 390 (2011), 1326-1331.