corrections

This commit is contained in:
Miha Kralj
2024-10-13 17:18:31 -07:00
parent 2236f5f483
commit bbefc72d73
65 changed files with 669 additions and 1087 deletions
+1 -51
View File
@@ -1,25 +1,10 @@
namespace QuanTAlib;
/// <summary>
/// Represents a Root Mean Squared Error calculator that measures the square root of the average
/// of the squares of the differences between actual values and predicted values.
/// </summary>
/// <remarks>
/// The Rmse class calculates the Root Mean Squared Error using a circular buffer
/// to efficiently manage the data points within the specified period.
/// </remarks>
public class Rmse : AbstractBase
{
private readonly CircularBuffer _actualBuffer;
private readonly CircularBuffer _predictedBuffer;
/// <summary>
/// Initializes a new instance of the Rmse class with the specified period.
/// </summary>
/// <param name="period">The period over which to calculate the Root Mean Squared Error.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when period is less than 1.
/// </exception>
public Rmse(int period)
{
if (period < 1)
@@ -33,19 +18,12 @@ public class Rmse : AbstractBase
Init();
}
/// <summary>
/// Initializes a new instance of the Mape class with the specified source and period.
/// </summary>
/// <param name="source">The source object to subscribe to for value updates.</param>
/// <param name="period">The period over which to calculate the Mean Absolute Percentage Error.</param>
public Rmse(object source, int period) : this(period)
{
var pubEvent = source.GetType().GetEvent("Pub");
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
}
/// <summary>
/// Initializes the Rmse instance by clearing the buffers.
/// </summary>
public override void Init()
{
base.Init();
@@ -53,10 +31,6 @@ public class Rmse : AbstractBase
_predictedBuffer.Clear();
}
/// <summary>
/// Manages the state of the Rmse instance based on whether new values are being processed.
/// </summary>
/// <param name="isNew">Indicates whether the current inputs are new values.</param>
protected override void ManageState(bool isNew)
{
if (isNew)
@@ -66,17 +40,6 @@ public class Rmse : AbstractBase
}
}
/// <summary>
/// Performs the Root Mean Squared Error calculation for the current period.
/// </summary>
/// <returns>
/// The calculated Root Mean Squared Error value for the current period.
/// </returns>
/// <remarks>
/// This method calculates the Root Mean Squared Error using the formula:
/// RMSE = sqrt(sum((actual - predicted)^2) / n)
/// where actual is each actual value, predicted is each predicted value, and n is the number of values.
/// </remarks>
protected override double Calculation()
{
ManageState(Input.IsNew);
@@ -106,17 +69,4 @@ public class Rmse : AbstractBase
IsHot = _index >= WarmupPeriod;
return rmse;
}
/// <summary>
/// Calculates the Root Mean Squared Error for the given actual and predicted values.
/// </summary>
/// <param name="actual">The actual value.</param>
/// <param name="predicted">The predicted value.</param>
/// <returns>The calculated Root Mean Squared Error.</returns>
public double Calc(double actual, double predicted)
{
Input = new TValue(DateTime.Now, actual);
Input2 = new TValue(DateTime.Now, predicted);
return Calculation();
}
}