pub struct SigmoidModel;Expand description
Provides a sigmoid (logistic) influence model with a configurable growth phase.
f(x) = L / (1 + e^(-k * (x - x0)))You do not set k or x0 directly. Instead you describe the shape of the
curve using five intuitive parameters, and the model derives k and x0
from them:
L: the maximum output the curve can ever reachalpha: what fraction ofLmarks the start of the growth phase (e.g. 0.1 = 10%)beta: what fraction ofLmarks the end of the growth phase (e.g. 0.9 = 90%)x_alpha: the input value where output first reachesalpha * Lx_beta: the input value where output reachesbeta * L
From those, the model computes:
w = x_beta - x_alpha(growth width)k = [ ln(beta / (1 - beta)) - ln(alpha / (1 - alpha)) ] / w(growth rate)x0 = x_alpha - (1 / k) * ln(alpha / (1 - alpha))(midpoint)
§Signed Arithmetic
Even when the context FixedPoint is unsigned, all intermediate steps
(logit, k, x0, the exponent) are computed in concrete FixedI128 via
FixedSignedCast. This is necessary because logit(alpha) is negative
for any alpha < 0.5, and the exponent -k * (x - x0) is negative for
all x > x0. Unsigned arithmetic would silently clamp both to zero,
producing a completely wrong curve.
§Precision Note
The ln -> k -> x0 -> exp chain accumulates a small amount of rounding
error across four fixed-point operations. The practical effect is that x0
lands fractionally above its exact value, shifting the curve slightly to the
right. At the definition points x_alpha and x_beta the logit cancels
cleanly and the output is exact. At all other points including the midpoint,
the output may be 1 integer unit below the ideal value – for example,
f(x_beta) may yield 89 instead of 90 when L = 100.
- Exact:
f(80) = 90.000000000 - Fixed-point:
f(80) = 89.999999...-> truncates to89
This is expected and inconsequential for integer influence scores.
§Guard Conditions (returns zero)
alpha <= 0oralpha >= 1beta <= 0orbeta >= 1x_beta <= x_alpha(degenerate or inverted growth window)k == 0(flat curve, midpoint is undefined)
Trait Implementations§
Source§impl Debug for SigmoidModel
impl Debug for SigmoidModel
Source§impl Default for SigmoidModel
impl Default for SigmoidModel
Source§fn default() -> SigmoidModel
fn default() -> SigmoidModel
Source§impl<FixedPoint, Input> PurePluginModel<Input, SigmoidModelConfig<FixedPoint>, Input> for SigmoidModelwhere
Input: IntegerToFixed + FixedForInteger<FixedPoint = FixedPoint> + Zero,
FixedPoint: FixedPointNumber + FixedSignedCast<Signed = FixedI128>,
impl<FixedPoint, Input> PurePluginModel<Input, SigmoidModelConfig<FixedPoint>, Input> for SigmoidModelwhere
Input: IntegerToFixed + FixedForInteger<FixedPoint = FixedPoint> + Zero,
FixedPoint: FixedPointNumber + FixedSignedCast<Signed = FixedI128>,
Source§fn compute(
&self,
input: Input,
context: &SigmoidModelConfig<FixedPoint>,
) -> Input
fn compute( &self, input: Input, context: &SigmoidModelConfig<FixedPoint>, ) -> Input
Auto Trait Implementations§
impl Freeze for SigmoidModel
impl RefUnwindSafe for SigmoidModel
impl Send for SigmoidModel
impl Sync for SigmoidModel
impl Unpin for SigmoidModel
impl UnwindSafe for SigmoidModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
§fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
§fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T, U, Tag> IntoTag<U, Tag> for Twhere
U: FromTag<T, Tag>,
Tag: DiscriminantTag,
impl<T, U, Tag> IntoTag<U, Tag> for Twhere
U: FromTag<T, Tag>,
Tag: DiscriminantTag,
§impl<Src, Dest> IntoTuple<Dest> for Srcwhere
Dest: FromTuple<Src>,
impl<Src, Dest> IntoTuple<Dest> for Srcwhere
Dest: FromTuple<Src>,
fn into_tuple(self) -> Dest
§impl<T> IsType<T> for T
impl<T> IsType<T> for T
§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
Source§impl<T, Time> Logging<Time> for Twhere
Time: Time,
impl<T, Time> Logging<Time> for Twhere
Time: Time,
Source§const FALLBACK_TARGET: &'static str = "routine"
const FALLBACK_TARGET: &'static str = "routine"
Default logging target if none is provided.
Most routines, especially offchain workers or background tasks, use this target for simplicity.
It allows a consistent place to look for routine logs without requiring every call to specify a target.
Note: This target is only a conveninence and may be somewhat vague. To ensure errors can still be traced accurately, the logged messages should include additional metadata (e.g., module name, error index, or contextual info) so that the source of the error can be identified even if the target is generic.
Source§type Logger = DispatchError
type Logger = DispatchError
The type taken and returned for logging.
We simply return the same [DispatchError] that was logged,
so logging does not change control flow or error propagation.
DispatchError is used because in Substrate it encompasses all
runtime errors - including module errors, token errors, arithmetic
issues, and transactional boundaries - making it the universal
substrate-side error representation.
Source§type Level = LogLevel
type Level = LogLevel
The log level type.
We use the LogLevel enum to standardize severity levels
(Info, Warn, Error, Debug) across all routine logs.
Source§fn log(
level: <T as Logging<Time>>::Level,
err: &<T as Logging<Time>>::Logger,
timestamp: Time,
target: Option<&str>,
fmt: Option<fn(Time, &<T as Logging<Time>>::Level, &str, &str) -> String>,
) -> <T as Logging<Time>>::Logger
fn log( level: <T as Logging<Time>>::Level, err: &<T as Logging<Time>>::Logger, timestamp: Time, target: Option<&str>, fmt: Option<fn(Time, &<T as Logging<Time>>::Level, &str, &str) -> String>, ) -> <T as Logging<Time>>::Logger
Source§fn info(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>,
) -> Self::Loggerwhere
Self: Sized,
fn info(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>,
) -> Self::Loggerwhere
Self: Sized,
Source§fn warn(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>,
) -> Self::Loggerwhere
Self: Sized,
fn warn(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>,
) -> Self::Loggerwhere
Self: Sized,
§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T. Read more§impl<T, U> TryIntoKey<U> for Twhere
U: TryFromKey<T>,
impl<T, U> TryIntoKey<U> for Twhere
U: TryFromKey<T>,
type Error = <U as TryFromKey<T>>::Error
fn try_into_key(self) -> Result<U, <U as TryFromKey<T>>::Error>
§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from.§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T.