RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • bayesopt
    • classify
    • confusionmat
    • crossvalind
    • cvpartition
    • fitclinear
    • fitctree
    • fitlm
    • kmeans
    • knnsearch
    • lasso
    • lassoglm
    • linkage
    • lscov
    • mnrfit
    • optimizableVariable
    • pdist
    • pdist2
    • perfcurve
    • predict
    • regress
    • ridge
    • squareform
    • test
    • training
    • tsne

ridge — Fit ridge regression coefficients for one or more regularization parameters.

ridge(y,X,k) returns ridge regression coefficient estimates for response vector y, predictor matrix X, and one or more nonnegative ridge parameters k.

Syntax

B = ridge(y, X, k)
B = ridge(y, X, k, scaled)

Inputs

NameTypeRequiredDefaultDescription
yNumericArrayYes—Response vector with one value per observation.
XNumericArrayYes—Predictor matrix with observations in rows and predictors in columns.
kNumericArrayYes—Nonnegative ridge parameters.
scaledAnyNo1Scaling flag: 1 returns standardized coefficients, 0 restores original scale and intercept.

Returns

NameTypeDescription
BNumericArrayCoefficient estimates, one column per ridge parameter.

Errors

IdentifierWhenMessage
RunMat:ridge:InvalidArgumentInputs, dimensions, ridge parameters, or scaling flag are malformed.ridge: invalid argument
RunMat:ridge:NumericalThe regularized normal equations cannot be solved numerically.ridge: numerical solve failed
RunMat:ridge:InternalRunMat cannot allocate or construct ridge outputs.ridge: internal error

How ridge works

  • X must be an n-by-p real numeric matrix and y must be a vector with n elements.
  • The documented computation domain is single or double. Native typed-integer y, X, k, and scaled controls are independently declared RunMat extensions; numerical values must be exactly representable at the explicit double solver boundary and MATLAB compatibility mode rejects them before gathering.
  • k accepts a nonnegative finite scalar or vector. Each output column corresponds to one k value in input order.
  • Rows containing NaN in X or y are omitted before fitting, matching MATLAB's missing-row behavior.
  • By default, RunMat centers y, centers and standardizes predictors, and returns p standardized coefficients without an intercept.
  • ridge(y,X,k,0) restores coefficients to the original predictor scale and returns a (p+1)-by-numel(k) matrix whose first row is the intercept.
  • ridge(y,X,k,1) is the default scaled form and returns a p-by-numel(k) matrix.

Examples

Fit an original-scale ridge model

X = [0; 1; 2; 3];
y = [1; 3; 5; 7];
B = ridge(y, X, 0, 0)

Expected output:

B is approximately [1; 2].

Fit a ridge trace

B = ridge(y, X, [0 1 10])

Expected output:

B has one column per ridge parameter and contains standardized coefficients.

Using ridge with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how ridge changes the result.

Run a small ridge example, explain the result, then change one input and compare the output.

FAQ

Should I include a column of ones in X?⌄

No. Like MATLAB, ridge centers the data internally. Use scaled=0 when you need the intercept in the returned coefficients.

How does scaled change the output size?⌄

scaled=1 returns p rows. scaled=0 returns p+1 rows, with the intercept in the first row.

Related Stats functions

Ml

bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · optimizableVariable · pdist · pdist2 · perfcurve · predict · regress · squareform · test · training · tsne

Summary

binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · kstest · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pdf · prctile · quantile · refline · rmse · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest2 · wblinv

Random

binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd

Hist

histc · histcounts · histcounts2

Options

statget · statset

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how ridge is executed, line by line, in Rust.

  • View the source for ridge in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How ridge works
  • Examples
  • Fit an original-scale ridge model
  • Fit a ridge trace
  • Using ridge with coding agents
  • FAQ
  • Related Stats functions
  • Ml
  • Summary
  • Random
  • Hist
  • Options
  • Open-source implementation
  • About RunMat