Skip to content

Commit

Permalink
feat:First version of NURBSBasis.
Browse files Browse the repository at this point in the history
  • Loading branch information
antononcube committed Feb 21, 2023
1 parent 0a0069c commit addc3e5
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions QuantileRegression.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ I experimented with using DualLinearProgramming (provided by Mathematica) and wi
QuantileEnvelopeRegion::usage = "QuantileEnvelopeRegion[data_?MatrixQ,q_?NumberQ,ndir_Integer] \
experimental implementation of 2D or 3D quantile envelope region finding.";

NURBSBasis::usage = "NURBSBasis[data_?MatrixQ, n_]";

Begin["`Private`"];

(************************************************************)
Expand Down Expand Up @@ -300,6 +302,47 @@ I experimented with using DualLinearProgramming (provided by Mathematica) and wi
];


(************************************************************)
(* NURBS basis *)
(************************************************************)

Clear[NURBSBasis];

Options[NURBSBasis] = {SplineClosed -> False};

NURBSBasis[data_?MatrixQ, n_Integer, opts : OptionsPattern[]] :=
NURBSBasis[data, Table[n, Length @ data[[1]]] ];

NURBSBasis[data_?MatrixQ, nsArg : { _Integer .. }, opts : OptionsPattern[]] :=
Block[{ns = nsArg, dim = Dimensions[data][[2]],
lsMinMaxes, cpts0, inds, cpts, lsBasis},

Which[
dim - 1 < Length[ns],
ns = Take[ns, dim - 1],

dim - 1 > Length[ns],
Take[Flatten[Table[ns, dim]], dim - 1]
];

lsMinMaxes = MinMax /@ Transpose[data];

cpts0 = Outer[{0} &, Sequence @@ Map[Table[i, {i, 0, 1, 1 / (# - 1)}] &, ns]];
inds = Outer[List, Sequence @@ Map[Range, ns]];

inds = Flatten[inds, dim - 2];

lsBasis = Map[(
cpts = cpts0;
cpts = ReplacePart[cpts, #1 -> {1}];
With[{f = BSplineFunction[cpts, Sequence @@ FilterRules[{opts}, Options[BSplineFunction]]]},
Evaluate[f @@ Table[ Rescale[Slot[i], lsMinMaxes[[i]]], {i, Length@lsMinMaxes}] ]&])&,
inds
];

lsBasis
];

(************************************************************)
(* QuantileRegression *)
(************************************************************)
Expand Down

0 comments on commit addc3e5

Please sign in to comment.