Skip to content

Commit

Permalink
Merge branch 'bela' of github.com:jarmitage/RapidLib into bela
Browse files Browse the repository at this point in the history
  • Loading branch information
jarmitage committed Jul 11, 2022
2 parents be8c67a + 7b4c041 commit 5450baf
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions test/rapidLibTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ int main(int argc, const char * argv[])
std::vector<rapidLib::trainingSeries> testVector;
rapidLib::trainingSeries tempSeriesTest;

for (int i = 0; i < 5; ++i) {
for (std::size_t i = 0; i < 5; ++i)
{
tempSeriesTest.input.push_back({ 0.1, 0.1, 0.1 });
}
tempSeriesTest.label = "zzz";
Expand Down Expand Up @@ -195,18 +196,22 @@ int main(int argc, const char * argv[])

//Testing exceptions for regression
std::vector<double> emptyVec = {};
try {
try
{
myNN.run(emptyVec);
}
catch (const std::length_error& e) {
catch (const std::length_error& e)
{
assert(e.what() == std::string("bad input size: 0"));
}

std::vector<double> wrongSizeVector = { 1, 1, 1, 1, 1, 1 };
try {
try
{
myNN.run(wrongSizeVector);
}
catch (const std::length_error& e) {
catch (const std::length_error& e)
{
assert(e.what() == std::string("bad input size: 6"));
}
std::cout << "----- Regression run exceptions passed." << std::endl;
Expand All @@ -222,10 +227,12 @@ int main(int argc, const char * argv[])
badExample.output = { 4.0 };
badSet.push_back(badExample);

try {
try
{
badNN.train(badSet);
}
catch (const std::length_error& e) {
catch (const std::length_error& e)
{
assert(e.what() == std::string("unequal feature vectors in input."));
}

Expand All @@ -238,10 +245,12 @@ int main(int argc, const char * argv[])
badExample.output = { 4.0, 5.0 };
badSet.push_back(badExample);

try {
try
{
badNN.train(badSet);
}
catch (const std::length_error& e) {
catch (const std::length_error& e)
{
assert(e.what() == std::string("unequal output vectors."));
}
std::cout << "----- Regression train exceptions passed." << std::endl;
Expand Down Expand Up @@ -271,17 +280,22 @@ int main(int argc, const char * argv[])
assert(myKnn.run(inputVec)[0] == myKnnFromString.run(inputVec)[0]);
assert(myKnn.run(inputVec)[0] == myKnnFromFile.run(inputVec)[0]);

try {
std::cout << "These errors are part of the test:" << std::endl;
try
{
myKnn.run(emptyVec);
}
catch (const std::length_error& e) {
catch (const std::length_error& e)
{
std::cout << "error: " << e.what() << std::endl;
assert(e.what() == std::string("bad input size: 0"));
}
try {
try
{
myKnn.run(wrongSizeVector);
}
catch (const std::length_error& e) {
catch (const std::length_error& e)
{
std::cout << "error: " << e.what() << std::endl;
assert(e.what() == std::string("bad input size: 6"));
}
Expand All @@ -298,18 +312,21 @@ int main(int argc, const char * argv[])
std::default_random_engine generator;
std::uniform_real_distribution<float> distribution(-0.5, 0.5);
int vecLength = 64;
for (int j = 0; j < vecLength; ++j) {
for (std::size_t j = 0; j < vecLength; ++j)
{
tempExample2.input.clear();
tempExample2.output.clear();
for (int i = 0; i < vecLength; ++i) {
for (std::size_t i = 0; i < vecLength; ++i)
{
tempExample2.input.push_back(distribution(generator));
}
tempExample2.output = { distribution(generator) };
trainingSet2.push_back(tempExample2);
}
// bigVector.train(trainingSet2);
std::vector<float> inputVec2;
for (int i = 0; i < vecLength; ++i) {
for (std::size_t i = 0; i < vecLength; ++i)
{
inputVec2.push_back(distribution(generator));
}
// assert (isfinite(bigVector.run(inputVec2)[0]));
Expand Down Expand Up @@ -453,18 +470,20 @@ int main(int argc, const char * argv[])
*/

//Long dtw test
int testSize = 800;
std::size_t testSize = 800;
seriesVector.clear();
std::vector<std::vector<double> > inputSeries;
tempSeries.input.clear();
for (int i = 0; i < testSize; ++i) {
for (std::size_t i = 0; i < testSize; ++i)
{
tempSeries.input.push_back({ (double)i, (double)i });
}
tempSeries.label = "long up";
seriesVector.push_back(tempSeries);

tempSeries.input.clear();
for (int i = 0; i < testSize; ++i) {
for (std::size_t i = 0; i < testSize; ++i)
{
tempSeries.input.push_back({ (double)i, double(testSize - i) });
}
tempSeries.label = "long down";
Expand Down Expand Up @@ -515,12 +534,12 @@ int main(int argc, const char * argv[])
mtofRegression.train(trainingSet_mtof);

//Get some user input
int newNote = 0;
char newNote { 0 };
std::cout << "Type a MIDI note number.\n"; std::cin >> newNote;

//Run the trained model on the user input
std::vector<double> inputVec_mtof = { double(newNote) };
double freqHz = mtofRegression.run(inputVec_mtof)[0];
double freqHz { mtofRegression.run(inputVec_mtof)[0] };

std::cout << "MIDI note " << newNote << " is " << freqHz << " Hertz" << std::endl;
#endif
Expand Down

0 comments on commit 5450baf

Please sign in to comment.