@@ -179,7 +179,7 @@ impl<T: Config> Pallet<T> {
179
179
// Compute the EMA of bonds using a normal alpha value.
180
180
Self :: compute_ema_bonds_normal ( & weights. clone ( ) , & bonds, netuid)
181
181
} ;
182
-
182
+ // Normalize EMA bonds.
183
183
inplace_col_normalize ( & mut ema_bonds) ; // sum_i b_ij = 1
184
184
log:: trace!( "emaB:\n {:?}\n " , & ema_bonds) ;
185
185
@@ -530,24 +530,30 @@ impl<T: Config> Pallet<T> {
530
530
inplace_col_normalize_sparse ( & mut bonds, n) ;
531
531
log:: trace!( "B (mask+norm): {:?}" , & bonds) ;
532
532
533
- // Compute bonds delta column normalized.
534
- let mut bonds_delta: Vec < Vec < ( u16 , I32F32 ) > > = row_hadamard_sparse ( & weights, & active_stake) ; // ΔB = W◦S (outdated W masked)
535
- log:: trace!( "ΔB: {:?}" , & bonds_delta) ;
536
-
537
- // Normalize bonds delta.
538
- inplace_col_normalize_sparse ( & mut bonds_delta, n) ; // sum_i b_ij = 1
539
- log:: trace!( "ΔB (norm): {:?}" , & bonds_delta) ;
540
-
541
533
// Compute the Exponential Moving Average (EMA) of bonds.
542
- let mut ema_bonds =
543
- Self :: compute_ema_bonds_sparse ( netuid, consensus. clone ( ) , bonds_delta, bonds) ;
534
+ let mut ema_bonds = if let Some ( clamped_bonds_alpha) =
535
+ Self :: compute_liquid_alpha ( netuid, consensus. clone ( ) )
536
+ {
537
+ // Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values.
538
+ Self :: compute_ema_bonds_with_liquid_alpha_sparse (
539
+ & weights. clone ( ) ,
540
+ & bonds,
541
+ clamped_bonds_alpha,
542
+ )
543
+ } else {
544
+ log:: trace!( "Using Bonds Moving Average" ) ;
545
+ // Compute the EMA of bonds using a normal alpha value.
546
+ Self :: compute_ema_bonds_normal_sparse ( & weights. clone ( ) , & bonds, netuid)
547
+ } ;
548
+
544
549
// Normalize EMA bonds.
545
550
inplace_col_normalize_sparse ( & mut ema_bonds, n) ; // sum_i b_ij = 1
546
551
log:: trace!( "Exponential Moving Average Bonds: {:?}" , & ema_bonds) ;
547
552
548
- // Compute dividends: d_i = SUM(j) b_ij * inc_j.
549
- // range: I32F32(0, 1)
550
- let mut dividends: Vec < I32F32 > = matmul_transpose_sparse ( & ema_bonds, & incentive) ;
553
+ // # === Dividend Calculation===
554
+ let total_bonds_per_validator: Vec < I32F32 > =
555
+ matmul_transpose_sparse ( & ema_bonds, & incentive) ;
556
+ let mut dividends: Vec < I32F32 > = vec_mul ( & total_bonds_per_validator, & active_stake) ;
551
557
inplace_normalize ( & mut dividends) ;
552
558
log:: trace!( "Dividends: {:?}" , & dividends) ;
553
559
@@ -1051,75 +1057,6 @@ impl<T: Config> Pallet<T> {
1051
1057
ema_bonds
1052
1058
}
1053
1059
1054
- /// Compute the Exponential Moving Average (EMA) of bonds based on the Liquid Alpha setting for a sparse matrix.
1055
- ///
1056
- /// # Args:
1057
- /// * `netuid` - The network ID.
1058
- /// * `consensus` - A vector of consensus values.
1059
- /// * `bonds_delta` - A vector of bond deltas.
1060
- /// * `bonds` - A vector of bonds.
1061
- ///
1062
- /// # Returns:
1063
- /// A vector of EMA bonds.
1064
- pub fn compute_ema_bonds_sparse (
1065
- netuid : u16 ,
1066
- consensus : Vec < I32F32 > ,
1067
- bonds_delta : Vec < Vec < ( u16 , I32F32 ) > > ,
1068
- bonds : Vec < Vec < ( u16 , I32F32 ) > > ,
1069
- ) -> Vec < Vec < ( u16 , I32F32 ) > > {
1070
- // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values.
1071
- // This way we avoid the quantil function panic.
1072
- if LiquidAlphaOn :: < T > :: get ( netuid)
1073
- && !consensus. is_empty ( )
1074
- && consensus. iter ( ) . any ( |& c| c != I32F32 :: from_num ( 0 ) )
1075
- {
1076
- // Calculate the 75th percentile (high) and 25th percentile (low) of the consensus values.
1077
- let consensus_high = quantile ( & consensus, 0.75 ) ;
1078
- let consensus_low = quantile ( & consensus, 0.25 ) ;
1079
- // Further check if the high and low consensus values meet the required conditions.
1080
- if ( consensus_high > consensus_low) || consensus_high != 0 || consensus_low < 0 {
1081
- // if (consensus_high > consensus_low) || consensus_high != 0) || consensus_low != 0 {
1082
- // if (consensus_high > consensus_low) || consensus_low != 0 {
1083
- log:: trace!( "Using Liquid Alpha" ) ;
1084
-
1085
- // Get the high and low alpha values for the network.
1086
- let ( alpha_low, alpha_high) : ( I32F32 , I32F32 ) = Self :: get_alpha_values_32 ( netuid) ;
1087
- log:: trace!( "alpha_low: {:?} alpha_high: {:?}" , alpha_low, alpha_high) ;
1088
-
1089
- // Calculate the logistic function parameters 'a' and 'b' based on alpha and consensus values.
1090
- let ( a, b) = Self :: calculate_logistic_params (
1091
- alpha_high,
1092
- alpha_low,
1093
- consensus_high,
1094
- consensus_low,
1095
- ) ;
1096
-
1097
- // Compute the alpha values using the logistic function parameters.
1098
- let alpha = Self :: compute_alpha_values ( & consensus, a, b) ;
1099
-
1100
- // Clamp the alpha values between alpha_high and alpha_low.
1101
- let clamped_alpha = Self :: clamp_alpha_values ( alpha, alpha_high, alpha_low) ;
1102
-
1103
- // Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values.
1104
- Self :: compute_ema_bonds_with_liquid_alpha_sparse (
1105
- & bonds_delta,
1106
- & bonds,
1107
- clamped_alpha,
1108
- )
1109
- } else {
1110
- log:: trace!( "Using Bonds Moving Average" ) ;
1111
-
1112
- // Compute the EMA of bonds using a normal alpha value.
1113
- Self :: compute_ema_bonds_normal_sparse ( & bonds_delta, & bonds, netuid)
1114
- }
1115
- } else {
1116
- log:: trace!( "Using Bonds Moving Average" ) ;
1117
-
1118
- // Compute the EMA of bonds using a normal alpha value.
1119
- Self :: compute_ema_bonds_normal_sparse ( & bonds_delta, & bonds, netuid)
1120
- }
1121
- }
1122
-
1123
1060
/// Compute liquid alphas based on the Liquid Alpha setting.
1124
1061
///
1125
1062
/// # Args:
0 commit comments