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
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ add_executable(HierarchicalClustering tests/clustering/HierarchicalClusteringTes
target_compile_definitions(HierarchicalClustering PRIVATE TEST_HIERARCHICAL_CLUSTERING)
target_link_libraries(HierarchicalClustering cpp_ml_library)

add_executable(SupportVectorRegression tests/regression/SupportVectorRegressionTest.cpp)
target_compile_definitions(SupportVectorRegression PRIVATE TEST_SUPPORT_VECTOR_REGRESSION)
target_link_libraries(SupportVectorRegression cpp_ml_library)

add_executable(NeuralNetwork tests/neural_network/NeuralNetworkTest.cpp)
target_compile_definitions(NeuralNetwork PRIVATE TEST_NEURAL_NETWORK)
target_link_libraries(NeuralNetwork cpp_ml_library)

# Register individual tests
add_test(NAME LogisticRegressionTest COMMAND LogisticRegressionTest)
add_test(NAME PolynomialRegressionTest COMMAND PolynomialRegressionTest)
Expand All @@ -81,6 +89,8 @@ add_test(NAME KMeansClustering COMMAND KMeansClustering)
add_test(NAME KNNClassifier COMMAND KNNClassifier)
add_test(NAME KNNRegressor COMMAND KNNRegressor)
add_test(NAME HierarchicalClustering COMMAND HierarchicalClustering)
add_test(NAME SupportVectorRegression COMMAND SupportVectorRegression)
add_test(NAME NeuralNetwork COMMAND NeuralNetwork)


# Add example executables if BUILD_EXAMPLES is ON
Expand Down Expand Up @@ -116,6 +126,10 @@ if(BUILD_EXAMPLES)
target_compile_definitions(${EXAMPLE_TARGET} PRIVATE TEST_KNN_REGRESSOR)
elseif(EXAMPLE_NAME STREQUAL "HierarchicalClusteringExample")
target_compile_definitions(${EXAMPLE_TARGET} PRIVATE TEST_HIERARCHICAL_CLUSTERING)
elseif(EXAMPLE_NAME STREQUAL "SupportVectorRegressionExample")
target_compile_definitions(${EXAMPLE_TARGET} PRIVATE TEST_SUPPORT_VECTOR_REGRESSION)
elseif(EXAMPLE_NAME STREQUAL "NeuralNetworkExample")
target_compile_definitions(${EXAMPLE_TARGET} PRIVATE TEST_NEURAL_NETWORK)
endif()
endforeach()
endif()
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ The following machine learning algorithms are planned, inspired by concepts and
- [x] Logistic Regression
- [x] Decision Tree Regression
- [x] Random Forest Regression
- [ ] K-Nearest Neighbors
- [x] K-Nearest Neighbors


2. **Classification**
- [x] Decision Tree Classifier
- [x] Random Forest Classifier
- [ ] K-Nearest Neighbors
- [x] K-Nearest Neighbors

3. **Clustering**
- [ ] K-Means Clustering
- [ ] Hierarchical clustering
- [x] K-Means Clustering
- [x] Hierarchical clustering

4. **Neural Networks**
- [ ] Neural Network (NN)
- [x] Neural Network (NN)
- [ ] Artificial Neural Network (ANN)
- [ ] Convolutional Neural Network (CNN)

Expand All @@ -100,7 +100,7 @@ The following machine learning algorithms are planned, inspired by concepts and
| | Random Forest Classifier | [ ] | [ ] | [ ] |
| | K-Nearest Neighbors | [ ] | [ ] | [ ] |
| **Clustering** | K-Means Clustering | [ ] | [ ] | [ ] |
| **Neural Networks** | Neural Network (NN) | [x] | [ ] | [ ] |
| **Neural Networks** | Neural Network (NN) | [x] | [x] | [x] |
| | Artificial Neural Network | [ ] | [ ] | [ ] |
| | Convolutional Neural Network | [ ] | [ ] | [ ] |
| **Association Rule Learning** | Apriori | [ ] | [ ] | [ ] |
Expand Down
46 changes: 46 additions & 0 deletions examples/NeuralNetworkExample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "../ml_library_include/ml/neural_network/NeuralNetwork.hpp"
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>

/**
* @brief Utility function to display vector values.
* @param label A label for the output.
* @param v The vector to display.
*/
void showVectorVals(const std::string& label, const std::vector<double>& v) {
std::cout << label << " ";
for (double val : v) {
std::cout << val << " ";
}
std::cout << std::endl;
}

void testNeuralNetwork() {
// Set up the topology: 3 layers with 2, 4, and 1 neurons respectively
std::vector<unsigned> topology = {2, 4, 1};
NeuralNetwork myNet(topology);

// Sample input and target output
std::vector<double> inputVals = {1.0, 0.0};
std::vector<double> targetVals = {1.0};
std::vector<double> resultVals;

// Train the network with multiple iterations
for (int i = 0; i < 1000; ++i) {
myNet.feedForward(inputVals);
myNet.backProp(targetVals);
}

// Get the results after training
myNet.feedForward(inputVals);
myNet.getResults(resultVals);

showVectorVals("Inputs:", inputVals);
showVectorVals("Outputs:", resultVals);
}

int main() {
testNeuralNetwork();
}
39 changes: 39 additions & 0 deletions examples/SupportVectorRegressionExample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "../ml_library_include/ml/regression/SupportVectorRegression.hpp"
#include <iostream>

int testSupportVectorRegression() {
// Training data
std::vector<std::vector<double>> X_train = {
{1.0},
{2.0},
{3.0},
{4.0},
{5.0}
};
std::vector<double> y_train = {1.5, 2.0, 2.5, 3.0, 3.5};

// Test data
std::vector<std::vector<double>> X_test = {
{1.5},
{2.5},
{3.5}
};

// Create and train the model
SupportVectorRegression svr(1.0, 0.1, SupportVectorRegression::KernelType::RBF, 3, 0.1);
svr.fit(X_train, y_train);

// Make predictions
std::vector<double> predictions = svr.predict(X_test);

// Output predictions
for (size_t i = 0; i < predictions.size(); ++i) {
std::cout << "Sample " << i << " predicted value: " << predictions[i] << std::endl;
}

return 0;
}

int main(){
testSupportVectorRegression();
}
Loading
Loading