feat(profiler/behave_shell): G.5 emotional_valence.valence
Soft primitive — pure ratio over G.0 lexical counters: * positive — positive_lex_hits > negative + obscenity, ≥ VALENCE_MIN_HITS * negative — (negative + obscenity) > positive, sum ≥ VALENCE_MIN_HITS * neutral — fall-through Skip below VALENCE_MIN_TYPED_CHARS (80). Confidence hard-capped at EMOTIONAL_VALENCE_CONFIDENCE_CAP (0.5) inside the feature function; 0.30 below VALENCE_FULL_CONFIDENCE_MIN (200). Cap is registry convention.
This commit is contained in:
@@ -24,6 +24,9 @@ from decnet.profiler.behave_shell._features.cognitive import (
|
||||
inter_command_consistency,
|
||||
inter_command_latency_class,
|
||||
)
|
||||
from decnet.profiler.behave_shell._features.emotional_valence import (
|
||||
valence,
|
||||
)
|
||||
from decnet.profiler.behave_shell._features.environmental import (
|
||||
keyboard_layout,
|
||||
locale,
|
||||
@@ -91,4 +94,5 @@ FEATURES: tuple[FeatureFn, ...] = (
|
||||
opsec_discipline,
|
||||
cleanup_behavior,
|
||||
multi_actor_indicators,
|
||||
valence,
|
||||
)
|
||||
|
||||
65
decnet/profiler/behave_shell/_features/emotional_valence.py
Normal file
65
decnet/profiler/behave_shell/_features/emotional_valence.py
Normal file
@@ -0,0 +1,65 @@
|
||||
"""``emotional_valence.*`` feature functions (Phase G, soft block).
|
||||
|
||||
All four primitives in this module ride a hard 0.5 confidence cap
|
||||
(:data:`EMOTIONAL_VALENCE_CONFIDENCE_CAP`). Cap is enforced inside
|
||||
the feature functions, *not* via :func:`make_observation` — sample-size
|
||||
honesty may still pull confidence below 0.5.
|
||||
|
||||
Step G.5: ``emotional_valence.valence``.
|
||||
Step G.6: ``emotional_valence.arousal`` (lands later).
|
||||
Step G.7: ``emotional_valence.stress_response`` (lands later).
|
||||
Step G.8: ``emotional_valence.frustration_venting`` (lands later).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Iterator
|
||||
|
||||
from decnet_behave_core.spec.envelope import Observation
|
||||
|
||||
from decnet.profiler.behave_shell._ctx import SessionContext
|
||||
from decnet.profiler.behave_shell._features._emit import make_observation
|
||||
from decnet.profiler.behave_shell._thresholds import (
|
||||
EMOTIONAL_VALENCE_CONFIDENCE_CAP,
|
||||
VALENCE_FULL_CONFIDENCE_MIN,
|
||||
VALENCE_MIN_HITS,
|
||||
VALENCE_MIN_TYPED_CHARS,
|
||||
)
|
||||
|
||||
|
||||
def _cap_soft(c: float) -> float:
|
||||
"""Clamp confidence to the soft-primitive ceiling."""
|
||||
return min(c, EMOTIONAL_VALENCE_CONFIDENCE_CAP)
|
||||
|
||||
|
||||
def valence(ctx: SessionContext) -> Iterator[Observation]:
|
||||
"""Emit ``emotional_valence.valence`` ∈ {positive, neutral, negative}.
|
||||
|
||||
Pure ratio over the lexical counters built in G.0:
|
||||
|
||||
* ``positive`` — ``positive_lex_hits > negative_lex_hits +
|
||||
obscenity_hits`` AND ``positive_lex_hits ≥ VALENCE_MIN_HITS`` (2).
|
||||
* ``negative`` — ``negative_lex_hits + obscenity_hits >
|
||||
positive_lex_hits`` AND that sum ≥ ``VALENCE_MIN_HITS``.
|
||||
* ``neutral`` — fall-through.
|
||||
|
||||
Skip emission below ``VALENCE_MIN_TYPED_CHARS`` (80) typed letters.
|
||||
Confidence hard-capped at 0.50 (registry convention); 0.30 below
|
||||
``VALENCE_FULL_CONFIDENCE_MIN`` (200).
|
||||
"""
|
||||
if ctx.typed_letter_count < VALENCE_MIN_TYPED_CHARS:
|
||||
return
|
||||
pos = ctx.positive_lex_hits
|
||||
neg_total = ctx.negative_lex_hits + ctx.obscenity_hits
|
||||
if pos > neg_total and pos >= VALENCE_MIN_HITS:
|
||||
value = "positive"
|
||||
elif neg_total > pos and neg_total >= VALENCE_MIN_HITS:
|
||||
value = "negative"
|
||||
else:
|
||||
value = "neutral"
|
||||
raw = 0.50 if ctx.typed_letter_count >= VALENCE_FULL_CONFIDENCE_MIN else 0.30
|
||||
yield make_observation(
|
||||
ctx,
|
||||
primitive="emotional_valence.valence",
|
||||
value=value,
|
||||
confidence=_cap_soft(raw),
|
||||
)
|
||||
Reference in New Issue
Block a user