<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://invarians.org/index.php?action=history&amp;feed=atom&amp;title=The_Principia_Machina%2FTPC-PY%2Ftpc_cluster.py</id>
	<title>The Principia Machina/TPC-PY/tpc cluster.py - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://invarians.org/index.php?action=history&amp;feed=atom&amp;title=The_Principia_Machina%2FTPC-PY%2Ftpc_cluster.py"/>
	<link rel="alternate" type="text/html" href="https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/tpc_cluster.py&amp;action=history"/>
	<updated>2026-10-21T13:01:28Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/tpc_cluster.py&amp;diff=4205&amp;oldid=prev</id>
		<title>BFP Rauch: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/tpc_cluster.py&amp;diff=4205&amp;oldid=prev"/>
		<updated>2026-09-28T04:37:36Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 04:37, 28 September 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>BFP Rauch</name></author>
	</entry>
	<entry>
		<id>https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/tpc_cluster.py&amp;diff=4204&amp;oldid=prev</id>
		<title>BFP Rauch: TPC-PY source tpc_cluster.py (0.3.0), SHA-256 e2d6808553ba64da; conformed TPS 0.3.0; PROPOSED, not declared (CO-8)</title>
		<link rel="alternate" type="text/html" href="https://invarians.org/index.php?title=The_Principia_Machina/TPC-PY/tpc_cluster.py&amp;diff=4204&amp;oldid=prev"/>
		<updated>2026-09-27T15:43:18Z</updated>

		<summary type="html">&lt;p&gt;TPC-PY source tpc_cluster.py (0.3.0), SHA-256 e2d6808553ba64da; conformed TPS 0.3.0; PROPOSED, not declared (CO-8)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;quot;&amp;quot;&amp;quot;tpc_cluster 0.3.0 (DRAFT, pending D143, D144): the top-performer&lt;br /&gt;
cluster rule, with the paired noise input under FIXED-SET and the&lt;br /&gt;
RESOLVING STEP.&lt;br /&gt;
&lt;br /&gt;
Reference implementation, Python standard library only. DATA for landing&lt;br /&gt;
round 8 of branch tpm_project_closeout (0.2.0: the tpm_cluster&lt;br /&gt;
speculation 0.2.0 section 8.3, TC-7 to TC-12; 0.3.0: record D143.1 (e)&lt;br /&gt;
and D144.1 (i), PMP-TPM 0.12.0 THE TOP-PERFORMER CLUSTER, THE CLUSTER&lt;br /&gt;
RULE and RESOLUTION AND FLAGS; the cluster docs 0.2.0 TP-9 and its&lt;br /&gt;
specimen figure); not a declared TPC-PY version. The 26 vectors of 0.2.0&lt;br /&gt;
are unchanged (cluster() without a paired input computes exactly as&lt;br /&gt;
0.2.0; the corpus&amp;#039;s 0.2.0 cases are byte-identical, proved by&lt;br /&gt;
gen_cluster_corpus.py).&lt;br /&gt;
&lt;br /&gt;
cluster(rows, in_max, cusp_max, z, spacing_floor, paired=None)&lt;br /&gt;
    -&amp;gt; (spacing, spacing_source, out)&lt;br /&gt;
  rows: list of (model_id, config_id, score, se); non-empty str ids,&lt;br /&gt;
        (model_id, config_id) unique; score and se finite, se &amp;gt;= 0.&lt;br /&gt;
  in_max, cusp_max: step thresholds in spacings, 0 &amp;lt; in_max &amp;lt; cusp_max.&lt;br /&gt;
  z &amp;gt;= 0: the one-sided noise threshold; spacing_floor &amp;gt;= 0 (a&lt;br /&gt;
        declaration requires it &amp;gt; 0; 0 is allowed here for vectors).&lt;br /&gt;
  paired: None under ITEM-SAMPLING; under FIXED-SET the paired SEs of&lt;br /&gt;
        the differences, a list of (model_a, config_a, model_b, config_b,&lt;br /&gt;
        se_diff), se_diff finite and &amp;gt;= 0, each unordered pair at most&lt;br /&gt;
        once (a second entry for one pair, in either order, is refused:&lt;br /&gt;
        &amp;quot;paired&amp;quot;), every pair the rule tests present (a missing pair is&lt;br /&gt;
        refused: &amp;quot;paired&amp;quot;; spec note PD-OC-1). A row&amp;#039;s own se is still&lt;br /&gt;
        used to order representatives (R1, R2).&lt;br /&gt;
  spacing_source: &amp;quot;GAP&amp;quot;, &amp;quot;FLOOR&amp;quot; or &amp;quot;NOISE&amp;quot; (which term set the&lt;br /&gt;
        spacing), or &amp;quot;NONE&amp;quot; with fewer than three models.&lt;br /&gt;
  out: list of (rank, model_id, config_id, score, se, step, spacings,&lt;br /&gt;
        class); class is IN, CUSP or OUT; rank is None for a row that is&lt;br /&gt;
        not its model&amp;#039;s representative; step and spacings None where&lt;br /&gt;
        not defined.&lt;br /&gt;
