Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xml doc comments and tests for discrete padRnd. #307

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/FSharp.Stats/Signal/Padding.fs
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,23 @@ module Padding =
module Discrete =


/// <summary>Adds additional data points to the beginning and end of data set (number: borderpadding; y_Value: random).</summary>
/// <remarks></remarks>
/// <param name="data"></param>
/// <param name="borderpadding"></param>
/// <returns></returns>
/// <summary>
/// Adds additional random data points to the beginning and end of the given data. Values are
/// taken at random from the original data.
/// </summary>
/// <param name="data">An array of values</param>
/// <param name="borderpadding">The number of points to add to each end</param>
/// <example>
/// <code>
/// </code>
/// </example>
/// <code>
/// let data = [|0.1; 0.2; 0.3; 0.4|]
///
/// let padding = 2
///
/// // padding the data points with 2 artificial random-valued points on each side
/// let paddedData = Padding.Discrete.padRnd data padding
///
/// </code>
/// </example>
let inline padRnd (data : 'a []) (borderpadding : int) =
let rnd = System.Random()
let n = data.Length
Expand All @@ -373,7 +381,7 @@ module Padding =
let paddY = data.[rnd.Next(0,n)] //n+1
paddY)
|> Array.rev
///adds 'borderpadding' number of random data points to the rigth
///adds 'borderpadding' number of random data points to the right
let rightPadding =
Array.init borderpadding (fun i ->
let paddY = data.[rnd.Next(0,n)] //n+1
Expand All @@ -393,7 +401,7 @@ module Padding =
/// let padding = 2
///
/// // padding the data points with 2 artificial zero-valued points on each side
/// let paddedData =Padding.Discrete.padZero data padding
/// let paddedData = Padding.Discrete.padZero data padding
///
/// </code>
/// </example>
Expand Down Expand Up @@ -434,7 +442,7 @@ module Padding =
/// let padding = 11
///
/// // padding the data points with 11 artificial random points on each side
/// let paddedData2D =Padding.Discrete.ThreeDimensional.pad data2D padding Padding.Discrete.ThreeDimensional.Random
/// let paddedData2D = Padding.Discrete.ThreeDimensional.pad data2D padding Padding.Discrete.ThreeDimensional.Random
///
/// </code>
/// </example>
Expand Down
10 changes: 10 additions & 0 deletions tests/FSharp.Stats.Tests/Signal.fs
Original file line number Diff line number Diff line change
Expand Up @@ -401,5 +401,15 @@ let paddingTests =
let paddedData = padZero originalData padding

Expect.equal paddedData expected "padded data incorrect"

testCase "padRnd to discrete data" <| fun() ->
let originalData = randomArray dataLength
let newLength = (dataLength + 2 * padding)

let paddedData = padRnd originalData padding

Expect.equal paddedData.Length newLength "padded data length incorrect"
// All the padded values should belong to the original data set
Expect.containsAll originalData paddedData "padded data contains item not in original data"
]

Loading