Skip to content

Commit 98505fd

Browse files
committed
feat:C implementation of stats/base/dists/weibull/skewness
--- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent fdbf73d commit 98505fd

File tree

1 file changed

+28
-20
lines changed
  • lib/node_modules/@stdlib/stats/base/dists/weibull/skewness/src

1 file changed

+28
-20
lines changed
Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,32 +19,40 @@
1919
#include "stdlib/stats/base/dists/weibull/skewness.h"
2020
#include "stdlib/math/base/assert/is_nan.h"
2121
#include "stdlib/math/base/special/gamma.h"
22-
#include <math.h>
22+
#include "stdlib/math/base/special/pow.h"
23+
#include "stdlib/math/base/special/sqrt.h"
2324

2425
/**
25-
* Evaluates the skewness for a Weibull distribution with shape parameter `k`.
26+
* Evaluates the skewness for a Weibull distribution with shape parameter `k` and scale parameter `lambda`.
2627
*
27-
* @param k shape parameter (k > 0)
28-
* @return skewness
28+
* @param k shape parameter
29+
* @param lambda scale parameter
30+
* @return skewness of the distribution
2931
*
3032
* @example
31-
* double y = stdlib_base_dists_weibull_skewness( 1.5 );
32-
* // returns ~1.14
33+
* double y = stdlib_base_dists_weibull_skewness( 4.0, 12.0 );
34+
* // returns ~-0.087
3335
*/
34-
double stdlib_base_dists_weibull_skewness( const double k ) {
35-
if ( stdlib_base_is_nan( k ) || k <= 0.0 ) {
36-
return 0.0/0.0; // NaN
37-
}
36+
double stdlib_base_dists_weibull_skewness( const double k, const double lambda ) {
37+
if (
38+
stdlib_base_is_nan( k ) ||
39+
stdlib_base_is_nan( lambda ) ||
40+
k <= 0.0 ||
41+
lambda <= 0.0
42+
) {
43+
return 0.0/0.0; // NaN
44+
}
3845

39-
// Compute gamma-related terms:
40-
double gamma1 = stdlib_base_gamma( 1.0 + ( 1.0 / k ) );
41-
double gamma2 = stdlib_base_gamma( 1.0 + ( 2.0 / k ) );
42-
double gamma3 = stdlib_base_gamma( 1.0 + ( 3.0 / k ) );
46+
double gamma1 = stdlib_base_gamma( 1.0 + (3.0 / k) );
47+
double gamma2 = stdlib_base_gamma( 1.0 + (2.0 / k) );
48+
double gamma3 = stdlib_base_gamma( 1.0 + (1.0 / k) );
4349

44-
// Compute variance and mean terms:
45-
double variance = gamma2 - ( gamma1 * gamma1 );
46-
double stddev = sqrt( variance );
50+
double mu = gamma3 * lambda;
51+
double sigma2 = (gamma2 * lambda * lambda) - (mu * mu);
52+
double sigma = stdlib_base_sqrt( sigma2 );
4753

48-
// Compute skewness:
49-
return ( gamma3 - ( 3.0 * gamma1 * gamma2 ) + ( 2.0 * pow( gamma1, 3 ) ) ) / pow( stddev, 3 );
54+
double numerator = (gamma1 * lambda * lambda * lambda) - (3.0 * mu * sigma2) - (mu * mu * mu);
55+
double denominator = stdlib_base_pow( sigma, 3.0 );
56+
57+
return numerator / denominator;
5058
}

0 commit comments

Comments
 (0)