V;
- P generator;
- pair findLocatorAndEvaluator(P const& syndromePoly, int t)const
- {
- P evPrev(ari, V(1, ari.one())), ev = syndromePoly,
- locPrev = P::zero(ari), loc = evPrev;
- evPrev <<= t;
- while(ev.degree() >= t/2)
- {
- P q(ari);
- evPrev.reduce(ev, q);
- swap(ev, evPrev);
- locPrev -= q * loc;
- swap(loc, locPrev);
- }//normalize them
- if(loc != P::zero(ari))
- {
- int normalizer = ari.div(ari.one(), loc[0]);
- loc *= normalizer;
- ev *= normalizer;
- }
- return make_pair(loc, ev);
- }
-public:
- ReedSolomon(int theK = 223, int primPoly = 301): ari(primPoly),
- generator(ari, V(1, 1)), k(theK),
- n(twoPower(lgFloor(primPoly)) - 1)
- {
- assert(k < n && numeric_limits::digits == 8);
- P x = P::makeX(ari);
- for(int i = 0, aPower = ari.alpha(); i < n - k; ++i)
- {
- generator *= (x - P(ari, V(1, aPower)));
- aPower = ari.mult(aPower, ari.alpha());
- }
- assert(generator.getSize() == n - k + 1);
- }
- V lengthPadBlock(V block)
- {
- assert(block.getSize() < k);
- block.append(block.getSize());
- while(block.getSize() < k) block.append(0);
- return block;
- }
- pair lengthUnpadBlock(V block)
- {
- assert(block.getSize() == k);
- while(block.getSize() >= 0 && block.lastItem() == 0)block.removeLast();
- bool correct = block.getSize() >= 0 &&
- block.lastItem() == block.getSize() - 1;
- assert(correct);
- if(correct) block.removeLast();
- return make_pair(block, correct);
- }
- V encodeBlock(V const& block)const
- {
- assert(block.getSize() == k);
- P c(ari, block);//init c
- c <<= (n - k);//make space for code
- c += c % generator;//add code
- //beware of poly trim if block is 0
- while(c.storage.getSize() < n) c.storage.append(0);
- return c.storage;
- }
- pair decodeBlock(V const& code)const
- {//calculate syndrome polynomial
- assert(code.getSize() == n);
- P c(ari, code);
- int t = n - k, aPower = ari.alpha();
- V syndromes(t);
- for(int i = 0; i < t; ++i)
- {
- syndromes[i] = c.eval(aPower);
- aPower = ari.mult(aPower, ari.alpha());
- }
- P s(ari, syndromes);
- if(s == P::zero(ari))//no error if yes
- {//take out check data and restore trimmed 0's
- c >>= t;
- while(c.storage.getSize() < k) c.storage.append(0);
- return make_pair(c.storage, true);
- }//find locator and evaluator polys
- pair locEv = findLocatorAndEvaluator(s, t);
- if(locEv.first == P::zero(ari)) return make_pair(code, false);
- //find locator roots
- V roots;
- for(int i = 1; i < n + 1; ++i)
- if(locEv.first.eval(i) == 0) roots.append(i);
- if(roots.getSize() == 0) return make_pair(code, false);
- //find error values
- P fd = locEv.first.formalDeriv();
- V errors;
- for(int i = 0; i < roots.getSize(); ++i) errors.append(ari.sub(0,
- ari.div(locEv.second.eval(roots[i]), fd.eval(roots[i]))));
- //correct errors
- while(c.storage.getSize() < n) c.storage.append(0);
- for(int i = 0; i < roots.getSize(); ++i)
- {
- int location = ari.elementToPower(ari.div(ari.one(), roots[i]));
- assert(location < c.getSize());
- c.storage[location] = ari.add(c.storage[location], errors[i]);
- }
- if(c % generator != P::zero(ari)) return make_pair(code, false);
- c >>= t;
- return make_pair(c.storage, true);
- }
-};
-
-}//end namespace
-#endif
diff --git a/src/tmp/ImplementingUsefulAlgorithms/ErrorCorrectingCodes/test.cpp b/src/tmp/ImplementingUsefulAlgorithms/ErrorCorrectingCodes/test.cpp
deleted file mode 100644
index 5a1ce6a..0000000
--- a/src/tmp/ImplementingUsefulAlgorithms/ErrorCorrectingCodes/test.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-#include
-#include
-#include "ErrorCorrectingCodesTestAuto.h"
-using namespace std;
-using namespace igmdk;
-
-void testLDPCAuto()//takes ~100 seconds on my pc
-{//not quite auto need better statistical tests here
- int n = 20, k = 5;
- int nFailed = 0, nFalseSuccess = 0, nCodes = 100, nTests = 100;
- for(int m = 0; m < nCodes; ++m)
- {
- LDPC l(n, k);
- Bitset<> message(l.getNewK());
- for(int i = 0; i < message.getSize(); ++i)
- message.set(i, GlobalRNG().mod(2));//random message
- for(int j = 0; j < nTests; ++j)
- {
- Bitset<> code = l.encode(message);
- //below use the worst-case bound but need to try other values
- for(int i = 0; i < (n - l.getNewK())/2; ++i)
- code.set(GlobalRNG().mod(code.getSize()), GlobalRNG().mod(2));
-
- pair, bool> result = l.decode(code);
- if(!result.second) ++nFailed;
- else if(message != result.first) ++nFalseSuccess;
- }
- }
- DEBUG(nFailed * 1.0/nTests/nCodes);//0.34 particular run
- DEBUG(nFalseSuccess * 1.0/nTests/nCodes);//0.09 particular run
-}
-
-void testLDPC()
-{
- LDPC l(20, 5);
- Bitset<> message(l.getNewK());
- message.setAll();
- message.set(1, 0);
- message.set(0, 0);
- DEBUG("message");
- message.debug();
- Bitset<> code = l.encode(message);
- DEBUG("code");
- code.debug();
- for(int i = 0; i < 3; ++i)
- code.set(GlobalRNG().mod(code.getSize()), GlobalRNG().mod(2));
- DEBUG("code");
- code.debug();
- pair, bool> result = l.decode(code);
- message = result.first;
- DEBUG(result.second);
- DEBUG("message");
- message.debug();//fails very occasionally
-}
-
-int main()
-{
- testAllAutoErrorCorrectingCodes();
- testLDPC();
- testLDPCAuto();
- return 0;
-}
diff --git a/src/tmp/ImplementingUsefulAlgorithms/ExternalMemoryAlgorithms/CSV.h b/src/tmp/ImplementingUsefulAlgorithms/ExternalMemoryAlgorithms/CSV.h
deleted file mode 100644
index a8a9cc8..0000000
--- a/src/tmp/ImplementingUsefulAlgorithms/ExternalMemoryAlgorithms/CSV.h
+++ /dev/null
@@ -1,140 +0,0 @@
-#ifndef IGMDK_CSV_H
-#define IGMDK_CSV_H
-
-#include "File.h"
-#include "../RandomNumberGeneration/MultipleComparison.h"
-using namespace std;
-namespace igmdk{
-
-void createCSV(Vector > const& matrix, const char* filename)
-{
- ofstream file(filename);
- assert(file);
- for(int i = 0; i < matrix.getSize(); ++i)
- {
- for(int j = 0; j < matrix[i].getSize(); ++j)
- {
- if(j > 0) file << ",";
- file << matrix[i][j];
- }
- file << endl;
- }
-}
-
-Vector > > splitRegularMatrix(
- Vector > const& matrix, int nMetrics)
-{//must have proper number of columns in every row
- assert(nMetrics > 0);//calculate the number of row, columns,
- //and metrics
- for(int i = 0; i < matrix.getSize(); ++i)
- assert((matrix[i].getSize() - 1) % (nMetrics + 1) == 0);
- int nNewRows = matrix.getSize() + 1,
- nNewColumns = 1 + (matrix[0].getSize() - 1)/(nMetrics + 1);
- //do the splitting
- Vector > > result(nMetrics,
- Vector >(nNewRows, Vector(nNewColumns)));
- for(int i = 0; i < nMetrics; ++i)
- {//copy over algorithms names from first row
- for(int c = 1; c < nNewColumns; ++c) result[i][0][c] =
- matrix[1][1 + (c - 1) * (nMetrics + 1)];
- for(int r = 1; r < nNewRows; ++r)
- {//copy over problem metricNames
- result[i][r][0] = matrix[r - 1][0];
- //copy over all relevant columns
- for(int c = 1; c < nNewColumns; ++c) result[i][r][c] =
- matrix[r - 1][2 + i + (c - 1) * (nMetrics + 1)];
- }
- }
- return result;
-}
-
-
-string cellValue(int r, int c)
-{//convert cell and reference
- return "INDIRECT(ADDRESS(" + to_string(r + 1) + ";" +
- to_string(c + 1) + ";4))";
-}
-string fixNumber(int r, int c)
-{//convert cell, reference, and convert to number if scientific notation
- return "VALUE(TRIM(" + cellValue(r, c) + "))";
-}
-string rankFormula(int r, int c, int c0, int cLast)
-{//rank column c in range [c0, cLast] in given row
- return "RANK(" + cellValue(r, c) + ";" + cellValue(r, c0) +
- ":" + cellValue(r, cLast) + ";1)";
-}
-string minFormula(int r, int c0, int cLast)
- {return "MIN(" + cellValue(r, c0) + ":" + cellValue(r, cLast) + ")";}
-string aveFormula(int r0, int c0, int rLast, int cLast)
-{//average over a row to a column
- assert(r0 == rLast || c0 == cLast);
- return "AVERAGE(" + cellValue(r0, c0) + ":" +
- cellValue(rLast, cLast) + ")";
-}
-
-void augmentComparableMatrix(Vector >& matrix, int nRepeats = 1)
-{//assume first row is algorithm names + first column problem names
- int nDataRows = matrix.getSize() - 1, nColumns = matrix[0].getSize();
- //append empty row as separator
- matrix.append(Vector(nColumns, ""));
- //extract numerical values in all columns
- int fixedStart = matrix.getSize();
- for(int r = 0; r < nDataRows; ++r)
- {
- Vector newRow(nColumns, "");
- for(int c = 1; c < nColumns; c++)
- newRow[c] = string("=") + fixNumber(1 + r, c);
- matrix.append(newRow);
- }
- //append empty row as separator
- matrix.append(Vector(nColumns, ""));
- //make rank formulas for all data points
- for(int r = 0; r < nDataRows; ++r)
- {
- Vector newRow(nColumns, "");
- for(int c = 1; c < nColumns; c++) newRow[c] = string("=") +
- rankFormula(fixedStart + r, c, 1, nColumns - 1);
- matrix.append(newRow);
- }
- //average the ranks in each column
- Vector newRow2(nColumns, "Ave Ranks");
- for(int c = 1; c < nColumns; c++) newRow2[c] = string("=") + aveFormula(
- matrix.getSize() - nDataRows, c, matrix.getSize() - 1, c);
- matrix.append(newRow2);
- //rank the averages
- Vector newRow(nColumns, "Total Rank");
- for(int c = 1; c < nColumns; c++) newRow[c] = string("=") +
- rankFormula(matrix.getSize() - 1, c, 1, nColumns - 1);
- matrix.append(newRow);
- //find significant rankDifference
- double maxDiff = findNemenyiSignificantAveRankDiff(nColumns - 1,
- nDataRows/nRepeats);
- Vector newRow3(nColumns, toStringDouble(maxDiff));
- newRow3[0] = "Significant Diff";
- matrix.append(newRow3);
- Vector newRow4(nColumns, "Cutoff Rank");
- for(int c = 1; c < nColumns; c++) newRow4[c] = string("=") +
- minFormula(matrix.getSize() - 3, 1, nColumns - 1) + "+" +
- cellValue(matrix.getSize() - 1, c);
- matrix.append(newRow4);
- Vector newRow5(nColumns, "Same as Best");
- for(int c = 1; c < nColumns; c++) newRow5[c] = string("=") + "IF(" +
- cellValue(matrix.getSize() - 1, c) + ">" +
- cellValue(matrix.getSize() - 4, c) + ";1;0)";
- matrix.append(newRow5);
-}
-
-void createAugmentedCSVFiles(Vector > const& matrix,
- Vector const& metricNames, string filename, int nRepeats = 1)
-{
- Vector > > pieces(
- splitRegularMatrix(matrix, metricNames.getSize()));
- for(int i = 0; i < pieces.getSize(); ++i)
- {
- augmentComparableMatrix(pieces[i], nRepeats);
- createCSV(pieces[i], (metricNames[i] + "_" + filename).c_str());
- }
-}
-
-}//end namespace
-#endif
diff --git a/src/tmp/ImplementingUsefulAlgorithms/ExternalMemoryAlgorithms/EMBTree.h b/src/tmp/ImplementingUsefulAlgorithms/ExternalMemoryAlgorithms/EMBTree.h
deleted file mode 100644
index 04d6b0c..0000000
--- a/src/tmp/ImplementingUsefulAlgorithms/ExternalMemoryAlgorithms/EMBTree.h
+++ /dev/null
@@ -1,286 +0,0 @@
-#ifndef IGMDK_EMBT_H
-#define IGMDK_EMBT_H
-#include "EMVector.h"
-#include "EMFreelist.h"
-namespace igmdk{
-
-template, typename VALUE_SERIALIZER = CastSerializer >
- class EMBPlusTree
-{
- typedef KVPair Key;
- typedef KVPair Record;
- //satisfy the constraints on M and L, but first from internal node make
- //space for size and from leaf also the next pointer
- enum{NULL_IO_POINTER = -1, NODE_SIZE_BYTES = 4, POINTER_SIZE = 8,
- KEY_SIZE = KEY_SERIALIZER::byteSize() + POINTER_SIZE, RECORD_SIZE =
- KEY_SERIALIZER::byteSize() + VALUE_SERIALIZER::byteSize(), B =
- BlockFile::targetBlockSize() - NODE_SIZE_BYTES, M = 2 * min