forked from gabraham/flashpca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandompca.h
108 lines (91 loc) · 2.97 KB
/
randompca.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2014 Gad Abraham
* All rights reserved.
*/
#pragma once
#include <Eigen/QR>
#include <Eigen/SVD>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/random/uniform_real_distribution.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/math/distributions.hpp>
#include <boost/math/distributions/fisher_f.hpp>
#include <Spectra/SymEigsSolver.h>
#include "data.h"
using namespace Eigen;
#define _8GiB 8589934592
#define METHOD_EIGEN 1
#define METHOD_SVD 2
#define KERNEL_LINEAR 1
#define KERNEL_RBF 2
#define MODE_PCA 1
#define MODE_CCA 2
#define MODE_SCCA 3
#define MODE_UCCA 4
#define MODE_CHECK_PCA 5
#define MODE_PREDICT_PCA 6
#define MEM_MODE_OFFLINE 1
#define MEM_MODE_ONLINE 2
#define LOWMEM 1
#define HIGHMEM 2
#define DIVISOR_NONE 0
#define DIVISOR_N1 1
#define DIVISOR_P 2
class RandomPCA {
public:
MatrixXd U, V, W, Px, Py;
VectorXd d;
MatrixXd V0;
double trace;
VectorXd pve;
MatrixXd X_meansd, Y_meansd;
ArrayXXd res;
VectorXd err;
double mse;
double rmse;
int stand_method_x, stand_method_y;
bool verbose;
bool debug;
int divisor;
bool converged;
void pca_fast(MatrixXd &X, unsigned int block_size,
unsigned int ndim,
unsigned int maxiter, double tol, long seed,
bool do_loadings);
void pca_fast(Data &dat, unsigned int block_size,
unsigned int ndim,
unsigned int maxiter, double tol, long seed,
bool do_loadings);
void scca(MatrixXd &X, MatrixXd &Y, double lambda1, double lambda2,
long seed, unsigned int ndim,
unsigned int maxiter, double tol);
void scca(MatrixXd &X, MatrixXd &Y, double lambda1, double lambda2,
long seed, unsigned int ndim,
unsigned int maxiter, double tol, MatrixXd &V);
void scca(Data &dat, double lambda1, double lambda2,
long seed, unsigned int ndim,
unsigned int maxiter, double tol,
unsigned int block_size);
void scca(Data &dat, double lambda1, double lambda2,
long seed, unsigned int ndim,
unsigned int maxiter, double tol,
unsigned int block_size, MatrixXd &V);
void zca_whiten(bool transpose);
void ucca(MatrixXd &X, MatrixXd &Y);
void ucca(Data &dat);
void check(Data& dat, unsigned int block_size,
std::string evec_file, std::string eval_file);
void check(Data& dat, unsigned int block_size,
MatrixXd& evec, VectorXd& eval);
void check(MatrixXd& X, MatrixXd& evec, VectorXd& eval);
void project(Data& dat, unsigned int block_size,
std::string loadings_file, std::string maf_file,
std::string meansd_file);
void project(Data& dat, unsigned int block_size);
};