Godtone (talk | contribs)
Godtone (talk | contribs)
add option to disable direct mapping; this changes the order of only the last parameter which i suspect wasnt used by anyone in argument order; also makes the omission of et2 make more sense later on and also makes more sense in general as specifying the et2 suggests using a mapping may not be desirable
Line 1,320: Line 1,320:
# IMPORTANT: on Jan 9 i corrected rel_err**2 * et2 to rel_err**2 * et2**2 in et_badness which optimal_edo_sequence depends on;
# IMPORTANT: on Jan 9 i corrected rel_err**2 * et2 to rel_err**2 * et2**2 in et_badness which optimal_edo_sequence depends on;
#            strict_optimal_edo_sequence is unaffected however.
#            strict_optimal_edo_sequence is unaffected however.
def et_badness(ivs,v,badness=lambda rel_err,x,et2: rel_err**2 * et2**2,weighting=lambda x: iv_complexity(x),combine='avg',et2=0):
def et_badness(ivs,v,badness=lambda rel_err,x,et2: rel_err**2 * et2**2,weighting=lambda x: iv_complexity(x),combine='avg',mapping=True,et2=0):
# if the weighting is unspecified, use the default of:
# if the weighting is unspecified, use the default of:
# weighting an interval x's (by default squared) error contribution proportional to its odd-limit complexity (iv_complexity(x));
# weighting an interval x's (by default squared) error contribution proportional to its odd-limit complexity (iv_complexity(x));
Line 1,394: Line 1,394:
et2 = 1/v[0]
et2 = 1/v[0]
# finally, return the result:
# finally, return the result:
return combine([ badness3args(abs( map_iv(v,x) - steps(x,et2) ), x, et2) * weighting(x) for x in ivs ]) / (ivs_sum_weights_cache if using_avg else 1)
if not mapping: # new path
return combine([ badness3args(abs( step_err(x,et2) ), x, et2) * weighting(x) for x in ivs ]) / (ivs_sum_weights_cache if using_avg else 1)
else:
return combine([ badness3args(abs( map_iv(v,x) - steps(x,et2) ), x, et2) * weighting(x) for x in ivs ]) / (ivs_sum_weights_cache if using_avg else 1)
# if you just give a list or set of intervals (a,b), the default behaviour is to judge the badness of an edo as:
# if you just give a list or set of intervals (a,b), the default behaviour is to judge the badness of an edo as:
# * sum of squares of errors with each interval's contribution weighted proportional to its odd-limit complexity,
# * sum of squares of errors with each interval's contribution weighted proportional to its odd-limit complexity,
Line 1,401: Line 1,404:
# IMPORTANT: on Jan 9 i corrected rel_err**2 * et2 to rel_err**2 * et2**2 in et_badness which optimal_edo_sequence depends on;
# IMPORTANT: on Jan 9 i corrected rel_err**2 * et2 to rel_err**2 * et2**2 in et_badness which optimal_edo_sequence depends on;
#            strict_optimal_edo_sequence is unaffected however.
#            strict_optimal_edo_sequence is unaffected however.
def optimal_edo_sequence(ivs_or_edo_badness,edo_set=range(2,311+1),weighting=lambda x: iv_complexity(x),combine='avg'):
def optimal_edo_sequence(ivs_or_edo_badness,edo_set=range(2,311+1),weighting=lambda x: iv_complexity(x),combine='avg',mapping=True):
et_badness_judger = ivs_or_edo_badness
et_badness_judger = ivs_or_edo_badness
if type(ivs_or_edo_badness) in [int,set,list]: # user gave intervals (default et_badness)
if type(ivs_or_edo_badness) in [int,set,list]: # user gave intervals (default et_badness)
ivs = ivs_or_edo_badness
ivs = ivs_or_edo_badness
et_badness_judger = lambda edo: et_badness(ivs,edo,weighting=weighting,combine=combine)
et_badness_judger = lambda edo: et_badness(ivs,edo,weighting=weighting,combine=combine,mapping=mapping)
# else user gave et_badness manually (custom)
# else user gave et_badness manually (custom)
best_edo = et_badness_judger(1)
best_edo = et_badness_judger(1)
Line 1,419: Line 1,422:
# this gives much sparser but also much more interesting lists.
# this gives much sparser but also much more interesting lists.
# default weighting of an interval x is proportional to its odd-limit complexity iv_complexity(x).
# default weighting of an interval x is proportional to its odd-limit complexity iv_complexity(x).
def strict_optimal_edo_sequence(ivs,edo_set=range(2,311+1),weighting=lambda x: iv_complexity(x),combine='avg'):
def strict_optimal_edo_sequence(ivs,edo_set=range(2,311+1),weighting=lambda x: iv_complexity(x),combine='avg',mapping=True):
return optimal_edo_sequence(lambda edo: et_badness(ivs,edo,lambda rel_err: rel_err**2,weighting,combine),edo_set)
return optimal_edo_sequence(lambda edo: et_badness(ivs,edo,lambda rel_err: rel_err**2,weighting,combine,mapping),edo_set)


</syntaxhighlight>
</syntaxhighlight>