Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ To add a new kernel, you need to follow these steps.

1. Place your kernel header file in the inst/include/kernels/concrete directory. The file name should match the kernel's name. For instance, if your header file is named UnivariateMaternStationary.hpp, it can be invoked using either univariate_matern_stationary or UnivariateMaternStationary. The naming linkage is handled automatically, so there's no additional setup required on your part.

2. Derive from the base class located in kernel.hpp and implement the necessary functions.
2. Derive from the base class located in Kernel.hpp and implement the necessary functions.

3. Ensure your kernel includes all the requisite functions that adhere to the established naming conventions found in other kernels. This will allow for proper support and integration of your new kernel.

Expand Down
85 changes: 85 additions & 0 deletions inst/include/kernels/concrete/UnivariatePowExpStationary.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@

// Copyright (c) 2017-2023 King Abdullah University of Science and Technology,
// All rights reserved.
// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST).

/**
* @file UnivariatePowExpStationary.hpp
* @brief Defines the UnivariatePowExpStationary class, a univariate stationary PowExp kernel.
* @version 1.0.0
* @author Mahmoud ElKarargy
* @author Sameh Abdulah
* @author Suhas Shankar
* @author Mary Lai Salvana
* @date 2024-11-22
*
* This file provides the declaration of the UnivariatePowExpStationary class, which is a subclass of the Kernel class
* and represents a univariate stationary PowExp kernel. It provides a method for generating a covariance matrix
* using a set of input locations and kernel parameters.
*
**/

#ifndef EXAGEOSTATCPP_UNIVARIATEMATERNSTATIONARY_HPP
#define EXAGEOSTATCPP_UNIVARIATEMATERNSTATIONARY_HPP

#include <kernels/Kernel.hpp>

namespace exageostat::kernels {

/**
* @class UnivariatePowExpStationary
* @brief A class representing a Univariate PowExp Stationary kernel.
* @details This class represents a Univariate PowExp Stationary, which is a subclass of the Kernel class.
* It provides a method for generating a covariance matrix using a set of input locations and kernel parameters.
*
*/
template<typename T>
class UnivariatePowExpStationary : public Kernel<T> {

public:

/**
* @brief Constructs a new UnivariatePowExpStationary object.
* @details Initializes a new UnivariatePowExpStationary object with default values.
*/
UnivariatePowExpStationary();

/**
* @brief Virtual destructor to allow calls to the correct concrete destructor.
*
*/
~UnivariatePowExpStationary() override = default;

/**
* @brief Generates a covariance matrix using a set of locations and kernel parameters.
* @copydoc Kernel::GenerateCovarianceMatrix()
*/
void
GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset,
const int &aColumnOffset, dataunits::Locations<T> &aLocation1,
dataunits::Locations<T> &aLocation2, dataunits::Locations<T> &aLocation3,
T *apLocalTheta, const int &aDistanceMetric) override;

/**
* @brief Creates a new UnivariatePowExpStationary object.
* @details This method creates a new UnivariatePowExpStationary object and returns a pointer to it.
* @return A pointer to the new UnivariatePowExpStationary object.
*
*/
static Kernel<T> *Create();

private:
//// Used plugin name for static registration
static bool plugin_name;
};

/**
* @brief Instantiates the Data Generator class for float and double types.
* @tparam T Data Type: float or double
*
*/
EXAGEOSTAT_INSTANTIATE_CLASS(UnivariatePowExpStationary)

}//namespace exageostat

#endif //EXAGEOSTATCPP_UNIVARIATEMATERNSTATIONARY_HPP
2 changes: 1 addition & 1 deletion src/kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Automatically add all kernels in the concrete directory.
file(GLOB ALL_KERNELS ${CMAKE_CURRENT_SOURCE_DIR}/concrete/*.cpp)

# Add the Configurations.cpp file to the list of source files.
# Add the kernel.cpp file to the list with other kernels.
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/Kernel.cpp
${ALL_KERNELS}
Expand Down
66 changes: 66 additions & 0 deletions src/kernels/concrete/UnivariatePowExpStationary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

// Copyright (c) 2017-2023 King Abdullah University of Science and Technology,
// All rights reserved.
// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST).

/**
* @file UnivariatePowExpStationary.cpp
* @brief Implementation of the UnivariatePowExpStationary kernel.
* @version 1.0.1
* @author Sameh Abdulah
* @author Mahmoud ElKarargy
* @date 2023-04-14
**/

#include <kernels/concrete/UnivariatePowExpStationary.hpp>
#include <helpers/DistanceCalculationHelpers.hpp>

using namespace exageostat::kernels;
using namespace exageostat::dataunits;
using namespace exageostat::helpers;

template<typename T>
UnivariatePowExpStationary<T>::UnivariatePowExpStationary() {
this->mP = 1;
this->mParametersNumber = 3;
}

template<typename T>
Kernel<T> *UnivariatePowExpStationary<T>::Create() {
KernelsConfigurations::GetParametersNumberKernelMap()["UnivariatePowExpStationary"] = 3;
return new UnivariatePowExpStationary();
}

namespace exageostat::kernels {
template<typename T> bool UnivariatePowExpStationary<T>::plugin_name = plugins::PluginRegistry<exageostat::kernels::Kernel<T>>::Add(
"UnivariatePowExpStationary", UnivariatePowExpStationary<T>::Create);
}

template<typename T>
void
UnivariatePowExpStationary<T>::GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber,
const int &aRowOffset, const int &aColumnOffset,
Locations<T> &aLocation1, Locations<T> &aLocation2,
Locations<T> &aLocation3, T *aLocalTheta,
const int &aDistanceMetric) {

const T sigma_square = aLocalTheta[0];
const T nu = aLocalTheta[2];
int i0 = aRowOffset;
int flag = 0;
int j0;
int i, j;
T dist;

for (i = 0; i < aRowsNumber; i++) {
j0 = aColumnOffset;
for (j = 0; j < aColumnsNumber; j++) {
dist = DistanceCalculationHelpers<T>::CalculateDistance(aLocation1, aLocation2, i0, j0, aDistanceMetric,
flag);
dist = pow(dist, nu);
*(apMatrixA + i + j * aRowsNumber) = (dist == 0.0) ? sigma_square : sigma_square * exp(-(dist / aLocalTheta[1]));
j0++;
}
i0++;
}
}
25 changes: 5 additions & 20 deletions tests/cpp-tests/kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,11 @@
# @author Mahmoud ElKarargy
# @date 2023-04-29

