@@ -137,18 +137,22 @@ impl<T: Config> Pallet<T> {
137
137
// Compute preranks: r_j = SUM(i) w_ij * s_i
138
138
let preranks: Vec < I32F32 > = matmul ( & weights, & active_stake) ;
139
139
140
- // Clip weights at majority consensus
141
- let kappa: I32F32 = Self :: get_float_kappa ( netuid) ; // consensus majority ratio, e.g. 51%.
140
+ // Consensus majority ratio, e.g. 51%.
141
+ let kappa: I32F32 = Self :: get_float_kappa ( netuid) ;
142
+ // Calculate consensus as stake-weighted median of weights.
142
143
let consensus: Vec < I32F32 > = weighted_median_col ( & active_stake, & weights, kappa) ;
143
- inplace_col_clip ( & mut weights, & consensus) ;
144
- let validator_trust: Vec < I32F32 > = row_sum ( & weights) ;
144
+ // Clip weights at majority consensus.
145
+ let mut clipped_weights: Vec < Vec < I32F32 > > = weights. clone ( ) ;
146
+ inplace_col_clip ( & mut clipped_weights, & consensus) ;
147
+ // Calculate validator trust as sum of clipped weights set by validator.
148
+ let validator_trust: Vec < I32F32 > = row_sum ( & clipped_weights) ;
145
149
146
150
// ====================================
147
151
// == Ranks, Server Trust, Incentive ==
148
152
// ====================================
149
153
150
154
// Compute ranks: r_j = SUM(i) w_ij * s_i
151
- let mut ranks: Vec < I32F32 > = matmul ( & weights , & active_stake) ;
155
+ let mut ranks: Vec < I32F32 > = matmul ( & clipped_weights , & active_stake) ;
152
156
153
157
// Compute server trust: ratio of rank after vs. rank before.
154
158
let trust: Vec < I32F32 > = vecdiv ( & ranks, & preranks) ;
@@ -161,14 +165,22 @@ impl<T: Config> Pallet<T> {
161
165
// == Bonds and Dividends ==
162
166
// =========================
163
167
168
+ // Get validator bonds penalty in [0, 1].
169
+ let bonds_penalty: I32F32 = Self :: get_float_bonds_penalty ( netuid) ;
170
+ // Calculate weights for bonds, apply bonds penalty to weights.
171
+ // bonds_penalty = 0: weights_for_bonds = weights.clone()
172
+ // bonds_penalty = 1: weights_for_bonds = clipped_weights.clone()
173
+ let weights_for_bonds: Vec < Vec < I32F32 > > =
174
+ interpolate ( & weights, & clipped_weights, bonds_penalty) ;
175
+
164
176
// Access network bonds.
165
177
let mut bonds: Vec < Vec < I32F32 > > = Self :: get_bonds ( netuid) ;
166
178
inplace_mask_matrix ( & outdated, & mut bonds) ; // mask outdated bonds
167
179
inplace_col_normalize ( & mut bonds) ; // sum_i b_ij = 1
168
180
log:: trace!( "B:\n {:?}\n " , & bonds) ;
169
181
170
182
// Compute bonds delta column normalized.
171
- let mut bonds_delta: Vec < Vec < I32F32 > > = row_hadamard ( & weights , & active_stake) ; // ΔB = W◦S
183
+ let mut bonds_delta: Vec < Vec < I32F32 > > = row_hadamard ( & weights_for_bonds , & active_stake) ; // ΔB = W◦S
172
184
inplace_col_normalize ( & mut bonds_delta) ; // sum_i b_ij = 1
173
185
log:: trace!( "ΔB:\n {:?}\n " , & bonds_delta) ;
174
186
// Compute the Exponential Moving Average (EMA) of bonds.
@@ -474,23 +486,26 @@ impl<T: Config> Pallet<T> {
474
486
let preranks: Vec < I32F32 > = matmul_sparse ( & weights, & active_stake, n) ;
475
487
log:: trace!( "Ranks (before): {:?}" , & preranks) ;
476
488
477
- // Clip weights at majority consensus
478
- let kappa: I32F32 = Self :: get_float_kappa ( netuid) ; // consensus majority ratio, e.g. 51%.
489
+ // Consensus majority ratio, e.g. 51%.
490
+ let kappa: I32F32 = Self :: get_float_kappa ( netuid) ;
491
+ // Calculate consensus as stake-weighted median of weights.
479
492
let consensus: Vec < I32F32 > = weighted_median_col_sparse ( & active_stake, & weights, n, kappa) ;
480
493
log:: trace!( "Consensus: {:?}" , & consensus) ;
481
494
482
- weights = col_clip_sparse ( & weights, & consensus) ;
483
- log:: trace!( "Weights: {:?}" , & weights) ;
495
+ // Clip weights at majority consensus.
496
+ let clipped_weights: Vec < Vec < ( u16 , I32F32 ) > > = col_clip_sparse ( & weights, & consensus) ;
497
+ log:: trace!( "Clipped Weights: {:?}" , & clipped_weights) ;
484
498
485
- let validator_trust: Vec < I32F32 > = row_sum_sparse ( & weights) ;
499
+ // Calculate validator trust as sum of clipped weights set by validator.
500
+ let validator_trust: Vec < I32F32 > = row_sum_sparse ( & clipped_weights) ;
486
501
log:: trace!( "Validator Trust: {:?}" , & validator_trust) ;
487
502
488
503
// =============================
489
504
// == Ranks, Trust, Incentive ==
490
505
// =============================
491
506
492
507
// Compute ranks: r_j = SUM(i) w_ij * s_i.
493
- let mut ranks: Vec < I32F32 > = matmul_sparse ( & weights , & active_stake, n) ;
508
+ let mut ranks: Vec < I32F32 > = matmul_sparse ( & clipped_weights , & active_stake, n) ;
494
509
log:: trace!( "Ranks (after): {:?}" , & ranks) ;
495
510
496
511
// Compute server trust: ratio of rank after vs. rank before.
@@ -505,6 +520,14 @@ impl<T: Config> Pallet<T> {
505
520
// == Bonds and Dividends ==
506
521
// =========================
507
522
523
+ // Get validator bonds penalty in [0, 1].
524
+ let bonds_penalty: I32F32 = Self :: get_float_bonds_penalty ( netuid) ;
525
+ // Calculate weights for bonds, apply bonds penalty to weights.
526
+ // bonds_penalty = 0: weights_for_bonds = weights.clone()
527
+ // bonds_penalty = 1: weights_for_bonds = clipped_weights.clone()
528
+ let weights_for_bonds: Vec < Vec < ( u16 , I32F32 ) > > =
529
+ interpolate_sparse ( & weights, & clipped_weights, n, bonds_penalty) ;
530
+
508
531
// Access network bonds.
509
532
let mut bonds: Vec < Vec < ( u16 , I32F32 ) > > = Self :: get_bonds_sparse ( netuid) ;
510
533
log:: trace!( "B: {:?}" , & bonds) ;
@@ -523,7 +546,8 @@ impl<T: Config> Pallet<T> {
523
546
log:: trace!( "B (mask+norm): {:?}" , & bonds) ;
524
547
525
548
// Compute bonds delta column normalized.
526
- let mut bonds_delta: Vec < Vec < ( u16 , I32F32 ) > > = row_hadamard_sparse ( & weights, & active_stake) ; // ΔB = W◦S (outdated W masked)
549
+ let mut bonds_delta: Vec < Vec < ( u16 , I32F32 ) > > =
550
+ row_hadamard_sparse ( & weights_for_bonds, & active_stake) ; // ΔB = W◦S (outdated W masked)
527
551
log:: trace!( "ΔB: {:?}" , & bonds_delta) ;
528
552
529
553
// Normalize bonds delta.
@@ -713,6 +737,9 @@ impl<T: Config> Pallet<T> {
713
737
pub fn get_float_kappa ( netuid : u16 ) -> I32F32 {
714
738
I32F32 :: from_num ( Self :: get_kappa ( netuid) ) . saturating_div ( I32F32 :: from_num ( u16:: MAX ) )
715
739
}
740
+ pub fn get_float_bonds_penalty ( netuid : u16 ) -> I32F32 {
741
+ I32F32 :: from_num ( Self :: get_bonds_penalty ( netuid) ) . saturating_div ( I32F32 :: from_num ( u16:: MAX ) )
742
+ }
716
743
717
744
pub fn get_block_at_registration ( netuid : u16 ) -> Vec < u64 > {
718
745
let n = Self :: get_subnetwork_n ( netuid) ;
0 commit comments