16 arma::mat deriv(cx_func f, arma::vec theta) {
17 arma::cx_vec thetac = arma::conv_to<arma::cx_vec>::from(theta);
18 arma::cx_mat val0 = f(thetac);
19 unsigned n = val0.n_elem;
20 unsigned p = theta.n_elem;
23 cx_dbl h0 = cx_dbl(0, h);
24 for (
unsigned i=0; i < p; i++) {
25 arma::cx_vec theta0 = thetac;
27 arma::mat val = imag(f(theta0))/h;
28 for (
unsigned j=0; j < n; j++)
36 arma::umat clusterid(
const arma::uvec &
id) {
38 unsigned n =
id.size();
40 for (
unsigned i=0; i < n; i++) {
46 arma::umat res(ncl, 2);
50 for (
unsigned i=0; i < n; i++) {
62 arma::mat groupsum(
const arma::mat &x,
63 const arma::uvec &cluster,
65 unsigned ncl = cluster.n_elem;
71 arma::mat res(n, x.n_cols);
72 arma::rowvec tmp(x.n_cols);
73 for (
unsigned i=0; i < ncl; i++) {
74 unsigned start = cluster(i);
81 for (
unsigned j=start; j < stop; j++) {
87 for (
unsigned j=start; j < stop; j++) {
96 void fastpattern(
const arma::umat &y,
99 unsigned categories) {
100 unsigned n = y.n_rows;
101 unsigned k = y.n_cols;
103 arma::uvec mygroup(n);
104 double lognpattern = k*std::log(static_cast<double>(categories));
105 unsigned npattern = n;
106 if (lognpattern<std::log(static_cast<double>(npattern))) {
107 npattern = (unsigned) pow(static_cast<double>(categories),
108 static_cast<double>(k));
110 arma::umat mypattern(npattern, k);
114 for (
unsigned i=0; i < n; i++) {
115 arma::urowvec ri = y.row(i);
117 for (
unsigned j=0; j < K; j++) {
118 if (sum(ri != mypattern.row(j)) == 0) {
126 mypattern.row(K-1) = ri;
130 pattern = mypattern.rows(0, K-1);
135 arma::umat fastapprox(arma::vec &time,
136 const arma::vec &newtime,
140 arma::uvec idx(newtime.n_elem);
141 arma::uvec eq(newtime.n_elem);
143 double vmax = time(time.n_elem-1);
144 arma::mat::iterator it;
147 for (
unsigned i=0; i < newtime.n_elem; i++) {
149 if (newtime(i) > vmax) {
152 it = std::lower_bound(time.begin(), time.end(), newtime(i));
154 if (it == time.begin()) {
156 if (equal && (newtime(i) == upper)) { eq(i) = 1; }
158 pos =
static_cast<int>(it-time.begin());
159 if (type == 0 && std::fabs(newtime(i)-time(pos-1)) <
160 std::fabs(newtime(i)-time(pos)))
162 if (equal && (newtime(i) == upper)) { eq[i] = pos+1; }
165 if (type == 2 && newtime(i) < upper) pos--;
169 return( arma::join_horiz(idx, eq) );
175 double SupTest(
const arma::vec &D) {
176 return arma::max(arma::abs(D));
179 double L2Test(
const arma::vec &D,
const arma::vec &t) {
180 arma::vec delta(t.n_elem);
181 for (
unsigned i=0; i < t.n_elem-1; i++) delta(i) = t[i+1]-t[i];
182 delta(delta.n_elem-1) = 0;
183 return std::sqrt(sum(delta % D % D));
188 double CramerVonMises(
const arma::vec &x, arma::vec G) {
190 arma::uvec ord = arma::stable_sort_index(x);
192 unsigned n = G.n_elem;
193 double res = 1/(12*n);
194 for (
unsigned i=0; i < G.n_elem; i++) {
195 double val = (2*i-1)/(2*n)-G(i);
202 arma::mat
const EmptyMat = arma::mat();
203 arma::vec
const EmptyVec = arma::vec();
207 const char* COL_RESET =
"\x1b[0m";
208 const char* COL_DEF =
"\x1b[39m";
209 const char* BLACK =
"\x1b[30m";
210 const char* RED =
"\x1b[31m";
211 const char* MAGENTA =
"\x1b[35m";
212 const char* YELLOW =
"\x1b[33m";
213 const char* GREEN =
"\x1b[32m";
214 const char* BLUE =
"\x1b[34m";
215 const char* CYAN =
"\x1b[36m";
216 const char* WHITE =
"\x1b[37m";
217 const char* GRAY =
"\x1b[90m";
218 const char* LRED =
"\x1b[91m";
219 const char* LGREEN =
"\x1b[92m";
220 const char* LYELLOW =
"\x1b[93m";
221 const char* LBLUE =
"\x1b[94m";
222 const char* LMAGENTA =
"\x1b[95m";
223 const char* LCYAN =
"\x1b[96m";
224 const char* LWHITE =
"\x1b[97m";
Various utility functions and constants.