Permalink
Browse files

Initial import, switched from svn to git.

  • Loading branch information...
0 parents commit 1ecfed5e4a48404bd8d9ca7a50a5ae539b075364 @jwf committed Nov 4, 2009
Showing with 126,929 additions and 0 deletions.
  1. +414 −0 .cproject
  2. +82 −0 .project
  3. +169 −0 BuildTree.cpp
  4. +11 −0 BuildTree.h
  5. BIN BuildTree.o
  6. +116 −0 Classifier.cpp
  7. +27 −0 Classifier.h
  8. BIN Classifier.o
  9. +166 −0 ClassifyTrajectory.cpp
  10. +24 −0 ClassifyTrajectory.h
  11. BIN ClassifyTrajectory.o
  12. +19 −0 Makefile
  13. BIN ManifoldExperiment.o
  14. +227 −0 TDEModel.cpp
  15. +49 −0 TDEModel.h
  16. BIN TDEModel.o
  17. +92 −0 Utils.cpp
  18. +44 −0 Utils.h
  19. BIN Utils.o
  20. BIN buildtree
  21. BIN classifytrajectory
  22. +6 −0 data/.svn/dir-prop-base
  23. +342 −0 data/.svn/entries
  24. +11,845 −0 data/.svn/text-base/bike-2009-03-18.csv.svn-base
  25. +1,770 −0 data/.svn/text-base/bike.dat.svn-base
  26. +4,675 −0 data/.svn/text-base/mixed.dat.svn-base
  27. +7,496 −0 data/.svn/text-base/run-2009-03-02.csv.svn-base
  28. +1,701 −0 data/.svn/text-base/run.dat.svn-base
  29. +501 −0 data/.svn/text-base/stand.dat.svn-base
  30. +867 −0 data/.svn/text-base/standing-2009-02-27.csv.svn-base
  31. +2,870 −0 data/.svn/text-base/walk-2009-02-27-1.csv.svn-base
  32. +1,701 −0 data/.svn/text-base/walk.dat.svn-base
  33. +1,351 −0 data/amin-train.dat
  34. +4,007 −0 data/amin-train.dat.dmp
  35. +11,845 −0 data/bike-2009-03-18.csv
  36. +1,770 −0 data/bike.dat
  37. +5,246 −0 data/bike.dat.dmp
  38. +1,351 −0 data/cosmin-train.dat
  39. +4,007 −0 data/cosmin-train.dat.dmp
  40. +4,675 −0 data/mixed.dat
  41. +14,011 −0 data/mixed.dat.dmp
  42. +1,251 −0 data/robert-train.dat
  43. +3,707 −0 data/robert-train.dat.dmp
  44. +7,496 −0 data/run-2009-03-02.csv
  45. +1,701 −0 data/run.dat
  46. +5,063 −0 data/run.dat.dmp
  47. 0 data/short.dat.dmp
  48. +1,351 −0 data/sophia-train.dat
  49. +4,007 −0 data/sophia-train.dat.dmp
  50. +4,007 −0 data/sophia-train.dat.dmp2
  51. +501 −0 data/stand.dat
  52. +1,466 −0 data/stand.dat.dmp
  53. +867 −0 data/standing-2009-02-27.csv
  54. +2,870 −0 data/walk-2009-02-27-1.csv
  55. +1,701 −0 data/walk.dat
  56. +5,039 −0 data/walk.dat.dmp
  57. +1,204 −0 data/walks-test.dat
  58. 0 data/walks-test.dat.dmp
  59. +1,171 −0 data/walks-test.out
  60. +4 −0 models-activities.ini
  61. +4 −0 models.ini
  62. +31 −0 plottrajectory.r
  63. +11 −0 run-walks-test.sh
  64. 0 stdin.dmp
