Efficient Gradient Computation for Binary Features
Calculus & Optimization DS practice problem on Onlearn.
Difficulty: medium.
Topics: Understanding Sparse Gradient Updates in Binary Feature Spaces, Active Feature Set Identification, Computational Efficiency in ML, Sparse Gradient Representation, Backpropagation Optimization, Memory Bandwidth Minimization, Calculus, Optimization, Linear Algebra, Computational Complexity, Sparse Data Structures, Gradient Descent, Sparse Matrix Operations, Partial Derivatives, Feature Engineering, Vectorization.
Implement a function 'compute binary gradient' that calculates the weight update for a single data point in a logistic regression model, assuming binary features (x i in {0, 1}). The function should accept a feature vector 'x' and an error term 'error'. Instead of performing a full vector scalar multiplication, identify the indices where x i is non zero and return a dictionary mapping only those indices to their respective gradient values.