34. Logistic Regression medium
Solve the logistic regression problem on a GPU. Given a feature matrix of size and a binary target vector of size (containing only 0s and 1s), compute the coefficient vector that maximizes the log-likelihood: where and is the sigmoid function.
Implementation Requirements
- External libraries are not permitted
- The
solvefunction signature must remain unchanged - The final coefficients must be stored in the
betavector - The target vector
ycontains only binary values (0 and 1)
Example:
Input:
(samples × features):
:
Output:
:
Constraints
- 1 ≤
n_samples≤ 100,000 - 1 ≤
n_features≤ 1,000 n_samples≥n_features- -10.0 ≤ values in
X≤ 10.0 ycontains only binary values: 0 or 1- Solutions are tested with absolute tolerance of 1e-2 and relative tolerance of 1e-2
- Performance is measured with
n_features= 8,n_samples= 16
Starter code (CUDA)
#include <cuda_runtime.h>
// X, y, beta are device pointers
extern "C" void solve(const float* X, const float* y, float* beta, int n_samples, int n_features) {}
From LeetGPU, CC BY-NC-ND 4.0.