414 .cproject

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ManifoldExperiment</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+ <triggers>clean,full,incremental,</triggers>
+ <arguments>
+ <dictionary>
+ <key>?name?</key>
+ <value></value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.append_environment</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.autoBuildTarget</key>
+ <value>all</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.buildArguments</key>
+ <value></value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.buildCommand</key>
+ <value>make</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.buildLocation</key>
+ <value>${workspace_loc:/ManifoldExperiment}</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
+ <value>clean</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.contents</key>
+ <value>org.eclipse.cdt.make.core.activeConfigSettings</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.enableAutoBuild</key>
+ <value>false</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.enableCleanBuild</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.enableFullBuild</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.fullBuildTarget</key>
+ <value>all</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.stopOnError</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
+ <value>false</value>
+ </dictionary>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.cdt.core.cnature</nature>
+ <nature>org.eclipse.cdt.core.ccnature</nature>
+ <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+ <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,169 @@
+//============================================================================
+// Name : ManifoldExperiment.cpp
+// Author :
+// Version :
+// Copyright : BSD
+// Description : Constructs a time-delay embedding of the data, equipped with
+// a model of the dynamics using an approximation of the
+// one step transition matrix based on averaging the sample
+// dynamics of the k-nearest neighbours.
+//============================================================================
+/*
+ * main.cpp
+ *
+ * Created on: Jun 28, 2009
+ * Author: jordan
+ */
+
+#include <stdlib.h>
+#include <cstring>
+#include <ctype.h>
+#include <iostream>
+#include <fstream>
+#include <ANN/ANN.h>
+#include <Tisean/tsa.h>
+
+#include "Utils.h"
+#include "BuildTree.h"
+#include "TDEModel.h"
+
+using namespace std;
+
+using namespace std;
+
+#define WID_STR "Build a model"
+
+void show_options(char *progname) {
+ what_i_do(progname, (char*)WID_STR);
+ fprintf(stderr,"\nUsage: %s [options]\n",progname);
+ fprintf(stderr,"Options:\n");
+ fprintf(stderr,"Everything not being a valid option will be interpreted as a"
+ " possible datafile.\nIf no datafile is given stdin is read."
+ " Just - also means stdin\n");
+ fprintf(stderr,"\t-l # of data [default: whole file]\n");
+ fprintf(stderr,"\t-x # of rows to ignore [default: 0]\n");
+ fprintf(stderr,"\t-M num. of columns to read [default: 1]\n");
+ fprintf(stderr,"\t-c columns to read [default: 1,...,M]\n");
+ fprintf(stderr,"\t-m dimension [default: 2]\n");
+ fprintf(stderr,"\t-p # dimension to reduce to using PCA [default: same as m, ie. no reduction]\n");
+ fprintf(stderr,"\t-d delay [default: 1]\n");
+ fprintf(stderr,"\t-V verbosity level [default: 1]\n\t\t"
+ "0='only panic messages'\n\t\t"
+ "1='+ input/output messages'\n");
+ fprintf(stderr,"\t-o output file [default: 'datafile'.del, "
+ "without -o: stdout]\n");
+ fprintf(stderr,"\t-h show these options\n");
+ exit(0);
+}
+void scan_options(int n,char **str, Settings *settings) {
+ char *out;
+ if ((out=check_option(str,n,'l','u')) != NULL)
+ sscanf(out,"%lu",&settings->length);
+ if ((out=check_option(str,n,'x','u')) != NULL)
+ sscanf(out,"%lu",&settings->exclude);
+ if ((out=check_option(str,n,'c','s')) != NULL)
+ settings->column=out;
+ if ((out=check_option(str,n,'M','u')) != NULL) {
+ sscanf(out,"%u",&settings->indim);
+ settings->dimset=1;
+ }
+ if ((out=check_option(str,n,'m','u')) != NULL) {
+ sscanf(out,"%u",&settings->embdim);
+ settings->embset=1;
+ }
+ if ((out=check_option(str,n,'p','u')) != NULL) {
+ sscanf(out,"%u",&settings->pcaembdim);
+ settings->pcaembset=1;
+ }
+ if ((out=check_option(str,n,'d','u')) != NULL) {
+ sscanf(out,"%u",&settings->delay);
+ settings->delayset=1;
+ }
+ if ((out=check_option(str,n,'V','u')) != NULL)
+ sscanf(out,"%u",&settings->verbosity);
+ if ((out=check_option(str,n,'o','o')) != NULL) {
+ settings->stdo=0;
+ if (strlen(out) > 0)
+ settings->outfile=out;
+ }
+}
+
+int main (int argc, char *argv[]) {
+ srand((unsigned)time(NULL));
+ TDEModel *tdeModel;
+ Settings settings = { ULONG_MAX, 0, 0xff, 1, 1, 2, 2, NULL, NULL, NULL, 0, 0, 0, 0, 1 };
+ char stin=0;
+ uint i, j;
+
+ if (scan_help(argc,argv))
+ show_options(argv[0]);
+ scan_options(argc,argv, &settings);
+
+ settings.infile=search_datafile(argc,argv,NULL,settings.verbosity);
+ if (settings.infile == NULL)
+ stin=1;
+ if (settings.outfile == NULL) {
+ if (!stin) {
+ check_alloc(settings.outfile=(char*)calloc(strlen(settings.infile)+5,sizeof(char)));
+ strcpy(settings.outfile,settings.infile);
+ strcat(settings.outfile,".dmp");
+ } else {
+ check_alloc(settings.outfile=(char*)calloc(10,sizeof(char)));
+ strcpy(settings.outfile,"stdin.dmp");
+ }
+ }
+ if (!settings.stdo) {
+ test_outfile(settings.outfile);
+ }
+
+ if (settings.delay < 1) {
+ fprintf(stderr,"Delay has to be larger than 0. Exiting!\n");
+ exit(DELAY_SMALL_ZERO);
+ }
+
+ if (!settings.pcaembset) {
+ settings.pcaembdim = settings.embdim;
+ }
+
+ tdeModel = new TDEModel(&settings);
+ tdeModel->DumpTree(settings.outfile);
+
+ ANNpoint ap = tdeModel->getDataPoint(0);
+ uint N = 1000;
+ ANNpointArray pts = annAllocPts(N, settings.embdim);;
+ tdeModel->simulateTrajectory(ap, pts, settings.embdim, N);
+
+/*
+ uint k = 8;
+ ANNidxArray nn_idx;
+ ANNdistArray dists;
+ nn_idx = new ANNidx[k];
+ dists = new ANNdist[k];
+
+ tdeModel->getKNN(ap, k, nn_idx, dists);
+
+
+ delete [] nn_idx;
+ delete [] dists;
+*/
+ // DUMP Manifold and Trajectory
+ ofstream fout("/tmp/trajectory.csv");
+ for (i = 0; i < N; i++) {
+ fout << pts[i][0];
+ for (j = 1; j < settings.embdim; j++) {
+ fout << "\t";
+ fout << pts[i][j];
+ }
+ fout << endl;
+ }
+ fout.close();
+ annDeallocPt(ap);
+ delete [] pts;
+
+ delete tdeModel;
+ annClose();
+ if (settings.column != NULL) free(settings.column);
+ if (settings.infile != NULL) free(settings.infile);
+ if (settings.outfile != NULL) free(settings.outfile);
+ return 0;
+}
@@ -0,0 +1,11 @@
+/*
+ * ManifoldExperiment.h
+ *
+ * Created on: 2009-06-29
+ * Author: jfrank8
+ */
+
+#ifndef MANIFOLDEXPERIMENT_H_
+#define MANIFOLDEXPERIMENT_H_
+
+#endif /* MANIFOLDEXPERIMENT_H_ */
Binary file not shown.
@@ -0,0 +1,116 @@
+/*
+ * Classifier.cpp
+ *
+ * Created on: 2009-06-30
+ * Author: jfrank8
+ */
+
+#include <stdlib.h>
+#include <vector>
+#include <omp.h>
+#include <ANN/ANN.h>
+
+#include "ClassifyTrajectory.h"
+#include "Classifier.h"
+
+#define MATCH_STEPS 32
+#define NEIGHBOURS 4
+
+using namespace std;
+
+Classifier::Classifier(vector<NamedModel*> models) {
+ this->models = models;
+}
+
+Classifier::~Classifier() {
+ // TODO Auto-generated destructor stub
+}
+
+void Classifier::go(double** data, ulong length) {
+ // For each set of MATCH_STEPS points, compute the likelihood under each model.
+ TDEModel* model;
+ uint M = models.size();
+ char* model_name;
+ double *projected_data;
+ ANNpointArray ap;
+ ANNidx nn_idx[NEIGHBOURS+1];
+ ANNdist dists[NEIGHBOURS+1];
+ CvMat *navg[M], *navg_next[M], *proj_next[M];
+ CvMat p, *mdists, *nn[M], *nnn[M];
+ ulong i,j,k,l,a,N,pcaembdim;
+ double dist, dist_next, *dst, *p1, *p2, *p3, *p4;
+ mdists = cvCreateMat(length-MATCH_STEPS-1,models.size(),CV_64FC1);
+ cvZero(mdists);
+
+ for (i = 0; i < M; i++) {
+ pcaembdim = models[i]->model->getPCAEmbDim();
+ navg[i] = cvCreateMat(1,pcaembdim,CV_64FC1);
+ navg_next[i] = cvCreateMat(1,pcaembdim,CV_64FC1);
+ proj_next[i] = cvCreateMat(1,pcaembdim, CV_64FC1);
+ nn[i] = cvCreateMat(NEIGHBOURS,pcaembdim, CV_64FC1);
+ nnn[i] = cvCreateMat(NEIGHBOURS,pcaembdim, CV_64FC1);
+ }
+
+ for (i = 0; i < length-MATCH_STEPS-1; i++) { //=MATCH_STEPS) {
+ // Get the MATCH_STEPS points
+ // cout << "Step " << i << endl;
+ for (k = 0; k < M; k++) {
+ model = models[k]->model;
+ model_name = models[k]->name;
+ N = model->getLength();
+ pcaembdim = model->getPCAEmbDim();
+ //projected_data = model->projectData(data+i*embdim,MATCH_STEPS+1,embdim);
+ get_ann_points(ap, data[k]+i*pcaembdim, MATCH_STEPS+1, pcaembdim);
+
+ for (j = 0; j < MATCH_STEPS; j++) {
+ p = cvMat(1,pcaembdim,CV_64FC1, ap[j]);// &projected_data[j*pcaembdim]);
+ // cout << "Checking point: ";
+ // print_matrix(&p);
+
+ model->getKNN(ap[j], NEIGHBOURS+1, nn_idx, dists);
+ for (l = 0; l < NEIGHBOURS; l++) {
+ // Make sure none of the first NEIGHBOURS neighbours is N
+ if (nn_idx[l] == ANN_NULL_IDX) break;
+ else if ((ulong)nn_idx[l] == N-1) nn_idx[l] = nn_idx[NEIGHBOURS];
+ p1 = (double*)(nn[k]->data.ptr+l*nn[k]->step);
+ p2 = (double*)(nnn[k]->data.ptr+l*nnn[k]->step);
+ p3 = model->getDataPoint(nn_idx[l]);
+ p4 = model->getDataPoint(nn_idx[l]+1);
+ for (a = 0; a < pcaembdim; a++) {
+ *p1++ = *p3++;
+ *p2++ = *p4++;
+ }
+ }
+ if (l < NEIGHBOURS) cout << "Warning: Couldn't find enough neighbours." << endl;
+
+ cvReduce(nn[k], navg[k], 0, CV_REDUCE_AVG );
+ dist = -sqrt(annDist(pcaembdim,(double*)p.data.ptr,(double*)navg[k]->data.ptr));
+
+ cvReduce(nnn[k], navg_next[k], 0, CV_REDUCE_AVG );
+ p1 = (double*)navg_next[k]->data.ptr;
+ p2 = (double*)navg[k]->data.ptr;
+ dst = (double*)proj_next[k]->data.ptr;
+ for (l = 0; l < pcaembdim; l++) {
+ *dst++ = ap[j][l] + (*p1++ - *p2++);
+ }
+ p = cvMat(1,pcaembdim,CV_64FC1, ap[j+1]);
+ dist_next = -sqrt(annDist(pcaembdim,(double*)p.data.ptr,(double*)proj_next[k]->data.ptr));
+ /*
+ cout << "Expected next point: "; print_matrix(proj_next);
+ cout << "Real next point: "; print_matrix(&p);
+ cout << model_name << ". Dist1: " << dist << ", Dist2: " << dist_next << endl;
+ */
+ cvmSet(mdists,i,k,cvmGet(mdists,i,k)+(dist+dist_next));
+ }
+ //cout << model_name << ": " << cvmGet(mdists,i,k) << endl;
+ }
+ }
+ print_matrix(mdists);
+ for (i = 0; i < M; i++) {
+ cvReleaseMat(&navg[i]);
+ cvReleaseMat(&navg_next[i]);
+ cvReleaseMat(&nn[i]);
+ cvReleaseMat(&nnn[i]);
+ }
+ cvReleaseMat(&mdists);
+}
Oops, something went wrong.

0 comments on commit 1ecfed5

Please sign in to comment.