1 #include <iostream>
2 #include <string>
3 #include "testlib/testlib_test.h"
4 #include <bsta/algo/bsta_fit_weibull.h>
5 #ifdef _MSC_VER
6 # include "vcl_msvc_warnings.h"
7 #endif
8
9 template <class T>
test_fit_weibull_type(T epsilon,const std::string & type_name)10 void test_fit_weibull_type(T epsilon, const std::string& type_name)
11 {
12 T sample_mean = T(0.404), sample_std_dev = T(0.33);
13 bsta_weibull_cost_function wcf(sample_mean, sample_std_dev);
14 bsta_fit_weibull<T> fw(&wcf);
15 T k = T(0);
16 fw.init(k);
17 fw.solve(k);
18 T residual = fw.residual();
19 TEST("residual", residual, residual);
20 T lambda = fw.lambda(k);
21
22 TEST_NEAR(("shape param k <"+type_name+">").c_str(),
23 k, static_cast<T>(1.2309439), epsilon);
24
25 TEST_NEAR(("shape param lambda <"+type_name+">").c_str(),
26 lambda, static_cast<T>(0.43221056), epsilon);
27 }
28
29
test_fit_weibull()30 static void test_fit_weibull()
31 {
32 test_fit_weibull_type(1e-5f,"float");
33 test_fit_weibull_type(1e-8 ,"double");
34 }
35
36 TESTMAIN(test_fit_weibull);
37