Module:Harmonic entropy: Difference between revisions

ArrowHead294 (talk | contribs)
No edit summary
ArrowHead294 (talk | contribs)
Remove already finished Todo
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
-- TODO: this module should just be called harmonic entropy!
local limits = require("Module:Limits")
local limits = require("Module:Limits")
local rat = require("Module:Rational")
local rat = require("Module:Rational")
local p = {}
local p = {}


-- compute harmonic Shannon entropy for an interval of `c` cents
-- Compute Harmonic Shannon entropy for an interval of `c` cents
-- `c`, `deviation`: in cents
-- `c`, `deviation`: in cents
-- `ratios`: an array of rational numbers
-- `ratios`: an array of rational numbers
Line 12: Line 11:
return math.sqrt(rat.benedetti_height(ratio))
return math.sqrt(rat.benedetti_height(ratio))
end
end
deviation = deviation or 0.01
deviation = deviation or 1200 * math.log(1.01, 2)
ratios = ratios
ratios = ratios
or limits.integer_limit(200, function(ratio)
or limits.integer_limit(200, function(ratio)
if math.abs(ratio[0] * 2^(c / 1200)) > 3 * deviation then
if math.abs(rat.cents(ratio) - c) > 3 * deviation then
return 1 / 0
return 1 / 0
end
end
Line 26: Line 25:


local function weighted_gaussian(ratio)
local function weighted_gaussian(ratio)
return gaussian(ratio[0] * 2^(c / 1200)) / norm(ratio)
return gaussian(rat.cents(ratio) - c) / norm(ratio)
end
end