Skip to content

actionet.tools.scale differs from R’s base::scale with disabled or explicit centering #2

Open

Description

@SaadQacif

actionet.tools.scale is documented as mirroring R’s base::scale(). With scale=True, it currently divides by the sample standard deviation around the column mean, even when centering is disabled or an explicit centre is supplied.

R instead divides each column, after any centering, by its root mean square. These calculations agree when center=True, but generally differ when center=False or a centre vector is supplied. Calls with scale=False or an explicit scale vector are unaffected.

Reproduction

import numpy as np
from actionet.tools import scale

scale(np.array([1.0, 2.0, 3.0, 6.0]), center=False)
# Current ACTIONet: [0.4629, 0.9258, 1.3887, 2.7775]
# R's documented formula: [0.2449, 0.4899, 0.7348, 1.4697]

x = np.array([[1, 10], [2, 20], [3, 60], [6, 30]], dtype=float)
scale(x, center=np.array([1.0, 10.0]))[:, 0]
# Current ACTIONet: [0, 0.4629, 0.9258, 2.3146]
# R's documented formula: [0, 0.3162, 0.6325, 1.5811]

The same discrepancy occurs with one-dimensional and sparse input. The expected numbers above were calculated from R’s documented scale formula; R itself was not run for this reproduction.

Against a reference implementation of that formula, upstream main (e9e33a7) matches in the default and scale=False matrix cases, but differs in the center=False and explicit-centre cases.

Impact

The in-repository run_actionet pipeline calls scale() with its defaults, so this issue does not claim a change to its layouts. It affects direct callers using scale=True with disabled or explicit centering, whose outputs can differ from R.

Expected behavior

With scale=True, compute the scaling factor from each column after centering, using sqrt(sum(x²) / (n - 1)) for the cases above, as specified by R’s base::scale documentation.

Activity

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