@@ -332,20 +332,6 @@ pub fn weighted_sum(arr: List(#(Float, Float))) -> Result(Float, Nil) {
332
332
}
333
333
}
334
334
335
- // let weight_is_negative = list.any(arr, fn(tuple) { tuple.1 <. 0.0 })
336
-
337
- // case weight_is_negative {
338
- // True -> Error(Nil)
339
- // False -> {
340
- // let weighted_sum =
341
- // list.fold(arr, 0.0, fn(acc, a) { a.0 *. a.1 +. acc })
342
- // Ok(weighted_sum)
343
- // }
344
- // }
345
- // }
346
- // }
347
- // }
348
-
349
335
/// <div style="text-align: right;">
350
336
/// <a href="https://github.com/gleam-community/maths/issues">
351
337
/// <small>Spot a typo? Open an issue!</small>
@@ -2170,7 +2156,7 @@ pub fn absolute_difference(a: Float, b: Float) -> Float {
2170
2156
/// \\]
2171
2157
///
2172
2158
/// The function takes two inputs \\(x\\) and \\(y\\) and returns a positive integer
2173
- /// value which is the the absolute difference of the inputs.
2159
+ /// value which is the absolute difference of the inputs.
2174
2160
///
2175
2161
/// <details>
2176
2162
/// <summary>Example:</summary>
@@ -3363,7 +3349,7 @@ pub fn norm(arr: List(Float), p: Float) -> Result(Float, Nil) {
3363
3349
[ ] -> Ok ( 0.0 )
3364
3350
_ -> {
3365
3351
case p {
3366
- // Handle the the special case when 'p' is equal to zero. In this case, we compute a
3352
+ // Handle the special case when 'p' is equal to zero. In this case, we compute a
3367
3353
// pseudo-norm, which is the number of non-zero elements in the given list 'arr'
3368
3354
0.0 ->
3369
3355
Ok (
@@ -3473,7 +3459,7 @@ pub fn norm_with_weights(
3473
3459
False -> {
3474
3460
case p {
3475
3461
0.0 -> {
3476
- // Handle the the special case when 'p' is equal to zero. In this case, we compute
3462
+ // Handle the special case when 'p' is equal to zero. In this case, we compute
3477
3463
// a pseudo-norm, which is the number of non-zero elements in the given list 'arr'
3478
3464
Ok (
3479
3465
list . fold ( arr , 0.0 , fn ( acc , tuple ) {
@@ -3931,7 +3917,7 @@ pub fn chebyshev_distance_with_weights(
3931
3917
/// </a>
3932
3918
/// </div>
3933
3919
///
3934
- /// Calculcate the n'th moment about the mean of a list of elements.
3920
+ /// Calculate the n'th moment about the mean of a list of elements.
3935
3921
///
3936
3922
/// <details>
3937
3923
/// <summary>Example:</summary>
@@ -3968,40 +3954,6 @@ pub fn chebyshev_distance_with_weights(
3968
3954
/// </a>
3969
3955
/// </div>
3970
3956
///
3971
- // pub fn moment(arr: List(Float), n: Int) -> Result(Float, Nil) {
3972
- // case list.length(arr), n {
3973
- // 0, _ -> Error(Nil)
3974
- // // 0th moment is always 1.0
3975
- // __, 0 -> Ok(1.0)
3976
- // // 1st moment (about the mean) is 0.0 by definition
3977
- // _, 1 -> Ok(0.0)
3978
- // _, n if n >= 0 -> {
3979
- // // Check if the list has enough elements for the nth moment
3980
- // case list.length(arr) >= n {
3981
- // True -> {
3982
- // // Usage of let assert: The function 'mean' will only return an error if the given list
3983
- // // is emptry. No error will occur since we already checked that the list is non-empty.
3984
- // let assert Ok(m1) = mean(arr)
3985
- // let result =
3986
- // list.try_fold(arr, 0.0, fn(acc, a) {
3987
- // case float.power(a -. m1, int.to_float(n)) {
3988
- // Error(Nil) -> Error(Nil)
3989
- // Ok(value) -> Ok(value +. acc)
3990
- // }
3991
- // })
3992
- // case result {
3993
- // Error(Nil) -> Error(Nil)
3994
- // Ok(value) -> Ok(value /. int.to_float(list.length(arr)))
3995
- // }
3996
- // }
3997
- // // Not enough elements for meaningful computation
3998
- // False -> Error(Nil)
3999
- // }
4000
- // }
4001
- // _, _ -> Error(Nil)
4002
- // }
4003
- // }
4004
-
4005
3957
pub fn moment ( arr : List ( Float ) , n : Int ) -> Result ( Float , Nil ) {
4006
3958
case arr , n {
4007
3959
// Handle empty list: no moments can be calculated
@@ -4089,7 +4041,7 @@ pub fn mean(arr: List(Float)) -> Result(Float, Nil) {
4089
4041
/// </a>
4090
4042
/// </div>
4091
4043
///
4092
- /// Calculcate the harmonic mean \\(\bar{x}\\) of the elements in a list:
4044
+ /// Calculate the harmonic mean \\(\bar{x}\\) of the elements in a list:
4093
4045
///
4094
4046
/// \\[
4095
4047
/// \bar{x} = \frac{n}{\sum_{i=1}^{n}\frac{1}{x_i}}
@@ -4158,7 +4110,7 @@ pub fn harmonic_mean(arr: List(Float)) -> Result(Float, Nil) {
4158
4110
/// </a>
4159
4111
/// </div>
4160
4112
///
4161
- /// Calculcate the geometric mean \\(\bar{x}\\) of the elements in a list:
4113
+ /// Calculate the geometric mean \\(\bar{x}\\) of the elements in a list:
4162
4114
///
4163
4115
/// \\[
4164
4116
/// \bar{x} = \left(\prod^{n}_{i=1} x_i\right)^{\frac{1}{n}}
@@ -4414,7 +4366,7 @@ pub fn standard_deviation(arr: List(Float), ddof: Int) -> Result(Float, Nil) {
4414
4366
/// </a>
4415
4367
/// </div>
4416
4368
///
4417
- /// Calculcate the sample kurtosis of a list of elements using the
4369
+ /// Calculate the sample kurtosis of a list of elements using the
4418
4370
/// definition of Fisher.
4419
4371
///
4420
4372
/// <details>
@@ -4469,7 +4421,7 @@ pub fn kurtosis(arr: List(Float)) -> Result(Float, Nil) {
4469
4421
/// </a>
4470
4422
/// </div>
4471
4423
///
4472
- /// Calculcate the sample skewness of a list of elements using the
4424
+ /// Calculate the sample skewness of a list of elements using the
4473
4425
/// Fisher-Pearson coefficient of skewness.
4474
4426
///
4475
4427
/// <details>
@@ -5296,7 +5248,7 @@ pub fn canberra_distance(arr: List(#(Float, Float))) -> Result(Float, Nil) {
5296
5248
/// import gleam_community/maths
5297
5249
///
5298
5250
/// pub fn example() {
5299
- /// maths.canberra_distance ([])
5251
+ /// maths.canberra_distance_with_weights ([])
5300
5252
/// |> should.be_error()
5301
5253
///
5302
5254
/// maths.canberra_distance_with_weights([#(1.0, -2.0, 0.5), #(2.0, -1.0, 1.0)])
@@ -5365,8 +5317,8 @@ pub fn canberra_distance_with_weights(
5365
5317
/// maths.canberra_distance([])
5366
5318
/// |> should.be_error()
5367
5319
///
5368
- /// maths.canberra_distance_with_weights ([#(1.0, -2.0, 0.5 ), #(2.0, -1.0, 1 .0)])
5369
- /// |> should.equal(Ok(1.5 ))
5320
+ /// maths.braycurtis_distance ([#(1.0, 3.0 ), #(2.0, 4 .0)])
5321
+ /// |> should.equal(Ok(0.4 ))
5370
5322
/// }
5371
5323
/// </details>
5372
5324
///
0 commit comments