Musical Applications of Fuzzy Logic
Musical Applications of Fuzzy Logic
Musical Applications of Fuzzy Logic
The rules for set operations under fuzzy logic differ only slightly from those of
standard (or crisp) logic.
A union A∪B of two fuzzy sets has the maximum of the values for each member.
The intersection A∩B, contains the minimum values found for each member.
The fuzzy complement A' is 1-µ for each member.
The product AB is the product of each member pair.
The power function An is µn for each member.
A2 and A0.5 are specially defined as concentration (CON) and dilation (DIL)
respectively.
The bounded sum A⊕B is the sums of the member pairs limited to 1.
The bounded difference AΘB is µA(x)- µB(x) limited to 0.
For complete explanations of fuzzy operations see [Zadeh 1993].
Functions
In fuzzy logic, a characteristic such as "Tall" may be represented by a membership
function in an appropriate continuous domain such as height. A domain will
support several sets of related characteristics such as short, very short and so on.
The functions may be a simple increase or decrease across a portion of the
Fuzzy Numbers
A particularly useful type of fuzzy set is the fuzzy number [Dubois 1993]. This is a
representation of the concept "around n." In a typical implementation, the value n
would have a membership in the set N of 1, n + 1 and n-1 would have a
membership between 0 and 1, n+2 and n-1 would have lower memberships and so
on to values that are not near n and have memberships of 0. It is possible to do
math with fuzzy numbers but this seldom arises in musical applications. The
fuzzy number is often used for approximate equalities, where for fuzzy number
N, x==N is interpreted as µN(x). This principle has been successfully expanded to
give reliable pattern matching for noisy data.[Dubois 1983]
In complex reasoning, several inferences are evaluated and the results combined.
As an example, consider the factors that might determine optimum performance
tempo. These can be stated as a set of rules:
Peter Elsea June 25, 2011
Musical Applications of Fuzzy logic
There are five quantities that can be represented by fuzzy sets, which are shown
graphically in figure 4. Skill of the performers may be a complex issue, or a
separate value for each player. In this example let the conductor rate them from
one to ten. Then the minimum value would be used. Difficulty of music is also
complex, and probably changes throughout the piece. It might be based on
average number of notes per measure.
The universe of discourse for the results is the range of practical tempi. "Near the
marked tempo" might be a fuzzy set corresponding to allegro, adagio, and so on,
or it might be a fuzzy number generated by shifting a triangular function to a
specific metronome setting. "Faster" is a function that increases across this
domain, and slower is a decreasing function. Note that these functions may
overlap or there may be a gap. Slow is not the compliment of fast.
To find optimum tempo, evaluate all three rules and take the union1 of the result
sets. A solution value can be extracted in many ways, but the most common is
finding the centroid or "center of gravity" of the result.[Cox 1993, p 249]
This method will produce a reasonable tempo for any set of conditions. It is very
easy to add rules such as "if the hall is reverberant, play slowly". The result set of
the new rule is simply included in the final union. It is easy to turn rules on and
off to test their effect, or to weight a rule to adjust its importance.
1
In some situations, the final set can be constructed by summing the memberships of the result sets.
Do this when several rules affect the same part of the resultant domain and you don't want one
them to hide each other. It is not necessary to normalize the solution set before finding the centroid.
It is important to remember that these are not distributions of any kind. The low
membership of forte at velocity 67 simply indicates that a velocity of 67 is not
particularly loud. A velocity of 32 also has a value in the set forte, a value of 0.
µT(i) = µM ((i+t)mod12)
M = {1 0 1 0 1 1 0 1 0 1 0 1}
(TT>>2) ∩ M= {0 0 0 0 0 1 0 0 0 0 0 0}
However, this approach does not generalize to other scales. A harmonic minor
scale H would be
H ={ 1 0 1 1 0 1 0 1 1 0 0 1}.
But finding the third above A flat implies:
2
This is not the set of musical set theory.
(TT>>8) ∩ H ={1 0 0 0 0 0 0 0 0 0 0 0 1}
This is not a useful answer. Fuzzy logic allows us to define the third as :
F3= {0 0 0 1 0.9 0 0 0 0 0 0 0 }
The partial membership 0.9 indicates that the interval of 4 half steps is a bit less
representative of the third in a minor scale. Thus
(F3>>8) ∩ H = {0.9 0 0 0 0 0 0 0 0 0 0 1}
This can be easily reduced to a single answer by finding the locus of the highest
membership. The locus of highest membership is common enough in music
applications to justify a definition: TOPn A = the set of loci of the top n
membership values, which can be determined by a simple iterative procedure.
This is not to imply that the question cannot be answered by traditional sets. It
can, simply by considering the two types of third separately:
If (MT>>8) ∩ H
then (MT>>8) ∩ H
else (mT>>8) ∩ H
The fuzzy approach is a bit more efficient, and such efficiencies add up in a
complex program. However, a more important benefit is that the definition of the
fuzzy third contains a preference for the minor. The major could be encouraged
by a simple change in the membership values, which would likely only be
defined once in a program. A similar modification in the traditional code requires
changing the order of operation everywhere it occurs, which could mean
substantial revision. This trivial example survives generalization- that is, in most
applications fuzzy logic yields simpler code that is easier to modify than
traditional approaches.
Table 1 defines fuzzy sets for common intervals above and below a given root.
Fuzzy Algorithms
A more subtle benefit of fuzzy logic is that construction algorithms tend to follow
human paradigms very closely. Here is a common procedure for building a chord
Where S = {1 0 0 0 0 0 0 0 0 0 0 0 }
The set S is the singleton set which is rotated to designate a particular pitch. This
rotation can also be indicated by Sr, and the intersection with the scale set can be
omitted if we are assured the root is in the scale, or we are harmonizing
chromatic motion. The result set R can be converted into a list of pitch classes by
the TOP3 procedure.
This algorithm works well in major keys, and in natural and harmonic minor
when the goal is to favor major and minor sonorities over diminished. When the
diminished sound is preferred, the algorithm is:
This algorithm works nicely in natural and harmonic minor, favoring diminished
chords a bit. In a practical application, the algorithm would be selected according
to context.
Chords of the seventh which are natural to the scale can be derived by adding an
interval of a fifth above the third of a triad constructed using either of the above
algorithms.
When non-scale seventh chords are desired, they can be created directly by
rotation of a template set
Dom7 = {1 0 0 0 1 0 0 1 0 0 1 0}
Simple Harmonizer
To build a complete triadic harmonizer, we find the three candidate chords for a
given pitch, then choose the best according to context. To find the chord with p as
the third, take
r6 = TOP1((F3b>>p) ∩ W)
where F3b is the third below set from table 1. Then
R6 = Sr6 ∪ Sp ∪ ((F5>>r) ∩ W)
Likewise, for the chord with p as a fifth find
r6-4 = TOP1((F5b>>p) ∩ W),
then:
R6-4 = Sr6-4 ∪ ((F3>>r6-4) ∩ W) ∪ Sp
In other words find the fifth below the given pitch, and the third above that. (To
build 7th chords, we find the fifth above the third.)
We then test the three candidates against the previous chord. To favor
progressions with common tones, we construct a result set:
The sets DCP represent the desirability of possible following chords. This is
reminiscent of the Markov process, but the values do not have to add up to
anything. Two equally desirable chords may both have a possibility3 of 1, and
less interesting choices may have arbitrarily lower memberships.
From these sets we produce
Rd = {Sr∩ DCP, Sr6∩ DCP, Sr6-4∩ DCP,}
A third rule may be simply to avoid too many repetitions of the same chord. The
concept "too many repetitions" would be represented by a set like
T = { 0 0 0.2 0.4 0.6 0.8 1 1 1 1}
We then keep a running count of occurrences n of each chord in the last 10 and
build the set
Rt = {µTm(nSr), µTm(nSr6), µTm(nSr64)}
To select the winning chord we combine Rcom, Rdes and the complement of Rt in
some way. Simply adding the sets gives:
More applications
The fuzzy process can be applied to any musical decision. Here is an outline for a
simple phrase generator.
Phrase Generator
Interval direction
• If early in phrase go up
• If late in phrase go down
• If near top of range go down
• If near bottom of range go up
• If high in range go down
• If low in range go up
• If late in phrase and above attractor go down
• If late in phrase and below attractor go up
• Dither
Interval size
1. If too many small intervals pick medium
3
The concept of fuzzy memberships representing possibility was introduced in [Zadeh 1978]
In this application the phrase length would be an input variable that would scale
the indexing for the "where in the phrase" clauses, as well as determine the
number of pitches generated. An "attractor" is some desirable target pitch,
perhaps tonic. The calculation of start points and attractors would be fuzzy and
related to the structure of the piece. Dither is a random fuzzy number that can be
added to any decision to make the process less deterministic.
To produce a value from direction rule 1, you would define a downward sloping
function for "early in the phrase" such as (to pseudocode):
Then:
Direction += Late[where];
Direction -= High[lastnote];
Direction += Low[lastnote];
Direction -= min(Late[where] , AboveAttractor [Lastnote]);
Direction +=min (Late[where], BelowAttractor [Lastnote]);
Direction += random(0.5) – 0.25; // dither
Top(Histogram) and Direction will point to the direction and class of interval to
use in a case statement. The choice within the class could be random or
conditioned by more rules.
Rhythm Recognizer
The problem of parsing rhythm is central to the problem of transcribing music
from real performances. There have been many crisp logic attempts that
foundered on problems such as distinguishing dotted from triplet rhythms. The
fuzzy approach is to classify pattern sets by the number of events during a beat.
Fitting the times of the onsets against a set of fuzzy descriptions of all patterns (to
a desired resolution) will quickly produce a best fit. Figure 6 show an example of
this.
Figure 6.
The downward arrows in figure 6 represent the observed times. The triangles
represent fuzzy sets for some4 of the combinations of three events in a quarter
note. The membership of a time in each set is the intersection of a line and triangle.
A simple confidence value is generated by summing the memberships of the three
times in each set. The best fit here is S*S*E.
Of course, this is after a process of identifying the beats by examining all notes
according to a rule set that might go like this:
And so on. After actual beats are found, "missing" beats are identified by
interpolation.
These examples are only a sampling of opportunities for use of fuzzy logic in
solving musical problems. In the author’s experience, no program will make
exclusive use of a single approach: standard logic is the most efficient when the
choices are clear cut, and some processes are best described by math functions.
However, in the majority of cases where outcomes are traditionally determined by
rules of thumb, fuzzy logic is the clearest route to the goal.
pqe
Bibliography
All works cited as in readings* can be found in
Dubois, D,H. Prade and R Yeager ed., Readings in Fuzzy Sets For intelligent
Systems Morgan Kaufman, San Mateo CA, 1993.
4
The complete group of sets is determined by the desired resolution.
Zadah, L.A., Fuzzy Sets as a Basis for a Theory of Possibility. org pub1978,
reprinted in Selected Papers by L.A. Zadeh (ed Yeager, Ovichinnikov, Tong,
Nguyen) New York: Wiley
Zadah, L.A., Fuzzy Sets. 1993, readings* p.27 ff