MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / test_regression

Function test_regression

external/ggml/tests/test-opt.cpp:746–840  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

744}
745
746static std::pair<int, int> test_regression(
747 enum ggml_opt_optimizer_type optim,
748 ggml_backend_sched_t backend_sched, ggml_backend_t backend) {
749 int ntest = 0;
750 int npass = 0;
751
752 // Test for simple regression with f(x) = a*x + b
753
754 constexpr int64_t ndata_regression = 201;
755 constexpr float a_true = 1.2f;
756 constexpr float b_true = 3.4f;
757
758 std::mt19937 gen(12345);
759 std::normal_distribution<float> nd{0.0f, 0.1f};
760
761 ggml_opt_dataset_t dataset = ggml_opt_dataset_init(
762 GGML_TYPE_F32, GGML_TYPE_F32, 1, 1, ndata_regression, ndata_regression);
763
764 float * data = ggml_get_data_f32(ggml_opt_dataset_data( dataset));
765 float * labels = ggml_get_data_f32(ggml_opt_dataset_labels(dataset));
766
767 constexpr float x_min = -100.0f;
768 constexpr float x_max = 100.0f;
769
770 for (int64_t idata = 0; idata < ndata_regression; ++idata) {
771 const float x = x_min + (x_max - x_min) * idata/(ndata_regression-1);
772 const float y = a_true*x + b_true + nd(gen);
773
774 data[idata] = x;
775 labels[idata] = y;
776 }
777
778 struct ggml_context * ctx_static;
779 struct ggml_context * ctx_compute;
780 {
781 struct ggml_init_params params = {
782 /*.mem_size =*/ 3*ggml_tensor_overhead(),
783 /*.mem_buffer =*/ nullptr,
784 /*.no_alloc =*/ true,
785 };
786 ctx_static = ggml_init(params);
787 }
788 {
789 struct ggml_init_params params = {
790 /*.mem_size =*/ GGML_DEFAULT_GRAPH_SIZE*ggml_tensor_overhead() + 3*ggml_graph_overhead(),
791 /*.mem_buffer =*/ nullptr,
792 /*.no_alloc =*/ true,
793 };
794 ctx_compute = ggml_init(params);
795 }
796
797 // The first dimension is the dimension of the datapoints, the second dimension is the number of datapoints.
798 struct ggml_tensor * x = ggml_new_tensor_2d(ctx_static, GGML_TYPE_F32, 1, ndata_regression);
799 ggml_set_name(x, "x");
800
801 struct ggml_tensor * a = ggml_new_tensor_1d(ctx_static, GGML_TYPE_F32, 1);
802 ggml_set_name(a, "a");
803 ggml_set_param(a);

Callers 1

test_backendFunction · 0.85

Calls 15

ggml_opt_dataset_initFunction · 0.85
ggml_get_data_f32Function · 0.85
ggml_opt_dataset_dataFunction · 0.85
ggml_opt_dataset_labelsFunction · 0.85
ggml_tensor_overheadFunction · 0.85
ggml_initFunction · 0.85
ggml_graph_overheadFunction · 0.85
ggml_new_tensor_2dFunction · 0.85
ggml_set_nameFunction · 0.85
ggml_new_tensor_1dFunction · 0.85
ggml_set_paramFunction · 0.85
ggml_addFunction · 0.85

Tested by

no test coverage detected