mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-21 03:58:04 +00:00
normalization of methods
This commit is contained in:
@@ -238,7 +238,7 @@ public class SigmoidTests
|
||||
series.Add(new TValue(DateTime.UtcNow.AddSeconds(i), i - 50), isNew: true);
|
||||
}
|
||||
|
||||
var result = Sigmoid.Calculate(series);
|
||||
var result = Sigmoid.Batch(series);
|
||||
|
||||
Assert.Equal(series.Count, result.Count);
|
||||
}
|
||||
@@ -251,7 +251,7 @@ public class SigmoidTests
|
||||
public void Calculate_Span_EmptySource_ThrowsArgumentException()
|
||||
{
|
||||
double[] output = new double[10];
|
||||
Assert.Throws<ArgumentException>(() => Sigmoid.Calculate(ReadOnlySpan<double>.Empty, output.AsSpan()));
|
||||
Assert.Throws<ArgumentException>(() => Sigmoid.Batch(ReadOnlySpan<double>.Empty, output.AsSpan()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -260,7 +260,7 @@ public class SigmoidTests
|
||||
double[] source = [1, 2, 3, 4, 5];
|
||||
double[] output = new double[3];
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Sigmoid.Calculate(source.AsSpan(), output.AsSpan()));
|
||||
Assert.Throws<ArgumentException>(() => Sigmoid.Batch(source.AsSpan(), output.AsSpan()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -269,7 +269,7 @@ public class SigmoidTests
|
||||
double[] source = [1, 2, 3, 4, 5];
|
||||
double[] output = new double[5];
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Sigmoid.Calculate(source.AsSpan(), output.AsSpan(), k: 0));
|
||||
Assert.Throws<ArgumentException>(() => Sigmoid.Batch(source.AsSpan(), output.AsSpan(), k: 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -283,7 +283,7 @@ public class SigmoidTests
|
||||
}
|
||||
|
||||
double[] spanOutput = new double[source.Length];
|
||||
Sigmoid.Calculate(source.AsSpan(), spanOutput.AsSpan());
|
||||
Sigmoid.Batch(source.AsSpan(), spanOutput.AsSpan());
|
||||
|
||||
var sigmoid = new Sigmoid();
|
||||
double[] streamOutput = new double[source.Length];
|
||||
@@ -304,7 +304,7 @@ public class SigmoidTests
|
||||
double[] source = [1.0, double.NaN, 2.0];
|
||||
double[] output = new double[3];
|
||||
|
||||
Sigmoid.Calculate(source.AsSpan(), output.AsSpan());
|
||||
Sigmoid.Batch(source.AsSpan(), output.AsSpan());
|
||||
|
||||
Assert.True(double.IsFinite(output[0]));
|
||||
Assert.True(double.IsFinite(output[1])); // NaN replaced with last valid
|
||||
|
||||
@@ -228,7 +228,7 @@ public class SigmoidValidationTests
|
||||
|
||||
// Span calculation
|
||||
double[] spanOutput = new double[source.Length];
|
||||
Sigmoid.Calculate(source.AsSpan(), spanOutput.AsSpan(), k, x0);
|
||||
Sigmoid.Batch(source.AsSpan(), spanOutput.AsSpan(), k, x0);
|
||||
|
||||
// Streaming calculation
|
||||
var sigmoid = new Sigmoid(k, x0);
|
||||
|
||||
@@ -136,7 +136,7 @@ public sealed class Sigmoid : AbstractBase
|
||||
}
|
||||
}
|
||||
|
||||
public static TSeries Calculate(TSeries source, double k = 1.0, double x0 = 0.0)
|
||||
public static TSeries Batch(TSeries source, double k = 1.0, double x0 = 0.0)
|
||||
{
|
||||
var indicator = new Sigmoid(k, x0);
|
||||
return indicator.Update(source);
|
||||
@@ -145,7 +145,7 @@ public sealed class Sigmoid : AbstractBase
|
||||
/// <summary>
|
||||
/// Calculates Sigmoid over a span of values.
|
||||
/// </summary>
|
||||
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, double k = 1.0, double x0 = 0.0)
|
||||
public static void Batch(ReadOnlySpan<double> source, Span<double> output, double k = 1.0, double x0 = 0.0)
|
||||
{
|
||||
if (source.Length == 0)
|
||||
{
|
||||
@@ -190,10 +190,17 @@ public sealed class Sigmoid : AbstractBase
|
||||
}
|
||||
}
|
||||
|
||||
public static (TSeries Results, Sigmoid Indicator) Calculate(TSeries source, double k = 1.0, double x0 = 0.0)
|
||||
{
|
||||
var indicator = new Sigmoid(k, x0);
|
||||
TSeries results = indicator.Update(source);
|
||||
return (results, indicator);
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
_state = default;
|
||||
_p_state = default;
|
||||
Last = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user