IterativeReweightedLeastSquares Class 
Namespace: Accord.Statistics.Models.Regression.Fitting
public class IterativeReweightedLeastSquares : IterativeReweightedLeastSquares<GeneralizedLinearRegression>
The IterativeReweightedLeastSquares type exposes the following members.
Name  Description  

IterativeReweightedLeastSquares(GeneralizedLinearRegression) 
Constructs a new Iterative Reweighted Least Squares.
 
IterativeReweightedLeastSquares(LogisticRegression) 
Constructs a new Iterative Reweighted Least Squares.

Name  Description  

ComputeStandardErrors 
Gets or sets a value indicating whether standard
errors should be computed in the next iteration.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
CurrentIteration 
Gets the current iteration number.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
Gradient 
Gets the Gradient vector computed in
the last NewtonRaphson iteration.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
HasConverged 
Gets or sets whether the algorithm has converged.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
Hessian 
Gets the Hessian matrix computed in
the last NewtonRaphson iteration.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
Iterations  Obsolete.
Please use MaxIterations instead.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
MaxIterations 
Gets or sets the maximum number of iterations
performed by the learning algorithm.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
Model 
Gets or sets the regression model being learned.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
Parameters 
Gets the total number of parameters in the model.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
Previous 
Gets the previous values for the coefficients which were
in place before the last learning iteration was performed.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
Regularization 
Gets or sets the regularization value to be
added in the objective function. Default is
1e10.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
Solution 
Gets the current values for the coefficients.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
Token 
Gets or sets a cancellation token that can be used to
stop the learning algorithm while it is running.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
Tolerance 
Gets or sets the tolerance value used to determine
whether the algorithm has converged.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
Updates 
Gets the last parameter updates in the last iteration.
(Inherited from IterativeReweightedLeastSquaresTModel.) 
Name  Description  

ComputeError  Obsolete.
Computes the sumofsquared error between the
model outputs and the expected outputs.
 
Equals  Determines whether the specified object is equal to the current object. (Inherited from Object.)  
Finalize  Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)  
GetHashCode  Serves as the default hash function. (Inherited from Object.)  
GetInformationMatrix 
Gets the information matrix used to update the regression
weights in the last call to Learn(Double, Double, Double) (Inherited from IterativeReweightedLeastSquaresTModel.)  
GetType  Gets the Type of the current instance. (Inherited from Object.)  
Initialize 
Initializes this instance.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
Learn(Double, Boolean, Double) 
Learns a model that can map the given inputs to the given outputs.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
Learn(Double, Double, Double) 
Learns a model that can map the given inputs to the given outputs.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
Learn(Double, Int32, Double) 
Learns a model that can map the given inputs to the given outputs.
(Inherited from IterativeReweightedLeastSquaresTModel.)  
MemberwiseClone  Creates a shallow copy of the current Object. (Inherited from Object.)  
Run(Double, Double)  Obsolete.
Runs one iteration of the Reweighted Least Squares algorithm.
 
Run(Double, Double)  Obsolete.
Runs one iteration of the Reweighted Least Squares algorithm.
 
Run(Double, Int32)  Obsolete.
Runs one iteration of the Reweighted Least Squares algorithm.
 
Run(Double, Int32)  Obsolete.
Runs one iteration of the Reweighted Least Squares algorithm.
 
Run(Double, Double, Double)  Obsolete.
Runs one iteration of the Reweighted Least Squares algorithm.
 
Run(Double, Int32, Double)  Obsolete.
Runs one iteration of the Reweighted Least Squares algorithm.
 
Run(Double, Int32, Double)  Obsolete.
Runs one iteration of the Reweighted Least Squares algorithm.
 
ToString  Returns a string that represents the current object. (Inherited from Object.) 
Name  Description  

HasMethod 
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)  
IsEqual  Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices. (Defined by Matrix.)  
ToT 
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) 
The Iterative Reweighted Least Squares is an iterative technique based on the NewtonRaphson iterative optimization scheme. The IRLS method uses a local quadratic approximation to the loglikelihood function.
By applying the NewtonRaphson optimization scheme to the crossentropy error function (defined as the negative logarithm of the likelihood), one arises at a weighted formulation for the Hessian matrix.
The Iterative Reweighted Least Squares algorithm can also be used to learn arbitrary generalized linear models. However, the use of this class to learn such models is currently experimental.
References:
// Suppose we have the following data about some patients. // The first variable is continuous and represent patient // age. The second variable is dichotomic and give whether // they smoke or not (This is completely fictional data). // We also know if they have had lung cancer or not, and // we would like to know whether smoking has any connection // with lung cancer (This is completely fictional data). double[][] input = { // age, smokes?, had cancer? new double[] { 55, 0 }, // false  no cancer new double[] { 28, 0 }, // false new double[] { 65, 1 }, // false new double[] { 46, 0 }, // true  had cancer new double[] { 86, 1 }, // true new double[] { 56, 1 }, // true new double[] { 85, 0 }, // false new double[] { 33, 0 }, // false new double[] { 21, 1 }, // false new double[] { 42, 1 }, // true }; bool[] output = // Whether each patient had lung cancer or not { false, false, false, true, true, true, false, false, false, true }; // To verify this hypothesis, we are going to create a logistic // regression model for those two inputs (age and smoking), learned // using a method called "Iteratively Reweighted Least Squares": var learner = new IterativeReweightedLeastSquares<LogisticRegression>() { Tolerance = 1e4, // Let's set some convergence parameters Iterations = 100, // maximum number of iterations to perform Regularization = 0 }; // Now, we can use the learner to finally estimate our model: LogisticRegression regression = learner.Learn(input, output); // At this point, we can compute the odds ratio of our variables. // In the model, the variable at 0 is always the intercept term, // with the other following in the sequence. Index 1 is the age // and index 2 is whether the patient smokes or not. // For the age variable, we have that individuals with // higher age have 1.021 greater odds of getting lung // cancer controlling for cigarette smoking. double ageOdds = regression.GetOddsRatio(1); // 1.0208597028836701 // For the smoking/non smoking category variable, however, we // have that individuals who smoke have 5.858 greater odds // of developing lung cancer compared to those who do not // smoke, controlling for age (remember, this is completely // fictional and for demonstration purposes only). double smokeOdds = regression.GetOddsRatio(2); // 5.8584748789881331 // If we would like to use the model to predict a probability for // each patient regarding whether they are at risk of cancer or not, // we can use the Probability function: double[] scores = regression.Probability(input); // Finally, if we would like to arrive at a conclusion regarding // each patient, we can use the Decide method, which will transform // the probabilities (from 0 to 1) into actual true/false values: bool[] actual = regression.Decide(input);