DR error measures: Difference between revisions
No edit summary |
|||
| Line 2: | Line 2: | ||
This article will describe several '''least-squares error measures for [[delta-rational chord]]s'''. They have the advantage of not fixing a particular interval in the chord when constructing the chord of best fit. However, like any other numerical measure of concordance or error, you should take them with a grain of salt. | This article will describe several '''least-squares error measures for [[delta-rational chord]]s'''. They have the advantage of not fixing a particular interval in the chord when constructing the chord of best fit. However, like any other numerical measure of concordance or error, you should take them with a grain of salt. | ||
The idea motivating least-squares error measures on a chord as an approximation to a given delta signature is the following (for simplicity, let’s talk about the fully DR case first): | |||
Say we want the error of a chord 1:''r''<sub>1</sub>:''r''<sub>2</sub>:...:''r''<sub>''n''</sub> (in increasing order), with ''n'' > 1, in the linear domain as an approximation to a fully delta-rational chord with signature +δ<sub>1</sub> +δ<sub>2</sub> ... +δ<sub>''n''</sub>, i.e. a chord | |||
<math>x : x + \delta_1 : \cdots : x + \sum_{l=1}^n \delta_l.</math> | |||
Let <math>D_0 = 0, D_i = \sum_{k=1}^i \delta_k</math> be the delta signature +δ<sub>1</sub> +δ<sub>2</sub> ... +δ<sub>''n''</sub> written cumulatively. | |||
== Rooted linear error == | == Rooted linear error == | ||
'''Rooted linear error''' (here ''linear'' means "in frequency space, not pitch space") measures error by optimizing how well ''cumulative'' intervals from the root real-valued harmonic match the target chord's DR signature. | '''Rooted linear error''' (here ''linear'' means "in frequency space, not pitch space") measures error by optimizing how well ''cumulative'' intervals from the root real-valued harmonic match the target chord's DR signature. | ||
Revision as of 06:59, 12 December 2025
This article will describe several least-squares error measures for delta-rational chords. They have the advantage of not fixing a particular interval in the chord when constructing the chord of best fit. However, like any other numerical measure of concordance or error, you should take them with a grain of salt.
The idea motivating least-squares error measures on a chord as an approximation to a given delta signature is the following (for simplicity, let’s talk about the fully DR case first):
Say we want the error of a chord 1:r1:r2:...:rn (in increasing order), with n > 1, in the linear domain as an approximation to a fully delta-rational chord with signature +δ1 +δ2 ... +δn, i.e. a chord
Let be the delta signature +δ1 +δ2 ... +δn written cumulatively.
Rooted linear error
Rooted linear error (here linear means "in frequency space, not pitch space") measures error by optimizing how well cumulative intervals from the root real-valued harmonic match the target chord's DR signature.
Fully DR
We wish to minimize the following frequency-domain error function by optimizing x:
Setting the derivative to 0 gives us the closed-form solution
which can be plugged back into
to obtain the least-squares linear error.
Partially DR (one related delta set, one free variable)
Suppose we wish to approximate a target delta signature of the form with the chord (where the +? is free to vary). By a derivation similar to the above, the least-squares problem is
where y represents the free delta +?.
We can set the partial derivatives with respect to x and y of the inner expression equal to zero (since the derivative of sqrt() is never 0) and use SymPy to solve the system:
import sympy
x = sympy.Symbol("x", real=True)
y = sympy.Symbol("y", real=True)
d1 = sympy.Symbol("\\delta_{1}", real=True)
d2 = sympy.Symbol("\\delta_{2}", real=True)
d3 = sympy.Symbol("\\delta_{3}", real=True)
r1 = sympy.Symbol("r_1", real=True)
r2 = sympy.Symbol("r_2", real=True)
r3 = sympy.Symbol("r_3", real=True)
err_squared = ((x + d1) / x - r1) ** 2 + ((x + d1 + y) / x - r2) ** 2 + ((x + d1 + y + d3) / x - r3) ** 2
err_squared.expand()
err_squared_x = sympy.diff(err_squared, x)
err_squared_y = sympy.diff(err_squared, y)
sympy.nonlinsolve([err_squared_x, err_squared_y], [x, y])The unique solution with x > 0 is
Partially DR (one related delta set, arbitrary free deltas)
We similarly include a free variable to be optimized for every additional +?, after coalescing strings of consecutive +?'s and omitting the middle notes, and after trimming leading and trailing +?'s.
Todo: The L-BFGS-B algorithm is suited for five-variable (base real-valued harmonic + four free deltas; a realistic upper bound on real-world use cases of partial DR) optimization problems with bounds, so let's talk about that
Arbitrary related delta sets
<hj>Here be dragons. No one really wants to do this, right</hj>
Rooted logarithmic error
This error measure also measures errors of rooted intervals, but measures the error in logarithmic interval distance and thus arguably has a more musically intuitive meaning.
Fully DR
The error function to be minimized, with units in nepers (logarithmic unit for frequency ratio of e), is
(To scale to cents, multiply by 1200/log 2.)
All-interval linear error
Measure all pairwise intervals, linearly
Fully DR
All-interval logarithmic error
This error measure measures errors of all intervals, not just rooted ones.
Fully DR
The error function to be minimized, with units in nepers, is
