From da1d9ea7cc22c2f221c55fd30e8de785024c1675 Mon Sep 17 00:00:00 2001 From: Andru Liu <90433630+WallabyLester@users.noreply.github.com> Date: Tue, 8 Oct 2024 20:51:01 -0700 Subject: [PATCH] Implementing constructor. --- CPP_Implementation/rbf_model.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 CPP_Implementation/rbf_model.cpp diff --git a/CPP_Implementation/rbf_model.cpp b/CPP_Implementation/rbf_model.cpp new file mode 100644 index 0000000..50b4427 --- /dev/null +++ b/CPP_Implementation/rbf_model.cpp @@ -0,0 +1,31 @@ +#include "rbf_model.h" + +/** + * @brief Constructor to initialize the RBF model. + */ +RBFModel::RBFModel(int numCenters, int inputDim, double sigma, bool randomCenters) + : numCenters(numCenters), inputDim(inputDim), sigma(sigma) { + centers = new double*[numCenters]; // Allocate memory for centers + weights = new double[numCenters]; // Allocate memory for weights + + // Check if memory allocation was successful + if (!centers || !weights) { + if (centers) delete[] centers; // Clean up if centers allocation was successful + return; // Indicate failure (Use whatever exception handling you have) + } + + // Initialize centers and weights + for (int i = 0; i < numCenters; ++i) { + centers[i] = new double[inputDim]; // Allocate memory for each center + if (randomCenters) { + for (int j = 0; j < inputDim; ++j) { + centers[i][j] = static_cast(rand()) / RAND_MAX; // Random centers + } + } else { + for (int j = 0; j < inputDim; ++j) { + centers[i][j] = static_cast(i); // Fixed centers + } + } + weights[i] = 0.0; // Initialize weights to zero + } +}