Table of Contents

Class NDPolyFitResult

Namespace
NumSharp
Assembly
NumSharp.dll

The result of a numpy.polynomial least-squares fit (polyfit, chebfit, legfit, lagfit, hermfit, hermefit): the fitted coefficient array ITSELF — an NDArray, so it indexes, computes and passes to every function (chebval(x, chebfit(x, y, 3))) exactly like NumPy's ndarray — that also carries NumPy's full=True statistics.

public sealed class NDPolyFitResult : NDArray, IIndex, ICloneable, IEnumerable, IDisposable
Inheritance
NDPolyFitResult
Implements
Inherited Members
Extension Methods

Remarks

NumPy returns the coefficient ndarray, or with full=True the tuple (c, [resids, rank, sv, rcond]). C# cannot change a method's return type with a flag, so the one result stands for both: NDArray c = P.polyfit(x, y, 3) and var c = P.polyfit(x, y, 3) are the coefficients, and var (c, (resids, rank, sv, rcond)) = P.polyfit(x, y, 3, full: true) deconstructs as NumPy's tuple (or var (c, info) = …). Without full the four statistics are null and deconstruction is refused, as NumPy's ndarray does not unpack into (c, info) either.

Lifetime. Disposing the result releases the coefficients only. The statistics are separate arrays the result owns: no NDScope tracks them (a scope that yields the result would yield only the coefficient array, and would reclaim scope-tracked statistics under it), so they are released by the garbage collector, or by disposing them explicitly.

Its memory is NumPy's: for a scalar degree the coefficients are a VIEW of the computed quotient (OWNDATA false), for a degree list a new array that owns its data.

Constructors

NDPolyFitResult(UnmanagedStorage, NDArray, NDArray, NDArray, NDArray)

Wraps the coefficient storage and the statistics.

public NDPolyFitResult(UnmanagedStorage storage, NDArray residuals, NDArray rank, NDArray singularValues, NDArray rcond)

Parameters

storage UnmanagedStorage

The coefficients' storage (an alias for a view, or the owner's storage taken over).

residuals NDArray

lstsq's residuals, or null without full.

rank NDArray

lstsq's rank (a 0-d int32, NumPy's np.intc), or null without full.

singularValues NDArray

lstsq's singular values, or null without full.

rcond NDArray

The rcond used, or null without full.

Remarks

The fit functions build this; a caller building one itself gets the same object. The four statistics are kept by reference (not copied) and become the result's to own: disposing one of them while the result is still read leaves residuals and its siblings pointing at a released buffer. Deconstruction reads residuals as the full=True mark: null refuses it, so pass all four or none.

Exceptions

NullReferenceException

storage is null.

Properties

rank

The numerical rank of the scaled design matrix (a 0-d int32); null unless full: true.

public NDArray rank { get; }

Property Value

NDArray

rcond

The rcond the fit used: the caller's value (an NDArray as given, a number as the 0-d array of its dtype), or the default len(x)*eps of x's float dtype. Null unless full: true.

public NDArray rcond { get; }

Property Value

NDArray

residuals

The sum of squared residuals of the fit, per data set (NumPy's resids): EMPTY unless the scaled design matrix has full rank and more points than coefficients. Null unless the fit ran with full: true.

public NDArray residuals { get; }

Property Value

NDArray

singular_values

The singular values of the scaled design matrix; null unless full: true.

public NDArray singular_values { get; }

Property Value

NDArray

Methods

Deconstruct(out NDArray, out (NDArray residuals, NDArray rank, NDArray singular_values, NDArray rcond))

NumPy's c, [resids, rank, sv, rcond] = …fit(…, full=True): the coefficients and the four statistics.

public void Deconstruct(out NDArray c, out (NDArray residuals, NDArray rank, NDArray singular_values, NDArray rcond) info)

Parameters

c NDArray

The coefficients (this array).

info (NDArray, NDArray, NDArray, NDArray)

(residuals, rank, singular values, rcond) — NumPy's list, in its order.

Exceptions

ValueError

The fit ran without full (NumPy's result is the bare coefficient array, which does not unpack into (c, info)).