/******************************************************** * ██████╗ ██████╗████████╗██╗ * ██╔════╝ ██╔════╝╚══██╔══╝██║ * ██║ ███╗██║ ██║ ██║ * ██║ ██║██║ ██║ ██║ * ╚██████╔╝╚██████╗ ██║ ███████╗ * ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝ * Geophysical Computational Tools & Library (GCTL) * * Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn) * * GCTL is distributed under a dual licensing scheme. You can redistribute * it and/or modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation, either version 2 * of the License, or (at your option) any later version. You should have * received a copy of the GNU Lesser General Public License along with this * program. If not, see . * * If the terms and conditions of the LGPL v.2. would prevent you from using * the GCTL, please consider the option to obtain a commercial license for a * fee. These licenses are offered by the GCTL's original author. As a rule, * licenses are provided "as-is", unlimited in time for a one time fee. Please * send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget * to include some description of your company and the realm of its activities. * Also add information on how to contact you by electronic and paper mail. ******************************************************/ #include "../lib/core.h" #include "../lib/algorithm.h" using namespace gctl; int main(int argc, char const *argv[]) try { array x(201); x.sequence(-1.0, 0.01); kde k(0.02, x); array d; array a(100000); a.random_float(0.2, 0.2, RdNormal, 0); k.get_distribution(a, d); gaussian_para1d g1(0, 0.2); array g(201); for (size_t i = 0; i < x.size(); i++) { g[i] = gaussian_dist1d(x[i], g1); } array dm(201); array am(100000, 0.0); /* for (size_t i = 0; i < am.size(); i++) { k.get_gradient_at(i, a, dm); for (size_t j = 0; j < x.size(); j++) { am[i] += 2.0*(d[j] - g[j])*dm[j]; } std::cout << a[i] << " " << am[i] << "\n"; } */ for (size_t i = 0; i < x.size(); i++) { std::cout << x[i] << " " << d[i] - g[i] << "\n"; } /* array a(100000), b(100000); a.random(0, 0.2, RdNormal, 0); b.random(1, 0.2, RdNormal, 0); kde2d k(0.02, a, b); array x, y; linespace(-1.0, 1.0, 201, x); linespace(0.0, 2.0, 201, y); gaussian_para2d g1(0, 1, 0.2, 0.2, 0); double t, sum = 0; for (size_t i = 0; i < y.size(); i++) { for (size_t j = 0; j < x.size(); j++) { t = k.get_density_at(x[j], y[i]); sum += t*0.01*0.01; std::cout << x[j] << " " << y[i] << " " << gaussian_dist2d(x[j], y[i], g1) << " " << t << "\n"; } } std::clog << "sum = " << sum << "\n"; */ return 0; } catch(std::exception &e) { GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0); }