Skip to content

Commit

Permalink
chore: saturating div , update ema dense
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Dare committed Jun 21, 2024
1 parent e0c9f2a commit adce61b
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions pallets/subtensor/src/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,8 @@ impl<T: Config> Pallet<T> {
consensus_high: I32F32,
consensus_low: I32F32,
) -> (I32F32, I32F32) {
log::info!("alpha_high: {:?}", alpha_high);
log::info!("alpha_low: {:?}", alpha_low);
log::trace!("alpha_high: {:?}", alpha_high);
log::trace!("alpha_low: {:?}", alpha_low);
log::trace!("consensus_high: {:?}", consensus_high);
log::trace!("consensus_low: {:?}", consensus_low);
// Check for division by zero
Expand All @@ -846,9 +846,9 @@ impl<T: Config> Pallet<T> {
// Calculate the slope 'a' of the logistic function.
// a = (ln((1 / alpha_high - 1)) - ln((1 / alpha_low - 1))) / (consensus_low - consensus_high)
let a =
(safe_ln((I32F32::from_num(1.0) / alpha_high).saturating_sub(I32F32::from_num(1.0)))
(safe_ln((I32F32::from_num(1.0).saturating_div( alpha_high)).saturating_sub(I32F32::from_num(1.0)))
.saturating_sub(safe_ln(
(I32F32::from_num(1.0) / alpha_low).saturating_sub(I32F32::from_num(1.0)),
(I32F32::from_num(1.0).saturating_div( alpha_low)).saturating_sub(I32F32::from_num(1.0)),
)))
.saturating_div(consensus_low.saturating_sub(consensus_high));
log::trace!("a: {:?}", a);
Expand Down Expand Up @@ -1073,10 +1073,6 @@ impl<T: Config> Pallet<T> {
// Calculate the 75th percentile (high) and 25th percentile (low) of the consensus values.
let consensus_high = quantile(&consensus, 0.75);
let consensus_low = quantile(&consensus, 0.25);
// consensus_low < 0 ||
// consensus_high <= consensus_low ||
// alpha_low < 0 ||
// alpha_high <= alpha_low
// Further check if the high and low consensus values meet the required conditions.
if (consensus_high > consensus_low) || consensus_high != 0 || consensus_low < 0 {
// if (consensus_high > consensus_low) || consensus_high != 0) || consensus_low != 0 {
Expand Down Expand Up @@ -1149,7 +1145,7 @@ impl<T: Config> Pallet<T> {
let consensus_low = quantile(&consensus, 0.25);

// Further check if the high and low consensus values meet the required conditions.
if (consensus_high > consensus_low) && consensus_high != 0 && consensus_low != 0 {
if (consensus_high > consensus_low) || consensus_high != 0 || consensus_low < 0 {
log::trace!("Using Liquid Alpha");

// Get the high and low alpha values for the network.
Expand Down

0 comments on commit adce61b

Please sign in to comment.