set(EXAGEOSTAT_TESTFILES
# Automatically add all kernels tests in the concrete directory.
file(GLOB ALL_KERNELS ${CMAKE_CURRENT_SOURCE_DIR}/concrete/*.cpp)

${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternStationary.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestBivariateMaternFlexible.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDsigmaSquare.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestBivariateMaternParsimonious.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternNuggetsStationary.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateSpacetimeMaternStationary.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDnu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDbeta.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDdsigmaSquare.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDdsigmaSquareBeta.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDdsigmaSquareNu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDdbetaBeta.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDdbetaNu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDdnuNu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestBivariateSpacetimeMaternStationary.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternNonGaussian.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateExpNonGaussian.cpp
${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestTrivariateMaternParsimonious.cpp
set(SOURCES
${ALL_KERNELS}
${EXAGEOSTAT_TESTFILES}
PARENT_SCOPE
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

// Copyright (c) 2017-2023 King Abdullah University of Science and Technology,
// All rights reserved.
// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST).

/**
* @file TestUnivariatePowExpStationary.cpp
* @brief Unit tests for the TestUnivariatePowExpStationary kernel in the ExaGeoStat software package.
* @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariatePowExpStationary kernel
* in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations.
* @version 1.0.0
* @author Mahmoud ElKarargy
* @author Sameh Abdulah
* @date 2024-01-16
**/

#include <catch2/catch_all.hpp>
#include <api/ExaGeoStat.hpp>
#include <hardware/ExaGeoStatHardware.hpp>

using namespace std;

using namespace exageostat::configurations;
using namespace exageostat::api;
using namespace exageostat::common;
using namespace exageostat::hardware;

void TEST_KERNEL_GENERATION_UnivariatePowExpStationary() {

SECTION("UnivariatePowExpStationary")
{

// Create a new synthetic_data_configurations object with the provided command line arguments
Configurations synthetic_data_configurations;

int N = 9;
synthetic_data_configurations.SetProblemSize(N);
synthetic_data_configurations.SetKernelName("UnivariatePowExpStationary");
synthetic_data_configurations.SetDimension(Dimension2D);

vector<double> initial_theta{1, 0.1, 0.5};
synthetic_data_configurations.SetInitialTheta(initial_theta);

int dts = 5;
synthetic_data_configurations.SetDenseTileSize(dts);
synthetic_data_configurations.SetComputation(EXACT_DENSE);
// initialize ExaGeoStat Hardware.
auto hardware = ExaGeoStatHardware(EXACT_DENSE, 3, 0);

int seed = 0;
srand(seed);
exageostat::dataunits::ExaGeoStatData<double> data;
exageostat::api::ExaGeoStat<double>::ExaGeoStatLoadData(hardware, synthetic_data_configurations,
data);

auto *CHAM_descriptorZ = data.GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR,
exageostat::common::DESCRIPTOR_Z).chameleon_desc;
auto *A = (double *) CHAM_descriptorZ->mat;
// Define the expected output
double expected_output_data[] = { -1.272336, -2.362813, 0.616384, -0.072468, 0.401498, -1.559690, 0.211848,
0.776627, -1.524810};

for (size_t i = 0; i < N; i++) {
double diff = A[i] - expected_output_data[i];
REQUIRE(diff == Catch::Approx(0.0).margin(1e-6));
}
}
}

TEST_CASE("Univariate Pow-Exp Stationary kernel test") {
TEST_KERNEL_GENERATION_UnivariatePowExpStationary();

}