void likelihoodfunction(double *r,int *nn, double *x,int *nnx,double *EPSL,double *y,int *fault) { VECTOR y1, y2, e1, e2, e3, e4; double EPS, s1, s2, s3; int n = *nn, nx = *nnx, i, j, k, _fault1; if (n != nx) { for (i = 0; i < 4; i++) y[i] = 0.0; fault[0] = 3;//The length(r) is not equal to the length(x) return; } EPS = *EPSL; y1 = Vector(n); e1 = Vector(n-1); e3 = Vector(n); // e3: vector of size n x 1 with all elements equal to 1. for (j = 0; j < n; j++) e3[j] = 1.0; _fault1 = lev(r,n,e3,y1,e1,EPS);// y1: solution of the system R * y1 = e3 if (_fault1 != 0) { for (i = 0; i < 2; i++) y[i] = 0.0; fault[0] = _fault1; free_vector(y1); free_vector(e1); free_vector(e3); return; } else fault[0] = 0;// The program is normally performed y2 = Vector(n); e2 = Vector(n-1); e4 = Vector(n); s1 = sum(n,y1);// s1 equals to t(e3) * inv(R) * e3. s2 = dot(n,x,y1);// s2 equals to t(x) * inv(R) * e3 y[2] = s2/s1; // e4 equals to x - (s2/s1)*e3 for (k = 0; k < n; k++) e4[k] = x[k]-y[2] * e3[k]; lev(r,n,e4,y2,e2,EPS); // y2: solution of the system R * y2 = x -(s2/s1)*e3 y[1] = levDet(n-1,e1);// Computation of the logarithm of the determinant. s3 = dot(n,e4,y2); y[3] = sqrt(s3/n); y[0] = -0.5 * y[1]- 0.5 * n *log(s3); free_vector(y1); free_vector(y2); free_vector(e1); free_vector(e2); free_vector(e3); free_vector(e4); }
void logpHx(double *r,int *nn, double *x,int *nnx,double *EPSL,double *y,int *fault) { VECTOR y1, y2, e1, e2, e3; double EPS, s1, s2, s3; int n = *nn, nx = *nnx, i, k, _fault1; if (n != nx) { for (i = 0; i < 2; i++) y[i] = 0.0; fault[0] = 3;//The length(r) is not equal to the length(x) return; } EPS = *EPSL; y1 = Vector(n); e1 = Vector(n-1); _fault1 = lev(r,n,x,y1,e1,EPS);// y1 solution of the system R * y1 = x if (_fault1 != 0) { for (i = 0; i < 2; i++) y[i] = 0.0; fault[0] = _fault1; free_vector(y1); free_vector(e1); return; } else fault[0] = 0;// The program is normally performed y2 = Vector(n); e2 = Vector(n-1); e3 = Vector(n); // e3: vector of size n x 1 with all elements equal to 1. for (k = 0; k < n; k++) e3[k] = 1.0; lev(r,n,e3,y2,e2,EPS);// y2 solution of the system R * y2 = e3 y[1] = levDet(n-1,e2);// Computation of the logarithm of the determinant. s1 = sum(n,y2);// s1 equals to t(e3) * inv(R) * e3. s2 = sum(n,y1);// s2 equals to t(e3) * inv(R) * x. s3 = dot(n,x,y1);// s3 equals to t(x) * inv(R) * x. y[0] = -0.5 * y[1]- 0.5 * (n-1.0)*log(s1 * s3 - s2*s2) + (0.5*n-1.0) * log(s1); y[2] = s2/s1; y[3] = 1/s1; y[4] = 0.5 * (s3 - y[3]* s2* s2); free_vector(y1); free_vector(y2); free_vector(e1); free_vector(e2); free_vector(e3); }
void test() { const char *str2 = "kitten"; const char *str1 = "sitting"; /*levenstein lev(str1, str1 + strlen(str1), str2, str2 + strlen(str2)); int res = lev.compute(); std::cout << res << std::endl;*/ const int count = 128; data_element *s1 = new data_element[count]; data_element *s2 = new data_element[count]; for (int i = 0; i < count; ++i) { s1[i] = i; s2[i] = count + i; } s1[0] = 0; s1[2] = 0; s2[1] = 0; levenstein lev(s1, s1 + count, s2, s2 + count); int res = lev.compute(); std::cout << res << std::endl; }
void block(Token *tk) {// block ent(); next(tk); if (tk->id == '}') PANIC("expected statement", tk->line); while (tk->id != '}' && tk->id) { stmt(tk); next(tk); } lev(); }
int main() { long pow, p1, p2, now, ind, xx = 0; scanf("%ld %ld", &a, &b); if (a > b) p1 = a, a = b, b = p1; if (a == b) { printf("0\n"); return 0; } if (a % 2 == 0) xx += lev(a++) - 1; if (b % 2 == 0) xx += lev(b--) - 1; for (pow = 4, ind = 2; ind <= 30; ind++, pow *= 2) { p1 = a; p2 = b; p1 += (pow - p1 % pow); p2 -= p2 % pow; if (p1 > p2) break; now = (p2 - p1) / pow + 1; sol += now; if (now == 1 && p1 < p2) break; } sol = (!sol) ? xx : sol * 2 + xx; printf("%ld\n", sol); return 0; }
vector<vector<string>> findLadders(string start, string end, unordered_set<string> &dict) { vector<vector<string> > result; unordered_map<string, vector<string> > parent; vector<unordered_set<string> > lev(2); int currlev = 0; int nextlev = 1; lev[currlev].insert(start); bool stop = false; while (!stop && lev[currlev].size() != 0) { // Erase from dict, must do it before moving on for (auto it = lev[currlev].begin(); it != lev[currlev].end(); it++) { dict.erase(*it); } for (auto it = lev[currlev].begin(); it != lev[currlev].end(); it++) { if (!adjToEnd(*it, end)) { // Not adjacent to end, collect children vector<string> children = changeOne(*it, dict); for (int j = 0; j < children.size(); j++) { parent[children[j]].push_back(*it); // Update parents lev[nextlev].insert(children[j]); } } else { // Adjacent to end stop = true; parent[end].push_back(*it); } } lev[currlev].clear(); currlev = !currlev; nextlev = !nextlev; } if (stop) { result = reconstruct(end, parent); } return result; }
void syntax(Token *tk) {// syntax analyzer char *fun_name; int fun_pos; Func *fun = (Func *)malloc(sizeof(Func)); while (tk->id) { make_empty(); if (tk->id == Void || tk->id == Int) { fun->ret = tk->id; next(tk); if (tk->id == Id) { adjust_ebp(); if (lookup(tk->beg, Fun, tk->line, false) < 0) { fun_pos = fun_insert(tk->beg); fun_name = (char *)malloc((strlen(tk->beg) + 1) * sizeof(char)); strcpy(fun_name, tk->beg); } else PANIC("function redefinition", tk->line); } else PANIC("missing function name", tk->line); } else if (tk->id == Stru) { struct_def(tk); } else if (tk->id == '(') { ent(); fun->argc = 0; argument_dec(tk, fun); if (tk->id == ')') fun_info_insert(fun_name, fun_pos, fun); else PANIC("illegal function declaration", tk->line); } else if (tk->id == '{') { next(tk); if (tk->id == '}') PANIC("expected statement", tk->line); while (tk->id != '}' && tk->id) { stmt(tk); next(tk); } lev(); if (!tk->id) PANIC("expected right brace", tk->line); } next(tk); } }
int main() { Level lev("level1.lev"); lev.init(); std::cout << lev.getNextGroup() << std::endl; std::cout << lev.getNextGroup() << std::endl; }
void print(std::ostream& out, L<de_DE>, S<Full>) const { l_start(out) << "Testniveau = "; lev(dispatch(out, "Basis-Testniveau (\"basic\"; für das laufende Testen)", "Volles Testniveau (\"full\"; z.B. für den täglichen Test)", "Umfangreiches Testniveau (\"extensive\"; z.B. für den wöchentlichen Test)")); }
void print(std::ostream& out, L<de_DE>, S<Basic>) const { l_start(out) << "Testniveau = "; lev(dispatch(out, "Basis-Testniveau (\"basic\")", "Volles Testniveau (\"full\")", "Umfangreiches Testniveau (\"extensive\")")); }
void print(std::ostream& out, L<en_GB>, S<Full>) const { l_start(out) << "test level = "; lev(dispatch(out, "Basic test level (used for permanent testing)", "Full test level (for the daily test)", "Extensive test level (for the weekly test)")); }
void print(std::ostream& out, L<en_GB>, S<Basic>) const { l_start(out) << "test level = "; lev(dispatch(out, "Basic test level", "Full test level", "Extensive test level")); }