&lt;br /&gt;
Rule (tpm_cluster speculation 8.3, TC-7 to TC-12; D144.1 (a)-(h)):&lt;br /&gt;
  R1 Each model&amp;#039;s REPRESENTATIVE is its row with the highest score (then&lt;br /&gt;
     the lower se, then config_id). The rule ranks representatives, so&lt;br /&gt;
     with two or more models ranks 1 and 2 are two distinct models.&lt;br /&gt;
  R2 Sort representatives by score desc, se asc, model_id asc.&lt;br /&gt;
     Ranks 1 and 2 are IN.&lt;br /&gt;
  R3 g1 = s1 - s2, g2 = s2 - s3. The SPACING is&lt;br /&gt;
     u = max(min(g1, g2), spacing_floor, z * max(sd(1, 2), sd(2, 3))):&lt;br /&gt;
     never smaller than a top gap could be by noise.&lt;br /&gt;
  R4 For rank k &amp;gt;= 3 the STEP is s_(k-1) - s_k; its noise is&lt;br /&gt;
     n_k = z * sd(k-1, k). The row is OUT if step - cusp_max * u &amp;gt; n_k;&lt;br /&gt;
     else CUSP if step - in_max * u &amp;gt; n_k; else IN. The scan closes at&lt;br /&gt;
     the first CUSP or OUT.&lt;br /&gt;
  R5 After a CUSP, each following representative, down to the first&lt;br /&gt;
     that is significantly below the CUSP row (s_c - s &amp;gt; z * sd(c, row)),&lt;br /&gt;
     is CUSP; that one and every one after it are OUT. After an OUT,&lt;br /&gt;
     every following representative is OUT.&lt;br /&gt;
  R6 A row that is not its model&amp;#039;s representative is IN if it is not&lt;br /&gt;
     significantly below the lowest-scoring IN representative, else&lt;br /&gt;
     CUSP if it is not significantly below the lowest-scoring CUSP&lt;br /&gt;
     representative, else OUT.&lt;br /&gt;
  R7 THE SE OF A DIFFERENCE sd(a, b) (D143.1 (e); PMP-TPM 0.12.0: &amp;quot;Under&lt;br /&gt;
     FIXED-SET each noise term takes the paired SE of its difference&amp;quot;):&lt;br /&gt;
     under ITEM-SAMPLING sqrt(e_a^2 + e_b^2), as 0.2.0; under FIXED-SET&lt;br /&gt;
     the paired SE the input carries for the pair (a, b). Every noise&lt;br /&gt;
     term of R3-R6 reads sd.&lt;br /&gt;
