Skip to content

Commit

Permalink
matplotlib & qt4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ppwwyyxx committed Jul 19, 2015
1 parent abf6a0a commit b060974
Show file tree
Hide file tree
Showing 30 changed files with 4,136 additions and 24 deletions.
1 change: 0 additions & 1 deletion complete-report.pdf

This file was deleted.

Binary file added complete-report.pdf
Binary file not shown.
1 change: 0 additions & 1 deletion doc/Final-Report-Complete/img/crbm.pdf

This file was deleted.

Binary file added doc/Final-Report-Complete/img/crbm.pdf
Binary file not shown.
1 change: 0 additions & 1 deletion doc/Final-Report-Complete/img/gmm-compare.pdf

This file was deleted.

Binary file added doc/Final-Report-Complete/img/gmm-compare.pdf
Binary file not shown.
1 change: 0 additions & 1 deletion doc/Final-Report-Complete/img/performance.pdf

This file was deleted.

Binary file added doc/Final-Report-Complete/img/performance.pdf
Binary file not shown.
1 change: 0 additions & 1 deletion doc/Final-Report-Complete/img/time-comp-small.pdf

This file was deleted.

Binary file added doc/Final-Report-Complete/img/time-comp-small.pdf
Binary file not shown.
1 change: 0 additions & 1 deletion presentation.pdf

This file was deleted.

Binary file added presentation.pdf
Binary file not shown.
4 changes: 3 additions & 1 deletion src/filters/ltsd.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/python2
# -*- coding: utf-8 -*-
# $File: ltsd.py
# $Date: Sun Dec 29 13:12:21 2013 +0800
# $Date: Sun Jul 19 17:53:59 2015 +0800
# $Author: Xinyu Zhou <zxytim[at]gmail[dot]com>

import sys
from scipy.io import wavfile
import matplotlib
matplotlib.use("Qt4Agg")
import matplotlib.pyplot as plt
import numpy as np

Expand Down
1 change: 0 additions & 1 deletion src/gmm/test/src/Threadpool.cc

This file was deleted.

46 changes: 46 additions & 0 deletions src/gmm/test/src/Threadpool.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "Threadpool/Threadpool.hpp"

#include <iostream>
namespace ThreadLib {

void Worker::operator()() {
while(true) {
std::unique_lock<std::mutex> lock(pool.queue_mutex);

while(!pool.stop && pool.tasks.empty())
pool.condition.wait(lock);

if(pool.stop && pool.tasks.empty())
return;

std::function<void()> task(pool.tasks.top().second);
pool.tasks.pop();

lock.unlock();

task();
}
}

// the constructor just launches some amount of workers
Threadpool::Threadpool(Threadpool::size_type threads) : stop(false) {
workers.reserve(threads);

for(Threadpool::size_type i = 0; i < threads; ++i)
workers.emplace_back(Worker(*this));
}

// the destructor joins all threads
Threadpool::~Threadpool() {
{
std::unique_lock<std::mutex> lock(queue_mutex);
stop = true;
condition.notify_all();
}

for(Threadpool::size_type i = 0; i < workers.size(); ++i) {
workers[i].join();
}

}
}
1 change: 0 additions & 1 deletion src/gmm/test/src/common.hh

This file was deleted.

29 changes: 29 additions & 0 deletions src/gmm/test/src/common.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* $File: common.hh
* $Date: Sun Sep 08 08:35:24 2013 +0800
* $Author: Xinyu Zhou <zxytim[at]gmail[dot]com>
*/

#include "type.hh"
#include "dataset.hh"

#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>

#include <memory>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <limits>

#define For(i, n) for (__decltype(n) i = 0; i < (n); i ++)
#define Forr(i, l, r) for (__decltype(r) i = (l); i <= (r); i ++)

/**
* vim: syntax=cpp11 foldmethod=marker
*/

1 change: 0 additions & 1 deletion src/gmm/test/src/datamanip.cc

This file was deleted.

194 changes: 194 additions & 0 deletions src/gmm/test/src/datamanip.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/*
* $File: datamanip.cc
* $Date: Thu Dec 05 00:08:18 2013 +0000
* $Author: Xinyu Zhou <zxytim[at]gmail[dot]com>
*/

#include "datamanip.hh"

#include "common.hh"

#include <cstdio>
#include <cstdlib>

using namespace std;

static const int BUF_SIZE = 65536;

void read_svm_data(const char *fpath, Dataset &dataset, Labels &labels) {
FILE *fin = fopen(fpath, "r");
dataset.resize(0);
labels.resize(0);

char *buf = new char[BUF_SIZE];
while (fgets(buf, BUF_SIZE, fin) == buf) {
Instance x;
char *ptr;
for (ptr = buf; *ptr; ptr ++) {
if (*ptr == ' ' || *ptr == '\n' || *ptr == '\r') {
*ptr = 0;
int label = atoi(buf);
/*
if (label != 0 && label != 1) {
printf("!!!!%d\n", label);
}
*/
labels.push_back(label);
*ptr = ' ';
break;
}
}
char *last = ptr;
int ind = -1;
double val;
for (; ; ptr ++) {
if (*ptr == ' ' || *ptr == '\n' || *ptr == '\r' || *ptr == 0) {
if (ind != -1) {
char orig = *ptr;
*ptr = 0;
val = atof(last);
x.push_back(make_pair(ind, val));
*ptr = orig;
ind = -1;
}
last = ptr + 1;
} else if (*ptr == ':') {
*ptr = 0;
ind = atoi(last);
last = ptr + 1;
*ptr = ':';
}
if (*ptr == 0)
break;
}
dataset.push_back(x);
}
delete [] buf;
fclose(fin);
}

