2024-09-10 15:45:07 +08:00
|
|
|
/********************************************************
|
|
|
|
* ██████╗ ██████╗████████╗██╗
|
|
|
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
|
|
|
* ██║ ███╗██║ ██║ ██║
|
|
|
|
* ██║ ██║██║ ██║ ██║
|
|
|
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
|
|
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* 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
|
2024-10-09 14:11:00 +08:00
|
|
|
{
|
|
|
|
/*
|
2024-09-30 14:15:16 +08:00
|
|
|
array<double> x(201);
|
|
|
|
x.sequence(-1.0, 0.01);
|
|
|
|
kde k(0.02, x);
|
|
|
|
|
|
|
|
array<double> d;
|
2024-09-10 15:45:07 +08:00
|
|
|
array<double> a(100000);
|
2024-09-30 14:15:16 +08:00
|
|
|
a.random_float(0.2, 0.2, RdNormal, 0);
|
|
|
|
k.get_distribution(a, d);
|
2024-09-10 15:45:07 +08:00
|
|
|
|
|
|
|
gaussian_para1d g1(0, 0.2);
|
2024-09-30 14:15:16 +08:00
|
|
|
array<double> g(201);
|
2024-09-10 15:45:07 +08:00
|
|
|
for (size_t i = 0; i < x.size(); i++)
|
|
|
|
{
|
2024-09-30 14:15:16 +08:00
|
|
|
g[i] = gaussian_dist1d(x[i], g1);
|
2024-09-10 15:45:07 +08:00
|
|
|
}
|
|
|
|
|
2024-09-30 14:15:16 +08:00
|
|
|
array<double> dm(201);
|
|
|
|
array<double> am(100000, 0.0);
|
2024-10-09 14:11:00 +08:00
|
|
|
|
2024-09-30 14:15:16 +08:00
|
|
|
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";
|
|
|
|
}
|
2024-10-09 14:11:00 +08:00
|
|
|
*/
|
2024-09-30 14:15:16 +08:00
|
|
|
|
2024-10-09 14:11:00 +08:00
|
|
|
array<double> x(201), y(301);
|
|
|
|
x.sequence(-1.0, 0.01);
|
|
|
|
y.sequence(0.0, 0.01);
|
2024-10-09 14:30:46 +08:00
|
|
|
kde2d k(0.1, 0.1, x, y);
|
2024-10-09 14:11:00 +08:00
|
|
|
|
|
|
|
array<double> a(10000), b(10000);
|
|
|
|
a.random_float(0, 0.2, RdNormal, 0);
|
|
|
|
b.random_float(1.5, 0.3, RdNormal, 0);
|
|
|
|
|
|
|
|
gaussian_para2d g1(0, 1.5, 0.2, 0.3, 0);
|
2024-09-10 15:45:07 +08:00
|
|
|
|
2024-10-09 14:11:00 +08:00
|
|
|
array<double> d(201*301);
|
|
|
|
//k.get_distribution(a, b, d);
|
|
|
|
|
|
|
|
a[0] = 0;
|
|
|
|
b[0] = 1.5;
|
2024-10-09 20:22:22 +08:00
|
|
|
k.get_gradient_y_at(0, a, b, d);
|
2024-09-10 15:45:07 +08:00
|
|
|
|
|
|
|
double t, sum = 0;
|
|
|
|
for (size_t i = 0; i < y.size(); i++)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < x.size(); j++)
|
|
|
|
{
|
|
|
|
std::cout << x[j] << " " << y[i] << " "
|
2024-10-09 14:11:00 +08:00
|
|
|
//<< gaussian_dist2d(x[j], y[i], g1) << " "
|
|
|
|
<< d[201*i + j] << "\n";
|
2024-09-10 15:45:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
catch(std::exception &e)
|
|
|
|
{
|
|
|
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
|
|
|
}
|