shap/tree_shap.h
inline tfloat unwound_path_sum(const PathElement *unique_path, unsigned unique_depth,
                                  unsigned path_index) {
  const tfloat one_fraction = unique_path[path_index].one_fraction;
  const tfloat zero_fraction = unique_path[path_index].zero_fraction;
  tfloat next_one_portion = unique_path[unique_depth].pweight;
  tfloat total = 0;
  for (int i = unique_depth - 1; i >= 0; --i) {
    if (one_fraction != 0) {
      const tfloat tmp = next_one_portion * (unique_depth + 1)
                            / static_cast<tfloat>((i + 1) * one_fraction);
      total += tmp;
      next_one_portion = unique_path[i].pweight - tmp * zero_fraction * ((unique_depth - i)
                         / static_cast<tfloat>(unique_depth + 1));
    } else {
      total += (unique_path[i].pweight / zero_fraction) / ((unique_depth - i)
               / static_cast<tfloat>(unique_depth + 1));
    }
  }
  return total;
}
// determine what the total permuation weight would be if
// we unwound a previous extension in the decision path
determine what the total permuation weight would be if
we unwound a previous extension in the decision path
determine what the total permuation weight would be if we unwound a previous extension in the decision path
inline tfloat unwound_path_sum(const PathElement *unique_path, unsigned unique_depth,
                                  unsigned path_index) {
  const tfloat one_fraction = unique_path[path_index].one_fraction;
  const tfloat zero_fraction = unique_path[path_index].zero_fraction;
  tfloat next_one_portion = unique_path[unique_depth].pweight;
  tfloat total = 0;
  for (int i = unique_depth - 1; i >= 0; --i) {
    if (one_fraction != 0) {
      const tfloat tmp = next_one_portion * (unique_depth + 1)
                            / static_cast<tfloat>((i + 1) * one_fraction);
      total += tmp;
      next_one_portion = unique_path[i].pweight - tmp * zero_fraction * ((unique_depth - i)
                         / static_cast<tfloat>(unique_depth + 1));
    } else {
      total += (unique_path[i].pweight / zero_fraction) / ((unique_depth - i)
               / static_cast<tfloat>(unique_depth + 1));
    }
  }
  return total;
}
inline tfloat unwound_path_sum ( const PathElement * unique_path , unsigned unique_depth , unsigned path_index ) { const tfloat one_fraction = unique_path [ path_index ] . one_fraction ; const tfloat zero_fraction = unique_path [ path_index ] . zero_fraction ; tfloat next_one_portion = unique_path [ unique_depth ] . pweight ; tfloat total = 0 ; for ( int i = unique_depth - 1 ; i >= 0 ; -- i ) { if ( one_fraction != 0 ) { const tfloat tmp = next_one_portion * ( unique_depth + 1 ) / static_cast < tfloat > ( ( i + 1 ) * one_fraction ) ; total += tmp ; next_one_portion = unique_path [ i ] . pweight - tmp * zero_fraction * ( ( unique_depth - i ) / static_cast < tfloat > ( unique_depth + 1 ) ) ; } else { total += ( unique_path [ i ] . pweight / zero_fraction ) / ( ( unique_depth - i ) / static_cast < tfloat > ( unique_depth + 1 ) ) ; } } return total ; }
determine what the total permuation weight would be if
we unwound a previous extension in the decision path
determine what the total permuation weight would be if we unwound a previous extension in the decision path