Skip to content

[RFC]: Add batch machine learning algorithms in Javascript and C (tracking issue) #12875

Open

Description

@nakul-krishnakumar

Description

This RFC proposes adding Javascript and C implementation for some batch machine learning algorithms. The purpose of this issue is to serve as a tracking issue for adding Javascript and C implementations.

Packages

Loss functions

KMeans

SGD Classification

Activity

  1. stdlib-bot commented on Jun 14, 2026

    @stdlib-bot
    Contributor

    👋 Hi there! 👋

    And thank you for opening your first issue! We will get back to you shortly. 🏃 💨

    If you have any further questions while waiting for a response, please join our Zulip community to chat with project maintainers and other community members.

  2. added a commit that references this issue on Jun 23, 2026
  3. added a commit that references this issue on Aug 22, 2026
  4. AryanSharma48 commented on Oct 14, 2026

    @AryanSharma48
    Contributor

    @kgryte I've completed the PRs for the non-gradient float32 loss functions. Since these are the exact canonical counterparts to the gradient versions that were already merged, the logic maps directly and they shouldn't be much of a hassle to review.

    Feel free to take a look whenever you have the bandwidth!

  5. Sharman1661 commented on Dec 1, 2026

    @Sharman1661
    Contributor

    I'd like to work on ml/strided/dkmeans-compute-centroids (JS + C).

    SciPy implements this step as update_cluster_means in scipy/cluster/_vq.pyx:

    1. initializes a k × N codebook and a length-k count array.
    2. in one pass over the observations, adds each observation into its cluster's row and increments that cluster's count.
    3. divides each non-empty row by its count, skipping empty clusters, which are left as zeros and reported via a mask for the caller to handle.

    Cost is a single pass over the data: O(M·N + k·N).

    Proposed API

    dkmeansComputeCentroids( order, k, M, N, X, LDX, labels, strideL, out, LDO, counts, strideC )
    dkmeansComputeCentroids.ndarray( k, M, N, X, strideX1, strideX2, offsetX, labels, strideL, offsetL, out, strideO1, strideO2, offsetO, counts, strideC, offsetC )
    

    Returns out. Both out (k × N) and counts (length k) are caller-allocated, so neither the JS nor the C kernel allocates internally.

    A few default proposals:

    1. Empty clusters: leave the row as zeros (matching SciPy); callers detect them via counts[j] === 0. Preserving the previous centroid would need an extra counting pass before zeroing, so I think it'd be better if the caller did that.
    2. Accumulation: sum-then-divide, matching SciPy. If precision matters more, I can use an incremental mean as in ml/incr/kmeans.
    3. Naming and argument order: #12312 places X before out. Should this package follow that order, and given feat: add ml/strided/dsgd-trainer #13614, should it live under a kmeans/ sub-namespace?

    Could you please let me know your views on this @nakul-krishnakumar and @kgryte ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions