diff --git a/src/RankLib/Learning/IRanker.cs b/src/RankLib/Learning/IRanker.cs
index dd31086..c19c774 100644
--- a/src/RankLib/Learning/IRanker.cs
+++ b/src/RankLib/Learning/IRanker.cs
@@ -14,8 +14,13 @@ public interface IRankerParameters
}
///
-/// A ranker
+/// A ranker that can score and rank data points in a .
+/// A ranker can be trained by a , or a trained ranker model can be loaded
+/// from file
///
+///
+/// Use to create an for training and evaluation.
+///
public interface IRanker
{
///
@@ -120,15 +125,20 @@ public interface IRanker
}
///
-/// A generic ranker
+/// A generic ranker that can score and rank data points in a .
+/// A ranker can be trained by a , or a trained ranker model can be loaded
+/// from file
///
-/// The type of rank parameters
-public interface IRanker : IRanker
- where TParameters : IRankerParameters
+/// The type of ranker parameters
+///
+/// Use to create an for training and evaluation.
+///
+public interface IRanker : IRanker
+ where TRankerParameters : IRankerParameters
{
///
/// Gets or sets the parameters for the ranker.
/// The ranker uses parameters for training
///
- new TParameters Parameters { get; set; }
+ new TRankerParameters Parameters { get; set; }
}
diff --git a/src/RankLib/Learning/LinearRegression.cs b/src/RankLib/Learning/LinearRegression.cs
index 295e955..41611c6 100644
--- a/src/RankLib/Learning/LinearRegression.cs
+++ b/src/RankLib/Learning/LinearRegression.cs
@@ -36,7 +36,7 @@ public class LinearRegression : Ranker
private readonly ILogger _logger;
private double[] _weight = [];
- public LinearRegression(ILogger? logger = null) : base() =>
+ public LinearRegression(ILogger? logger = null) =>
_logger = logger ?? NullLogger.Instance;
public LinearRegression(List samples, int[] features, MetricScorer scorer,
@@ -44,14 +44,17 @@ public LinearRegression(List samples, int[] features, MetricScorer sco
: base(samples, features, scorer) =>
_logger = logger ?? NullLogger.Instance;
+ ///
public override string Name => RankerName;
+ ///
public override Task InitAsync()
{
_logger.LogInformation("Initializing...");
return Task.CompletedTask;
}
+ ///
public override Task LearnAsync()
{
_logger.LogInformation("Training starts...");
@@ -110,17 +113,18 @@ public override Task LearnAsync()
TrainingDataScore = SimpleMath.Round(Scorer.Score(Rank(Samples)), 4);
_logger.LogInformation("Finished successfully.");
- _logger.LogInformation("{ScorerName} on training data: {ScoreOnTrainingData}", Scorer.Name, TrainingDataScore);
+ _logger.LogInformation("{Scorer} on training data: {TrainingScore}", Scorer.Name, TrainingDataScore);
if (ValidationSamples != null)
{
ValidationDataScore = Scorer.Score(Rank(ValidationSamples));
- _logger.LogInformation("{ScorerName} on validation data: {BestScoreOnValidationData}", Scorer.Name, SimpleMath.Round(ValidationDataScore, 4));
+ _logger.LogInformation("{Scorer} on validation data: {ValidationScore}", Scorer.Name, SimpleMath.Round(ValidationDataScore, 4));
}
return Task.CompletedTask;
}
+ ///
public override double Eval(DataPoint dataPoint)
{
var score = _weight[^1];
@@ -130,6 +134,7 @@ public override double Eval(DataPoint dataPoint)
return score;
}
+ ///
public override string GetModel()
{
var output = new StringBuilder()
@@ -147,6 +152,7 @@ public override string GetModel()
return output.ToString();
}
+ ///
public override void LoadFromString(string model)
{
try
diff --git a/src/RankLib/Learning/Ranker.cs b/src/RankLib/Learning/Ranker.cs
index f7183d9..1e66a60 100644
--- a/src/RankLib/Learning/Ranker.cs
+++ b/src/RankLib/Learning/Ranker.cs
@@ -1,20 +1,26 @@
using System.Text;
+using RankLib.Eval;
using RankLib.Metric;
using RankLib.Utilities;
namespace RankLib.Learning;
///
-/// Base class for a generic ranker with typed ranker parameters.
+/// Base class for a generic ranker that can score and rank data points in a .
+/// A ranker can be trained by a , or a trained ranker model can be loaded
+/// from file
///
/// The type of ranker parameters
+///
+/// Use to create an for training and evaluation.
+///
public abstract class Ranker : IRanker
where TRankerParameters : IRankerParameters, new()
{
private MetricScorer? _scorer;
- protected double TrainingDataScore = 0.0;
- protected double ValidationDataScore = 0.0;
+ protected double TrainingDataScore = 0;
+ protected double ValidationDataScore = 0;
///
public List Samples { get; set; } = [];
diff --git a/src/RankLib/Learning/RankerTrainer.cs b/src/RankLib/Learning/RankerTrainer.cs
index 6cd5a89..2c23da1 100644
--- a/src/RankLib/Learning/RankerTrainer.cs
+++ b/src/RankLib/Learning/RankerTrainer.cs
@@ -10,9 +10,9 @@ public class RankerTrainer
private readonly RankerFactory _rankerFactory;
///
- /// Initializes a new instance of
+ /// Instantiates a new instance of
///
- ///
+ /// The ranker factory used to create rankers
public RankerTrainer(RankerFactory rankerFactory) => _rankerFactory = rankerFactory;
///
diff --git a/src/RankLib/Learning/Sampler.cs b/src/RankLib/Learning/Sampler.cs
index 6488895..49d5377 100644
--- a/src/RankLib/Learning/Sampler.cs
+++ b/src/RankLib/Learning/Sampler.cs
@@ -2,10 +2,6 @@
namespace RankLib.Learning;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
///
/// Samples rank lists from a pool of rank lists
///
diff --git a/src/RankLib/Parsing/ModelLineProducer.cs b/src/RankLib/Parsing/ModelLineProducer.cs
index b71bec5..2f29347 100644
--- a/src/RankLib/Parsing/ModelLineProducer.cs
+++ b/src/RankLib/Parsing/ModelLineProducer.cs
@@ -20,9 +20,7 @@ private bool ReadUntil(string fullTextChar, int beginOfLineCursor, int endOfLine
if (fullTextChar[beginOfLineCursor] != '#')
{
for (var j = beginOfLineCursor; j <= endOfLineCursor; j++)
- {
model.Append(fullTextChar[j]);
- }
}
// Check for ensemble tag