&lt;br /&gt;
resolving_step(spacing, ses, in_max, cusp_max, z, paired=None) -&amp;gt; dict&lt;br /&gt;
  The RESOLVING STEP (D144.1 (i); VOCABULARY &amp;quot;the least adjacent drop&lt;br /&gt;
  that would be OUT, stated each month&amp;quot;; the cluster docs 0.2.0 &amp;quot;the&lt;br /&gt;
  least adjacent drop that is OUT; for two rows of SE e_a, e_b it exceeds&lt;br /&gt;
  CUSP MAX u + Z sqrt(e_a^2 + e_b^2); shown in points and in spacings&amp;quot;).&lt;br /&gt;
  spacing: the month&amp;#039;s u as cluster() returned it; ses: the ranked&lt;br /&gt;
  representatives&amp;#039; SEs in rank order; paired: None, or the paired SE of&lt;br /&gt;
  each adjacent difference (rank k-1, k), a list of len(ses) - 1 values.&lt;br /&gt;
  RS1 For each rank k &amp;gt;= 3, out_k = cusp_max * u + z * sd(k-1, k) and&lt;br /&gt;
      cusp_k = in_max * u + z * sd(k-1, k): a drop at rank k larger than&lt;br /&gt;
      out_k is OUT and one larger than cusp_k is at least CUSP (R4).&lt;br /&gt;
  RS2 THE RESOLVING STEP is the least out_k over k &amp;gt;= 3 (the docs&amp;#039;&lt;br /&gt;
      specimen: u 1.6, SEs 0.6 with rank 6 at 0.7, gives 6.996 points,&lt;br /&gt;
      4.37 spacings, the 0.6/0.6 pairs, which the least reproduces; the&lt;br /&gt;
      greatest, 7.116, would not); shown in points and in spacings&lt;br /&gt;
      (points / u; None when u is 0). Beside it the least cusp_k, and the&lt;br /&gt;
      greatest of each (the drop that would be OUT, or CUSP, at every&lt;br /&gt;
      rank), for the page&amp;#039;s optional use (spec note PD-OC-2).&lt;br /&gt;
  RS3 Fewer than three ranks: status NONE, nothing computed (SPARSE&lt;br /&gt;
      MONTH is the page&amp;#039;s flag, outside this function).&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
import math&lt;br /&gt;
&lt;br /&gt;
VERSION = &amp;quot;0.3.0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _check(rows, in_max, cusp_max, z, spacing_floor):&lt;br /&gt;
    seen = set()&lt;br /&gt;
    for r in rows:&lt;br /&gt;
        if not (isinstance(r[0], str) and r[0] and isinstance(r[1], str)&lt;br /&gt;
                and r[1]):&lt;br /&gt;
            raise ValueError(&amp;quot;ids&amp;quot;)&lt;br /&gt;
        if (r[0], r[1]) in seen:&lt;br /&gt;
            raise ValueError(&amp;quot;ids&amp;quot;)&lt;br /&gt;
        seen.add((r[0], r[1]))&lt;br /&gt;
        if not (math.isfinite(r[2]) and math.isfinite(r[3]) and r[3] &amp;gt;= 0):&lt;br /&gt;
            raise ValueError(&amp;quot;score or se&amp;quot;)&lt;br /&gt;
    for x in (in_max, cusp_max, z, spacing_floor):&lt;br /&gt;
        if not math.isfinite(x):&lt;br /&gt;
            raise ValueError(&amp;quot;parameters&amp;quot;)&lt;br /&gt;
    if not (0 &amp;lt; in_max &amp;lt; cusp_max and z &amp;gt;= 0 and spacing_floor &amp;gt;= 0):&lt;br /&gt;
        raise ValueError(&amp;quot;parameters&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _check_paired(paired, rows):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;The paired-SE table as a dict keyed by the unordered pair.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if paired is None:&lt;br /&gt;
        return None&lt;br /&gt;
    keys = {(r[0], r[1]) for r in rows}&lt;br /&gt;
    table = {}&lt;br /&gt;
    for p in paired:&lt;br /&gt;
        if len(p) != 5:&lt;br /&gt;
            raise ValueError(&amp;quot;paired&amp;quot;)&lt;br /&gt;
        a = (p[0], p[1])&lt;br /&gt;
        b = (p[2], p[3])&lt;br /&gt;
        if a not in keys or b not in keys or a == b:&lt;br /&gt;
            raise ValueError(&amp;quot;paired&amp;quot;)&lt;br /&gt;
        if not (isinstance(p[4], (int, float)) and not isinstance(p[4], bool)&lt;br /&gt;
                and math.isfinite(p[4]) and p[4] &amp;gt;= 0):&lt;br /&gt;
            raise ValueError(&amp;quot;paired&amp;quot;)&lt;br /&gt;
        k = (a, b) if a &amp;lt; b else (b, a)&lt;br /&gt;
        if k in table:&lt;br /&gt;
            raise ValueError(&amp;quot;paired&amp;quot;)&lt;br /&gt;
        table[k] = float(p[4])&lt;br /&gt;
    return table&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class _Noise(object):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;sd(a, b): the SE of the difference of two rows (R7).&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, table):&lt;br /&gt;
        self.table = table&lt;br /&gt;
&lt;br /&gt;
    def sd(self, ra, rb):&lt;br /&gt;
        if self.table is None:&lt;br /&gt;
            return math.sqrt(ra[3] * ra[3] + rb[3] * rb[3])&lt;br /&gt;
        a = (ra[0], ra[1])&lt;br /&gt;
        b = (rb[0], rb[1])&lt;br /&gt;
        k = (a, b) if a &amp;lt; b else (b, a)&lt;br /&gt;
        if k not in self.table:&lt;br /&gt;
            raise ValueError(&amp;quot;paired&amp;quot;)&lt;br /&gt;
        return self.table[k]&lt;br /&gt;
&lt;br /&gt;
    def below(self, ref, row, z):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;True when row is significantly below ref.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return ref[2] - row[2] &amp;gt; z * self.sd(ref, row)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def cluster(rows, in_max=2.5, cusp_max=3.5, z=1.645, spacing_floor=0.0,&lt;br /&gt;
            paired=None):&lt;br /&gt;
    _check(rows, in_max, cusp_max, z, spacing_floor)&lt;br /&gt;
    noise = _Noise(_check_paired(paired, rows))&lt;br /&gt;
    best = {}&lt;br /&gt;
    for r in rows:&lt;br /&gt;
        k = (-r[2], r[3], r[1])&lt;br /&gt;
        if r[0] not in best or k &amp;lt; best[r[0]][0]:&lt;br /&gt;
            best[r[0]] = (k, r)&lt;br /&gt;
    reps = sorted((v[1] for v in best.values()),&lt;br /&gt;
                  key=lambda r: (-r[2], r[3], r[0]))&lt;br /&gt;
    n = len(reps)&lt;br /&gt;
    s = [r[2] for r in reps]&lt;br /&gt;
    e = [r[3] for r in reps]&lt;br /&gt;
    std = []&lt;br /&gt;
    steps = []&lt;br /&gt;
    spacing = 0.0&lt;br /&gt;
    source = &amp;quot;NONE&amp;quot;&lt;br /&gt;
    for i in range(min(n, 2)):&lt;br /&gt;
        std.append(&amp;quot;IN&amp;quot;)&lt;br /&gt;
        steps.append((0.0, 0.0))&lt;br /&gt;
    if n &amp;gt;= 3:&lt;br /&gt;
        g1 = s[0] - s[1]&lt;br /&gt;
        g2 = s[1] - s[2]&lt;br /&gt;
        gmin = g1 if g1 &amp;lt; g2 else g2&lt;br /&gt;
        d1 = noise.sd(reps[0], reps[1])&lt;br /&gt;
        d2 = noise.sd(reps[1], reps[2])&lt;br /&gt;
        top = z * (d1 if d1 &amp;gt; d2 else d2)&lt;br /&gt;
        spacing = gmin&lt;br /&gt;
        source = &amp;quot;GAP&amp;quot;&lt;br /&gt;
        if spacing_floor &amp;gt; spacing:&lt;br /&gt;
            spacing = spacing_floor&lt;br /&gt;
            source = &amp;quot;FLOOR&amp;quot;&lt;br /&gt;
        if top &amp;gt; spacing:&lt;br /&gt;
            spacing = top&lt;br /&gt;
            source = &amp;quot;NOISE&amp;quot;&lt;br /&gt;
        closed = None&lt;br /&gt;
        cusp_row = -1&lt;br /&gt;
        for i in range(2, n):&lt;br /&gt;
            step = s[i - 1] - s[i]&lt;br /&gt;
            spacings = step / spacing if spacing &amp;gt; 0.0 else None&lt;br /&gt;
            steps.append((step, spacings))&lt;br /&gt;
            if closed == &amp;quot;CUSP&amp;quot;:&lt;br /&gt;
                if noise.below(reps[cusp_row], reps[i], z):&lt;br /&gt;
                    std.append(&amp;quot;OUT&amp;quot;)&lt;br /&gt;
                    closed = &amp;quot;OUT&amp;quot;&lt;br /&gt;
                else:&lt;br /&gt;
                    std.append(&amp;quot;CUSP&amp;quot;)&lt;br /&gt;
                continue&lt;br /&gt;
            if closed == &amp;quot;OUT&amp;quot;:&lt;br /&gt;
                std.append(&amp;quot;OUT&amp;quot;)&lt;br /&gt;
                continue&lt;br /&gt;
            nk = z * noise.sd(reps[i - 1], reps[i])&lt;br /&gt;
            if step - cusp_max * spacing &amp;gt; nk:&lt;br /&gt;
                std.append(&amp;quot;OUT&amp;quot;)&lt;br /&gt;
                closed = &amp;quot;OUT&amp;quot;&lt;br /&gt;
            elif step - in_max * spacing &amp;gt; nk:&lt;br /&gt;
                std.append(&amp;quot;CUSP&amp;quot;)&lt;br /&gt;
                closed = &amp;quot;CUSP&amp;quot;&lt;br /&gt;
                cusp_row = i&lt;br /&gt;
            else:&lt;br /&gt;
                std.append(&amp;quot;IN&amp;quot;)&lt;br /&gt;
    rep_key = {(r[0], r[1]) for r in reps}&lt;br /&gt;
    low_in = None&lt;br /&gt;
    low_cusp = None&lt;br /&gt;
    for i in range(n):&lt;br /&gt;
        if std[i] == &amp;quot;IN&amp;quot;:&lt;br /&gt;
            low_in = i&lt;br /&gt;
        elif std[i] == &amp;quot;CUSP&amp;quot;:&lt;br /&gt;
            low_cusp = i&lt;br /&gt;
    out = []&lt;br /&gt;
    for i in range(n):&lt;br /&gt;
        out.append((i + 1, reps[i][0], reps[i][1], s[i], e[i],&lt;br /&gt;
                    steps[i][0], steps[i][1], std[i]))&lt;br /&gt;
    others = sorted((r for r in rows if (r[0], r[1]) not in rep_key),&lt;br /&gt;
                    key=lambda r: (-r[2], r[3], r[0], r[1]))&lt;br /&gt;
    for r in others:&lt;br /&gt;
        if low_in is not None and not noise.below(reps[low_in], r, z):&lt;br /&gt;
            st = &amp;quot;IN&amp;quot;&lt;br /&gt;
        elif low_cusp is not None and not noise.below(reps[low_cusp], r, z):&lt;br /&gt;
            st = &amp;quot;CUSP&amp;quot;&lt;br /&gt;
        else:&lt;br /&gt;
            st = &amp;quot;OUT&amp;quot;&lt;br /&gt;
        out.append((None, r[0], r[1], r[2], r[3], None, None, st))&lt;br /&gt;
    return spacing, source, out&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def fmt(x):&lt;br /&gt;
    return &amp;quot;-&amp;quot; if x is None else &amp;quot;%.6f&amp;quot; % x&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def render(result):&lt;br /&gt;
    spacing, source, out = result&lt;br /&gt;
    lines = [&amp;quot;spacing|%s|%s&amp;quot; % (fmt(spacing), source)]&lt;br /&gt;
    for r in out:&lt;br /&gt;
        lines.append(&amp;quot;%s|%s|%s|%s|%s|%s|%s|%s&amp;quot; % (&lt;br /&gt;
            &amp;quot;-&amp;quot; if r[0] is None else str(r[0]), r[1], r[2], fmt(r[3]),&lt;br /&gt;
            fmt(r[4]), fmt(r[5]), fmt(r[6]), r[7]))&lt;br /&gt;
    return &amp;quot;\n&amp;quot;.join(lines)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------- resolving_step&lt;br /&gt;
&lt;br /&gt;
def resolving_step(spacing, ses, in_max=2.5, cusp_max=3.5, z=1.645,&lt;br /&gt;
                   paired=None):&lt;br /&gt;
    if not (isinstance(spacing, (int, float)) and not isinstance(spacing, bool)&lt;br /&gt;
            and math.isfinite(spacing) and spacing &amp;gt;= 0):&lt;br /&gt;
        raise ValueError(&amp;quot;spacing&amp;quot;)&lt;br /&gt;
    if not isinstance(ses, list):&lt;br /&gt;
        raise ValueError(&amp;quot;ses&amp;quot;)&lt;br /&gt;
    for x in ses:&lt;br /&gt;
        if not (isinstance(x, (int, float)) and not isinstance(x, bool)&lt;br /&gt;
                and math.isfinite(x) and x &amp;gt;= 0):&lt;br /&gt;
            raise ValueError(&amp;quot;ses&amp;quot;)&lt;br /&gt;
    for x in (in_max, cusp_max, z):&lt;br /&gt;
        if not (isinstance(x, (int, float)) and not isinstance(x, bool)&lt;br /&gt;
                and math.isfinite(x)):&lt;br /&gt;
            raise ValueError(&amp;quot;parameters&amp;quot;)&lt;br /&gt;
    if not (0 &amp;lt; in_max &amp;lt; cusp_max and z &amp;gt;= 0):&lt;br /&gt;
        raise ValueError(&amp;quot;parameters&amp;quot;)&lt;br /&gt;
    n = len(ses)&lt;br /&gt;
    if paired is not None:&lt;br /&gt;
        if not isinstance(paired, list) or len(paired) != max(n - 1, 0):&lt;br /&gt;
            raise ValueError(&amp;quot;paired&amp;quot;)&lt;br /&gt;
        for x in paired:&lt;br /&gt;
            if not (isinstance(x, (int, float)) and not isinstance(x, bool)&lt;br /&gt;
                    and math.isfinite(x) and x &amp;gt;= 0):&lt;br /&gt;
                raise ValueError(&amp;quot;paired&amp;quot;)&lt;br /&gt;
    if n &amp;lt; 3:&lt;br /&gt;
        return {&amp;quot;status&amp;quot;: &amp;quot;NONE&amp;quot;}&lt;br /&gt;
    u = float(spacing)&lt;br /&gt;
    ranks = []&lt;br /&gt;
    for k in range(2, n):&lt;br /&gt;
        if paired is None:&lt;br /&gt;
            sd = math.sqrt(ses[k - 1] * ses[k - 1] + ses[k] * ses[k])&lt;br /&gt;
        else:&lt;br /&gt;
            sd = float(paired[k - 1])&lt;br /&gt;
        nk = z * sd&lt;br /&gt;
        ranks.append((k + 1, cusp_max * u + nk, in_max * u + nk))&lt;br /&gt;
    out_least = min(r[1] for r in ranks)&lt;br /&gt;
    out_most = max(r[1] for r in ranks)&lt;br /&gt;
    cusp_least = min(r[2] for r in ranks)&lt;br /&gt;
    cusp_most = max(r[2] for r in ranks)&lt;br /&gt;
&lt;br /&gt;
    def sp(x):&lt;br /&gt;
        return x / u if u &amp;gt; 0.0 else None&lt;br /&gt;
&lt;br /&gt;
    return {&amp;quot;status&amp;quot;: &amp;quot;OK&amp;quot;, &amp;quot;out&amp;quot;: out_least, &amp;quot;out_spacings&amp;quot;: sp(out_least),&lt;br /&gt;
            &amp;quot;cusp&amp;quot;: cusp_least, &amp;quot;cusp_spacings&amp;quot;: sp(cusp_least),&lt;br /&gt;
            &amp;quot;out_most&amp;quot;: out_most, &amp;quot;cusp_most&amp;quot;: cusp_most, &amp;quot;ranks&amp;quot;: ranks}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def render_resolving(d):&lt;br /&gt;
    if d[&amp;quot;status&amp;quot;] == &amp;quot;NONE&amp;quot;:&lt;br /&gt;
        return &amp;quot;resolving|NONE&amp;quot;&lt;br /&gt;
    lines = [&amp;quot;resolving|%s|%s|%s|%s&amp;quot; % (fmt(d[&amp;quot;out&amp;quot;]), fmt(d[&amp;quot;out_spacings&amp;quot;]),&lt;br /&gt;
                                        fmt(d[&amp;quot;cusp&amp;quot;]),&lt;br /&gt;
                                        fmt(d[&amp;quot;cusp_spacings&amp;quot;])),&lt;br /&gt;
             &amp;quot;greatest|%s|%s&amp;quot; % (fmt(d[&amp;quot;out_most&amp;quot;]), fmt(d[&amp;quot;cusp_most&amp;quot;]))]&lt;br /&gt;
    for k, o, c in d[&amp;quot;ranks&amp;quot;]:&lt;br /&gt;
        lines.append(&amp;quot;rank|%d|%s|%s&amp;quot; % (k, fmt(o), fmt(c)))&lt;br /&gt;
    return &amp;quot;\n&amp;quot;.join(lines)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# --------------------------------------------------------------- corpus&lt;br /&gt;
&lt;br /&gt;
def run_case(case):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;One corpus case (0.2.0&amp;#039;s shape, plus fn and paired): the render, or&lt;br /&gt;
    &amp;quot;ERROR:&amp;quot; and the message.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    fn = case.get(&amp;quot;fn&amp;quot;, &amp;quot;cluster&amp;quot;)&lt;br /&gt;
    p = case[&amp;quot;params&amp;quot;]&lt;br /&gt;
    try:&lt;br /&gt;
        if fn == &amp;quot;cluster&amp;quot;:&lt;br /&gt;
            paired = case.get(&amp;quot;paired&amp;quot;)&lt;br /&gt;
            if paired is not None:&lt;br /&gt;
                paired = [tuple(x) for x in paired]&lt;br /&gt;
            return render(cluster([tuple(x) for x in case[&amp;quot;rows&amp;quot;]],&lt;br /&gt;
                                  p[&amp;quot;in_max&amp;quot;], p[&amp;quot;cusp_max&amp;quot;], p[&amp;quot;z&amp;quot;],&lt;br /&gt;
                                  p[&amp;quot;spacing_floor&amp;quot;], paired))&lt;br /&gt;
        if fn == &amp;quot;resolving&amp;quot;:&lt;br /&gt;
            return render_resolving(resolving_step(&lt;br /&gt;
                case[&amp;quot;spacing&amp;quot;], case[&amp;quot;ses&amp;quot;], p[&amp;quot;in_max&amp;quot;], p[&amp;quot;cusp_max&amp;quot;],&lt;br /&gt;
                p[&amp;quot;z&amp;quot;], case.get(&amp;quot;paired&amp;quot;)))&lt;br /&gt;
        raise ValueError(&amp;quot;fn&amp;quot;)&lt;br /&gt;
    except ValueError as ex:&lt;br /&gt;
        return &amp;quot;ERROR:&amp;quot; + str(ex)&lt;br /&gt;
&lt;/div&gt;</summary>
		<author><name>BFP Rauch</name></author>
	</entry>
</feed>