//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testUniform() public virtual void testUniform() { BasisFunctionKnots knots = BasisFunctionKnots.fromUniform(1.0, 2.0, 10, 3); assertEquals(3, knots.Degree); assertEquals(16, knots.NumKnots); assertEquals(12, knots.NumSplines); }
/// <summary> /// Given a set of data {x_i ,y_i} where each x_i is a vector and the y_i are scalars, we wish to find a function (represented /// by B-splines) that fits the data while maintaining smoothness in each direction. </summary> /// <param name="x"> The independent (vector) variables, as List<double[]> </param> /// <param name="y"> The dependent variables, as List<Double> y </param> /// <param name="sigma"> The error (or tolerance) on the y variables </param> /// <param name="xa"> The lowest value of x in each dimension </param> /// <param name="xb"> The highest value of x in each dimension </param> /// <param name="nKnots"> Number of knots in each dimension (note, the actual number of basis splines and thus fitted weights, /// equals nKnots + degree-1) </param> /// <param name="degree"> The degree of the basis function in each dimension - 0 is piecewise constant, 1 is a sawtooth function /// (i.e. two straight lines joined in the middle), 2 gives three quadratic sections joined together, etc. For a large /// value of degree, the basis function tends to a gaussian </param> /// <param name="lambda"> The weight given to the penalty function in each dimension </param> /// <param name="differenceOrder"> applies the penalty the nth order difference in the weights, so a differenceOrder of 2 /// will penalize large 2nd derivatives etc. A difference differenceOrder can be used in each dimension </param> /// <returns> The results of the fit </returns> public virtual GeneralizedLeastSquareResults <double[]> solve(IList <double[]> x, IList <double> y, IList <double> sigma, double[] xa, double[] xb, int[] nKnots, int[] degree, double[] lambda, int[] differenceOrder) { BasisFunctionKnots[] knots = new BasisFunctionKnots[xa.Length]; for (int i = 0; i < xa.Length; i++) { knots[i] = BasisFunctionKnots.fromUniform(xa[i], xb[i], nKnots[i], degree[i]); } IList <System.Func <double[], double> > bSplines = _generator.generateSet(knots); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int dim = xa.length; int dim = xa.Length; int[] sizes = new int[dim]; for (int i = 0; i < dim; i++) { sizes[i] = nKnots[i] + degree[i] - 1; } return(_gls.solve(x, y, sigma, bSplines, sizes, lambda, differenceOrder)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(expectedExceptions = IllegalArgumentException.class) public void testDegreeToHigh1() public virtual void testDegreeToHigh1() { BasisFunctionKnots.fromUniform(0.0, 10.0, 11, 11); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(expectedExceptions = IllegalArgumentException.class) public void testWrongOrderUniform() public virtual void testWrongOrderUniform() { BasisFunctionKnots.fromUniform(2.0, 1.0, 10, 3); }
/// <summary> /// Fits a curve to x-y data. </summary> /// <param name="x"> The independent variables </param> /// <param name="y"> The dependent variables </param> /// <param name="sigma"> The error (or tolerance) on the y variables </param> /// <param name="xa"> The lowest value of x </param> /// <param name="xb"> The highest value of x </param> /// <param name="nKnots"> Number of knots (note, the actual number of basis splines and thus fitted weights, equals nKnots + degree-1) </param> /// <param name="degree"> The degree of the basis function - 0 is piecewise constant, 1 is a sawtooth function (i.e. two straight lines joined in the middle), 2 gives three /// quadratic sections joined together, etc. For a large value of degree, the basis function tends to a gaussian </param> /// <param name="lambda"> The weight given to the penalty function </param> /// <param name="differenceOrder"> applies the penalty the nth order difference in the weights, so a differenceOrder of 2 will penalise large 2nd derivatives etc </param> /// <returns> The results of the fit </returns> public virtual GeneralizedLeastSquareResults <double> solve(IList <double> x, IList <double> y, IList <double> sigma, double xa, double xb, int nKnots, int degree, double lambda, int differenceOrder) { IList <System.Func <double, double> > bSplines = _generator.generateSet(BasisFunctionKnots.fromUniform(xa, xb, nKnots, degree)); return(_gls.solve(x, y, sigma, bSplines, lambda, differenceOrder)); }