/* * Copyright (C) 2009-2011 by Benedict Paten (benedictpaten@gmail.com) * * Released under the MIT license, see LICENSE.txt */ #include "CuTest.h" #include "sonLib.h" #include "cactusReference.h" #include "adjacencyProblem.h" #include "cactusMatchingAlgorithms.h" #include "checkEdges.h" static stList *stubs; static stList *chains; static double *zMatrix; static int32_t nodeNumber; static void teardown() { if (nodeNumber != -1) { stList_destruct(stubs); stList_destruct(chains); free(zMatrix); nodeNumber = -1; } } static void setup() { teardown(); assert(nodeNumber == -1); while(nodeNumber % 2 != 0) { nodeNumber = st_randomInt(0, 100); } assert(nodeNumber >= 0); assert(nodeNumber % 2 == 0); stubs = stList_construct3(0, (void (*)(void *))stIntTuple_destruct); chains = stList_construct3(0, (void (*)(void *))stIntTuple_destruct); for(int32_t i=0; i 0); stIntTuple *edge = stIntTuple_construct(2, i, nodeNumber/2 + i); if(stList_length(stubs) == 0 || st_random(stubs) > 0.9) { stList_append(stubs, edge); } else { stList_append(chains, edge); } } zMatrix = st_calloc(nodeNumber*nodeNumber, sizeof(double)); for(int32_t i=0; i= totalScore); } teardown(); } } static void testGibbsSamplingWithSimulatedAnnealing_NoExponentiation_Greedy_Fast( CuTest *testCase) { st_logDebug("Running adjacency problem tests using gibbs sampling, but greedy sampling\n"); testGibbsSamplingWithSimulatedAnnealing(testCase, NULL, 1, 0); } static void testGibbsSamplingWithSimulatedAnnealing_NoExponentiation_Greedy( CuTest *testCase) { st_logDebug("Running adjacency problem tests using gibbs sampling, but greedy sampling\n"); testGibbsSamplingWithSimulatedAnnealing(testCase, NULL, 1, INT32_MAX); } static void testGibbsSamplingWithSimulatedAnnealing_NoExponentiation( CuTest *testCase) { st_logDebug("Running adjacency problem tests using gibbs sampling, but no exponentiation\n"); testGibbsSamplingWithSimulatedAnnealing(testCase, NULL, 0, INT32_MAX); } static void testGibbsSamplingWithSimulatedAnnealing_ConstantTemperature( CuTest *testCase) { st_logDebug("Running adjacency problem tests using gibbs sampling, but with constant temperature\n"); testGibbsSamplingWithSimulatedAnnealing(testCase, constantTemperatureFn, 0, INT32_MAX); } static void testGibbsSamplingWithSimulatedAnnealing_WithCooling( CuTest *testCase) { st_logDebug("Running adjacency problem tests using gibbs sampling, with exponentially decreasing temperature function\n"); testGibbsSamplingWithSimulatedAnnealing(testCase, exponentiallyDecreasingTemperatureFn, 0, INT32_MAX); } static double calculateZScoreSlow(int32_t n, int32_t m, int32_t k, double theta) { double score = 0.0; for(int32_t i=0; i 0.05 ? st_random() : 0.0; double zScore = calculateZScore(n, m, k, theta); double zScoreSlow = calculateZScoreSlow(n, m, k, theta); st_logDebug("The slow computed score: %f the fast computed score: %f, n: %i m: %i k: %i, theta: %lf\n", zScoreSlow, zScore, n, m, k, theta); CuAssertDblEquals(testCase, zScoreSlow, zScore, 0.000001); } } CuSuite* adjacencyProblemTestSuite(void) { CuSuite* suite = CuSuiteNew(); SUITE_ADD_TEST(suite, testMakeReferenceGreedily); SUITE_ADD_TEST(suite, testGibbsSamplingWithSimulatedAnnealing_NoExponentiation_Greedy_Fast); SUITE_ADD_TEST(suite, testGibbsSamplingWithSimulatedAnnealing_NoExponentiation_Greedy); SUITE_ADD_TEST(suite, testGibbsSamplingWithSimulatedAnnealing_NoExponentiation); SUITE_ADD_TEST(suite, testGibbsSamplingWithSimulatedAnnealing_ConstantTemperature); SUITE_ADD_TEST(suite, testGibbsSamplingWithSimulatedAnnealing_WithCooling); SUITE_ADD_TEST(suite, testCalculateZScore); return suite; }