feat(dommer): the power solutions compared on equal terms, and the axes of the surfaces (clarifications 134, 135 and 137)
M7 gives, for each of the five solutions, the share of the draws in which it is best alone and in which it shares the place, with no verdict on A; part II and the thresholds for M7 are gone. T-F and T-K share the place where they are the same path. The surfaces carry the classes along their axes, and kontroll prints a line per file. The made-up reference files are regenerated: everything outside the comparison is unchanged to the last digit. Nothing is computed on the frozen parameters. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
d650ce219e
commit
5a54fba628
15 changed files with 8804 additions and 758 deletions
|
|
@ -8,8 +8,10 @@ figures, and ``innhold.json``, written last, lists them with their SHA-256.
|
|||
|
||||
The figures come from the existing functions of ``kjoring``, ``folsomheter``,
|
||||
``terskler``, ``sobol`` and ``ligninger``; nothing here computes a figure of
|
||||
its own beyond picking them out. The builders turn the result objects into
|
||||
plain JSON structures with the field order of clarification 128: the
|
||||
its own beyond picking them out, except the count and the median per class
|
||||
along the axes of a surface, which use ``sobol.klasser`` and
|
||||
``dommer.persentil`` (clarification 134). The builders turn the result
|
||||
objects into plain JSON structures with the field order of clarification 128: the
|
||||
solutions in the order A, B, B', C, R, T-F, T-K, the steps ascending, the
|
||||
scenarios as in clarification 95, the targets M1 to M7, the quantities as in
|
||||
the parameter file, the rows as in the list and the years ascending; never
|
||||
|
|
@ -32,6 +34,15 @@ order. The files have the same bytes however many processes there are.
|
|||
Every file starts with the same head: the mark of the basis with its
|
||||
checksums, the number of draws, the ladder, the scenarios and the solutions
|
||||
of the run (clarification 127: the mark stands in everything a tool writes).
|
||||
|
||||
M7 is the comparison of the five solutions on equal terms, with no verdict
|
||||
(clarification 135 f, corrected by 137 d): where the files had M7 with a
|
||||
verdict, they have, for each of A, B, C, T-F and T-K in that order, the four
|
||||
shares of 137 b, then how often the place is shared (``delt``) with the share
|
||||
per pair, and then how often none can be built (``ingen``). There is no part
|
||||
II and no threshold for M7.
|
||||
The surfaces (b) and (c) carry, per axis, the count and the median of the
|
||||
quantity in each of the five classes (clarification 134).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
|
@ -66,6 +77,7 @@ if TYPE_CHECKING:
|
|||
Kjoring,
|
||||
Losningsdommer,
|
||||
Maaldom,
|
||||
Sammenligning,
|
||||
Scenario,
|
||||
Sidetall,
|
||||
)
|
||||
|
|
@ -216,6 +228,32 @@ def maaldom(m: Maaldom) -> dict[str, Json]:
|
|||
}
|
||||
|
||||
|
||||
DELT: Final = "delt"
|
||||
"""The key of the share in which the place is shared, after the five (137 d)."""
|
||||
|
||||
INGEN_BEST: Final = "ingen"
|
||||
"""The key of the share in which none of the five can be built, last (137 d)."""
|
||||
|
||||
|
||||
def sammenligning(s: Sammenligning) -> dict[str, Json]:
|
||||
"""M7: the four shares per solution, then «delt» with the pairs, then «ingen» (137 d)."""
|
||||
ut: dict[str, Json] = {
|
||||
a.value: {
|
||||
"best_alene": b.best_alene,
|
||||
"deler_plassen": b.deler_plassen,
|
||||
"ikke_byggbar": b.ikke_byggbar,
|
||||
"best_alene_blant_byggbare": b.best_alene_blant_byggbare,
|
||||
}
|
||||
for a, b in s.losninger.items()
|
||||
}
|
||||
ut[DELT] = {
|
||||
"andel": s.delt,
|
||||
"par": [{"losninger": [a.value, b.value], "andel": x} for (a, b), x in s.par.items()],
|
||||
}
|
||||
ut[INGEN_BEST] = {"andel": s.ingen}
|
||||
return ut
|
||||
|
||||
|
||||
def sidetall(s: Sidetall) -> dict[str, Json]:
|
||||
"""Median, 10th and 90th percentile and count over the draws with a value (103 c)."""
|
||||
p10, p90 = (None, None) if s.persentiler is None else s.persentiler
|
||||
|
|
@ -362,7 +400,7 @@ def lag_dommer(hodet: Mapping[str, Json], kjoring: Kjoring, dommer: kj.Dommer) -
|
|||
a.value: losningsdommer(ld, kj.ved_siden_av_m6(kjoring.utfall(scenario, a, n)))
|
||||
for a, ld in sd.per_trinn[n].items()
|
||||
},
|
||||
"M7": maaldom(sd.M7[n]) if n in sd.M7 else None,
|
||||
"M7": sammenligning(sd.M7[n]) if n in sd.M7 else None,
|
||||
}
|
||||
for n in kjoring.stige
|
||||
]
|
||||
|
|
@ -373,11 +411,9 @@ def lag_dommer(hodet: Mapping[str, Json], kjoring: Kjoring, dommer: kj.Dommer) -
|
|||
"trinn": trinn,
|
||||
"del_I": sd.del_I.value,
|
||||
"del_I_avgjort": sd.del_I_avgjort,
|
||||
"del_II": None if sd.del_II is None else sd.del_II.value,
|
||||
"betingelser": None
|
||||
if sd.betingelser is None
|
||||
else {a.value: betingelser(b) for a, b in sd.betingelser.items()},
|
||||
"terskler_M7": [terskel(t) for t in sd.terskler_M7],
|
||||
}
|
||||
)
|
||||
return {
|
||||
|
|
@ -385,7 +421,6 @@ def lag_dommer(hodet: Mapping[str, Json], kjoring: Kjoring, dommer: kj.Dommer) -
|
|||
**_valg(dommer.valg),
|
||||
"teller": dommer.teller,
|
||||
"del_I": dommer.del_I.value,
|
||||
"del_II": None if dommer.del_II is None else dommer.del_II.value,
|
||||
"per_scenario": scenarioer,
|
||||
}
|
||||
|
||||
|
|
@ -510,6 +545,23 @@ def _trukket(grunnlag: Grunnlag, navn: str) -> tuple[float, ...]:
|
|||
return grunnlag.storrelser[navn]
|
||||
|
||||
|
||||
def akse(x: Sequence[float]) -> list[Json]:
|
||||
"""One axis of a surface: per class, the draws in it and the median of the quantity (134).
|
||||
|
||||
The classes are those the surface makes (``sobol.klasser`` with five
|
||||
classes over the draws passed in); the median is the percentile rule of
|
||||
clarification 99. A class without draws has the count 0 and no median.
|
||||
"""
|
||||
klasse = sobol.klasser(x, terskler.KLASSER_FLATE)
|
||||
ut: list[Json] = []
|
||||
for q in range(terskler.KLASSER_FLATE):
|
||||
verdier = [v for v, m in zip(x, klasse, strict=True) if m == q]
|
||||
ut.append(
|
||||
{"antall": len(verdier), "median": dm.persentil(verdier, 0.5) if verdier else None}
|
||||
)
|
||||
return ut
|
||||
|
||||
|
||||
def _flater(
|
||||
grunnlag: Grunnlag,
|
||||
kjoring: Kjoring,
|
||||
|
|
@ -531,20 +583,35 @@ def _flater(
|
|||
p_v = _trukket(grunnlag, "p_v")
|
||||
for a in kjoring.losninger:
|
||||
antall, ruter = kj.kraftprisflate(kjoring, p_v, a, trinn)
|
||||
# the classes of both axes among the draws in which the path can be built (111 b)
|
||||
byggbare = [
|
||||
(p, u.c_snitt)
|
||||
for p, u in zip(p_v, kjoring.utfall(kjoring.hovedscenario, a, trinn), strict=True)
|
||||
if u is not None and u.c_snitt is not None
|
||||
]
|
||||
kraftpris[a.value] = {
|
||||
"antall_trekninger": antall,
|
||||
"ruter": [[rute(r) for r in rad] for rad in ruter],
|
||||
"akser": {
|
||||
"p_v": akse([p for p, _ in byggbare]),
|
||||
"c_snitt": akse([c for _, c in byggbare]),
|
||||
},
|
||||
}
|
||||
avkastning: dict[str, Json] = {}
|
||||
krav = ("rho_D", "rho_N")
|
||||
for a in kjerne:
|
||||
avkastning[a.value] = {
|
||||
krav: [
|
||||
[rute(r) for r in rad]
|
||||
for rad in kj.flate_over_trekningene(
|
||||
kjoring, _trukket(grunnlag, krav), c_N_ref, a, trinn
|
||||
)
|
||||
]
|
||||
for krav in ("rho_D", "rho_N")
|
||||
**{
|
||||
k: [
|
||||
[rute(r) for r in rad]
|
||||
for rad in kj.flate_over_trekningene(
|
||||
kjoring, _trukket(grunnlag, k), c_N_ref, a, trinn
|
||||
)
|
||||
]
|
||||
for k in krav
|
||||
},
|
||||
# the classes over all the draws (111 c): the same for every solution
|
||||
"akser": {k: akse(_trukket(grunnlag, k)) for k in (*krav, "c_N_ref")},
|
||||
}
|
||||
return {
|
||||
"pris_mot_reaktorkostnad": pris,
|
||||
|
|
@ -715,9 +782,8 @@ def radtabell(rt: fs.Radtabell) -> dict[str, Json]:
|
|||
"losninger": {
|
||||
a.value: losningsdommer(ld, rt.ved_siden_av[a]) for a, ld in rt.losninger.items()
|
||||
},
|
||||
"M7": None if rt.M7 is None else maaldom(rt.M7),
|
||||
"M7": None if rt.M7 is None else sammenligning(rt.M7),
|
||||
"del_I": rt.del_I.value,
|
||||
"del_II": None if rt.del_II is None else rt.del_II.value,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -801,6 +867,7 @@ def skriv_hovedkjoring(
|
|||
losninger: Sequence[Losning] = tuple(Losning),
|
||||
prosesser: int = 1,
|
||||
filer: Sequence[str] = FILER,
|
||||
laget: Callable[[str], None] | None = None,
|
||||
) -> tuple[str, ...]:
|
||||
"""Write the chosen files of the main run; ``innhold.json`` when all five are there.
|
||||
|
||||
|
|
@ -809,7 +876,9 @@ def skriv_hovedkjoring(
|
|||
thresholds (clarification 128, «Kostnaden»); the files are the same.
|
||||
``innhold.json`` is written last, when all five files are in the folder
|
||||
with the same head; a file from another run is an error. Returns the
|
||||
names of the files written, in the order they were written.
|
||||
names of the files written, in the order they were written. ``laget`` is
|
||||
called with the name of each file as soon as it is written, so a long run
|
||||
can say how far it has come (clarification 134); it changes no file.
|
||||
"""
|
||||
ukjent = [f for f in filer if f not in FILER]
|
||||
if ukjent:
|
||||
|
|
@ -838,9 +907,13 @@ def skriv_hovedkjoring(
|
|||
if navn in filer:
|
||||
skriv(mappe / navn, lag[navn]())
|
||||
skrevet.append(navn)
|
||||
if laget is not None:
|
||||
laget(navn)
|
||||
if all((mappe / navn).is_file() for navn in FILER):
|
||||
skriv_innhold(mappe, hodet)
|
||||
skrevet.append(INNHOLD)
|
||||
if laget is not None:
|
||||
laget(INNHOLD)
|
||||
return tuple(skrevet)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,15 +3,17 @@
|
|||
A verdict is read from the share of the draws in which a condition is met
|
||||
(S37). This module holds the condition per draw for each target, the verdict
|
||||
from the shares (the table in chapter 11), the step of the ladder the verdicts
|
||||
are read on (pre-registration, clarification 1) and the overall verdicts.
|
||||
are read on (pre-registration, clarification 1), part I, and which of the five
|
||||
solutions are best in a draw (M7, the comparison on equal terms; no verdict).
|
||||
|
||||
A draw in which the path cannot be built has no values; it is passed in as
|
||||
None. It counts in the denominator and never meets the condition for «holder».
|
||||
In M1, M2, M6 and M7, where «holder ikke» is that too few draws reach the
|
||||
target, it counts as a draw that does not reach it. In M3 and M4, where
|
||||
«holder ikke» is a harm that occurs, it meets neither condition. That reading,
|
||||
and which step counts as one that can be built, stand in chapter 16 of the
|
||||
specification (clarifications 56 and 57); they touch clarification 1 of the
|
||||
In M1, M2 and M6, where «holder ikke» is that too few draws reach the target,
|
||||
it counts as a draw that does not reach it. In M3 and M4, where «holder ikke»
|
||||
is a harm that occurs, it meets neither condition. In M7 a solution that
|
||||
cannot be built is not best in that draw. That reading, and which step counts
|
||||
as one that can be built, stand in chapter 16 of the specification
|
||||
(clarifications 56, 57, 135 and 137); they touch clarification 1 of the
|
||||
pre-registration and are the project owner's to approve.
|
||||
|
||||
The thresholds are those of the pre-registration. Nothing here is computed
|
||||
|
|
@ -42,10 +44,7 @@ ANDEL_HOLDER: Final = 0.8
|
|||
"""«Holder» needs the condition met in at least this share of the draws."""
|
||||
|
||||
ANDEL_HOLDER_IKKE: Final = 0.2
|
||||
"""M1, M2 and M7: «holder ikke» when the target is reached in less than this share."""
|
||||
|
||||
ANDEL_M7: Final = 0.5
|
||||
"""M7: «holder» when A is best in at least half of the draws."""
|
||||
"""M1 and M2: «holder ikke» when the target is reached in less than this share."""
|
||||
|
||||
M3_HOYST: Final = 0.05
|
||||
M3_OVER: Final = 0.15
|
||||
|
|
@ -56,7 +55,11 @@ M6_UNDER: Final = 0.05
|
|||
"""M6: at least 25 % of the petroleum cash flow holds; under 5 % does not."""
|
||||
|
||||
DOMSLOSNINGER: Final = (Losning.A, Losning.B, Losning.C, Losning.T_F, Losning.T_K)
|
||||
"""The solutions the ladder, part I and M7 are about (pre-registration, clarifications 3 and 13)."""
|
||||
"""The solutions the ladder, part I and the comparison in M7 are about (clarifications 13, 135).
|
||||
|
||||
Pre-registration, clarifications 3 and 13; chapter 16, clarification 135: the
|
||||
comparison is reported in this order, then «ingen».
|
||||
"""
|
||||
|
||||
MAAL_DEL_I: Final = ("M1", "M2", "M3", "M4", "M5", "M6")
|
||||
MAAL_SOM_FELLER: Final = ("M1", "M2", "M3", "M4", "M5")
|
||||
|
|
@ -148,9 +151,9 @@ def dom_av_andeler(andel_holder: float, andel_holder_ikke: float) -> Dom:
|
|||
return Dom.BETINGELSER
|
||||
|
||||
|
||||
def dom_av_andel_som_naar(andel_naar: float, *, holder_fra: float = ANDEL_HOLDER) -> Dom:
|
||||
"""M1, M2 and M7: the verdict from the share of the draws that reach the target."""
|
||||
if andel_naar >= holder_fra:
|
||||
def dom_av_andel_som_naar(andel_naar: float) -> Dom:
|
||||
"""M1 and M2: the verdict from the share of the draws that reach the target."""
|
||||
if andel_naar >= ANDEL_HOLDER:
|
||||
return Dom.HOLDER
|
||||
if andel_naar < ANDEL_HOLDER_IKKE:
|
||||
return Dom.HOLDER_IKKE
|
||||
|
|
@ -251,28 +254,28 @@ def dom_m6(m6: Utfall) -> Dom:
|
|||
return dom_av_andeler(holder, under)
|
||||
|
||||
|
||||
def a_er_best(nnv: Mapping[Losning, Utfall]) -> list[bool]:
|
||||
"""M7 per draw: A can be built and has a strictly higher net present value than the others.
|
||||
def beste_per_trekning(nnv: Mapping[Losning, Utfall]) -> list[tuple[Losning, ...]]:
|
||||
"""M7 per draw: the best of the five solutions (clarification 137 a, correcting 135 a).
|
||||
|
||||
``nnv[losning]`` holds the net present value per draw, None where the path
|
||||
cannot be built. The others are B, C, T-F and T-K (chapter 17.1), each
|
||||
only in the draws where it can be built. A draw in which A cannot be built
|
||||
is not one where A is best. The reference run R and B' are not part of M7.
|
||||
cannot be built. The best are those that can be built and have the highest
|
||||
net present value among those that can be built, in the order A, B, C, T-F,
|
||||
T-K. One is best alone; several with exactly the same value share the
|
||||
place; an empty tuple is a draw in which none can be built. The rule is the
|
||||
same for all five; a solution that is not passed in is not compared (a run
|
||||
without it). The reference run R and B' are not part of M7.
|
||||
"""
|
||||
ukjent = [a for a in nnv if a not in DOMSLOSNINGER]
|
||||
if Losning.A not in nnv or ukjent:
|
||||
msg = f"M7 compares A with B, C, T-F and T-K; got {sorted(nnv)}"
|
||||
if not nnv or ukjent:
|
||||
msg = f"M7 compares A, B, C, T-F and T-K; got {sorted(nnv)}"
|
||||
raise ValueError(msg)
|
||||
andre = [nnv[a] for a in DOMSLOSNINGER if a is not Losning.A and a in nnv]
|
||||
return [
|
||||
a is not None and all(a > x for x in rad if x is not None)
|
||||
for a, *rad in zip(nnv[Losning.A], *andre, strict=True)
|
||||
]
|
||||
|
||||
|
||||
def dom_m7(nnv: Mapping[Losning, Utfall]) -> Dom:
|
||||
"""M7: A has the highest net present value in at least half of the draws; under 20 % not."""
|
||||
return dom_av_andel_som_naar(lg.s37_andel(a_er_best(nnv)), holder_fra=ANDEL_M7)
|
||||
losninger = [a for a in DOMSLOSNINGER if a in nnv]
|
||||
beste: list[tuple[Losning, ...]] = []
|
||||
for rad in zip(*(nnv[a] for a in losninger), strict=True):
|
||||
byggbare = [(v, a) for v, a in zip(rad, losninger, strict=True) if v is not None]
|
||||
hoyest = max((v for v, _ in byggbare), default=None)
|
||||
beste.append(tuple(a for v, a in byggbare if v == hoyest))
|
||||
return beste
|
||||
|
||||
|
||||
# ------------------------------------------------- the step of the ladder
|
||||
|
|
@ -404,8 +407,3 @@ def del_I(
|
|||
return Dom.BETINGELSER
|
||||
navngitt = any(kan_navngis(dommer[a], har_terskel.get(a, {})) for a in ikke_felt)
|
||||
return Dom.BETINGELSER if navngitt else Dom.HOLDER_IKKE
|
||||
|
||||
|
||||
def del_II(m7: Dom) -> Dom:
|
||||
"""The verdict for part II (the power solution) follows M7."""
|
||||
return m7
|
||||
|
|
|
|||
|
|
@ -6,9 +6,10 @@ The list of the parameter file has 37 lines and gives 42 rows: five lines
|
|||
have two values. A row is the main run with one change, over the same draws.
|
||||
It is computed for the solutions it applies to, on the step the main run's
|
||||
verdicts are read on and in the scenario it is read in; every other solution
|
||||
keeps the main run's outcome. The verdicts per target, M7, part I and part II
|
||||
are then put together from the row's outcomes as in the main run, without
|
||||
thresholds. No verdict of a row counts.
|
||||
keeps the main run's outcome. The verdicts per target, part I and the
|
||||
comparison of the five solutions in M7 (clarification 135) are then put
|
||||
together from the row's outcomes as in the main run, without thresholds. No
|
||||
verdict of a row counts.
|
||||
|
||||
Four rows concern only the comparison of the ownership forms and are computed
|
||||
by ``kjoring.eierformer_paa_trinnet``; one row, M6 against the median of the
|
||||
|
|
@ -39,7 +40,7 @@ if TYPE_CHECKING:
|
|||
from collections.abc import Iterable, Mapping, Sequence
|
||||
|
||||
from tokenfabrikker.inndata import Inndata
|
||||
from tokenfabrikker.kjoring import Losningsdommer, Maaldom, Sidetall, Utfall
|
||||
from tokenfabrikker.kjoring import Losningsdommer, Sammenligning, Sidetall, Utfall
|
||||
|
||||
ALLE: Final = tuple(Losning)
|
||||
MED_KJERNEKRAFT: Final = (Losning.A, Losning.B, Losning.B_MERKET, Losning.T_K)
|
||||
|
|
@ -341,9 +342,11 @@ class Radtabell:
|
|||
the path stands in the place of C.
|
||||
ved_siden_av: per solution the figures next to M6, among them M6 against the
|
||||
median of the ten years.
|
||||
M7: the share of the draws in which A is best, and the verdict; None without A.
|
||||
M7: the comparison as the row gives it: for each of the five solutions in the run
|
||||
the four shares of clarification 137 b, the share in which the place is shared
|
||||
with the share per pair, and the share in which none can be built; no verdict
|
||||
(clarifications 135 e and 137). None when none of the five is in the run.
|
||||
del_I: part I as the row gives it, on the main run's step and without thresholds.
|
||||
del_II: part II as the row gives it; None without A.
|
||||
"""
|
||||
|
||||
rad: str
|
||||
|
|
@ -351,9 +354,8 @@ class Radtabell:
|
|||
gjelder: tuple[Losning, ...]
|
||||
losninger: Mapping[Losning, Losningsdommer]
|
||||
ved_siden_av: Mapping[Losning, Mapping[str, Sidetall]]
|
||||
M7: Maaldom | None
|
||||
M7: Sammenligning | None
|
||||
del_I: Dom
|
||||
del_II: Dom | None
|
||||
|
||||
|
||||
def _mot_medianen(utfall: Sequence[Utfall | None]) -> list[Utfall | None]:
|
||||
|
|
@ -374,8 +376,8 @@ def _radtabell(
|
|||
fem = [a for a in DOMSLOSNINGER if a in for_dommene]
|
||||
dom = {a: kj.losningsdommer(for_dommene[a], M5[a]) for a in fem}
|
||||
m7 = (
|
||||
kj.maaldom_m7({a: [None if u is None else u.NNV for u in for_dommene[a]] for a in fem})
|
||||
if Losning.A in fem
|
||||
kj.sammenligning({a: [None if u is None else u.NNV for u in for_dommene[a]] for a in fem})
|
||||
if fem
|
||||
else None
|
||||
)
|
||||
return Radtabell(
|
||||
|
|
@ -388,7 +390,6 @@ def _radtabell(
|
|||
del_I=dommer.del_I(
|
||||
{a: dom[a].dommer for a in fem}, {a: dom[a].median_M1 for a in fem}, valg
|
||||
),
|
||||
del_II=None if m7 is None else dommer.del_II(m7.dom),
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -418,9 +419,9 @@ def tabell(
|
|||
row and ``valg`` the main run's step. A solution the row does not apply
|
||||
to has the main run's outcome. For the row «M6 against the median» the
|
||||
verdict in M6 is set with that figure in every solution, and nothing is
|
||||
run. For «C in modules» the path stands in the place of C, and M7, part I
|
||||
and part II are the main run's. The rows of the ownership forms have no
|
||||
table here.
|
||||
run. For «C in modules» the path stands in the place of C, and part I and
|
||||
the comparison in M7 are the main run's. The rows of the ownership forms
|
||||
have no table here.
|
||||
"""
|
||||
if valg.trinn is None or rad.eierrad is not None:
|
||||
return {}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ value (S26), the sum of S42, the worst price effect (M3), the two conditions
|
|||
of M4 and M6 in the first year of stable operation. The verdicts are put
|
||||
together from them with ``dommer`` and ``miljo``, on the step the
|
||||
pre-registration points to, and the timeline (S50) is summarised over the
|
||||
draws. The ownership forms are compared on that step in a second pass.
|
||||
draws. M7 is the comparison of the five solutions on equal terms: how often
|
||||
each is best, with no verdict (clarifications 135 and 137). The ownership forms are
|
||||
compared on that step in a second pass.
|
||||
|
||||
With the drawn values of the quantities passed in, the thresholds behind
|
||||
«holder under betingelser» are found and part I is decided (clarifications 108
|
||||
|
|
@ -366,10 +368,10 @@ class Maaldom:
|
|||
dom: the verdict.
|
||||
andel_holder: the share of all the draws that meets the condition for «holder» (S37).
|
||||
andel_holder_ikke: the share that meets the condition for «holder ikke», for M3, M4
|
||||
and M6, where that is a condition of its own; None for M1, M2 and M7, where
|
||||
and M6, where that is a condition of its own; None for M1 and M2, where
|
||||
«holder ikke» is that too few draws reach the target.
|
||||
ikke_byggbar: the share of all the draws in which the path cannot be built
|
||||
(clarification 69); in M7 the path of A.
|
||||
(clarification 69).
|
||||
oppfylt_blant_byggbare: the share that meets the condition for «holder» among the
|
||||
draws in which it can be built; None when there is none.
|
||||
"""
|
||||
|
|
@ -454,31 +456,65 @@ class Betingelser:
|
|||
return not self.felt and not self.maal
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Bestandel:
|
||||
"""How often one of the five solutions is best, on one step in one scenario (137 b).
|
||||
|
||||
Attributes:
|
||||
best_alene: the share of all the draws in which the solution is best alone (S37).
|
||||
deler_plassen: the share of all the draws in which it shares the highest value.
|
||||
ikke_byggbar: the share of all the draws in which its path cannot be built.
|
||||
best_alene_blant_byggbare: the share in which it is best alone among the draws in
|
||||
which its path can be built (clarification 69); None when there is none.
|
||||
"""
|
||||
|
||||
best_alene: float
|
||||
deler_plassen: float
|
||||
ikke_byggbar: float
|
||||
best_alene_blant_byggbare: float | None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Sammenligning:
|
||||
"""M7: the five solutions compared on equal terms, with no verdict (135 and 137).
|
||||
|
||||
Attributes:
|
||||
losninger: per solution among A, B, C, T-F and T-K that is in the run, in that
|
||||
order, how often it is best.
|
||||
delt: the share of all the draws in which two or more share the highest value.
|
||||
par: per pair of solutions in the run, in the order A-B, A-C, ..., T-F-T-K, the
|
||||
share of all the draws in which the two share the place; a draw in which three
|
||||
share counts for each of its pairs.
|
||||
ingen: the share of all the draws in which none of them can be built. With «best
|
||||
alene» of the solutions and ``delt`` it sums to one.
|
||||
"""
|
||||
|
||||
losninger: Mapping[Losning, Bestandel]
|
||||
delt: float
|
||||
par: Mapping[tuple[Losning, Losning], float]
|
||||
ingen: float
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Scenariodommer:
|
||||
"""The verdicts in one scenario.
|
||||
|
||||
Attributes:
|
||||
per_trinn: the verdicts per step of the ladder and solution.
|
||||
M7: M7 per step, among the five solutions of the verdicts that are in the run.
|
||||
M7: the comparison per step among the five solutions that are in the run; empty
|
||||
when none of them is (clarifications 135 and 137). It carries no verdict.
|
||||
del_I: part I on the step the verdicts are read on. Without the drawn values of
|
||||
the quantities it is given as far as it follows from the targets: where it is
|
||||
«holder under betingelser», whether the conditions can be named is then still
|
||||
to be decided (clarifications 93, 97 and 109).
|
||||
del_II: part II on that step; None when no step can be built, or when A is not in
|
||||
the run (clarification 102).
|
||||
betingelser: the conditions per solution on that step; None without the drawn
|
||||
values, or when there is no step.
|
||||
terskler_M7: the thresholds for M7 when it holds under conditions; they are shown
|
||||
and change nothing.
|
||||
"""
|
||||
|
||||
per_trinn: Mapping[int, Mapping[Losning, Losningsdommer]]
|
||||
M7: Mapping[int, Maaldom]
|
||||
M7: Mapping[int, Sammenligning]
|
||||
del_I: Dom
|
||||
del_II: Dom | None
|
||||
betingelser: Mapping[Losning, Betingelser] | None = None
|
||||
terskler_M7: tuple[Terskel, ...] = ()
|
||||
|
||||
@property
|
||||
def del_I_avgjort(self) -> bool:
|
||||
|
|
@ -506,11 +542,6 @@ class Dommer:
|
|||
"""Part I in the scenario that counts."""
|
||||
return self.scenarioer[self.teller].del_I
|
||||
|
||||
@property
|
||||
def del_II(self) -> Dom | None:
|
||||
"""Part II in the scenario that counts."""
|
||||
return self.scenarioer[self.teller].del_II
|
||||
|
||||
|
||||
def dommer_m5(
|
||||
losninger: Sequence[Losning],
|
||||
|
|
@ -670,15 +701,45 @@ def _samtidig(
|
|||
)
|
||||
|
||||
|
||||
def vilkaar_m7(nnv: Mapping[Losning, Sequence[float | None]]) -> list[bool | None]:
|
||||
"""Whether A is best per draw; None where A cannot be built (clarification 69)."""
|
||||
best = dommer.a_er_best(nnv)
|
||||
return [None if a is None else b for a, b in zip(nnv[Losning.A], best, strict=True)]
|
||||
def sammenligning(nnv: Mapping[Losning, Sequence[float | None]]) -> Sammenligning:
|
||||
"""M7 from the net present value per solution and draw (clarification 137 b).
|
||||
|
||||
``nnv`` holds, for the solutions among A, B, C, T-F and T-K that are
|
||||
compared, the net present value per draw with None where the path cannot
|
||||
be built. For each of them: the share of all the draws in which it is
|
||||
best alone, the share in which it shares the place, the share in which its
|
||||
path cannot be built, and the share in which it is best alone among the
|
||||
draws in which it can be built. For the comparison as a whole: the share
|
||||
in which the place is shared, the share per pair of solutions, and the
|
||||
share in which none can be built.
|
||||
"""
|
||||
beste = dommer.beste_per_trekning(nnv)
|
||||
fem = [a for a in DOMSLOSNINGER if a in nnv]
|
||||
losninger: dict[Losning, Bestandel] = {}
|
||||
for a in fem:
|
||||
ikke_byggbar, blant_byggbare = dommer.ved_siden_av_dommen(
|
||||
[None if v is None else b == (a,) for v, b in zip(nnv[a], beste, strict=True)]
|
||||
)
|
||||
losninger[a] = Bestandel(
|
||||
best_alene=lg.s37_andel([b == (a,) for b in beste]),
|
||||
deler_plassen=lg.s37_andel([len(b) > 1 and a in b for b in beste]),
|
||||
ikke_byggbar=ikke_byggbar,
|
||||
best_alene_blant_byggbare=blant_byggbare,
|
||||
)
|
||||
return Sammenligning(
|
||||
losninger=losninger,
|
||||
delt=lg.s37_andel([len(b) > 1 for b in beste]),
|
||||
par={
|
||||
(a, b): lg.s37_andel([len(x) > 1 and a in x and b in x for x in beste])
|
||||
for i, a in enumerate(fem)
|
||||
for b in fem[i + 1 :]
|
||||
},
|
||||
ingen=lg.s37_andel([not b for b in beste]),
|
||||
)
|
||||
|
||||
|
||||
def maaldom_m7(nnv: Mapping[Losning, Sequence[float | None]]) -> Maaldom:
|
||||
"""M7 from the net present value per solution and draw, with the figures next to it."""
|
||||
return _maaldom(dommer.dom_m7(nnv), vilkaar_m7(nnv))
|
||||
def _nnv(utfall: Sequence[Utfall | None]) -> list[float | None]:
|
||||
return [None if u is None else u.NNV for u in utfall]
|
||||
|
||||
|
||||
def sett_dommer(
|
||||
|
|
@ -688,13 +749,15 @@ def sett_dommer(
|
|||
storrelser: Mapping[str, Sequence[float]] | None = None,
|
||||
status: Mapping[str, str] | None = None,
|
||||
) -> Dommer:
|
||||
"""The verdicts of the run: per target, the step they are read on, part I and part II.
|
||||
"""The verdicts of the run: per target, the step they are read on, and part I.
|
||||
|
||||
``M5`` holds the verdict for M5 per solution (``dommer_m5``). The step is
|
||||
set once, from M6 in «normalisering» on the main path for A, B, C, T-F and
|
||||
T-K, and the verdicts of every scenario are read on it (clarification 97).
|
||||
B' and R get a verdict per target but are in neither the ladder, part I
|
||||
nor M7.
|
||||
nor M7. M7 is the comparison of the five on every step, with no verdict and
|
||||
no threshold (clarifications 135 and 137); the five that are in the run are
|
||||
compared.
|
||||
|
||||
``storrelser`` holds the drawn values of the quantities, one per draw in
|
||||
the order of the run, and ``status`` the status of each in the parameter
|
||||
|
|
@ -719,17 +782,14 @@ def sett_dommer(
|
|||
scenarioer: dict[str, Scenariodommer] = {}
|
||||
for scenario in kjoring.scenarioer:
|
||||
per_trinn: dict[int, dict[Losning, Losningsdommer]] = {}
|
||||
m7: dict[int, Maaldom] = {}
|
||||
m7: dict[int, Sammenligning] = {}
|
||||
for trinn in kjoring.stige:
|
||||
utfall = {a: kjoring.utfall(scenario, a, trinn) for a in kjoring.losninger}
|
||||
per_trinn[trinn] = {a: losningsdommer(utfall[a], M5[a]) for a in kjoring.losninger}
|
||||
if Losning.A in fem:
|
||||
m7[trinn] = maaldom_m7(
|
||||
{a: [None if u is None else u.NNV for u in utfall[a]] for a in fem}
|
||||
)
|
||||
if fem:
|
||||
m7[trinn] = sammenligning({a: _nnv(utfall[a]) for a in fem})
|
||||
paa_trinnet = {} if valg.trinn is None else per_trinn[valg.trinn]
|
||||
betingelser: dict[Losning, Betingelser] | None = None
|
||||
terskler_M7: tuple[Terskel, ...] = ()
|
||||
if storrelser is not None and status is not None and valg.trinn is not None:
|
||||
betingelser = {
|
||||
a: betingelser_for_losning(
|
||||
|
|
@ -737,21 +797,6 @@ def sett_dommer(
|
|||
)
|
||||
for a in kjoring.losninger
|
||||
}
|
||||
if valg.trinn in m7 and m7[valg.trinn].dom is Dom.BETINGELSER:
|
||||
terskler_M7 = terskler.terskler_for_maal(
|
||||
storrelser,
|
||||
status,
|
||||
vilkaar_m7(
|
||||
{
|
||||
a: [
|
||||
None if u is None else u.NNV
|
||||
for u in kjoring.utfall(scenario, a, valg.trinn)
|
||||
]
|
||||
for a in fem
|
||||
}
|
||||
),
|
||||
grense=dommer.ANDEL_M7,
|
||||
)
|
||||
scenarioer[scenario.navn] = Scenariodommer(
|
||||
per_trinn=per_trinn,
|
||||
M7=m7,
|
||||
|
|
@ -766,9 +811,7 @@ def sett_dommer(
|
|||
for a in fem
|
||||
},
|
||||
),
|
||||
del_II=dommer.del_II(m7[valg.trinn].dom) if valg.trinn in m7 else None,
|
||||
betingelser=betingelser,
|
||||
terskler_M7=terskler_M7,
|
||||
)
|
||||
return Dommer(valg=valg, scenarioer=scenarioer, teller=hoved.navn)
|
||||
|
||||
|
|
@ -829,8 +872,10 @@ def utfall_for_indeksene(
|
|||
The net present value among the draws in which the path can be built
|
||||
(None elsewhere), whether it can be built, the condition for «holder» in
|
||||
M1, M2, M3, M4 and M6, the condition for «holder ikke» in M3, M4 and M6,
|
||||
and for A whether A is best. The conditions are one or zero over all the
|
||||
draws, as S37 counts them.
|
||||
and, for each of A, B, C, T-F and T-K, whether it is among the best, alone
|
||||
or sharing the place (M7, compared with the others of the five that are in
|
||||
the run; clarifications 135 d and 137 c). The
|
||||
conditions are one or zero over all the draws, as S37 counts them.
|
||||
"""
|
||||
scenario = kjoring.hovedscenario if scenario is None else scenario
|
||||
utfall = kjoring.utfall(scenario, losning, trinn)
|
||||
|
|
@ -843,12 +888,11 @@ def utfall_for_indeksene(
|
|||
for maal, ikke in vilkaar_holder_ikke(utfall).items():
|
||||
y[f"{maal} holder ikke"] = [float(x) for x in ikke]
|
||||
fem = [a for a in DOMSLOSNINGER if a in kjoring.losninger]
|
||||
if losning is Losning.A and Losning.A in fem:
|
||||
nnv: dict[Losning, list[float | None]] = {
|
||||
a: [None if u is None else u.NNV for u in kjoring.utfall(scenario, a, trinn)]
|
||||
for a in fem
|
||||
}
|
||||
y["M7"] = [float(x) for x in dommer.a_er_best(nnv)]
|
||||
if losning in fem:
|
||||
beste = dommer.beste_per_trekning(
|
||||
{a: _nnv(kjoring.utfall(scenario, a, trinn)) for a in fem}
|
||||
)
|
||||
y["M7"] = [float(losning in b) for b in beste]
|
||||
return y
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -244,6 +244,12 @@ def _stige_fra_tekst(tekst: str) -> tuple[int, ...]:
|
|||
# ------------------------------------------------------------------ commands
|
||||
|
||||
|
||||
def skriv_laget(navn: str) -> None:
|
||||
"""One line, flushed, as each data file is made, so a long run does not look stalled (134)."""
|
||||
sys.stdout.write(f"Laget {navn}\n")
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def kjor_hovedkjoring(valg: argparse.Namespace) -> int:
|
||||
"""``hovedkjoring``: write the chosen data files of the main run."""
|
||||
filer = df.FILER if valg.filer is None else tuple(valg.filer.split(","))
|
||||
|
|
@ -254,7 +260,12 @@ def kjor_hovedkjoring(valg: argparse.Namespace) -> int:
|
|||
stige = kj.STIGE if valg.stige is None else _stige_fra_tekst(valg.stige)
|
||||
grunnlag = hent_grunnlag(valg)
|
||||
skrevet = df.skriv_hovedkjoring(
|
||||
grunnlag, Path(valg.ut), stige=stige, prosesser=valg.prosesser, filer=filer
|
||||
grunnlag,
|
||||
Path(valg.ut),
|
||||
stige=stige,
|
||||
prosesser=valg.prosesser,
|
||||
filer=filer,
|
||||
laget=skriv_laget,
|
||||
)
|
||||
sys.stdout.write(f"Grunnlaget er merket «{grunnlag.merke}». Skrevet: {', '.join(skrevet)}\n")
|
||||
return 0
|
||||
|
|
@ -283,6 +294,7 @@ def kjor_kontroll(valg: argparse.Namespace) -> int:
|
|||
scenarioer=scenarioer,
|
||||
losninger=losninger,
|
||||
prosesser=valg.prosesser,
|
||||
laget=skriv_laget,
|
||||
)
|
||||
resultat = df.sammenlign_mapper(ny, fasit)
|
||||
for fil in resultat.filer:
|
||||
|
|
@ -397,14 +409,23 @@ def _maal(a: Mapping[str, object], b: Mapping[str, object]) -> dict[str, object]
|
|||
|
||||
|
||||
def _m7(a: object, b: object) -> dict[str, object]:
|
||||
"""The comparison in M7 in both, for each solution, «delt» and «ingen» both have (137).
|
||||
|
||||
A solution gives the share in which it is best alone; «delt» and «ingen» their share.
|
||||
The shares per pair are not compared.
|
||||
"""
|
||||
da, db = cast("dict[str, object] | None", a), cast("dict[str, object] | None", b)
|
||||
return {
|
||||
"a": None if da is None else da["dom"],
|
||||
"b": None if db is None else db["dom"],
|
||||
"endring_andel_holder": None
|
||||
if da is None or db is None
|
||||
else _forskjell(da["andel_holder"], db["andel_holder"]),
|
||||
}
|
||||
if da is None or db is None:
|
||||
return {}
|
||||
ut: dict[str, object] = {}
|
||||
for navn, xa in da.items():
|
||||
if navn not in db:
|
||||
continue
|
||||
felt = "andel" if navn in (df.DELT, df.INGEN_BEST) else "best_alene"
|
||||
andel_a = cast("dict[str, object]", xa)[felt]
|
||||
andel_b = cast("dict[str, object]", db[navn])[felt]
|
||||
ut[navn] = {"a": andel_a, "b": andel_b, "endring": _forskjell(andel_a, andel_b)}
|
||||
return ut
|
||||
|
||||
|
||||
def sammenlign_dommer(a: Mapping[str, object], b: Mapping[str, object]) -> dict[str, object]:
|
||||
|
|
@ -412,9 +433,12 @@ def sammenlign_dommer(a: Mapping[str, object], b: Mapping[str, object]) -> dict[
|
|||
|
||||
For every scenario, step and solution in both: the verdict per target in
|
||||
both, the change in the share that meets the condition for «holder» (b
|
||||
minus a), and the median in M1 in both with the difference; M7, part I,
|
||||
part II and the step in both. When the two come from different bases or
|
||||
different numbers of draws, that stands first.
|
||||
minus a), and the median in M1 in both with the difference; the comparison
|
||||
in M7 (the share in which each solution is best alone, the place is shared
|
||||
and none can be built, in both and the change; clarifications 135 and
|
||||
137), part I and the step in both. When the two
|
||||
come from different bases or different numbers of draws, that stands
|
||||
first.
|
||||
"""
|
||||
ulikt = []
|
||||
if a["grunnlag"] != b["grunnlag"]:
|
||||
|
|
@ -448,7 +472,6 @@ def sammenlign_dommer(a: Mapping[str, object], b: Mapping[str, object]) -> dict[
|
|||
scenarioer[navn] = {
|
||||
"trinn": trinn,
|
||||
"del_I": {"a": sa["del_I"], "b": sb["del_I"]},
|
||||
"del_II": {"a": sa["del_II"], "b": sb["del_II"]},
|
||||
}
|
||||
return {
|
||||
"ulikt_grunnlag": ulikt,
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -29,10 +29,10 @@
|
|||
"T-K"
|
||||
],
|
||||
"filer": {
|
||||
"dommer.json": "39ba305e19ae04bb77c912d0c7c5547d5e225ca60bd3277000a0ed4890c202b8",
|
||||
"dommer.json": "12ef6afb87d9a161fda090741fe7d6f45bf1c8070ba51304779475eed0962a96",
|
||||
"tidslinje.json": "a6dd290e13a2cee9de1b5030aea553f3c592a64c01ec67d1e6081b7038dbe5bf",
|
||||
"eierformer.json": "5460b8e836edb60638ea56db239ad0d2d1a7ba939c50a55e0deb147a5ca38342",
|
||||
"terskler.json": "6d8df88997947a1bf980258ef7076e1cb97856af100dd0cce1de5bae67f1677e",
|
||||
"folsomheter.json": "879248ce9753a3f76a8df98fb726fb6431a672913f233621d2a85cfa192a54fa"
|
||||
"terskler.json": "b892ba98bdaab46e6d104f21e4182a87ba92ea9047a0151a3175bc62363271f5",
|
||||
"folsomheter.json": "afa6eb1712497eaa22887a2a09f6da31e28396100f5f2a9f022b102ff29bf2da"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -10,19 +10,20 @@ from __future__ import annotations
|
|||
import json
|
||||
import math
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
|
||||
from tokenfabrikker import datafiler as df
|
||||
from tokenfabrikker import grunnlag as gl
|
||||
from tokenfabrikker import kjoring as kj
|
||||
from tokenfabrikker import terskler
|
||||
from tokenfabrikker.dommer import Dom, Forsyning
|
||||
from tokenfabrikker.kjoring import Bane, Kjoring, Utfall
|
||||
from tokenfabrikker.utbygging import Kraft, Losning
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
from tokenfabrikker.kjoring import Scenario
|
||||
|
||||
NORM, VARER = kj.SCENARIOER[1], kj.SCENARIOER[0]
|
||||
|
|
@ -134,7 +135,6 @@ def test_dommer_json_har_tallene_sett_dommer_gir() -> None:
|
|||
"grunnlag_for_trinnet",
|
||||
"teller",
|
||||
"del_I",
|
||||
"del_II",
|
||||
"per_scenario",
|
||||
]
|
||||
assert (lest["trinn"], lest["grunnlag_for_trinnet"]) == (5, "25 %-trinnet")
|
||||
|
|
@ -157,7 +157,32 @@ def test_dommer_json_har_tallene_sett_dommer_gir() -> None:
|
|||
# B cannot be built in 25 of 40 draws: the median in M1 has no value
|
||||
assert sd.per_trinn[5][Losning.B].median_M1 == -math.inf
|
||||
assert norm["trinn"][0]["losninger"]["B"]["median_M1"] is None
|
||||
assert norm["trinn"][0]["M7"]["dom"] == sd.M7[5].dom.value
|
||||
# M7 is the comparison: A is best in all 40 draws, B cannot be built in 25 (135 f)
|
||||
assert norm["trinn"][0]["M7"] == {
|
||||
"A": {
|
||||
"best_alene": 1.0,
|
||||
"deler_plassen": 0.0,
|
||||
"ikke_byggbar": 0.0,
|
||||
"best_alene_blant_byggbare": 1.0,
|
||||
},
|
||||
"B": {
|
||||
"best_alene": 0.0,
|
||||
"deler_plassen": 0.0,
|
||||
"ikke_byggbar": 0.625,
|
||||
"best_alene_blant_byggbare": 0.0,
|
||||
},
|
||||
"delt": {"andel": 0.0, "par": [{"losninger": ["A", "B"], "andel": 0.0}]},
|
||||
"ingen": {"andel": 0.0},
|
||||
}
|
||||
assert norm["trinn"][0]["M7"] == df.sammenligning(sd.M7[5])
|
||||
assert list(norm) == [
|
||||
"navn",
|
||||
"teller",
|
||||
"trinn",
|
||||
"del_I",
|
||||
"del_I_avgjort",
|
||||
"betingelser",
|
||||
]
|
||||
ved = kj.ved_siden_av_m6(kjoring.utfall(NORM, Losning.A, 5))["snitt"]
|
||||
assert a["ved_siden_av_M6"]["snitt"] == {
|
||||
"antall": ved.antall,
|
||||
|
|
@ -221,6 +246,94 @@ def test_tidslinje_json_har_tallene_over_trekningene() -> None:
|
|||
assert isinstance(rader[0]["aar"], int)
|
||||
|
||||
|
||||
def test_sammenligningen_i_M7_staar_i_fast_rekkefolge_med_delt_og_ingen_sist() -> None:
|
||||
"""Clarification 137 d: the four shares per solution, then «delt» with the pairs, «ingen»."""
|
||||
m7 = kj.Sammenligning(
|
||||
losninger={
|
||||
Losning.A: kj.Bestandel(0.25, 0.25, 0.5, 0.5),
|
||||
Losning.C: kj.Bestandel(0.25, 0.25, 0.0, 0.25),
|
||||
Losning.T_K: kj.Bestandel(0.0, 0.0, 1.0, None),
|
||||
},
|
||||
delt=0.25,
|
||||
par={
|
||||
(Losning.A, Losning.C): 0.25,
|
||||
(Losning.A, Losning.T_K): 0.0,
|
||||
(Losning.C, Losning.T_K): 0.0,
|
||||
},
|
||||
ingen=0.25,
|
||||
)
|
||||
lest = _lest(df.sammenligning(m7))
|
||||
assert isinstance(lest, dict)
|
||||
assert list(lest) == ["A", "C", "T-K", "delt", "ingen"]
|
||||
assert lest["T-K"] == {
|
||||
"best_alene": 0.0,
|
||||
"deler_plassen": 0.0,
|
||||
"ikke_byggbar": 1.0,
|
||||
"best_alene_blant_byggbare": None,
|
||||
}
|
||||
assert lest["delt"] == {
|
||||
"andel": 0.25,
|
||||
"par": [
|
||||
{"losninger": ["A", "C"], "andel": 0.25},
|
||||
{"losninger": ["A", "T-K"], "andel": 0.0},
|
||||
{"losninger": ["C", "T-K"], "andel": 0.0},
|
||||
],
|
||||
}
|
||||
assert lest["ingen"] == {"andel": 0.25}
|
||||
alene = [lest[a]["best_alene"] for a in ("A", "C", "T-K")]
|
||||
assert math.fsum([*alene, lest["delt"]["andel"], lest["ingen"]["andel"]]) == 1.0
|
||||
|
||||
|
||||
def test_aksene_i_flatene_har_antall_og_median_per_klasse() -> None:
|
||||
"""Clarification 134: five classes as the surface makes them; a class without draws is empty.
|
||||
|
||||
Ten values: the class is floor(5 r / 10), two draws per class, the median the midpoint.
|
||||
Three distinct values in six draws: the classes 0, 1 and 3 (floor(5 r / 6) for r = 0, 2, 4).
|
||||
"""
|
||||
x = [10.0, 1.0, 9.0, 2.0, 8.0, 3.0, 7.0, 4.0, 6.0, 5.0]
|
||||
assert df.akse(x) == [
|
||||
{"antall": 2, "median": 1.5},
|
||||
{"antall": 2, "median": 3.5},
|
||||
{"antall": 2, "median": 5.5},
|
||||
{"antall": 2, "median": 7.5},
|
||||
{"antall": 2, "median": 9.5},
|
||||
]
|
||||
assert df.akse([1.0, 1.0, 2.0, 2.0, 3.0, 3.0]) == [
|
||||
{"antall": 2, "median": 1.0},
|
||||
{"antall": 2, "median": 2.0},
|
||||
{"antall": 0, "median": None},
|
||||
{"antall": 2, "median": 3.0},
|
||||
{"antall": 0, "median": None},
|
||||
]
|
||||
assert df.akse([]) == [{"antall": 0, "median": None}] * 5
|
||||
# the counts are those of the surface's cells summed along the other axis
|
||||
y = [float(j % 3) for j in range(10)]
|
||||
flate = terskler.flate(x, y, [1.0] * 10)
|
||||
assert [sum(r.antall for r in rad) for rad in flate] == [k["antall"] for k in df.akse(x)] # type: ignore[index]
|
||||
assert [sum(rad[j].antall for rad in flate) for j in range(5)] == [
|
||||
k["antall"] # type: ignore[index]
|
||||
for k in df.akse(y)
|
||||
]
|
||||
|
||||
|
||||
def test_hovedkjoringen_sier_fra_om_hver_fil_etter_hvert(tmp_path: Path) -> None:
|
||||
"""Clarification 134: a line per file as it is made; the files are those it writes."""
|
||||
sti = Path(__file__).resolve().parent / "oppdiktet" / "grunnlag.json"
|
||||
data = json.loads(sti.read_text(encoding="utf-8"))
|
||||
data["trekninger"] = data["trekninger"][:1]
|
||||
liten = tmp_path / "grunnlag.json"
|
||||
liten.write_text(json.dumps(data, ensure_ascii=False), encoding="utf-8")
|
||||
laget: list[str] = []
|
||||
skrevet = df.skriv_hovedkjoring(
|
||||
gl.fra_fil(liten),
|
||||
tmp_path / "ut",
|
||||
stige=(1,),
|
||||
filer=(df.DOMMER, df.TIDSLINJE),
|
||||
laget=laget.append,
|
||||
)
|
||||
assert laget == list(skrevet) == [df.DOMMER, df.TIDSLINJE]
|
||||
|
||||
|
||||
def test_d_stjerne_med_den_faste_eps_d_og_med_0_5_og_2() -> None:
|
||||
assert df.d_stjerne(0.6, 1.0) == [
|
||||
{"eps_d": 1.0, "d_stjerne": 0.4},
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ def test_trekning_uten_verdi_teller_i_nevneren() -> None:
|
|||
assert dommer.median(_utfall((1.0, 4), (None, 6))) == -math.inf
|
||||
|
||||
|
||||
# -------------------------------------------------------------- M1, M2, M7
|
||||
# -------------------------------------------------------------- M1, M2
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -88,23 +88,32 @@ def test_dom_m2_teller_null_som_oppfylt() -> None:
|
|||
assert dommer.dom_m2(_utfall((1.0, 10), (-1.0, 50), (None, 40))) is Dom.HOLDER_IKKE
|
||||
|
||||
|
||||
def test_dom_m7_a_mot_b_og_c() -> None:
|
||||
"""A is best in 5 of 10 draws: holds. A draw where A cannot be built is not one of them.
|
||||
def test_m7_hvem_som_er_best_blant_a_b_og_c() -> None:
|
||||
"""Clarification 137 a, one rule for each: the highest value among those that can be built.
|
||||
|
||||
The two versions of solution T are left out here; ``test_trinnvis_dommer.py`` has all five.
|
||||
Ten draws. 0-4: A highest. 5-7: B highest (A lower, C equal to A in 5-7). 8-9: A cannot
|
||||
be built, B is negative and C cannot be built either: B is best alone. The two versions of
|
||||
solution T are left out here; ``test_trinnvis_dommer.py`` has all five.
|
||||
"""
|
||||
A = _utfall((10.0, 5), (1.0, 3), (None, 2))
|
||||
B = _utfall((5.0, 5), (2.0, 3), (-9.0, 2))
|
||||
C = _utfall((None, 5), (0.0, 5))
|
||||
assert dommer.a_er_best({Losning.A: A, Losning.B: B, Losning.C: C}) == [True] * 5 + [False] * 5
|
||||
assert dommer.dom_m7({Losning.A: A, Losning.B: B, Losning.C: C}) is Dom.HOLDER
|
||||
alltid_bedre = _utfall((5.0, 5), (2.0, 5))
|
||||
fire = {Losning.A: _utfall((10.0, 4), (1.0, 6)), Losning.B: alltid_bedre, Losning.C: C}
|
||||
assert dommer.dom_m7(fire) is Dom.BETINGELSER
|
||||
en = {Losning.A: _utfall((10.0, 1), (1.0, 9)), Losning.B: alltid_bedre, Losning.C: C}
|
||||
assert dommer.dom_m7(en) is Dom.HOLDER_IKKE
|
||||
# equal is not best
|
||||
assert dommer.a_er_best({Losning.A: [1.0], Losning.B: [1.0], Losning.C: [0.0]}) == [False]
|
||||
C = _utfall((None, 5), (1.0, 3), (None, 2))
|
||||
beste = dommer.beste_per_trekning({Losning.A: A, Losning.B: B, Losning.C: C})
|
||||
assert beste == [(Losning.A,)] * 5 + [(Losning.B,)] * 5
|
||||
# equal values share the place, in the order A, B, C; none built leaves none
|
||||
assert dommer.beste_per_trekning({Losning.A: [1.0], Losning.B: [1.0], Losning.C: [0.0]}) == [
|
||||
(Losning.A, Losning.B)
|
||||
]
|
||||
assert dommer.beste_per_trekning({Losning.C: [3.0], Losning.B: [2.0], Losning.A: [3.0]}) == [
|
||||
(Losning.A, Losning.C)
|
||||
]
|
||||
assert dommer.beste_per_trekning({Losning.A: [None], Losning.B: [None], Losning.C: [None]}) == [
|
||||
()
|
||||
]
|
||||
# C can be best as A can, and a solution that cannot be built is never among the best
|
||||
assert dommer.beste_per_trekning({Losning.A: [None], Losning.B: [-1.0], Losning.C: [0.0]}) == [
|
||||
(Losning.C,)
|
||||
]
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ M3 and M4
|
||||
|
|
@ -320,10 +329,6 @@ def test_del_I_ser_ikke_paa_referansekjoringen() -> None:
|
|||
assert dommer.del_I(per_losning, median, Trinnvalg(10, Grunnlag.TRINN_25)) is Dom.HOLDER_IKKE
|
||||
|
||||
|
||||
def test_del_II_folger_M7() -> None:
|
||||
assert dommer.del_II(Dom.BETINGELSER) is Dom.BETINGELSER
|
||||
|
||||
|
||||
def test_hvor_mye_av_dommen_som_skyldes_baner_som_ikke_lar_seg_bygge() -> None:
|
||||
"""Clarification 69: 2 of 8 draws cannot be built; 3 of the 6 others meet the condition."""
|
||||
oppfylt = [True, None, False, True, None, False, True, False]
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ draw for the table. Nothing here says anything about the hypothesis.
|
|||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
import math
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
|
|
@ -457,7 +458,7 @@ def test_hovedkjoringen_i_tabellen_er_dommene_paa_trinnet() -> None:
|
|||
norm = d.scenarioer[NORM.navn]
|
||||
assert (t.rad, t.scenario, t.gjelder) == (fs.HOVEDKJORINGEN, NORM.navn, ())
|
||||
assert t.losninger == norm.per_trinn[5]
|
||||
assert (t.M7, t.del_I, t.del_II) == (norm.M7[5], norm.del_I, norm.del_II)
|
||||
assert (t.M7, t.del_I) == (norm.M7[5], norm.del_I)
|
||||
assert t.ved_siden_av[Losning.A] == kj.ved_siden_av_m6(hoved.utfall(NORM, Losning.A, 5))
|
||||
with pytest.raises(ValueError, match="no table"):
|
||||
fs.hovedtabell(hoved, M5, Trinnvalg(trinn=None, grunnlag=Grunnlag.INGEN), NORM)
|
||||
|
|
@ -474,13 +475,17 @@ def test_en_rad_i_tabellen_har_radens_utfall_der_den_gjelder_og_hovedkjoringens_
|
|||
assert t.losninger[Losning.C] == fs.hovedtabell(hoved, M5, VALG, NORM).losninger[Losning.C]
|
||||
a = t.losninger[Losning.A]
|
||||
assert (a.maal["M1"].andel_holder, a.maal["M1"].dom, a.median_M1) == (1.0, Dom.HOLDER, 0.1)
|
||||
# the comparison from the row's outcomes: A best in 2, C (the main run's) in 8; no verdict
|
||||
assert t.M7 is not None
|
||||
assert (t.M7.andel_holder, t.M7.dom) == (0.2, Dom.BETINGELSER)
|
||||
assert (t.del_I, t.del_II) == (Dom.HOLDER, Dom.BETINGELSER)
|
||||
assert {a: b.best_alene for a, b in t.M7.losninger.items()} == {Losning.A: 0.2, Losning.C: 0.8}
|
||||
assert (t.M7.delt, t.M7.ingen) == (0.0, 0.0)
|
||||
assert t.del_I is Dom.HOLDER
|
||||
# the main run next to it: 7 of 10 positive, and A best in those 7
|
||||
h = fs.hovedtabell(hoved, M5, VALG, NORM)
|
||||
assert h.M7 is not None
|
||||
assert (h.losninger[Losning.A].maal["M1"].andel_holder, h.M7.andel_holder) == (0.7, 0.7)
|
||||
a_best = h.M7.losninger[Losning.A].best_alene
|
||||
assert (h.losninger[Losning.A].maal["M1"].andel_holder, a_best) == (0.7, 0.7)
|
||||
assert h.M7.losninger[Losning.C].best_alene == 0.3
|
||||
# without a run of the row every solution has the main run's figures
|
||||
(uten,) = fs.tabell(hoved, RADER["3"], None, M5, VALG).values()
|
||||
assert (uten.losninger, uten.M7, uten.del_I) == (h.losninger, h.M7, h.del_I)
|
||||
|
|
@ -504,16 +509,67 @@ def test_M6_mot_medianen_er_en_dom_og_ingen_kjoring() -> None:
|
|||
|
||||
|
||||
def test_C_i_moduler_staar_paa_plassen_til_C_og_endrer_ikke_M7_og_del_I() -> None:
|
||||
"""Row 35: the path beats A in every draw, and is still not one of the five solutions."""
|
||||
"""Row 35: the path beats A in one draw, and is still not one of the five solutions.
|
||||
|
||||
The comparison is the main run's (clarification 135 e): A is best in every draw there.
|
||||
"""
|
||||
hoved = _kjoring([{Losning.A: _u(1.0), Losning.C: _u(0.5)} for _ in range(10)])
|
||||
radkjoring = _kjoring([{Losning.C: _u(-2.0 if j < 9 else 3.0)} for j in range(10)])
|
||||
(t,) = fs.tabell(hoved, RADER["35"], radkjoring, M5, VALG).values()
|
||||
h = fs.hovedtabell(hoved, M5, VALG, NORM)
|
||||
assert t.losninger[Losning.C].maal["M1"].andel_holder == 0.1
|
||||
assert t.losninger[Losning.C].median_M1 == -2.0
|
||||
assert (t.M7, t.del_I, t.del_II) == (h.M7, h.del_I, h.del_II)
|
||||
assert (t.M7, t.del_I) == (h.M7, h.del_I)
|
||||
assert h.M7 is not None
|
||||
assert h.M7.andel_holder == 1.0
|
||||
assert (h.M7.losninger[Losning.A].best_alene, h.M7.losninger[Losning.C].best_alene) == (1.0, 0)
|
||||
|
||||
|
||||
def test_sammenligningen_i_tabellen_gjelder_de_fem_og_summerer_til_en() -> None:
|
||||
"""Clarifications 135 e and 137: row 22 (B, B', C, T-F, T-K) with B' highest, not compared.
|
||||
|
||||
Main run: A 2.0, B 1.0, C 1.0, T-F 0.5, T-K cannot be built in the last two of ten. In the
|
||||
row B rises to 2.0 in the first five draws (sharing the place with A) and to 3.0 in the
|
||||
next five.
|
||||
"""
|
||||
alle = (Losning.A, Losning.B, Losning.B_MERKET, Losning.C, Losning.T_F, Losning.T_K)
|
||||
|
||||
def hovedtrekning(j: int) -> dict[Losning, Utfall | None]:
|
||||
verdier = {Losning.A: 2.0, Losning.B: 1.0, Losning.B_MERKET: 99.0, Losning.C: 1.0}
|
||||
u: dict[Losning, Utfall | None] = {a: _u(v) for a, v in verdier.items()}
|
||||
return {**u, Losning.T_F: _u(0.5), Losning.T_K: None if j >= 8 else _u(0.0)}
|
||||
|
||||
hoved = _kjoring([hovedtrekning(j) for j in range(10)])
|
||||
assert hoved.losninger == alle
|
||||
egne = (Losning.B, Losning.B_MERKET, Losning.C, Losning.T_F, Losning.T_K)
|
||||
radkjoring = _kjoring(
|
||||
[
|
||||
{
|
||||
**{a: hovedtrekning(j)[a] for a in egne},
|
||||
Losning.B: _u(2.0 if j < 5 else 3.0),
|
||||
}
|
||||
for j in range(10)
|
||||
]
|
||||
)
|
||||
(t,) = fs.tabell(hoved, RADER["22"], radkjoring, M5, VALG).values()
|
||||
assert t.gjelder == egne
|
||||
assert t.M7 is not None
|
||||
assert list(t.M7.losninger) == [Losning.A, Losning.B, Losning.C, Losning.T_F, Losning.T_K]
|
||||
andeler = {a: b.best_alene for a, b in t.M7.losninger.items()}
|
||||
assert andeler == {
|
||||
Losning.A: 0.0,
|
||||
Losning.B: 0.5,
|
||||
Losning.C: 0.0,
|
||||
Losning.T_F: 0.0,
|
||||
Losning.T_K: 0.0,
|
||||
}
|
||||
assert (t.M7.delt, t.M7.ingen) == (0.5, 0.0)
|
||||
assert t.M7.losninger[Losning.A].deler_plassen == 0.5
|
||||
assert [p for p, x in t.M7.par.items() if x > 0] == [(Losning.A, Losning.B)]
|
||||
assert t.M7.losninger[Losning.T_K].ikke_byggbar == 0.2
|
||||
assert math.fsum([*andeler.values(), t.M7.delt, t.M7.ingen]) == 1.0
|
||||
h = fs.hovedtabell(hoved, M5, VALG, NORM)
|
||||
assert h.M7 is not None
|
||||
assert (h.M7.losninger[Losning.A].best_alene, h.M7.delt, h.M7.ingen) == (1.0, 0.0, 0.0)
|
||||
|
||||
|
||||
def test_tabellen_har_en_rad_per_scenario_raden_leses_av_i() -> None:
|
||||
|
|
|
|||
|
|
@ -297,15 +297,20 @@ def test_trinnet_settes_i_normalisering_og_gjelder_alle_scenarioene() -> None:
|
|||
d = kj.sett_dommer(_kjoring([trekning() for _ in range(5)]), M5)
|
||||
assert (d.valg.trinn, d.valg.grunnlag) == (5, Grunnlag.TRINN_25)
|
||||
assert d.teller == NORM.navn
|
||||
assert (d.del_I, d.del_II) == (Dom.HOLDER, Dom.HOLDER_IKKE)
|
||||
assert d.del_I is Dom.HOLDER
|
||||
varer = d.scenarioer[VARER.navn]
|
||||
assert (varer.del_I, varer.del_II) == (Dom.HOLDER, Dom.HOLDER_IKKE)
|
||||
assert varer.del_I is Dom.HOLDER
|
||||
assert varer.per_trinn[1][Losning.C].maal["M6"].dom is Dom.HOLDER
|
||||
assert d.scenarioer[NORM.navn].per_trinn[1][Losning.C].maal["M6"].dom is Dom.BETINGELSER
|
||||
assert set(varer.per_trinn[5]) == {Losning.A, Losning.C, Losning.R}
|
||||
assert varer.per_trinn[5][Losning.R].maal["M6"].dom is Dom.HOLDER
|
||||
# the comparison is on every step, among A and C; R is not part of it
|
||||
assert set(varer.M7) == {1, 5}
|
||||
assert varer.M7[5].andel_holder == 0.0
|
||||
assert list(varer.M7[5].losninger) == [Losning.A, Losning.C]
|
||||
assert varer.M7[5].losninger[Losning.A].best_alene == 0.0
|
||||
assert (varer.M7[5].delt, varer.M7[5].ingen) == (0.0, 0.0)
|
||||
assert varer.M7[5].losninger[Losning.C].best_alene == 1.0
|
||||
assert varer.M7[5].par == {(Losning.A, Losning.C): 0.0}
|
||||
|
||||
|
||||
def test_del_I_leses_paa_trinnet_fra_normalisering_ogsaa_naar_scenarioet_er_svakere() -> None:
|
||||
|
|
@ -319,15 +324,18 @@ def test_del_I_leses_paa_trinnet_fra_normalisering_ogsaa_naar_scenarioet_er_svak
|
|||
kjoring = _kjoring([trekning() for _ in range(4)], scenarioer=(LAVT, NORM))
|
||||
d = kj.sett_dommer(kjoring, {Losning.A: Dom.HOLDER})
|
||||
assert (d.valg.trinn, d.valg.grunnlag) == (2, Grunnlag.TRINN_25)
|
||||
assert (d.del_I, d.del_II) == (Dom.HOLDER, Dom.HOLDER)
|
||||
assert d.del_I is Dom.HOLDER
|
||||
lavt = d.scenarioer[LAVT.navn]
|
||||
assert lavt.per_trinn[2][Losning.A].felt
|
||||
# part II follows M7: A is alone in the run and is best wherever it can be built
|
||||
assert (lavt.del_I, lavt.del_II) == (Dom.HOLDER_IKKE, Dom.HOLDER)
|
||||
assert lavt.del_I is Dom.HOLDER_IKKE
|
||||
# A is alone in the run and is best wherever it can be built, whatever its value
|
||||
m7 = lavt.M7[2]
|
||||
assert (m7.losninger[Losning.A].best_alene, m7.delt, m7.ingen, m7.par) == (1.0, 0.0, 0.0, {})
|
||||
|
||||
|
||||
def test_M7_teller_A_mot_de_som_lar_seg_bygge_og_viser_tallene_for_A() -> None:
|
||||
# A is best in draws 0, 2 (C cannot be built there) and 4; equal in 1; not built in 3
|
||||
def test_M7_sammenligner_de_som_lar_seg_bygge_og_viser_tallene_for_hver() -> None:
|
||||
# A is best alone in draws 0, 2 (C cannot be built there) and 4; the two share draw 1;
|
||||
# C is best alone in 3
|
||||
per_trekning: list[dict[tuple[Losning, int], dict[str, Utfall] | None]] = [
|
||||
{(Losning.A, 1): _alle(_u(5.0)), (Losning.C, 1): _alle(_u(1.0))},
|
||||
{(Losning.A, 1): _alle(_u(1.0)), (Losning.C, 1): _alle(_u(1.0))},
|
||||
|
|
@ -338,16 +346,20 @@ def test_M7_teller_A_mot_de_som_lar_seg_bygge_og_viser_tallene_for_A() -> None:
|
|||
M5 = {Losning.A: Dom.HOLDER, Losning.C: Dom.HOLDER}
|
||||
d = kj.sett_dommer(_kjoring(per_trekning), M5)
|
||||
m7 = d.scenarioer[NORM.navn].M7[1]
|
||||
assert m7.andel_holder == 0.6
|
||||
assert m7.dom is Dom.HOLDER
|
||||
assert m7.andel_holder_ikke is None
|
||||
assert m7.ikke_byggbar == 0.2
|
||||
assert m7.oppfylt_blant_byggbare == 0.75
|
||||
assert m7.losninger == {
|
||||
Losning.A: kj.Bestandel(
|
||||
best_alene=0.6, deler_plassen=0.2, ikke_byggbar=0.2, best_alene_blant_byggbare=0.75
|
||||
),
|
||||
Losning.C: kj.Bestandel(
|
||||
best_alene=0.2, deler_plassen=0.2, ikke_byggbar=0.2, best_alene_blant_byggbare=0.25
|
||||
),
|
||||
}
|
||||
assert (m7.delt, m7.par, m7.ingen) == (0.2, {(Losning.A, Losning.C): 0.2}, 0.0)
|
||||
# step 1 holds 25 % but a single facility cannot give «holder» for part I
|
||||
assert (d.valg.trinn, d.del_I, d.del_II) == (1, Dom.BETINGELSER, Dom.HOLDER)
|
||||
assert (d.valg.trinn, d.del_I) == (1, Dom.BETINGELSER)
|
||||
|
||||
|
||||
def test_uten_noe_trinn_holder_ikke_del_I_og_del_II_har_ingen_dom() -> None:
|
||||
def test_uten_noe_trinn_holder_ikke_del_I_og_M7_vises_likevel() -> None:
|
||||
# the path is built in half the draws on both steps: no step can be built in 80 %
|
||||
per_trekning: list[dict[tuple[Losning, int], dict[str, Utfall] | None]] = [
|
||||
{(Losning.A, 1): _alle(_u()), (Losning.A, 2): _alle(_u())},
|
||||
|
|
@ -356,9 +368,173 @@ def test_uten_noe_trinn_holder_ikke_del_I_og_del_II_har_ingen_dom() -> None:
|
|||
d = kj.sett_dommer(_kjoring(per_trekning), {Losning.A: Dom.HOLDER})
|
||||
assert (d.valg.trinn, d.valg.grunnlag) == (None, Grunnlag.INGEN)
|
||||
assert d.del_I is Dom.HOLDER_IKKE
|
||||
assert d.del_II is None
|
||||
# M7 is still shown on every step
|
||||
assert d.scenarioer[NORM.navn].M7[2].andel_holder == 0.5
|
||||
# the comparison is still shown on every step: A is best where it can be built
|
||||
m7 = d.scenarioer[NORM.navn].M7[2]
|
||||
assert (m7.losninger[Losning.A].best_alene, m7.delt, m7.ingen) == (0.5, 0.0, 0.5)
|
||||
assert not hasattr(d, "del_II")
|
||||
|
||||
|
||||
FEM = (Losning.A, Losning.B, Losning.C, Losning.T_F, Losning.T_K)
|
||||
|
||||
FEM_NNV: dict[Losning, list[float | None]] = {
|
||||
# draw: 0 1 2 3 4 5 6 7 8 9
|
||||
Losning.A: [9.0, 1.0, 1.0, 1.0, 1.0, None, None, 3.0, 1.0, None],
|
||||
Losning.B: [1.0, 9.0, 1.0, 1.0, 1.0, None, None, None, 1.0, 5.0],
|
||||
Losning.C: [1.0, 1.0, 9.0, 1.0, None, None, None, 3.0, 1.0, 5.0],
|
||||
Losning.T_F: [1.0, 1.0, 1.0, 9.0, 1.0, None, None, 2.0, 4.0, 5.0],
|
||||
Losning.T_K: [1.0, 1.0, 1.0, 1.0, 9.0, -5.0, None, 1.0, 4.0, 4.0],
|
||||
}
|
||||
"""Ten invented draws: A, B, C, T-F and T-K best alone in turn in 0 to 4; T-K alone (and
|
||||
negative) in 5; nothing built in 6; A and C share in 7; T-F and T-K the same path in 8; B, C
|
||||
and T-F share in 9, where A cannot be built."""
|
||||
|
||||
|
||||
def _fem_kjoring(uten: tuple[Losning, ...] = ()) -> Kjoring:
|
||||
"""The draws of ``FEM_NNV`` on step 1, with R and B' far above and not compared."""
|
||||
|
||||
def bane(a: Losning, j: int) -> dict[str, Utfall] | None:
|
||||
v = FEM_NNV[a][j]
|
||||
return None if v is None else _alle(_u(v))
|
||||
|
||||
return _kjoring(
|
||||
[
|
||||
{
|
||||
**{(a, 1): bane(a, j) for a in FEM if a not in uten},
|
||||
(Losning.R, 1): _alle(_u(100.0)),
|
||||
(Losning.B_MERKET, 1): _alle(_u(100.0)),
|
||||
}
|
||||
for j in range(10)
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_sammenligningen_av_de_fem_haandregnet() -> None:
|
||||
"""Clarification 137 b on the ten draws of ``FEM_NNV``.
|
||||
|
||||
A: alone in 0, shares 7, not built in 5, 6, 9, alone in 1 of its 7. B: alone in 1, shares
|
||||
9, not built in 5, 6, 7, 1 of 7. C: alone in 2, shares 7 and 9, not built in 4, 5, 6, 1 of
|
||||
7. T-F: alone in 3, shares 8 and 9, not built in 5, 6, 1 of 8. T-K: alone in 4 and 5,
|
||||
shares 8, not built in 6, 2 of 9. Shared in 7, 8, 9; none built in 6.
|
||||
"""
|
||||
m7 = kj.sammenligning(FEM_NNV)
|
||||
assert list(m7.losninger) == list(FEM)
|
||||
assert {a: dataclasses.astuple(b) for a, b in m7.losninger.items()} == {
|
||||
Losning.A: (1 / 10, 1 / 10, 3 / 10, 1 / 7),
|
||||
Losning.B: (1 / 10, 1 / 10, 3 / 10, 1 / 7),
|
||||
Losning.C: (1 / 10, 2 / 10, 3 / 10, 1 / 7),
|
||||
Losning.T_F: (1 / 10, 2 / 10, 2 / 10, 1 / 8),
|
||||
Losning.T_K: (2 / 10, 1 / 10, 1 / 10, 2 / 9),
|
||||
}
|
||||
assert (m7.delt, m7.ingen) == (3 / 10, 1 / 10)
|
||||
# every pair in the fixed order; the three sharing draw 9 count for each of their pairs
|
||||
A, B, C, TF, TK = FEM
|
||||
assert list(m7.par.items()) == [
|
||||
((A, B), 0.0),
|
||||
((A, C), 1 / 10),
|
||||
((A, TF), 0.0),
|
||||
((A, TK), 0.0),
|
||||
((B, C), 1 / 10),
|
||||
((B, TF), 1 / 10),
|
||||
((B, TK), 0.0),
|
||||
((C, TF), 1 / 10),
|
||||
((C, TK), 0.0),
|
||||
((TF, TK), 1 / 10),
|
||||
]
|
||||
# «best alene» of the five, «delt» and «ingen» sum to one (exactly in counts: 6 + 3 + 1)
|
||||
summen = math.fsum([*(b.best_alene for b in m7.losninger.values()), m7.delt, m7.ingen])
|
||||
assert summen == pytest.approx(1.0, rel=0.0, abs=1e-15)
|
||||
# the order the solutions are passed in does not matter
|
||||
assert kj.sammenligning({a: FEM_NNV[a] for a in reversed(FEM)}) == m7
|
||||
|
||||
|
||||
def test_T_F_og_T_K_som_samme_bane_deler_plassen_og_er_ikke_ingen() -> None:
|
||||
"""Clarification 137: where T-K gets no nuclear power it is T-F, and the two share the top."""
|
||||
lik: list[float | None] = [7.0, 7.0, 7.0, 7.0]
|
||||
nnv: dict[Losning, list[float | None]] = {
|
||||
Losning.A: [1.0, 9.0, None, None],
|
||||
Losning.B: [1.0, 1.0, None, None],
|
||||
Losning.C: [None, 1.0, None, None],
|
||||
Losning.T_F: lik,
|
||||
Losning.T_K: [*lik[:3], 8.0],
|
||||
}
|
||||
m7 = kj.sammenligning(nnv)
|
||||
assert (m7.delt, m7.ingen) == (0.5, 0.0)
|
||||
assert m7.par[Losning.T_F, Losning.T_K] == 0.5
|
||||
assert m7.losninger[Losning.T_F].deler_plassen == 0.5
|
||||
assert m7.losninger[Losning.T_K].best_alene == 0.25
|
||||
assert m7.losninger[Losning.A].best_alene == 0.25
|
||||
|
||||
|
||||
def test_en_losning_som_ikke_lar_seg_bygge_er_aldri_best() -> None:
|
||||
"""B is never built; under it the four others share the top, or nothing is built."""
|
||||
nnv = {a: [None if a is Losning.B else 0.0, 5.0 if a is Losning.B else None] for a in FEM}
|
||||
nnv[Losning.B] = [None, None]
|
||||
m7 = kj.sammenligning(nnv)
|
||||
b = m7.losninger[Losning.B]
|
||||
assert dataclasses.astuple(b) == (0.0, 0.0, 1.0, None)
|
||||
# draw 0: the four others share the top at zero; draw 1: nothing is built
|
||||
assert (m7.delt, m7.ingen) == (0.5, 0.5)
|
||||
assert all(x.best_alene == 0.0 for x in m7.losninger.values())
|
||||
assert [a for a, x in m7.losninger.items() if x.deler_plassen == 0.5] == [
|
||||
Losning.A,
|
||||
Losning.C,
|
||||
Losning.T_F,
|
||||
Losning.T_K,
|
||||
]
|
||||
assert [p for p, x in m7.par.items() if x == 0.5] == [
|
||||
(Losning.A, Losning.C),
|
||||
(Losning.A, Losning.T_F),
|
||||
(Losning.A, Losning.T_K),
|
||||
(Losning.C, Losning.T_F),
|
||||
(Losning.C, Losning.T_K),
|
||||
(Losning.T_F, Losning.T_K),
|
||||
]
|
||||
|
||||
|
||||
def test_sammenligningen_gjennom_kjoringen_og_uten_A() -> None:
|
||||
"""The run puts the comparison together from the outcomes; R and B' are left out of it."""
|
||||
kjoring = _fem_kjoring()
|
||||
d = kj.sett_dommer(kjoring, dict.fromkeys(kjoring.losninger, Dom.HOLDER))
|
||||
for scenario in (NORM, VARER):
|
||||
assert d.scenarioer[scenario.navn].M7[1] == kj.sammenligning(FEM_NNV)
|
||||
# a run without A compares the four that are in it
|
||||
uten_a = _fem_kjoring(uten=(Losning.A,))
|
||||
m7 = (
|
||||
kj.sett_dommer(uten_a, dict.fromkeys(uten_a.losninger, Dom.HOLDER))
|
||||
.scenarioer[NORM.navn]
|
||||
.M7[1]
|
||||
)
|
||||
assert list(m7.losninger) == [Losning.B, Losning.C, Losning.T_F, Losning.T_K]
|
||||
assert m7 == kj.sammenligning({a: FEM_NNV[a] for a in FEM if a is not Losning.A})
|
||||
# draw 0: the four share at 1; draw 7: C alone; shared in 0, 8 and 9, none built in 6
|
||||
assert (m7.delt, m7.ingen) == (3 / 10, 1 / 10)
|
||||
assert m7.losninger[Losning.C].best_alene == 2 / 10
|
||||
assert m7.par[Losning.B, Losning.C] == 2 / 10
|
||||
assert len(m7.par) == 6
|
||||
# a run with none of the five has no comparison
|
||||
bare_r = _kjoring([{(Losning.R, 1): _alle(_u())}])
|
||||
assert kj.sett_dommer(bare_r, {Losning.R: Dom.HOLDER}).scenarioer[NORM.navn].M7 == {}
|
||||
|
||||
|
||||
def test_sobol_utfallet_M7_er_blant_de_beste_alene_eller_delt() -> None:
|
||||
"""Clarification 137 c: one where the solution is among the best, alone or shared."""
|
||||
kjoring = _fem_kjoring()
|
||||
best = {a: kj.utfall_for_indeksene(kjoring, a, 1)["M7"] for a in FEM}
|
||||
assert best == {
|
||||
Losning.A: [1.0, 0, 0, 0, 0, 0, 0, 1.0, 0, 0],
|
||||
Losning.B: [0, 1.0, 0, 0, 0, 0, 0, 0, 0, 1.0],
|
||||
Losning.C: [0, 0, 1.0, 0, 0, 0, 0, 1.0, 0, 1.0],
|
||||
Losning.T_F: [0, 0, 0, 1.0, 0, 0, 0, 0, 1.0, 1.0],
|
||||
Losning.T_K: [0, 0, 0, 0, 1.0, 1.0, 0, 0, 1.0, 0],
|
||||
}
|
||||
assert "M7" not in kj.utfall_for_indeksene(kjoring, Losning.R, 1)
|
||||
x = [float(j) for j in range(10)]
|
||||
indekser = kj.sobol_indekser(kjoring, {"x": x}, Losning.T_K, 1)
|
||||
# two classes of five: T-K is among the best in 1 of the lower and 2 of the upper
|
||||
snitt = 3 / 10
|
||||
mellom = 5 * (0.2 - snitt) ** 2 + 5 * (0.4 - snitt) ** 2
|
||||
total = 3 * (1 - snitt) ** 2 + 7 * (0 - snitt) ** 2
|
||||
assert indekser["M7"]["x"] == pytest.approx(mellom / total)
|
||||
|
||||
|
||||
def test_dommene_trenger_normalisering_paa_hovedforlopet_en_gang() -> None:
|
||||
|
|
@ -722,8 +898,11 @@ def test_M5_under_betingelser_er_navngitt_og_M6_trenger_ingen_terskel() -> None:
|
|||
assert norm.betingelser[Losning.A].bare_skalaen_mangler
|
||||
|
||||
|
||||
def test_tersklene_for_M7_vises_og_endrer_ingenting() -> None:
|
||||
"""A is best in the first 4 of 10 draws: at most 8 of the quantity gives 4 of 8."""
|
||||
def test_ingen_terskel_soekes_for_M7() -> None:
|
||||
"""Clarification 135 d: A is best in the first 4 of 10 draws, C in the other 6; no threshold.
|
||||
|
||||
Under the old rule this was M7 «holder under betingelser» with a threshold at most 8 of x.
|
||||
"""
|
||||
|
||||
def trekning(j: int) -> dict[tuple[Losning, int], dict[str, Utfall] | None]:
|
||||
return {
|
||||
|
|
@ -735,11 +914,18 @@ def test_tersklene_for_M7_vises_og_endrer_ingenting() -> None:
|
|||
M5 = dict.fromkeys((Losning.A, Losning.C), Dom.HOLDER)
|
||||
d = kj.sett_dommer(kjoring, M5, storrelser={"x": X10}, status={"x": "åpen forutsetning"})
|
||||
norm = d.scenarioer[NORM.navn]
|
||||
assert norm.M7[5].dom is Dom.BETINGELSER
|
||||
(t,) = norm.terskler_M7
|
||||
assert _kjerne(t) == ("x", Retning.HOYST, 8.0, 0.8, 0.5, False)
|
||||
assert (d.del_I, d.del_II) == (Dom.HOLDER, Dom.BETINGELSER)
|
||||
assert kj.sett_dommer(kjoring, M5).scenarioer[NORM.navn].terskler_M7 == ()
|
||||
m7 = norm.M7[5]
|
||||
assert [(a, b.best_alene) for a, b in m7.losninger.items()] == [
|
||||
(Losning.A, 0.4),
|
||||
(Losning.C, 0.6),
|
||||
]
|
||||
assert (m7.delt, m7.ingen) == (0.0, 0.0)
|
||||
assert not hasattr(norm, "terskler_M7")
|
||||
assert norm.betingelser is not None
|
||||
assert all("M7" not in b.terskler for b in norm.betingelser.values())
|
||||
# the comparison is the same with and without the drawn values
|
||||
assert kj.sett_dommer(kjoring, M5).scenarioer[NORM.navn].M7 == norm.M7
|
||||
assert d.del_I is Dom.HOLDER
|
||||
|
||||
|
||||
def test_tersklene_trenger_verdier_og_status_for_hver_trekning() -> None:
|
||||
|
|
@ -798,7 +984,8 @@ def test_utfallene_indeksene_gis_for() -> None:
|
|||
"M6 holder ikke": [0.0, 1.0, 0.0, 1.0],
|
||||
"M7": [1.0, 0.0, 0.0, 0.0],
|
||||
}
|
||||
assert "M7" not in kj.utfall_for_indeksene(kjoring, Losning.C, 5)
|
||||
# C is best where A is lower or cannot be built (clarification 135 d)
|
||||
assert kj.utfall_for_indeksene(kjoring, Losning.C, 5)["M7"] == [0.0, 1.0, 1.0, 1.0]
|
||||
indekser = kj.sobol_indekser(kjoring, {"x": [1.0, 2.0, 3.0, 4.0]}, Losning.A, 5)
|
||||
assert set(indekser) == set(y)
|
||||
# two classes of two draws: M1 follows the class exactly, M3 not at all
|
||||
|
|
|
|||
|
|
@ -116,11 +116,12 @@ def test_m5_for_tk_folger_ikke_trinnet_eller_trekningen() -> None:
|
|||
# ----------------------------------------------------------- M7 with five solutions
|
||||
|
||||
|
||||
def test_m7_a_maa_slaa_hver_av_de_fire_som_lar_seg_bygge() -> None:
|
||||
"""Six invented draws.
|
||||
def test_m7_de_beste_er_de_med_hoyest_verdi_blant_dem_som_lar_seg_bygge() -> None:
|
||||
"""Six invented draws (clarification 137 a).
|
||||
|
||||
1: A highest. 2: T-F higher. 3: T-K equal (strictly higher is required). 4: only A can
|
||||
be built. 5: A cannot be built. 6: A highest among those that can be built.
|
||||
1: A highest. 2: T-F highest. 3: A and T-K share the highest value. 4: only A can be built.
|
||||
5: A cannot be built and the four others share one value. 6: A highest among those that can
|
||||
be built.
|
||||
"""
|
||||
nnv: dict[Losning, list[float | None]] = {
|
||||
Losning.A: [10.0, 10.0, 10.0, 10.0, None, 10.0],
|
||||
|
|
@ -129,33 +130,52 @@ def test_m7_a_maa_slaa_hver_av_de_fire_som_lar_seg_bygge() -> None:
|
|||
Losning.T_F: [5.0, 11.0, 5.0, None, 1.0, None],
|
||||
Losning.T_K: [5.0, 5.0, 10.0, None, 1.0, 9.0],
|
||||
}
|
||||
assert dommer.a_er_best(nnv) == [True, False, False, True, False, True]
|
||||
assert dommer.dom_m7(nnv) is Dom.HOLDER # three of six
|
||||
# without the two versions of T, A is also best in draws 2 and 3
|
||||
tre = {a: nnv[a] for a in (Losning.A, Losning.B, Losning.C)}
|
||||
assert dommer.a_er_best(tre) == [True, True, True, True, False, True]
|
||||
A, B, C, TF, TK = dommer.DOMSLOSNINGER
|
||||
assert dommer.beste_per_trekning(nnv) == [(A,), (TF,), (A, TK), (A,), (B, C, TF, TK), (A,)]
|
||||
# without the two versions of T, A is best alone in draws 2 and 3 too, B and C share draw 5
|
||||
tre = {a: nnv[a] for a in (A, B, C)}
|
||||
assert dommer.beste_per_trekning(tre) == [(A,), (A,), (A,), (A,), (B, C), (A,)]
|
||||
# the order the solutions stand in does not matter
|
||||
snudd = {a: nnv[a] for a in reversed(list(nnv))}
|
||||
assert dommer.a_er_best(snudd) == dommer.a_er_best(nnv)
|
||||
assert dommer.beste_per_trekning(snudd) == dommer.beste_per_trekning(nnv)
|
||||
|
||||
|
||||
def test_m7_andelene() -> None:
|
||||
"""A is best in 4 of 10 and in 1 of 10 draws against a T-F that is otherwise higher."""
|
||||
andre = {a: _utfall((5.0, 10)) for a in (Losning.B, Losning.C, Losning.T_K)}
|
||||
tf_fire = {Losning.A: _utfall((10.0, 10)), Losning.T_F: _utfall((1.0, 4), (20.0, 6))}
|
||||
tf_en = {Losning.A: _utfall((10.0, 10)), Losning.T_F: _utfall((1.0, 1), (20.0, 9))}
|
||||
assert dommer.dom_m7({**andre, **tf_fire}) is Dom.BETINGELSER
|
||||
assert dommer.dom_m7({**andre, **tf_en}) is Dom.HOLDER_IKKE
|
||||
@pytest.mark.parametrize("vinner", [Losning.A, Losning.B, Losning.C, Losning.T_F, Losning.T_K])
|
||||
def test_m7_hver_av_de_fem_kan_vaere_best(vinner: Losning) -> None:
|
||||
"""The rule is the same for all five: the one above the others is best, whichever it is."""
|
||||
nnv: dict[Losning, list[float | None]] = {
|
||||
a: [3.0 if a is vinner else 1.0, None if a is vinner else 2.0] for a in dommer.DOMSLOSNINGER
|
||||
}
|
||||
# draw 2: the winner cannot be built, and the four others share the place
|
||||
andre = tuple(a for a in dommer.DOMSLOSNINGER if a is not vinner)
|
||||
assert dommer.beste_per_trekning(nnv) == [(vinner,), andre]
|
||||
|
||||
|
||||
def test_m7_gjelder_a_mot_b_c_tf_og_tk() -> None:
|
||||
"""Without A there is nothing to judge; R and B' are not part of M7."""
|
||||
with pytest.raises(ValueError, match="M7 compares A"):
|
||||
dommer.a_er_best({Losning.B: [1.0], Losning.C: [2.0]})
|
||||
with pytest.raises(ValueError, match="M7 compares A"):
|
||||
dommer.a_er_best({Losning.A: [1.0], Losning.R: [2.0]})
|
||||
with pytest.raises(ValueError, match="M7 compares A"):
|
||||
dommer.a_er_best({Losning.A: [1.0], Losning.B_MERKET: [2.0]})
|
||||
def test_m7_T_F_og_T_K_like_deler_plassen() -> None:
|
||||
"""Where no module of T-K gets nuclear power, T-K is T-F: the two share, not none (137)."""
|
||||
nnv: dict[Losning, list[float | None]] = {
|
||||
Losning.A: [1.0, 1.0, None],
|
||||
Losning.B: [2.0, 9.0, None],
|
||||
Losning.C: [3.0, 1.0, None],
|
||||
Losning.T_F: [7.0, 7.0, 7.0],
|
||||
Losning.T_K: [7.0, 7.0, 7.0],
|
||||
}
|
||||
TF, TK = Losning.T_F, Losning.T_K
|
||||
assert dommer.beste_per_trekning(nnv) == [(TF, TK), (Losning.B,), (TF, TK)]
|
||||
|
||||
|
||||
def test_m7_uten_a_sammenlignes_de_som_er_med() -> None:
|
||||
"""A run without A compares those of the five that are in it; R and B' are not part of M7."""
|
||||
assert dommer.beste_per_trekning({Losning.B: [1.0, None], Losning.C: [2.0, None]}) == [
|
||||
(Losning.C,),
|
||||
(),
|
||||
]
|
||||
assert dommer.beste_per_trekning({Losning.T_K: [-1.0]}) == [(Losning.T_K,)]
|
||||
for med in ({Losning.A: [1.0], Losning.R: [2.0]}, {Losning.A: [1.0], Losning.B_MERKET: [2.0]}):
|
||||
with pytest.raises(ValueError, match="M7 compares A, B, C, T-F and T-K"):
|
||||
dommer.beste_per_trekning(med)
|
||||
with pytest.raises(ValueError, match="M7 compares"):
|
||||
dommer.beste_per_trekning({})
|
||||
|
||||
|
||||
# ------------------------------------------------------ the ladder with five solutions
|
||||
|
|
|
|||
|
|
@ -174,6 +174,9 @@ def test_kontroll_med_to_prosesser_er_identisk(
|
|||
for navn in df.ALLE_FILER:
|
||||
assert f"{navn}: identisk\n" in ut
|
||||
assert "Samlet: identisk (største relative avvik 0). Grunnlaget er merket «oppdiktet»." in ut
|
||||
# a line per file as it is made, in the order they are made, before the verdicts (134)
|
||||
linjer = ut.splitlines()
|
||||
assert linjer[: len(df.ALLE_FILER)] == [f"Laget {navn}" for navn in df.ALLE_FILER]
|
||||
|
||||
|
||||
def test_kontroll_sier_endret_og_gir_feilkode(
|
||||
|
|
@ -275,6 +278,13 @@ def test_scenario_med_egne_verdier_og_sammenlign(hoved: Path, liten: Path, tmp_p
|
|||
assert list(trinn[0]["losninger"]) == ["A", "C"]
|
||||
m1 = trinn[0]["losninger"]["A"]["M1"]
|
||||
assert list(m1) == ["a", "b", "endring_andel_holder"]
|
||||
# the comparison in M7 for the solutions both have, then «delt» and «ingen»; no part II
|
||||
m7 = trinn[0]["M7"]
|
||||
assert list(m7) == ["A", "C", "delt", "ingen"]
|
||||
for x in m7.values():
|
||||
assert list(x) == ["a", "b", "endring"]
|
||||
assert x["endring"] == x["b"] - x["a"]
|
||||
assert list(per_scenario["normalisering"]) == ["trinn", "del_I"]
|
||||
median = trinn[0]["losninger"]["A"]["median_M1"]
|
||||
if median["a"] is not None and median["b"] is not None:
|
||||
assert median["endring"] == median["b"] - median["a"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue