More refactoring.

parent 193b02d6
/**
* Adds binary memoryless noise to an input matrix.
* \file add_noise_tool.cpp
* \brief Adds binary memoryless noise to an input matrix.
* Parameters: input.pbm output.pbm p [q]
* p is the crossover probability; this parameter is mandatory
* if q is specified, then p is the probability of turning a 0 into 1
......
/**
* \file bitplane_tool.cpp
* \brief Takes a PGM grayscale image and produces C binary images, one per bitplane in the original image.
*/
#include <cstdio>
#include "pbm.h"
#include "pnm.h"
......
......@@ -58,7 +58,7 @@ idx_t learn_model_traditional(binary_matrix& X,
do {
char tmpfname[128];
snprintf(tmpfname,127,"%04lu_dict_iter.pbm",iter);
render_mosaic(D,tmpfname);
//render_mosaic(D,tmpfname);
if (get_verbosity() >= 2) {
codelength L = model_codelength(E,D,A);
std::cout << "DLEARN"
......@@ -375,8 +375,8 @@ idx_t learn_model_mdl_forward_selection(binary_matrix& X,
<< std::endl;
{
char tmpfname[128];
snprintf(tmpfname,127,"%04lu_dict.pbm",K);
render_mosaic(currD,tmpfname);
//snprintf(tmpfname,127,"%04lu_dict.pbm",K);
//render_mosaic(currD,tmpfname);
}
tic = clock();
initialize_dictionary(currE,H,nextAtom,nextCoefs);
......
/**
* Classification experiment.
* \file bmf_classification_tool.cpp
* \brief Classification tool.
*
* Input pbm "image" with binary samples as columns and an ASCII space-separated file with class labels as numbers
* Procedure:
* 1) split dataset into training and testing subsets
......
......@@ -8,14 +8,14 @@
double max_err_weight = 0;
size_t max_coef_weight = 0;
mi_algorithm_t initialize_dictionary = initialize_dictionary_neighbor;
es_algorithm_t coefficients_update = coefficients_update_omp;
//es_algorithm_t coefficients_update = coefficients_update_mob;
du_algorithm_t update_dictionary = update_dictionary;
ml_algorithm_t learn_model = learn_model_traditional;
ml_algorithm_t learn_model_inner = learn_model_traditional;
model_init_algorithm_t initialize_dictionary = initialize_dictionary_neighbor;
coeffs_update_algorithm_t coefficients_update = coefficients_update_omp;
//coeffs_update_algorithm_t coefficients_update = coefficients_update_mob;
dict_update_algorithm_t update_dictionary = update_dictionary;
model_learn_algorithm_t learn_model = learn_model_traditional;
model_learn_algorithm_t learn_model_inner = learn_model_traditional;
mi_algorithm_t mi_algorithm_catalog[] = {
model_init_algorithm_t model_init_algorithm_catalog[] = {
initialize_dictionary_neighbor,
initialize_dictionary_partition,
initialize_dictionary_sdct,
......@@ -29,7 +29,7 @@ mi_algorithm_t mi_algorithm_catalog[] = {
0
};
const char* mi_algorithm_names[] = {
const char* model_init_algorithm_names[] = {
"Neighbor",
"Partition",
"sign of DCT",
......@@ -43,7 +43,7 @@ const char* mi_algorithm_names[] = {
0
};
es_algorithm_t es_algorithm_catalog[] = {
coeffs_update_algorithm_t coeffs_update_algorithm_catalog[] = {
coefficients_update_omp,
coefficients_update_basic,
coefficients_update_bmp,
......@@ -52,7 +52,7 @@ es_algorithm_t es_algorithm_catalog[] = {
0
};
const char* es_algorithm_names[] = {
const char* coeffs_update_algorithm_names[] = {
"Basic coefficients update (OpenMP)",
"Basic coefficients update",
"BMP coefficients update",
......@@ -61,20 +61,20 @@ const char* es_algorithm_names[] = {
0
};
du_algorithm_t du_algorithm_catalog[] = {update_dictionary_mob,
dict_update_algorithm_t dict_update_algorithm_catalog[] = {update_dictionary_mob,
update_dictionary_kprox,
update_dictionary_mob_omp,
update_dictionary_kprox_omp,
0
};
const char* du_algorithm_names[] = {"MOB dictionary update",
const char* dict_update_algorithm_names[] = {"MOB dictionary update",
"KPROX dictionary update",
"MOB dictionary update (OMP)",
"KPROX dictionary update (OMP)",0
};
ml_algorithm_t learn_model_algorithm_catalog[] = {learn_model_traditional,
model_learn_algorithm_t learn_model_algorithm_catalog[] = {learn_model_traditional,
learn_model_alter1,
learn_model_alter2,
learn_model_alter3,
......@@ -103,17 +103,17 @@ static int count_options(const char* names[]) {
void learn_model_setup(int mi_algo, int es_algo, int du_algo, int lm_algo, int lmi_algo) {
int n;
n = count_options(mi_algorithm_names);
n = count_options(model_init_algorithm_names);
if (mi_algo > n) {
std::cerr << "Invalid model initialization algorithm (0-" << n << ')' << std::endl;
exit(-1);
}
n = count_options(es_algorithm_names);
n = count_options(coeffs_update_algorithm_names);
if (es_algo > n) {
std::cerr << "Invalid coefficients update algorithm (0-" << n << ')' << std::endl;
exit(-1);
}
n = count_options(du_algorithm_names);
n = count_options(dict_update_algorithm_names);
if (du_algo > n) {
std::cerr << "Invalid dictionary update algorithm (0-" << n << ')' << std::endl;
exit(-1);
......@@ -130,16 +130,16 @@ void learn_model_setup(int mi_algo, int es_algo, int du_algo, int lm_algo, int l
}
if (mi_algo >= 0) {
initialize_dictionary = mi_algorithm_catalog[mi_algo];
std::cout << "Using " << mi_algorithm_names[mi_algo] << " for model initialization." << std::endl;
initialize_dictionary = model_init_algorithm_catalog[mi_algo];
std::cout << "Using " << model_init_algorithm_names[mi_algo] << " for model initialization." << std::endl;
} else {
std::cout << "Initialize dictionary from existing file." << std::endl;
initialize_dictionary = initialize_dictionary_dummy;
}
coefficients_update = es_algorithm_catalog[es_algo];
std::cout << "Using " << es_algorithm_names[es_algo] << " for coefficients update." << std::endl;
update_dictionary = du_algorithm_catalog[du_algo];
std::cout << "Using " << du_algorithm_names[du_algo] << " for dictionary update." << std::endl;
coefficients_update = coeffs_update_algorithm_catalog[es_algo];
std::cout << "Using " << coeffs_update_algorithm_names[es_algo] << " for coefficients update." << std::endl;
update_dictionary = dict_update_algorithm_catalog[du_algo];
std::cout << "Using " << dict_update_algorithm_names[du_algo] << " for dictionary update." << std::endl;
learn_model = learn_model_algorithm_catalog[lm_algo];
std::cout << "Using " << lm_algorithm_names[lm_algo] << " for outer learning loop." << std::endl;
learn_model_inner = learn_model_algorithm_catalog[lmi_algo];
......
......@@ -6,38 +6,38 @@
#define CONFIG_H
#include "binmat.h"
typedef void (*mi_algorithm_t)(const binary_matrix& E,
typedef void (*model_init_algorithm_t)(const binary_matrix& E,
const binary_matrix& H,
binary_matrix& D,
binary_matrix& A);
typedef idx_t (*es_algorithm_t)(binary_matrix& E,
typedef idx_t (*coeffs_update_algorithm_t)(binary_matrix& E,
const binary_matrix& H,
const binary_matrix& D,
binary_matrix& A,
const idx_t max_a_weight,
const idx_t max_e_weight);
typedef idx_t (*du_algorithm_t)(binary_matrix& E,
typedef idx_t (*dict_update_algorithm_t)(binary_matrix& E,
const binary_matrix& H,
binary_matrix& D,
binary_matrix& A);
typedef idx_t (*ml_algorithm_t)(binary_matrix& X,
typedef idx_t (*model_learn_algorithm_t)(binary_matrix& X,
const binary_matrix& H,
binary_matrix& E,
binary_matrix& D,
binary_matrix& A);
extern mi_algorithm_t initialize_dictionary;
extern es_algorithm_t coefficients_update;
extern du_algorithm_t update_dictionary;
extern ml_algorithm_t learn_model;
extern ml_algorithm_t learn_model_inner;
extern model_init_algorithm_t initialize_dictionary;
extern coeffs_update_algorithm_t coefficients_update;
extern dict_update_algorithm_t update_dictionary;
extern model_learn_algorithm_t learn_model;
extern model_learn_algorithm_t learn_model_inner;
extern const char* mi_algorithm_names[];
extern const char* es_algorithm_names[];
extern const char* du_algorithm_names[];
extern const char* model_init_algorithm_names[];
extern const char* coeffs_update_algorithm_names[];
extern const char* dict_update_algorithm_names[];
extern const char* lm_algorithm_names[];
......
/**
* B-SVD denoising experiment
* \file bmf_denoising_tool.cpp
* \brief B-SVD denoising experiment
*
* Takes a binary image and an initial wxw image patches dictionary as input
* Adds Bernoulli noise to the image of known probability of error p (use GSL RNG functions together with get_rng() defined here in random_number_generation.h)
* Split the image into wxw overlapping patches (use binmat functions for this)
......@@ -48,11 +50,11 @@ void show_help(const char* pname) {
std::cout << "USAGE: " << pname << " [options] <data_file>" << std::endl;
std::cout << "where [options can be any combination of: " << std::endl;
std::cout << "\t-i initialization algorithm. Choices are:" << std::endl;
list_choices("\t\t",mi_algorithm_names);
list_choices("\t\t",model_init_algorithm_names);
std::cout << "\t-c coefficients update algorithm. Choices are:" << std::endl;
list_choices("\t\t",es_algorithm_names);
list_choices("\t\t",coeffs_update_algorithm_names);
std::cout << "\t-d dictionary update algorithm. Choices are:" << std::endl;
list_choices("\t\t",du_algorithm_names);
list_choices("\t\t",dict_update_algorithm_names);
std::cout << "\t-l model selection algorithm. Choices are:" << std::endl;
list_choices("\t\t",lm_algorithm_names);
std::cout << "\t-L model learning algorithm. Choices are:" << std::endl;
......
/**
* B-SVD inpainting experiment
* \file bmf_inpainting_tool.cpp
* \brief B-SVD inpainting tool
*
* Takes a binary samples matrix, a binary mask of the same size, and an initial dictionary as input
* Adapt the dictionary using the input samples, each time using only those samples which are available and the corresponding subdictionary
* Encode the known parts of each sample using the corresponding subdictionary to obtain encoding coefficients
......
/**
* \file bmf_learn_tool.cpp
* \brief Learns or updates a Binary Matrix Factorization model of the form $X = DA + E$ where $X$ is the input matrix, $D$ is a dictionary, $A$ are linear coefficients, and $E$ is a residual.
*/
#include <cstdio>
#include <cstdlib>
#include <iomanip>
......@@ -41,11 +45,11 @@ void show_help(const char* pname) {
std::cout << "USAGE: " << pname << " [options] <data_file> [mask file]" << std::endl;
std::cout << "where [options can be any combination of: " << std::endl;
std::cout << "\t-i initialization algorithm/matrix. A file name indicates a matrrix.\n\tA number indicates one of the following algorithms:" << std::endl;
list_choices("\t\t",mi_algorithm_names);
list_choices("\t\t",model_init_algorithm_names);
std::cout << "\t-c coefficients update algorithm. Choices are:" << std::endl;
list_choices("\t\t",es_algorithm_names);
list_choices("\t\t",coeffs_update_algorithm_names);
std::cout << "\t-d dictionary update algorithm. Choices are:" << std::endl;
list_choices("\t\t",du_algorithm_names);
list_choices("\t\t",dict_update_algorithm_names);
std::cout << "\t-l model selection algorithm. Choices are:" << std::endl;
list_choices("\t\t",lm_algorithm_names);
std::cout << "\t-L model learning algorithm. Choices are:" << std::endl;
......
/**
* Take an image, a patch width, and save a matrix whose columns are the image patches
* \file extract_patches_tool.cpp
* \brief Takes an image, a patch width, a stride, and save a matrix whose columns are the image patches
* as columns.
*/
......
/**
* Takes an input image, interprets its rows as atoms, and produces a mosaic of it.
* \file mosaic_tool.cpp
* \brief Takes an input image, interprets its rows as atoms, and produces a mosaic of it.
*/
#include <cstdio>
#include <cstdlib>
......
/**
* \file plane2pgm_tool.cpp
* \brief Takes B bitplane binary images and constructs a grayscale out of it.
*/
#include <cstdio>
#include "pbm.h"
#include "pnm.h"
......
/**
* \file pred.h
* \brief Some basic prediction filters on binary matrices/images
*/
#include "binmat.h"
void med(const binary_matrix& P, binary_matrix& pP) {
......
/**
* Takes a matrix whose rows are vectorized square patches from an image,
* the image width and height, and reconstructs the image.
* \file stitch_patches_tool.cpp
* \brief Takes a matrix whose rows are vectorized square patches from an image, the image width and height, and reconstructs the image.
*/
#include <cstdlib>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment