A Musical Composition Application Based on a Multiagent System to Assist Novel Maria Navarro Computer Science Department Salamanca University Pza Merced, Salamanca 37005 Spain mar90ali94@usal.es Composers Juan Manuel Corchado Yves Demazeau Computer Science Department Laboratoire d’Informatique de Grenoble Salamanca University 110 avenue de la Chimie Pza Merced, Salamanca 37005 Spain Domaine Universitaire de Saint-Martin-dHres corchado@usal.es BP53 -38041 Grenoble cedex9France Yves.Demazeau@imag.fr Abstract This paper presents a solution to help new composers make harmonies. Amultiagent approach based on virtual organizations has been used to construct this application. This modelisbuiltby usinga multiagent system. This study presents a Multi-Agent System (MAS) built with PANGEA, a platform to develop different multiagent systems, capable of composing music following the HS algorithm. The results show the success of this application in correctly composing a classical harmony. Introduction Interest in computational creativity has been increasing in the scienti.c community. Although this interest is recent, there are a number of algorithms, schemas and procedures to develop an intelligent machine, capable of creating new ideas or new artistic compositions. Manymusic students, or even musicians, have problems composing or improvising melodies with their own instrument. Theymay find it difficult to practice their improvisation or to compose their own melody because theyusually needtoworkwithother musicianswhoaretoobusytocollaborate with them. This systemwas designedto assist these music students in improving their abilities. The goal of the system is to show that a simple and general agent framework such asPANGEA (Platform for Automatic coNstruction of orGanizations of intElligents Agents) (Zato and others 2012) canbuildaproper and scalable music composition system. Amultiagent system based on virtual organizations is used because it permits making changes in the problem specification, and can modify the music style or add new rules without altering the structural composition. Only the agents behavior needs modification. The BDI architecture was chosen for these reasons. We will evaluate the results by considering two types of criteria. First, we will consider mathematical criteria, which include an optimization function to minimize. The smaller the value in this function for one chord, the better the chord. This function considers constraint rules that evaluate the chord obtained. These rules and the evaluation method will be detailed in Section 3. InWestern music, dissonanceisthe qualityof sounds that seem unstable and have a need to resolve to a stable sound called consonance. The definition of dissonance is culturally conditioned, which is whya classical and an occidental music culture is considered for the evaluation of consonance. According to this criterion, we can consider these consonance intervals (in order of consonance): • Octaves • Perfect fourths and perfect .fths • Major thirds and minor sixths • Minor thirds and major sixths Wewill alsoevaluate whether the system helps composers to make their melodies or to improvise a melody by just listening to the harmonies. This evaluation consists of evaluatingthe systemwitha numberfrom1to10. The second section contains a brief review of algorithms in music composition, Multiagent Systems and basic concepts of virtual organizations. The third section presents our model, and our particular solution, attempting to solve the problem of harmonycomposition with an unknown melody, andhowVirtualOrganizations(VO)canhelpto improvethis system. The last section shows some results of the system, and proposes new lines of improvement. Background This section presents general information about composition algorithms, concepts about MAS andVOanda briefexplanation about the background of agents. Review in composition algorithms While grammar-based systems were initially widely used in composition tasks, today there are many other algorithms attempting to compose music. Some of these are called live algorithms (Bown 2011). One of the most successful algorithms involves Markov models (Eigenfeldt andPasquier 2013).There are also algorithms that uses lyrics as a variable into their compositions, as forexample (Monteith, Martinez, andVentura 2012). One interesting and notable study is that of F. Pachet (Pachet 2003). (Hoover,Szerlip, and Stanley2011) focused onevolvinga single monophonic accompaniment fora multipart MIDIby using a compositional pattern producing network (CPPN), a special type of artificial neural network (ANN). Agents and creativity are two disciplines that have interacted in several case studies (Martin, Jin, and Bown 2011; Lacomme, Demazeau, and Dugdale 2010). Harmony Search Algorithm Algorithm Music improvisationaimstoproduceanidealstate determinedbyaesthetic parameters, i. e., consonance or sound balance. The procedure has five steps described here (Geem and Choi 2007). First, it is necessary to choose the optimization function and to consider a “memory” called Harmony Memory (HM, a matrix filled with as many generated solution vectors as HMS (harmonymemory size)). The new harmonyis generatedbya random selection,a memory consideration, by using HM and a pitch adjustment (Geem and Choi 2007). The choice of one or another is conditioned by two probabilistic parameters:PAR (Pitch Adjustment Rate) and HMCR (Harmonymemory Considering Rate). Although the new harmony is built, the constraint rules that evaluate the obtained chord must also be taken into account. For this, a threshold is established. If the chord exceeds this value, it is dismissed, and the process starts again with a new chord that replaces the rejected chord. Finally,ifthenew harmonyvectorxhasa bettervaluefor the fitness function than the worst harmonyin the HM, the newharmonyis included in the HM. This process is repeated over andover until the stopping criterion (maximum number of improvisations) is reached. Virtual Organizations In the initial development of multiagent systems, the agents were seen as autonomous and dynamic entities that evolve according to their own objectives, without external explicit restrictions on their behavior and communications (Demazeau andM¨uller 1990). In recent years, developers have directed their interest to the organizational aspects of the societyof agents(H¨ubneretal. 2010). Thus,two descriptive levels are set: the organization and the agent. Agents are now seen as dynamic entities that evolve within organizations. The following sections present a description of the system, as well as the algorithm, and the agent structures used to solve the problem. Classical Harmony Composition Modeling musical composition is difficult because musical objects do not have any pre-assigned connotation. That means there are as many definitions of the same object as there are belief systems in musical history. For this reason, our efforts were centered on composing music from the classical period. In this period, there were many rules for composing classical music. In particular, the following main norms are considered. • R1 -8th and 5th parallels: these are produced when the interval between the i-note and the j-note of the chord n and the interval between the (i+1)-note and the (j+1)-note of the chord n+1 are both 5th or 8th. • R2 -Leading-note resolution. Thereisa rule that requires a resolution of the leading-note in the tonic. • R3 -Voices crossing. An ideal harmonymustavoidvoice igetting abovevoicej, when j=i+1. • R4 -Movements between tension. Each chord hasa peculiar role that produces stability or instability,depending on the functions (tonic, dominant and subdominant). It is the tension that permits the music to evolve in the composition.Forthis reason,our desireistoproduceamovement between chords, to prevent the music from becoming boring. Thus, the repetition of the same function over time must be penalized in some way. • R5 -Avoidalarge interval betweentwopitchesinachord. This is important because if we have a big pitch in the same chord, the connection between all pitches can break. • R6 -Avoid a large interval between two pitches in the samevoice. This rule allowsbuilding more “cantabile” melodies, in general. With all of these constraints and rules, the following optimization equationwasbuiltto minimize: N3N3 .. .. Rank(xij)+ P enalty(xij ) (1) i=1 j=1 i=1 j=1 Where: Rank(xij )= iRank(xij ,xi(j-1) + (2) ln(T ensioni)+ xij - x(i-1)j (3) T ension(x) values are considered with a discrete scale from 1 to 3, depending of the tension role. If the chord is Subdominant, the tension is 1, if it is dominant, tension is 3, and if it is tonic, tension would be 2. The values of iRank(x) for a specific harmonic interval are: • 3rd, 8th interval:Valueof1 • 6th interval:Valueof 1.5 • 4th interval:Valueof2 • 5th interval:Valueof 2.5 • Unisone interval:Valueof3 • 2nd, 7th interval:Valueof4 P enalty(x) areshownin equations 4,5,6and7,keeping in mind the constraints considered previously. x(i-1)j . SI . xij . (4) = DO . P enalty(xij )=5 xi(j-1) . xij . P enalty(xij)=4 (5) T ensioni-1 =3 . T ensioni =1 . P enalty(xij )=2 (6) x(i-1)j - x(i-1)(j-1) = xij - xi(j-1) =5 . 8 (7) . P enalty(xij)=3 (8) The algorithm starts with an initialization of the Harmony Memory (HM) matrix that is stored in the repository. SeveralPAR and HMCR were also tested, and we chose the best ones:0.3toPARand0.2to HMCR.Inthenext section,both the structure of MAS based onVO and its advantages will be explained. Multiagent System Structure Virtual organizations were used to implement and develop our model. Virtual organizations provide a certain number of roles easily replaceable by an agent, depending on the context. This allows the system to be very flexible. Besides, a methodology based onVO can provide us witha global vision of the problem, the model and the possible solutions. To design the virtual organization it is necessary to analyze the needs and expectations of the system. The result of this analysis will be the roles of the entities involved in the proposed system. The following specific roles were found: • Composer Role: This role creates the harmonic music following their rules to achieve a goal (desire). • Evaluator Role: This role evaluates the result of the composer role and decides if it is good enough to present it to the user. • Interface Role: This role allows the user to interact with the system. • Data Supplier Role: This role is an agent that accesses and stores all or most of the information needed to manage the actions that govern this system. • Control Role: The agents that exercise this role will have overall control of the system. To implement the roles of the VO we chose to develop a MAS. For the composer and evaluator agents, we chose a BDI agent architecture (Corchado et al. 2004), for two reasons: firstly, it is the most common deliberative agent architectures, and one of the simplest; and secondly, this structure is perfectly adapted to our requirements. The BDI agent process involves two fundamental activities: a) determining which goals should be achieved (deliberation) and b) deciding how to reach these goals (planning). Both processes should be carried out by taking into account the limited resources of each agent. The schemain Figure1showshow client agents are connected to model our problem. To begin, the composer agent has as a goal or “desire” to minimize thevalueof the optimization function.To achieve this goal, it has to make some rules or “intentions” (that is, the algorithm), starting from its “beliefs” or its initial stage. As we can see, the BDI architecture is perfectly suited to the agent. Additionally,the composer agenthasasa“desire”to classify the chord madeby the composer agent.To achieve this goal, it has to follow its “intentions”, starting with its “beliefs”. Finally, the remaining agents are given communication, coordination and representation tasks. The systemwasdeveloped onPANGEA (Zato and others 2012), which provides us with certain advantages.PANGEA is a service-oriented platform that allows the open multiagent system to take maximum advantage of the distribution of the resources. WithPANGEA, we can change our musical agent in order to change the composition algorithm or behavior. We can even change an agent and replace it with a multiagent system capable of communicating to compose a new music. Second, we can change our Constraint Agent. Figure 2: Harmonyachieved with 45 iterations However, the more iterations we performed, the better the results we obtained.Wehavea new line with 200 iterations, noticeably better than the previous one (See Figure 3). The first chord is perfect, taking the intervals between the notes Figure 3: Harmonyachieved after 200 iterations This means that we have an evolutionary algorithm. This depends not only on the iterations we perform,but also on the parameters PAR or HMCR, which indicate the probability of making a random value for a pitch in a chord, as explained in the previous section. The fitness of the results isevaluatedbystudying theway the rules and constraints are followed. In other words, the more the rules are followed, the better the harmonywill sound. The mathematical evaluation is to study the value of the optimization function as well as the number of the constraints that are violated. Nevertheless in music, there is also a qualitative form to evaluate the model. This method of evaluation is based on acoustic perception, and therefore depends on the listener. We conducted tests with two experts in classical music (composers) and two non-experts in classical music to punctuate both harmonies above. The evaluation criteria was: “completely dissonant”, “dissonant”, “a bit consonant”, “consonant”, “completely consonant”. The experts number1and number2evaluated the first harmonybetween “a bit consonant” and “dissonant”, and the others evaluated as “dissonant”. In the second harmony all four rated it as “consonant”. In our small study, two composers used our method and evaluated the results on a scale of 1-10. The first evaluated the result witha6and the second witha 7,5, which we consider as acceptable in our first approach to the system. With regards to the virtual organization, the process of identifying and organizing roles helped to improve the management and thus to improve ef.ciency. The MAS structure allows us to make an extensible and scalable system as we change rules, constraints and behavior, with little effort, searching new ways of mixing different techniques, or even tools in the composition. The BDI architecture is perfectly suited for the solution we were seeking. BDI has a clear methodology thatfacilitates the development stage, with manytheories that suit our problem. This architecture enables us to easily introduce a learning mechanism, as we can see in our case study. Moreover, using PANGEA as the platform allowed .uid communication between agents, which is evident in the design of the application, improving the modularity and the separation between client and provider as well. Asafuturework,we propose incorporatingrhythms. This model can also evolve to learn and self-check its own mistakes in harmonycomposition. References Bown, O. 2011. Experiments in modular design for the creative composition of live algorithms. Computer Music Journal35. Corchado, J. M.;Pav´on, J.; Corchado, E. S.; and Castillo, L.F. 2004. Development of cbr-bdi agents: a tourist guide application. In Advances in case-based reasoning. Springer. 547–559. Demazeau,Y., andM¨uller, J.-P. 1990. Decentralized Ai. Elsevier. Eigenfeldt, A., andPasquier,P. 2013. Consideringvertical and horizontal context in corpus-based generative electronic dance music. In Proceedings of the Fourth International Conference on Computational Creativity, 72. Geem, Z.W., and Choi, J.-Y. 2007. Music composition using harmony searchalgorithm. Springer Berlin Heidelberg. 593–600. Hoover,A.K.; Szerlip,P.A.;and Stanley,K.O. 2011. Interactively evolving harmonies through functional scaffolding. In Proceedings of the 13th annual conference on Genetic and evolutionary computation, 387–394. ACM. H¨ ubner, J.F.; Boissier, O.; Kitio, R.; and Ricci, A. 2010. Instrumenting multi-agent organisations with organisational artifacts and agents. Autonomous Agents and Multi-Agent Systems 20(3):369–400. Lacomme,L.; Demazeau,Y.;and Dugdale,J. 2010. Clic:an agent-based interactive and autonomous piece of art. In Advances in Practical Applications of Agents and Multiagent Systems. Springer. 25–34. Martin, A.; Jin, C.T.; and Bown, O. 2011. A toolkit for designing interactive musical agents. In Proceedings of the 23rdAustralian Computer-Human Interaction Conference, 194–197. ACM. Monteith, K.; Martinez,T.; andVentura, D. 2012. Automatic generation of melodic accompaniments for lyrics. In Proceedings of the International Conference on Computa tional Creativity, 87–94. Pachet,F. 2003. The continuator: Musical interaction with style. Journal of New Music Research32(3):333–341. Zato, C., et al. 2012. Pangea–platform for automatic construction of organizations of intelligent agents. In Distributed Computing and Artificial Intelligence. Springer. 229–239.