void read_svm_data(const char *fpath, Dataset &dataset, RealLabels &labels) {
FILE *fin = fopen(fpath, "r");
dataset.resize(0);
labels.resize(0);

char *buf = new char[BUF_SIZE];
while (fgets(buf, BUF_SIZE, fin) == buf) {
Instance x;
char *ptr;
for (ptr = buf; *ptr; ptr ++) {
if (*ptr == ' ' || *ptr == '\n' || *ptr == '\r') {
*ptr = 0;
real_t label = atof(buf);
/*
if (label != 0 && label != 1) {
printf("!!!!%d\n", label);
}
*/
labels.push_back(label);
*ptr = ' ';
break;
}
}
char *last = ptr;
int ind = -1;
double val;
for (; ; ptr ++) {
if (*ptr == ' ' || *ptr == '\n' || *ptr == '\r' || *ptr == 0) {
if (ind != -1) {
char orig = *ptr;
*ptr = 0;
val = atof(last);
x.push_back(make_pair(ind, val));
*ptr = orig;
ind = -1;
}
last = ptr + 1;
} else if (*ptr == ':') {
*ptr = 0;
ind = atoi(last);
last = ptr + 1;
*ptr = ':';
}
if (*ptr == 0)
break;
}
dataset.push_back(x);
}
delete [] buf;
fclose(fin);
}

void print_instance(FILE *fout, const Instance &instance) {
for (auto item: instance)
fprintf(fout, "%d:%lf ", item.first, item.second);
}

void print_data(FILE *fout, const Dataset &dataset) {
for (auto instance: dataset) {
print_instance(fout, instance);
fprintf(fout, "\n");
}
}

void print_data(FILE *fout, const Dataset &dataset, const Labels &labels) {
assert(dataset.size() == labels.size());
For(i, dataset.size()) {
fprintf(fout, "%d ", labels[i]);
print_instance(fout, dataset[i]);
fprintf(fout, "\n");
}
}

void print_data(FILE *fout, const Dataset &dataset, const RealLabels &labels) {
assert(dataset.size() == labels.size());
For(i, dataset.size()) {
fprintf(fout, "%f ", labels[i]);
print_instance(fout, dataset[i]);
fprintf(fout, "\n");
}
}

void print_labels(FILE *fout, const Labels &labels) {
for (auto i: labels)
fprintf(fout, "%d\n", i);
}

void print_labels(FILE *fout, const RealLabels &labels) {
for (auto i: labels)
fprintf(fout, "%f\n", i);
}

void get_data_metric(const Dataset &x, int &n, int &m) {
n = x.size();
m = 0;
for (size_t i = 0; i < x.size(); i ++) {
const Instance &xi = x[i];
for (size_t j = 0; j < xi.size(); j ++)
if (xi[j].first + 1 > m)
m = xi[j].first + 1;
}
}

void get_data_metric(const std::vector<std::vector<real_t> >&x, int &n, int &m) {
if (x.size() == 0) {
n = m = -1;
return;
}
n = x.size();
m = x[0].size();
for (size_t i = 0; i < x.size(); i ++)
if ((int)x[i].size() != m) {
n = m = -1;
break;
}
}





/**
* vim: syntax=cpp11 foldmethod=marker
*/

1 change: 0 additions & 1 deletion src/gmm/test/src/datamanip.hh

This file was deleted.

59 changes: 59 additions & 0 deletions src/gmm/test/src/datamanip.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* $File: datamanip.hh
* $Date: Thu Dec 05 00:08:15 2013 +0000
* $Author: Xinyu Zhou <zxytim[at]gmail[dot]com>
*/

#pragma once

#include "dataset.hh"

#include <cstdio>
#include <cassert>
#include "random.hh"

// integer label
void read_svm_data(const char *fpath, Dataset &dataset, Labels &labels);
void read_svm_data(const char *fpath, Dataset &dataset, RealLabels &labels);
void print_data(FILE *fout, const Dataset &dataset);
void print_data(FILE *fout, const Dataset &dataset, const Labels &labels);
void print_data(FILE *fout, const Dataset &dataset, const RealLabels &labels);
void print_labels(FILE *fout, const Labels &labels);
void print_labels(FILE *fout, const RealLabels &labels);
void print_instance(FILE *fout, const Instance &instance);

void get_data_metric(const Dataset &x, int &n, int &m);
void get_data_metric(const std::vector<std::vector<real_t> >&x, int &n, int &m);

template<typename Dataset>
void get_refdata_metric(const Dataset &x, int &n, int &m) {
n = x.size();
m = 0;
for (size_t i = 0; i < x.size(); i ++) {
auto &xi = *x[i];
for (size_t j = 0; j < xi.size(); j ++)
if (xi[j].first + 1 > m)
m = xi[j].first + 1;
}
}

// n_choose == -1 means the same number as dataset.size()
template<typename Dataset_t, typename Labels_t>
void bootstrap_samples(const Dataset_t &dataset, const Labels_t &labels,
Dataset_t &subdataset, Labels_t &sublabels, int n_choose = -1) {
Random random;
assert(dataset.size() == labels.size());
subdataset.resize(0); sublabels.resize(0);
if (n_choose == -1)
n_choose = dataset.size();
for (int i = 0; i < n_choose; i ++) {
int index = random.rand_int(dataset.size());
subdataset.push_back(dataset[index]);
sublabels.push_back(labels[index]);
}
}

/**
* vim: syntax=cpp11 foldmethod=marker
*/

1 change: 0 additions & 1 deletion src/gmm/test/src/dataset.hh

This file was deleted.

Loading

0 comments on commit b060974

Please sign in to comment.