User:Leandroferlin/sandbox

A musical composition networks is a network representation that describes a melody as set of connected nodes.

Overview
A melody is a sequence of notes that may or may not have intervals between each pair of pitches.

As a key component of melodies, notes can be represented as a pitch and an associated duration. In this sense, a musical composition network can be constructed by considering nodes as notes and links as connection between notes chronologically subsequent.

Nodes
In modern musical notation, a note resume the combination of a pitch and a duration. A Pitch represents the fundamental frequency of the sound, and the duration indicate how much it last.

The standardized pitch system — A440 system — states that the relation between a pitch p and a frequency f can be seen as:

$$ p = 69 + 12 \log_{2}{\left(\frac{f}{440Hz}\right)} $$

Notes and rests can be considered the building blocks of a melody. In a musical composition network, the nodes should be designed as either:


 * A pitch and its duration
 * A rest and its duration

Thus, nodes in the network can be fully qualified by the pitch and it duration in case of notes, and only a duration in case of a interval between notes.

Links
To construct the network, links can be described as connections between two notes as it is chronologically played in the analysed piece of music.

Let $$i_{0}$$, $$i_{1}$$ and $$i_{2}$$ be notes played at times $$t_{0}$$, $$t_{1}$$ and $$t_{2}$$, chronologically ordered. We can define the links between these notes as $$(n_{0}, n{1})$$ and $$(n_{1}, n_{2})$$.

More generally, given two subsequent notes $$n_{i}$$ and $$n_{i+1}$$, we can determine a link $$l_k$$ as follows:

$$l_k = (n_{i}, n_{i+1})$$

Weight
The property weight of links in a musical network can be described as follows: suppose that in a piece of music, a note $$n_{i}$$ and subsequently note $$n_{j}$$ are played. We determine the weight $$w_k$$ of the ling $$(i_{i}, i_{j})$$ in this scenario as being 1. Suppose now that, as the music is played, the notes $$n_{i}$$ and $$n_{j}$$ appear again in the melody — notice that a note is represented by the concatenation of its pitch and its duration, thus the same node would be seen multiple times in the same music. Now, we increment the weight $$w_k$$ by 1, assigning 2 to it. This process continue until the music ends, and the weight $$w_k$$ is considered as being number of time that the edges $$(n_{i}, n_{j})$$ appears in the music.

Scale-free property
Scale-free networks are networks whose node's degree follows a power law distribution. In other words, in a scale-free network, the probability P(k) of a node have degree k can be described as:

$$P(k) \thicksim k^{-\gamma}$$

Musical composition networks may follow a scale-free distribution with power law exponent ranging from 1 to 2.

However, not all pieces of musics may present the scale-free property.

Furthermore, musical networks displays the small-world phenomenon — in these networks, most of the nodes are not neighbors of other nodes but neighbors of a random node are likely to be neighbors between themselves.

Music generation from networks
Due it is likely that music composition networks follows a scale-free distribution and have the small-world property, it would be possible to generate a appealing melodies based on a controlled random walk algorithm.

The algorithm should starts with a musical composition network as the input. A melody can be seen, in simple words, as a sequence of notes. Thus, we can start from a random node and elect the next one based on some decision rule.

The algorithm should ends when the actual node do not have any outgoing link or if a maximum number of node have been reached.

The decision rule to chose the next node in the melody should be, for example, the neighbor whose link has the greater weight.

A simple algorithm considering the max value of the neighbor's weight is presented bellow: