@ -31,7 +31,6 @@
using System ;
using System.Collections.Generic ;
using MathNet.Numerics.LinearAlgebra ;
using MathNet.Numerics.LinearAlgebra.Storage ;
namespace MathNet.Numerics.LinearRegression
{
@ -40,6 +39,9 @@ namespace MathNet.Numerics.LinearRegression
/// <summary>
/// Weighted Linear Regression using normal equations.
/// </summary>
/// <param name="x">Predictor matrix X</param>
/// <param name="y">Response vector Y</param>
/// <param name="w">Weight matrix W, usually diagonal with an entry for each predictor (row).</param>
public static Vector < T > Weighted < T > ( Matrix < T > x , Vector < T > y , Matrix < T > w ) where T : struct , IEquatable < T > , IFormattable
{
return x . TransposeThisAndMultiply ( w * x ) . Cholesky ( ) . Solve ( x . TransposeThisAndMultiply ( w * y ) ) ;
@ -48,6 +50,9 @@ namespace MathNet.Numerics.LinearRegression
/// <summary>
/// Weighted Linear Regression using normal equations.
/// </summary>
/// <param name="x">Predictor matrix X</param>
/// <param name="y">Response matrix Y</param>
/// <param name="w">Weight matrix W, usually diagonal with an entry for each predictor (row).</param>
public static Matrix < T > Weighted < T > ( Matrix < T > x , Matrix < T > y , Matrix < T > w ) where T : struct , IEquatable < T > , IFormattable
{
return x . TransposeThisAndMultiply ( w * x ) . Cholesky ( ) . Solve ( x . TransposeThisAndMultiply ( w * y ) ) ;
@ -56,6 +61,9 @@ namespace MathNet.Numerics.LinearRegression
/// <summary>
/// Weighted Linear Regression using normal equations.
/// </summary>
/// <param name="x">Predictor matrix X</param>
/// <param name="y">Response vector Y</param>
/// <param name="w">Weight matrix W, usually diagonal with an entry for each predictor (row).</param>
/// <param name="intercept">True if an intercept should be added as first artificial perdictor value. Default = false.</param>
public static T [ ] Weighted < T > ( T [ ] [ ] x , T [ ] y , T [ ] w , bool intercept = false ) where T : struct , IEquatable < T > , IFormattable
{
@ -72,16 +80,19 @@ namespace MathNet.Numerics.LinearRegression
/// <summary>
/// Weighted Linear Regression using normal equations.
/// </summary>
/// <param name="samples">List of sample vectors (predictor) together with their response.</param>
/// <param name="weights">List of weights, one for each sample.</param>
/// <param name="intercept">True if an intercept should be added as first artificial perdictor value. Default = false.</param>
public static T [ ] Weighted < T > ( IEnumerable < Tuple < T [ ] , T > > samples , T [ ] w , bool intercept = false ) where T : struct , IEquatable < T > , IFormattable
public static T [ ] Weighted < T > ( IEnumerable < Tuple < T [ ] , T > > samples , T [ ] weights , bool intercept = false ) where T : struct , IEquatable < T > , IFormattable
{
var xy = samples . UnpackSinglePass ( ) ;
return Weighted ( xy . Item1 , xy . Item2 , w , intercept ) ;
return Weighted ( xy . Item1 , xy . Item2 , weights , intercept ) ;
}
/// <summary>
/// Locally-Weighted Linear Regression using normal equations.
/// </summary>
[Obsolete("Warning: This function is here to stay but its signature will likely change.")]
public static Vector < T > Local < T > ( Matrix < T > x , Vector < T > y , Vector < T > t , double radius , Func < double , T > kernel ) where T : struct , IEquatable < T > , IFormattable
{
// TODO: Weird kernel definition
@ -96,6 +107,7 @@ namespace MathNet.Numerics.LinearRegression
/// <summary>
/// Locally-Weighted Linear Regression using normal equations.
/// </summary>
[Obsolete("Warning: This function is here to stay but its signature will likely change.")]
public static Matrix < T > Local < T > ( Matrix < T > x , Matrix < T > y , Vector < T > t , double radius , Func < double , T > kernel ) where T : struct , IEquatable < T > , IFormattable
{
// TODO: Weird kernel definition
@ -107,6 +119,7 @@ namespace MathNet.Numerics.LinearRegression
return Weighted ( x , y , w ) ;
}
[Obsolete("Warning: This function is here to stay but will likely be refactored and/or moved to another place.")]
public static double GaussianKernel ( double normalizedDistance )
{
return Math . Exp ( - 0.5 * normalizedDistance * normalizedDistance ) ;