Type Foam::interpolation2DTable<Type>::operator() ( const scalar valueX, const scalar valueY ) const { // Considers all of the list in Y being equal label nX = this->size(); const table& t = *this; if (nX == 0) { WarningIn ( "Type Foam::interpolation2DTable<Type>::operator()" "(" "const scalar, " "const scalar" ") const" ) << "cannot interpolate a zero-sized table - returning zero" << endl; return pTraits<Type>::zero; } else if (nX == 1) { // only 1 column (in X) - interpolate to find Y value return interpolateValue(t.first().second(), valueY); } else { // have 2-D data, interpolate // find low and high indices in the X range that bound valueX label x0i = Xi(lessOp<scalar>(), valueX, false); label x1i = Xi(greaterOp<scalar>(), valueX, true); if (x0i == x1i) { return interpolateValue(t[x0i].second(), valueY); } else { Type y0(interpolateValue(t[x0i].second(), valueY)); Type y1(interpolateValue(t[x1i].second(), valueY)); // gradient in X scalar x0 = t[x0i].first(); scalar x1 = t[x1i].first(); Type mX = (y1 - y0)/(x1 - x0); // interpolate return y0 + mX*(valueX - x0); } } }
inline int solve (int sys, int n, int const* Ap, int const* Ai, traits::complex_d const* Ax, traits::complex_d* X, traits::complex_d const* B, void *Numeric, double const* Control, double* Info) { int nnz = Ap[n]; bindings::detail::array<double> Axr (nnz); if (!Axr.valid()) return UMFPACK_ERROR_out_of_memory; bindings::detail::array<double> Axi (nnz); if (!Axi.valid()) return UMFPACK_ERROR_out_of_memory; traits::detail::disentangle (Ax, Ax+nnz, Axr.storage(), Axi.storage()); bindings::detail::array<double> Br (n); if (!Br.valid()) return UMFPACK_ERROR_out_of_memory; bindings::detail::array<double> Bi (n); if (!Bi.valid()) return UMFPACK_ERROR_out_of_memory; traits::detail::disentangle (B, B+n, Br.storage(), Bi.storage()); bindings::detail::array<double> Xr (n); if (!Xr.valid()) return UMFPACK_ERROR_out_of_memory; bindings::detail::array<double> Xi (n); if (!Xi.valid()) return UMFPACK_ERROR_out_of_memory; int status = umfpack_zi_solve (sys, Ap, Ai, Axr.storage(), Axi.storage(), Xr.storage(), Xi.storage(), Br.storage(), Bi.storage(), Numeric, Control, Info); if (status != UMFPACK_OK) return status; traits::detail::interlace (Xr.storage(), Xr.storage() + n, Xi.storage(), X); return status; }
HydroProp* Sphere::getHydroProp(RealType viscosity, RealType temperature) { RealType Xitt = 6.0 * NumericConstant::PI * viscosity * radius_; RealType Xirr = 8.0 * NumericConstant::PI * viscosity * radius_ * radius_ * radius_; Mat6x6d Xi, XiCopy, D; Xi(0, 0) = Xitt; Xi(1, 1) = Xitt; Xi(2, 2) = Xitt; Xi(3, 3) = Xirr; Xi(4, 4) = Xirr; Xi(5, 5) = Xirr; Xi *= PhysicalConstants::viscoConvert; XiCopy = Xi; invertMatrix(XiCopy, D); RealType kt = PhysicalConstants::kb * temperature; // in kcal mol^-1 D *= kt; // now in angstroms^2 fs^-1 (at least for Trans-trans) HydroProp* hprop = new HydroProp(V3Zero, Xi, D); return hprop; }
// [[Rcpp::export]] VectorXd bootR2(const MatrixXd X, const VectorXd y, int nBoot){ RNGScope scope; const int n(X.rows()); // const int p(X.cols()); VectorXd R2s(nBoot); MatrixXd Xi(X); VectorXd yi(y); IntegerVector prm(n); // double R2i(R2(Xi, yi)); for(int i = 0; i < nBoot; ++i) { prm = bootPerm(n); Xi = shuffleMatrix(X, prm); yi = shuffleVector(y, prm); R2s(i) = R2(Xi, yi); } return R2s; }
void Kalman_SLAM::decorrelate( Bayesian_filter::Bayes_base::Float d ) // Reduce correlation by scaling cross-correlation terms { std::size_t i,j; const std::size_t n = full->X.size1(); for (i = 1; i < n; ++i) { FM::SymMatrix::Row Xi(full->X,i); for (j = 0; j < i; ++j) { Xi[j] *= d; } for (j = i+1; j < n; ++j) { Xi[j] *= d; } } full->init(); }
inline int report_vector (int n, traits::complex_d const* X, double const* Control) { #if 0 // see UMFPACK v 4.1 User Guide bindings::detail::array<double> Xr (n); if (!Xr.valid()) return UMFPACK_ERROR_out_of_memory; bindings::detail::array<double> Xi (n); if (!Xi.valid()) return UMFPACK_ERROR_out_of_memory; traits::detail::disentangle (X, X+n, Xr.storage(), Xi.storage()); return umfpack_zi_report_vector (n, Xr.storage(), Xi.storage(), Control); #endif return umfpack_zi_report_vector (n, reinterpret_cast<double const*> (X), reinterpret_cast<double const*> (0), Control); }
// [[Rcpp::export]] MatrixXd bootCoef(const MatrixXd X, const VectorXd y, int nBoot){ RNGScope scope; const int n(X.rows()); const int p(X.cols()); MatrixXd bootBeta(nBoot, p); MatrixXd Xi(X); VectorXd yi(y); IntegerVector prm(n); VectorXd betaHati(p); for(int i = 0; i < nBoot; ++i) { prm = bootPerm(n); Xi = shuffleMatrix(X, prm); yi = shuffleVector(y, prm); betaHati = betaHat(Xi, yi); for(int j = 0; j < p; ++j) { bootBeta(i, j) = betaHati[j]; } } return bootBeta; }
inline int scale (int n, traits::complex_d* X, traits::complex_d const* B, void* Numeric) { bindings::detail::array<double> Br (n); if (!Br.valid()) return UMFPACK_ERROR_out_of_memory; bindings::detail::array<double> Bi (n); if (!Bi.valid()) return UMFPACK_ERROR_out_of_memory; traits::detail::disentangle (B, B+n, Br.storage(), Bi.storage()); bindings::detail::array<double> Xr (n); if (!Xr.valid()) return UMFPACK_ERROR_out_of_memory; bindings::detail::array<double> Xi (n); if (!Xi.valid()) return UMFPACK_ERROR_out_of_memory; int status = umfpack_zi_scale (Xr.storage(), Xi.storage(), Br.storage(), Bi.storage(), Numeric); if (status != UMFPACK_OK) return status; traits::detail::interlace (Xr.storage(), Xr.storage() + n, Xi.storage(), X); return status; }
void Control::debugAction1() { std::ofstream f; f.open("custom.out"); OrbFit::fo.open("Orbfit.out"); const int NOR = Global::NOR; double to = Global::t0; double te = Global::te; double step = 0; //максимальное число итераций int NI = Global::Niter; //Output parameters int NS = 0, NBS = 0, Neq = 10, I = 0; vector<double> X0; vector<vector<double>> Xvar(21); Integration::Instance.SwitchVar(Variables::FODE_KS); Integration::Instance.setPar(X0, Global::SV, to); vector<double> Xi(X0), var(Neq); //вариации for (int i = 0; i < Neq; i++) var[i] = X0[i] * 0.01; var[3] = var[2]; //первое интегрирование без вариаций Integration::Instance.Gauss_FODE(Xi, to, te, step, NOR, NI, NS, NBS); Xvar[0] = Xi; //+ f << "Xvar\t" << Xvar.size() << endl; f << "varEq+\n"; for (I = 1; I < Neq + 1; I++) { Xi = X0; Xi[I - 1] += var[I - 1]; Integration::Instance.Gauss_FODE(Xi, to, te, step, NOR, NI, NS, NBS); Xvar[I] = Xi; f << Xvar[I].size() << endl; } //- f << "varEq-\n"; for (I = Neq + 1; I < 2 * Neq + 1; I++) { Xi = X0; Xi[I - Neq - 1] -= var[I - Neq - 1]; Integration::Instance.Gauss_FODE(Xi, to, te, step, NOR, NI, NS, NBS); Xvar[I] = Xi; f << Xvar[I].size() << endl; } f << setprecision(12); // Matrix M(Neq, Neq); for (int j = 0; j < Neq; j++) for (int k = 0; k < Neq; k++) { double p = (Xvar[j + 1][k] - Xvar[0][k]) / var[j]; double m = (Xvar[0][k] - Xvar[j + 11][k]) / var[j]; M(k, j) = (p + m) / 2.0; } f << "Xvar\n"; for (int j = 0; j < 21; j++) { for (int k = 0; k < 10; k++) { f << Xvar[j][k] << "\t"; } f << "\n"; } f << "Var\n"; for (int k = 0; k < 10; k++) f << var[k] << "\t"; f << "\n"; f << "findiff\n" << M.toString("\t", "%e", 20, 1); Matrix dXdX0(Neq, Neq); Integration::Instance.SwitchVar(Variables::IZO_KS); Integration::Instance.setPar(X0, Global::SV, to); Integration::Instance.Gauss_FODE(X0, to, te, Global::step, NOR, NI, NS, NBS); dXdX0.setFromVec(Neq, X0); f << "varEq\n" << dXdX0.toString("\t", "%e", 20, 1); f.close(); OrbFit::fo.close(); }
int main(int argc, char *argv[]) { timeSelector::addOptions(); # include "setRootCase.H" # include "createTime.H" instantList timeDirs = timeSelector::select0(runTime, args); # include "createMesh.H" forAll(timeDirs, timeI) { runTime.setTime(timeDirs[timeI], timeI); mesh.readUpdate(); volScalarField mgb ( IOobject ( "mgb", runTime.timeName(), mesh, IOobject::MUST_READ ), mesh ); volScalarField Su ( IOobject ( "Su", runTime.timeName(), mesh, IOobject::MUST_READ ), mesh ); volScalarField Xi ( IOobject ( "Xi", runTime.timeName(), mesh, IOobject::MUST_READ ), mesh ); volScalarField St ( IOobject ( "St", runTime.timeName(), mesh, IOobject::NO_READ ), Xi*Su ); St.write(); volScalarField wdot ( IOobject ( "wdot", runTime.timeName(), mesh, IOobject::NO_READ ), St*mgb ); wdot.write(); }
int main(int argc, char *argv[]) { clock_t start = clock(); // MILO int width = 256, height = 256; std::string sceneName = "cornell"; std::string rendererName = "simple"; int nSamples = 25; // # samples option long_options[] = { {"help", no_argument, 0, 'h'}, {"viewport",required_argument, 0, 'v'}, {"input", required_argument, 0, 'i'}, {"samples", required_argument, 0, 's'}, {"renderer",required_argument, 0, 'r'}, {0, 0, 0, 0} }; int opt; int option_index = 0; while ((opt = getopt_long (argc, argv, "hv:i:s:r:", long_options, &option_index)) != -1) { switch (opt) { case 'h': { fprintf(stdout, "smallpt --renderer simple --viewport 256 --input cornell --samples 100\n\n"); IScene::printBuiltInSceneNames(); exit(0); } case 'v':{width = height = atoi(optarg); break;} case 'i':{sceneName = optarg; break;} case 's':{nSamples = atoi(optarg)/4; break;} case 'r':{rendererName = optarg; break;} default: exit(0); } } if (optind < argc) { printf ("non-option ARGV-elements: "); while (optind < argc) printf ("%s ", argv[optind++]); printf ("\n"); exit(0); } IRenderer* renderer = NULL; { if (rendererName == "forward") renderer = new ForwardRenderer(); else if (rendererName == "diffuse") renderer = new DiffuseOnlyRenderer(); else renderer = new SimpleRenderer(); } Ray cam(Vec(50,52,295.6), Vec(0,-0.042612,-1).norm()); // cam pos, dir Vec cx = Vec(width*.5135/height); Vec cy=(cx.cross(cam.dir)).norm()*.5135; Vec* colorBuf = new Vec[width*height]; Vec r; IScene* scene = new SimpleScene(); if (!IScene::createBuiltInScene(scene, sceneName)) { fprintf(stderr, "Invalid scene name: %s\n", sceneName.c_str()); IScene::printBuiltInSceneNames(); exit(1); } char imageName[100]; sprintf(imageName, "%s_%s_%dX%dX%d.ppm", sceneName.c_str(), rendererName.c_str(), width, height, nSamples*4); fprintf(stdout, "Rendering to %s\n", imageName); #pragma omp parallel for schedule(dynamic, 1) private(r) // OpenMP for (int y = 0; y < height; y++) { // Loop over image rows fprintf(stderr,"\rRendering (%d spp) %5.2f%%",nSamples*4,100.*y/(height - 1)); RandomLCG Xi(y*y*y); // MILO for (unsigned short x = 0; x < width; x++) { // Loop cols int loc = (height - y - 1) * width + x; for (int sy = 0; sy < 2; sy++) { // 2x2 subpixel rows for (int sx = 0; sx < 2; sx++, r = Vec()) { // 2x2 subpixel cols for (int s = 0; s < nSamples; s++) { double dx = tentFilterRandom(Xi); double dy = tentFilterRandom(Xi); #if 1 Vec d = cx*( ( (sx+.5 + dx)/2 + x)/width - .5) + cy*( ( (sy+.5 + dy)/2 + y)/height - .5) + cam.dir; #else Vec d = cx*(x/(double)width - .5 ) + cy*(y/(double)height - .5) + cam.dir; #endif r = r + renderer->radiance(*scene, Ray(cam.orig+d*140,d.norm()),0,Xi)*(1./nSamples); } // Camera rays are pushed ^^^^^ forward to start in interior colorBuf[loc] = colorBuf[loc] + Vec(clamp(r.x),clamp(r.y),clamp(r.z))*.25; } } } } delete renderer; delete scene; printf("\n%f sec\n", (float)(clock() - start)/CLOCKS_PER_SEC); // MILO { FILE *f = fopen(imageName, "w"); // Write image to PPM file. fprintf(f, "P3\n%d %d\n%d\n", width, height, 255); for (int i = 0; i < width*height; i++) fprintf(f,"%d %d %d ", toInt(colorBuf[i].x), toInt(colorBuf[i].y), toInt(colorBuf[i].z)); fclose(f); } }
bool Reed_Solomon::decode(const bvec &coded_bits, const ivec &erasure_positions, bvec &decoded_message, bvec &cw_isvalid) { bool decoderfailure, no_dec_failure; int j, i, kk, l, L, foundzeros, iterations = floor_i(static_cast<double>(coded_bits.length()) / (n * m)); bvec mbit(m * k); decoded_message.set_size(iterations * k * m, false); cw_isvalid.set_length(iterations); GFX rx(q, n - 1), cx(q, n - 1), mx(q, k - 1), ex(q, n - 1), S(q, 2 * t), Xi(q, 2 * t), Gamma(q), Lambda(q), Psiprime(q), OldLambda(q), T(q), Omega(q); GFX dummy(q), One(q, (char*)"0"), Omegatemp(q); GF delta(q), tempsum(q), rtemp(q), temp(q), Xk(q), Xkinv(q); ivec errorpos; if ( erasure_positions.length() ) { it_assert(max(erasure_positions) < iterations*n, "Reed_Solomon::decode: erasure position is invalid."); } no_dec_failure = true; for (i = 0; i < iterations; i++) { decoderfailure = false; //Fix the received polynomial r(x) for (j = 0; j < n; j++) { rtemp.set(q, coded_bits.mid(i * n * m + j * m, m)); rx[j] = rtemp; } // Fix the Erasure polynomial Gamma(x) // and replace erased coordinates with zeros rtemp.set(q, -1); ivec alphapow = - ones_i(2); Gamma = One; for (j = 0; j < erasure_positions.length(); j++) { rx[erasure_positions(j)] = rtemp; alphapow(1) = erasure_positions(j); Gamma *= (One - GFX(q, alphapow)); } //Fix the syndrome polynomial S(x). S.clear(); for (j = 1; j <= 2 * t; j++) { S[j] = rx(GF(q, b + j - 1)); } // calculate the modified syndrome polynomial Xi(x) = Gamma * (1+S) - 1 Xi = Gamma * (One + S) - One; // Apply Berlekam-Massey algorithm if (Xi.get_true_degree() >= 1) { //Errors in the received word // Iterate to find Lambda(x), which hold all error locations kk = 0; Lambda = One; L = 0; T = GFX(q, (char*)"-1 0"); while (kk < 2 * t) { kk = kk + 1; tempsum = GF(q, -1); for (l = 1; l <= L; l++) { tempsum += Lambda[l] * Xi[kk - l]; } delta = Xi[kk] - tempsum; if (delta != GF(q, -1)) { OldLambda = Lambda; Lambda -= delta * T; if (2 * L < kk) { L = kk - L; T = OldLambda / delta; } } T = GFX(q, (char*)"-1 0") * T; } // Find the zeros to Lambda(x) errorpos.set_size(Lambda.get_true_degree()); foundzeros = 0; for (j = q - 2; j >= 0; j--) { if (Lambda(GF(q, j)) == GF(q, -1)) { errorpos(foundzeros) = (n - j) % n; foundzeros += 1; if (foundzeros >= Lambda.get_true_degree()) { break; } } } if (foundzeros != Lambda.get_true_degree()) { decoderfailure = true; } else { // Forney algorithm... //Compute Omega(x) using the key equation for RS-decoding Omega.set_degree(2 * t); Omegatemp = Lambda * (One + Xi); for (j = 0; j <= 2 * t; j++) { Omega[j] = Omegatemp[j]; } //Find the error/erasure magnitude polynomial by treating them the same Psiprime = formal_derivate(Lambda*Gamma); errorpos = concat(errorpos, erasure_positions); ex.clear(); for (j = 0; j < errorpos.length(); j++) { Xk = GF(q, errorpos(j)); Xkinv = GF(q, 0) / Xk; // we calculate ex = - error polynomial, in order to avoid the // subtraction when recunstructing the corrected codeword ex[errorpos(j)] = (Xk * Omega(Xkinv)) / Psiprime(Xkinv); if (b != 1) { // non-narrow-sense code needs corrected error magnitudes int correction_exp = ( errorpos(j)*(1-b) ) % n; ex[errorpos(j)] *= GF(q, correction_exp + ( (correction_exp < 0) ? n : 0 )); } } //Reconstruct the corrected codeword. // instead of subtracting the error/erasures, we calculated // the negative error with 'ex' above cx = rx + ex; //Code word validation S.clear(); for (j = 1; j <= 2 * t; j++) { S[j] = cx(GF(q, b + j - 1)); } if (S.get_true_degree() >= 1) { decoderfailure = true; } } } else { cx = rx; decoderfailure = false; } //Find the message polynomial mbit.clear(); if (decoderfailure == false) { if (cx.get_true_degree() >= 1) { // A nonzero codeword was transmitted if (systematic) { for (j = 0; j < k; j++) { mx[j] = cx[j]; } } else { mx = divgfx(cx, g); } for (j = 0; j <= mx.get_true_degree(); j++) { mbit.replace_mid(j * m, mx[j].get_vectorspace()); } } } else { //Decoder failure. // for a systematic code it is better to extract the undecoded message // from the received code word, i.e. obtaining a bit error // prob. p_b << 1/2, than setting all-zero (p_b = 1/2) if (systematic) { mbit = coded_bits.mid(i * n * m, k * m); } else { mbit = zeros_b(k); } no_dec_failure = false; } decoded_message.replace_mid(i * m * k, mbit); cw_isvalid(i) = (!decoderfailure); } return no_dec_failure; }
Bool_t TZigZag::PointsNear(Double_t x, Double_t y, Double_t &yi, TArrayD &Tn, TArrayD &Yn) const { // Two-dimensional case. Finds in I,T,X,Y the 4 points of the grid around point (x,y). //Then finds the 2 closest points along the zigzag in In,Tn,Xn,Yn. // If point (x,y) not inside [fXmin,fXmax] and [fYmin,fYmax], make a projection //towards center and stops at point just after entry and gives the 4 points for it. const Double_t un = 1.0; const Double_t aeps = 1.0e-6; TArrayI Ii(4); TArrayD Ti(4); TArrayD Xi(4); TArrayD Yi(4); Bool_t ok; Int_t i; Int_t kx=0; Int_t ky=0; Double_t mx,my,eps; Double_t xc,xl,xr,dx,dxs2; Double_t yc,yl,yr,dy,dys2; Double_t xi,xp,yp; Double_t xle,xre,yle,yre; Tn.Set(2); Yn.Set(2); dx = (fXmax-fXmin)/fNx; dxs2 = dx/2; dy = (fYmax-fYmin)/fNy; dys2 = dy/2; xl = dxs2; xr = dxs2 + (fNx-1)*dx; yl = dys2; yr = dys2 + (fNy-1)*dy; if ((yr-yl) > (xr-xl)) eps = aeps*(yr-yl); else eps = aeps*(xr-xl); xle = xl + eps; xre = xr - eps; yle = yl + eps; yre = yr - eps; if ((x>=xle) && (x<=xre) && (y>=yle) && (y<=yre)) { xi = x; yi = y; kx = Int_t((xi-dxs2)/dx) + 1; ky = Int_t((yi-dys2)/dy) + 1; ok = kTRUE; }//end if ((x>xl) && (x<xr) && (y>yl) && (y<yr)) else { xc = (fXmax-fXmin)/2; yc = (fYmax-fYmin)/2; mx = (y-yc)/(x-xc); my = un/mx; xi = xle; yi = yc + mx*(xi-xc); ok = IsInside(xi,yi,x,y,xc,yc,xl,xr,yl,yr); if (!ok) { xi = xre; yi = yc + mx*(xi-xc); ok = IsInside(xi,yi,x,y,xc,yc,xl,xr,yl,yr); if (!ok) { yi = yle; xi = xc + my*(yi-yc); ok = IsInside(xi,yi,x,y,xc,yc,xl,xr,yl,yr); if (!ok) { yi = yre; xi = xc + my*(yi-yc); ok = IsInside(xi,yi,x,y,xc,yc,xl,xr,yl,yr); }//end if (!ok) }//end if (!ok) }//end if (!ok) if (ok) { kx = Int_t((xi-dxs2)/dx) + 1; ky = Int_t((yi-dys2)/dy) + 1; } else { cout << "TZigZag::PointsNear : ERROR point inside not found" << endl; } }//end else if ((x>xl) && (x<xr) && (y>yl) && (y<yr)) if (ok) { //Point kx,ky xp = dxs2 + (kx-1)*dx; yp = dys2 + (ky-1)*dy; i = NToZZ(kx,ky); Ii[0] = i; Ti[0] = T(i); Xi[0] = xp; Yi[0] = yp; //Point kx+1,ky xp = dxs2 + kx*dx; yp = dys2 + (ky-1)*dy; i = NToZZ(kx+1,ky); Ii[1] = i; Ti[1] = T(i); Xi[1] = xp; Yi[1] = yp; //Point kx,ky+1 xp = dxs2 + (kx-1)*dx; yp = dys2 + ky*dy; i = NToZZ(kx,ky+1); Ii[2] = i; Ti[2] = T(i); Xi[2] = xp; Yi[2] = yp; //Point kx+1,ky+1 xp = dxs2 + kx*dx; yp = dys2 + ky*dy; i = NToZZ(kx+1,ky+1); Ii[3] = i; Ti[3] = T(i); Xi[3] = xp; Yi[3] = yp; //Finding the 2 points along the zigzag Order(4,Ii,Ti,Xi,Yi); Yn[0] = Yi[0]; Tn[0] = Ti[0] + ((Ti[1] - Ti[0])/(Xi[1] -Xi[0]))*(xi - Xi[0]); Yn[1] = Yi[2]; Tn[1] = Ti[2] + ((Ti[3] - Ti[2])/(Xi[3] -Xi[2]))*(xi - Xi[2]); } return ok; }