cv::Point3d PinholeCameraModel::projectPixelTo3dRay(const cv::Point2d& uv_rect) const { assert( initialized() ); cv::Point3d ray; ray.x = (uv_rect.x - cx() - Tx()) / fx(); ray.y = (uv_rect.y - cy() - Ty()) / fy(); ray.z = 1.0; return ray; }
static T__ fxy(const T__ &y, const T__ &x, const size_t &nx, const size_t &ny) { switch(nx) { case(0): { switch(ny) { case(0): { return f(y,x); break; } case(1): { return fy(y,x); break; } default: { // TODO: NEED TO IMPLEMENT THIS assert(false); return 0; break; } } } case(1): { switch(ny) { case(0): { return fx(y,x); break; } default: { // TODO: NEED TO IMPLEMENT THIS assert(false); return 0; break; } } } default: case(2): { // TODO: IMPLEMENT THIS assert(false); return 0; break; } } }
double max_euler_error(size_t k, Vector const *euler_ys_half_h) { double max_f = 0; double max_fx = 0; double max_fy = 0; for (size_t i = 0; i < euler_ys_half_h->size; ++i) { max_f = max(max_f, fabs(f(get_x(i, 0.5 * h), euler_ys_half_h->values[i]))); max_fx = max(max_fx, fabs(fx(get_x(i, 0.5 * h), euler_ys_half_h->values[i]))); max_fy = max(max_fy, fabs(fy(get_x(i, 0.5 * h), euler_ys_half_h->values[i]))); } return 0.5 * (max_fx + max_f * max_fy) / max_fy * h * exp(max_fy * (get_x(k, h) - get_x(0, h))); }
//线程2执行任务 void task2(int *num) { int y; do{ read(pipe2[0],&y,sizeof(int)); printf("fy(%d)=%d\n",y++,fy(y)); write(pipe1[1],&y,sizeof(int)); }while(y<=9); close(pipe1[1]); close(pipe2[0]); }
int main() { typedef Kokkos::DefaultNode::DefaultNodeType Node; typedef KokkosExamples::EmptySparseKernel<void,Node> SOBASE; typedef SOBASE::graph<int,Node>::graph_type Graph; typedef SOBASE::bind_scalar<float>::other_type FloatOps; typedef FloatOps::matrix< float,int,Node>::matrix_type FMatrix; typedef SOBASE::bind_scalar<double>::other_type DoubleOps; typedef DoubleOps::matrix<double,int,Node>::matrix_type DMatrix; typedef Kokkos::MultiVector<double,Node> DoubleVec; typedef Kokkos::MultiVector<float,Node> FloatVec; std::cout << "Note, this class doesn't actually do anything. We are only testing that it compiles." << std::endl; // get a pointer to the default node Teuchos::RCP<Node> node = Kokkos::DefaultNode::getDefaultNode(); // create the graph G const int numRows = 5, numCols = 5; Teuchos::RCP<Graph> G = Teuchos::rcp(new Graph(numRows,numCols,node,Teuchos::null)); // create a double-valued matrix dM using the graph G Teuchos::RCP<DMatrix> dM = Teuchos::rcp(new DMatrix(G,Teuchos::null)); DoubleOps doubleKernel(node); // initialize it with G and dM DoubleOps::finalizeGraphAndMatrix(Teuchos::UNDEF_TRI,Teuchos::NON_UNIT_DIAG,*G,*dM,Teuchos::null); doubleKernel.setGraphAndMatrix(G,dM); // create double-valued vectors and initialize them DoubleVec dx(node), dy(node); // call the sparse kernel operator interfaces doubleKernel.multiply( Teuchos::NO_TRANS, 1.0, dx, dy); doubleKernel.multiply( Teuchos::NO_TRANS, 1.0, dx, 1.0, dy); doubleKernel.solve( Teuchos::NO_TRANS, dy, dx); // create a float-valued matrix fM using the graph G Teuchos::RCP<FMatrix> fM = Teuchos::rcp(new FMatrix(G,Teuchos::null)); // create a double-valued sparse kernel using the rebind functionality FloatOps floatKernel(node); // initialize it with G and fM FloatOps::finalizeMatrix(*G,*fM,Teuchos::null); floatKernel.setGraphAndMatrix(G,fM); // create float-valued vectors and initialize them FloatVec fx(node), fy(node); // call the sparse kernel operator interfaces floatKernel.multiply( Teuchos::NO_TRANS, 1.0f, fx, fy); floatKernel.multiply( Teuchos::NO_TRANS, 1.0f, fx, 1.0f, fy); floatKernel.solve( Teuchos::NO_TRANS, fy, fx); std::cout << "End Result: TEST PASSED" << std::endl; return 0; }
cv::Point2d PinholeCameraModel::project3dToPixel(const cv::Point3d& xyz) const { assert( initialized() ); assert(P_(2, 3) == 0.0); // Calibrated stereo cameras should be in the same plane // [U V W]^T = P * [X Y Z 1]^T // u = U/W // v = V/W cv::Point2d uv_rect; uv_rect.x = (fx()*xyz.x + Tx()) / xyz.z + cx(); uv_rect.y = (fy()*xyz.y + Ty()) / xyz.z + cy(); return uv_rect; }
cameracalibration::cameracalibration(float _fx, float _fy, float _cx, float _cy) { m_intrinsic = cv::Matx33f::zeros(); fx() = _fx; fy() = _fy; cx() = _cx; cy() = _cy; m_distortion.create(5,1); for (int i=0; i<5; i++) m_distortion(i) = 0; }
// function definition to plot 8 different points of a circle at once at a time void paint(int x1,int y1,int x,int y) { // first quadrant putpixel(fx(x1+x),fy(y1-y),LWHITE); // starting from (0,r) and drawing the half semi-circle, left to right putpixel(fx(x1+y),fy(y1-x),LWHITE); // starting from (r,0) and drawing the half semi-circle, right to left // second quadrant putpixel(fx(x1-x),fy(y1-y),LWHITE); // starting from (0,r) and drawing the half semi-circle, right to left putpixel(fx(x1-y),fy(y1-x),LWHITE); // starting from (-r,0) and drawing the half semi-circle, left to right // third quadrant putpixel(fx(x1-x),fy(y1+y),LWHITE); // starting from (0,-r) and drawing the half semi-circle, right to left putpixel(fx(x1-y),fy(y1+x),LWHITE); // starting from (-r,0) and drawing the half semi-circle, left to right // fourth quadrant putpixel(fx(x1+y),fy(y1+x),LWHITE); // starting from (r,0) and drawing the half semi-circle, right to left putpixel(fx(x1+x),fy(y1+y),LWHITE); // starting from (0,-r) and drawing the half semi-circle, left to right }
// function definition to create quadrants void drawBlade(int x1,int y1,int x2,int y2,int x3,int y3,int color) { setcolor(color); // setting a color for the triangle // drawing the respective lines line(fx(x1),fy(y1),fx(x2),fy(y2)); line(fx(x2),fy(y2),fx(x3),fy(y3)); line(fx(x3),fy(y3),fx(x1),fy(y1)); } // end of function
int main() { typedef Kokkos::DefaultNode::DefaultNodeType Node; typedef KokkosExamples::DummySparseKernel<Node> SparseOps; typedef Kokkos::CrsGraph < int,Node,SparseOps> Graph; typedef Kokkos::CrsMatrix<double,int,Node,SparseOps> DoubleMat; typedef Kokkos::CrsMatrix< float,int,Node,SparseOps> FloatMat; typedef Kokkos::MultiVector<double,Node> DoubleVec; typedef Kokkos::MultiVector<float,Node> FloatVec; std::cout << "Note, this class doesn't actually do anything. We are only testing that it compiles." << std::endl; // get a pointer to the default node Teuchos::RCP<Node> node = Kokkos::DefaultNode::getDefaultNode(); // create the graph G const size_t numRows = 5; Graph G(numRows,node); // create a double-valued matrix dM using the graph G DoubleMat dM(G); // create a double-valued sparse kernel using the rebind functionality SparseOps::rebind<double>::other doubleKernel(node); // initialize it with G and dM doubleKernel.initializeStructure(G); doubleKernel.initializeValues(dM); // create double-valued vectors and initialize them DoubleVec dx(node), dy(node); // test the sparse kernel operator interfaces doubleKernel.multiply( Teuchos::NO_TRANS, 1.0, dx, dy); doubleKernel.multiply( Teuchos::NO_TRANS, 1.0, dx, 1.0, dy); doubleKernel.solve( Teuchos::NO_TRANS, Teuchos::UPPER_TRI, Teuchos::UNIT_DIAG, dy, dx); // create a float-valued matrix fM using the graph G FloatMat fM(G); // create a double-valued sparse kernel using the rebind functionality SparseOps::rebind<float>::other floatKernel(node); // initialize it with G and fM floatKernel.initializeStructure(G); floatKernel.initializeValues(fM); // create float-valued vectors and initialize them FloatVec fx(node), fy(node); // test the sparse kernel operator interfaces floatKernel.multiply( Teuchos::NO_TRANS, 1.0f, fx, fy); floatKernel.multiply( Teuchos::NO_TRANS, 1.0f, fx, 1.0f, fy); floatKernel.solve( Teuchos::NO_TRANS, Teuchos::UPPER_TRI, Teuchos::UNIT_DIAG, fy, fx); std::cout << "End Result: TEST PASSED" << std::endl; return 0; }
// --------------------------------------------------------------------------------------------------------------------- bool plasma_tick(const FrameInput& input, FrameOutput& output, FXState& state) { EffectData* data = (EffectData*)state.store; byte r, g; Fix16 mid(8.0f); Fix16 tx1, ty1, tx2, ty2; Fix16 XM1 = data->step.sinMV(0.3f, 3.0f) * data->attractorScales[0]; Fix16 YM1 = data->step.sinMV(0.1f, 2.0f) * data->attractorScales[1]; Fix16 XM2 = data->step.cosMV(0.2f, -3.0f) * data->attractorScales[2]; Fix16 YM2 = data->step.cosMV(0.05f, -5.0f) * data->attractorScales[3]; tx1 = mid + (data->step.sinV(-0.25f) * XM1); ty1 = mid + (data->step.cosV(0.1f) * YM1); tx1 = mid + (data->step.sinMV(-0.5f, 4.0f) * XM2); ty1 = mid + (data->step.cosV(0.1f) * YM2); for (int y=0; y<Constants::FrameHeight; y++) { for (int x=0; x<Constants::FrameWidth; x++) { Fix16 fx((float)x), fy((float)y); fx += fx.sinMV(0.3f, YM1); fy += fy.cosMV(0.3f, XM2); Fix16 dist1 = DistanceBetween(fx, fy, tx1, ty1); Fix16 dist2 = DistanceBetween(fx, fy, tx2, ty2); Fix16 tn = Fix16::atan2(dist1, dist2) * ((data->step.cosM(0.25f) + 2.0f) * 0.8f); tn += data->step * 0.4f; tn += fx.cosMV(0.1f, YM2) * (data->step.sinMV(0.1f, 25.0f) * 0.3f); tn -= fy.sinMV(0.1f, XM1) * (data->step.cosMV(0.1f, 15.0f) * 0.3f); FullSpectrum(tn, r, g); setLED(output.frame, x, y, r, g); } } data->step += 0.1f; return true; }
cv::Point2d PinholeCameraModel::unrectifyPoint(const cv::Point2d& uv_rect) const { assert( initialized() ); if (cache_->distortion_state == NONE) return uv_rect; if (cache_->distortion_state == UNKNOWN) throw Exception("Cannot call unrectifyPoint when distortion is unknown."); assert(cache_->distortion_state == CALIBRATED); /// @todo Make this just call projectPixelTo3dRay followed by cv::projectPoints. But /// cv::projectPoints requires 32-bit float, which is annoying. // Formulae from docs for cv::initUndistortRectifyMap, // http://opencv.willowgarage.com/documentation/cpp/camera_calibration_and_3d_reconstruction.html // x <- (u - c'x) / f'x // y <- (v - c'y) / f'y // c'x, f'x, etc. (primed) come from "new camera matrix" P[0:3, 0:3]. double x = (uv_rect.x - cx() - Tx()) / fx(); double y = (uv_rect.y - cy() - Ty()) / fy(); // [X Y W]^T <- R^-1 * [x y 1]^T double X = R_(0,0)*x + R_(1,0)*y + R_(2,0); double Y = R_(0,1)*x + R_(1,1)*y + R_(2,1); double W = R_(0,2)*x + R_(1,2)*y + R_(2,2); // x' <- X/W, y' <- Y/W double xp = X / W; double yp = Y / W; // x'' <- x'(1+k1*r^2+k2*r^4+k3*r^6) + 2p1*x'*y' + p2(r^2+2x'^2) // y'' <- y'(1+k1*r^2+k2*r^4+k3*r^6) + p1(r^2+2y'^2) + 2p2*x'*y' // where r^2 = x'^2 + y'^2 double r2 = xp*xp + yp*yp; double r4 = r2*r2; double r6 = r4*r2; double a1 = 2*xp*yp; double k1 = D_(0,0), k2 = D_(0,1), p1 = D_(0,2), p2 = D_(0,3), k3 = D_(0,4); double barrel_correction = 1 + k1*r2 + k2*r4 + k3*r6; if (D_.cols == 8) barrel_correction /= (1.0 + D_(0,5)*r2 + D_(0,6)*r4 + D_(0,7)*r6); double xpp = xp*barrel_correction + p1*a1 + p2*(r2+2*(xp*xp)); double ypp = yp*barrel_correction + p1*(r2+2*(yp*yp)) + p2*a1; // map_x(u,v) <- x''fx + cx // map_y(u,v) <- y''fy + cy // cx, fx, etc. come from original camera matrix K. return cv::Point2d(xpp*K_(0,0) + K_(0,2), ypp*K_(1,1) + K_(1,2)); }
/*! \fn Real avg2d(Real (*func)(Real, Real, Real), const GridS *pG, * const int i, const int j, const int k) * \brief RETURNS THE INTEGRAL OF A USER-SUPPLIED FUNCTION func OVER THE TWO- * DIMENSIONAL GRID CELL (i,j,k). * * INTEGRATION IS PERFORMED USING qsimp. * ADAPTED FROM NUMERICAL RECIPES BY AARON SKINNER */ Real avg2d(Real (*func)(Real, Real, Real), const GridS *pG, const int i, const int j, const int k) { Real x1,x2,x3,dvol=pG->dx1*pG->dx2; Real fy(Real y); nrfunc=func; cc_pos(pG,i,j,k,&x1,&x2,&x3); xmin = x1 - 0.5*pG->dx1; xmax = x1 + 0.5*pG->dx1; ymin = x2 - 0.5*pG->dx2; ymax = x2 + 0.5*pG->dx2; zsav = x3; #ifdef CYLINDRICAL dvol *= x1; #endif return qsimp(fy,ymin,ymax)/dvol; }
int main() { double a=0.0, b=11.0, h=0.5, X; int n =6; double x[6], y[6]; fx(a,b,n,x); vivod ( x, n, "X"); fy(x,y,n); vivod ( y, n, "Y"); X=a; eytken(x,y,n,3.5); while(X<=b) { printf("X=%f eytken=%f f(X)=%f\n",X,eytken(x,y,n,X),f(X)); X+=h; } return 0; }
/** * Evaluate the function at a point in a 2D space. * @param x :: The x co-ordinate * @param y :: The y co-ordinate */ double Chebfun2DSpline::operator()(const double& x, const double& y)const { auto ix = std::find_if(m_xLines.begin(), m_xLines.end(), [&x](double d)->bool{return d >= x;}); if ( ix == m_xLines.end() ) return 0.0; if ( ix == m_xLines.begin() && x < m_xBase->startX ) return 0.0; size_t i = ix - m_xLines.begin(); if ( m_xLines[i] == x ) { return m_yFuns[i]( y ); } --i; auto iy = std::find_if(m_yLines.begin(), m_yLines.end(), [&y](double d)->bool{return d >= y;}); if ( iy == m_yLines.end() ) return 0.0; if ( iy == m_yLines.begin() && y < m_yBase->startX ) return 0.0; size_t j = iy - m_yLines.begin(); if ( m_yLines[j] == y ) { return m_xFuns[j]( x ); } --j; std::vector<double> fx(m_xLines.size()); for(size_t k = 0; k < fx.size(); ++k) { fx[k] = m_yFuns[k]( y ); } m_xLineFun.setP( fx ); std::vector<double> fy(m_yLines.size()); for(size_t k = 0; k < fy.size(); ++k) { fy[k] = m_xFuns[k]( x ); } m_yLineFun.setP( fy ); return (m_xLineFun(x) + m_yLineFun(y)) / 2; }
void Distribution2D::init(const float* f, const size_t w, const size_t h) { /*! create arrays */ width = w; height = h; xDists.resize(height); std::vector<float> fy(height); /*! compute y distribution and initialize row distributions */ for (size_t y=0; y<height; y++) { /*! accumulate row to compute y distribution */ fy[y] = 0.0f; for (size_t x=0; x<width; x++) fy[y] += f[y*w+x]; /*! initialize distribution for current row */ xDists[y].init(f+y*width, width); } /*! initializes the y distribution */ yDist.init(fy.data(), height); }
static void init_lists(rubikblocks_conf *cp) { GLuint base; int i; float x, y, z; base = cp->list_base = glGenLists(27); for(i = 0; i < 27; i++) { x = cp->pieces[i].pos[0]; y = cp->pieces[i].pos[1]; z = cp->pieces[i].pos[2]; glNewList(base+i, GL_COMPILE); glBegin(GL_QUAD_STRIP); glNormal3f(1, 0, 0); glTexCoord2f(0, 0); glVertex3f(fx(x+0.5), fy(y-0.5), fz(z-0.5)); glTexCoord2f(0, 1); glVertex3f(fx(x+0.5), fy(y+0.5), fz(z-0.5)); glTexCoord2f(1, 0); glVertex3f(fx(x+0.5), fy(y-0.5), fz(z+0.5)); glTexCoord2f(1, 1); glVertex3f(fx(x+0.5), fy(y+0.5), fz(z+0.5)); glNormal3f(0, 0, 1); glTexCoord2f(0, 0); glVertex3f(fx(x-0.5), fy(y-0.5), fz(z+0.5)); glTexCoord2f(0, 1); glVertex3f(fx(x-0.5), fy(y+0.5), fz(z+0.5)); glNormal3f(-1, 0, 0); glTexCoord2f(1, 0); glVertex3f(fx(x-0.5), fy(y-0.5), fz(z-0.5)); glTexCoord2f(1, 1); glVertex3f(fx(x-0.5), fy(y+0.5), fz(z-0.5)); glNormal3f(0, 0, -1); glTexCoord2f(0, 0); glVertex3f(fx(x+0.5), fy(y-0.5), fz(z-0.5)); glTexCoord2f(0, 1); glVertex3f(fx(x+0.5), fy(y+0.5), fz(z-0.5)); glEnd(); glBegin(GL_QUADS); glNormal3f(0, 1, 0); glTexCoord2f(0, 0); glVertex3f(fx(x+0.5), fy(y+0.5), fz(z+0.5)); glTexCoord2f(0, 1); glVertex3f(fx(x+0.5), fy(y+0.5), fz(z-0.5)); glTexCoord2f(1, 1); glVertex3f(fx(x-0.5), fy(y+0.5), fz(z-0.5)); glTexCoord2f(1, 0); glVertex3f(fx(x-0.5), fy(y+0.5), fz(z+0.5)); glNormal3f(0, -1, 0); glTexCoord2f(0, 0); glVertex3f(fx(x+0.5), fy(y-0.5), fz(z-0.5)); glTexCoord2f(0, 1); glVertex3f(fx(x+0.5), fy(y-0.5), fz(z+0.5)); glTexCoord2f(1, 1); glVertex3f(fx(x-0.5), fy(y-0.5), fz(z+0.5)); glTexCoord2f(1, 0); glVertex3f(fx(x-0.5), fy(y-0.5), fz(z-0.5)); glEnd(); glEndList(); } }
double_vector L0Smoothing_1D(double_vector data, int jump) { double lambda = 0.01, kappa = 2.0; double_vector out(data.size()); Matrix SR(data.size(), 1); for(int j = 0; j < 1; ++j) { for(int i = 0; i < data.size(); ++i) { SR(i, j) = data[i]; } } double betamax = 1; Matrix fx(1, 2); fx(0, 0) = 1; fx(0, 1) = -1; Matrix fy(2, 1); fy(0, 0) = 1; fy(1, 0) = -1; Matrix sizeI2D(1, 2); sizeI2D(0, 0) = data.size(); sizeI2D(0, 1) = 1; Matrix2 otfFx = psf2otf(fx, sizeI2D); Matrix2 otfFy = psf2otf(fy, sizeI2D); Matrix otfFx2 = MatAbsPow2(otfFx); Matrix otfFy2 = MatAbsPow2(otfFy); Matrix2 Normin1R = fft2_1D(SR); Matrix Denormin2 = otfFx2; float beta = 2 * lambda; while(beta < betamax) { float lb = lambda / beta; Matrix Denormin = ZMatrix(data.size(), 1); Denormin = beta * Denormin2; MatAdd(Denormin, 1); Matrix vR = Matdiff(SR, 1); Matrix Pos2Sum = MatPow2(vR); for(int j = 0; j < 1; ++j) { for(int i = 0; i < data.size(); ++i) { if(Pos2Sum(i, j) < lb) { vR(i, j) = 0; } } } Matrix Normin2R = Matdiffinv(vR, 1); Matrix2 FSR = (Normin1R + fft2_1D(vR) * beta) / Denormin; SR = ifft2_1D(FSR); beta = beta * kappa; printf("."); for(uint i = 0; i < data.size(); ++i) { for(uint j = 0; j < 1; ++j) { out[i] = SR(i, j); } } } return out; }
void KVSpIdGUI::SpiderIdentification() { if ((!fHisto) || (!fGrid)) return; TVirtualPad* pad = fGrid->GetPad(); fGrid->UnDraw(); fZp = fZpEntry->GetIntNumber(); if (!fUserParameter) fSpFactor = GetFactor(); else fSpFactor = fSpiderFactorEntry->GetNumber(); fAnglesUp = fAngleUpEntry->GetIntNumber(); fAnglesDown = fAngleDownEntry->GetIntNumber(); fAlpha = fApertureUpEntry->GetNumber(); fPiedType = fPiedChoice->GetSelected(); fMatrixType = fTypeChoice->GetSelected(); Int_t type = fMatrixType; TH2* tmpHisto = fHisto; TList* tmpCut = 0; if (fUseCut) { tmpHisto = (TH2*)fHisto->Clone(Form("%s_cut", fHisto->GetName())); tmpHisto->Reset(); for (int i = 1; i <= fHisto->GetNbinsX(); i++) { for (int j = 1; j <= fHisto->GetNbinsY(); j++) { Stat_t ww = fHisto->GetBinContent(i, j); Axis_t x0 = fHisto->GetXaxis()->GetBinCenter(i); Axis_t y0 = fHisto->GetYaxis()->GetBinCenter(j); if (fGrid->IsIdentifiable(x0, y0)) tmpHisto->Fill(x0, y0, ww); } } tmpCut = (TList*)fGrid->GetCuts()->Clone("tmpCuts"); } fGrid->Clear(); if (fScaledHisto) delete fScaledHisto; KVHistoManipulator hm; TF1 RtLt("RtLt", Form("x*%lf", fSfx), 0, tmpHisto->GetXaxis()->GetXmax()); TF1 RtLty("RtLty", Form("x*%lf", fSfy), 0, tmpHisto->GetXaxis()->GetXmax()); fScaledHisto = (TH2F*)hm.ScaleHisto(tmpHisto, &RtLt, &RtLty); if (fIdentificator) delete fIdentificator; fIdentificator = new KVSpiderIdentificator(fScaledHisto, fXm * fSfx, fYm * fSfy); switch (fPiedType) { case kUser: fIdentificator->SetX0(fPdx * fSfx); fIdentificator->SetY0(fPdy * fSfy); break; case kAuto: break; case kNone: fIdentificator->SetX0(0.); fIdentificator->SetY0(0.); } fIdentificator->SetParameters(fSpFactor); fIdentificator->SetNangles(fAnglesUp, fAnglesDown); fIdentificator->SetAlpha(fAlpha); fProgressBar->SetRange(0, fAnglesUp + fAnglesDown + 1); fProgressBar->Reset(); fIdentificator->Connect("Increment(Float_t)", "TGHProgressBar", fProgressBar, "SetPosition(Float_t)"); fTestButton->SetEnabled(kFALSE); fCloseButton->SetEnabled(kFALSE); fIdentificator->ProcessIdentification(); fTestButton->SetEnabled(kTRUE); fCloseButton->SetEnabled(kTRUE); fIdentificator->Disconnect("Increment(Float_t)", fProgressBar, "SetPosition(Float_t)"); fProgressBar->Reset(); if (fDebug) fIdentificator->Draw(fOption.Data()); TList* ll = (TList*)fIdentificator->GetListOfLines(); KVIDZALine* TheLine = 0; int zmax = 0; KVSpiderLine* spline = 0; TIter next_line(ll); while ((spline = (KVSpiderLine*)next_line())) { if ((spline->GetN() > 10)) { //&&(spline->GetX(0)<=fIdentificator->GetX0()+200.)) TF1* ff1 = 0; if (type == kSiCsI) ff1 = spline->GetFunction(fPdx * fSfx, TMath::Max(fScaledHisto->GetXaxis()->GetXmax() * 0.9, spline->GetX(spline->GetN() - 1))); else if (type == kSiSi) ff1 = spline->GetFunction(fPdx * fSfx, TMath::Min(fScaledHisto->GetXaxis()->GetXmax() * 0.9, spline->GetX(spline->GetN() - 1) * 1.5)); else if (type == kChIoSi) ff1 = spline->GetFunction(fPdx * fSfx, TMath::Min(fScaledHisto->GetXaxis()->GetXmax() * 0.9, spline->GetX(spline->GetN() - 1) * 1.5)); else ff1 = spline->GetFunction(); if ((type == kSiCsI) && (ff1->GetParameter(1) >= 3000. || (ff1->GetParameter(2) <= 0.35) || (ff1->GetParameter(2) >= 1.))) { Info("SpiderIdentification", "Z = %d has been rejected (fit parameters)", spline->GetZ()); continue; } TheLine = (KVIDZALine*)((KVIDZAGrid*)fGrid)->NewLine("ID"); TheLine->SetZ(spline->GetZ()); double min, max; ff1->GetRange(min, max); double step = TMath::Min((max - min) * 0.05, 20.); //20.; double stepmax = (max - min) * 0.2; //800.; double x = 0.; for (x = min + 1; x < max + step; x += step) { if (step <= stepmax) step *= 1.3; if (ff1->Eval(x) < 4000) TheLine->SetPoint(TheLine->GetN(), x, ff1->Eval(x)); } if (max > x) TheLine->SetPoint(TheLine->GetN(), max, ff1->Eval(max)); fGrid->Add("ID", TheLine); if (spline->GetZ() >= zmax) zmax = spline->GetZ(); } else { Info("SpiderIdentification", "Z = %d has been rejected (too few points)", spline->GetZ()); } } TF1 fx("fx12", Form("x/%lf", fSfx), 0., fScaledHisto->GetNbinsX() * 1.); TF1 fy("fy12", Form("x/%lf", fSfy), 0., fScaledHisto->GetNbinsY() * 1.); fGrid->Scale(&fx, &fy); if (fUseCut) delete tmpHisto; if (tmpCut) fGrid->GetCuts()->AddAll(tmpCut); pad->cd(); fGrid->Draw(); pad->Modified(); pad->Update(); DoClose(); }
void lineto3(vec2 pt) { LineTo(hdc, fx(pt.x), fy(pt.y)); }
// function definition to create trunk of the mill void drawMillStand(int x,int y) { setcolor(LCYAN); // setting a color for the co-ordinate axes line(fx(x),fy(y),fx(x),Y); // drawing the stand } // end of function
void moveto3(vec2 pt) { MoveToEx(hdc, fx(pt.x), fy(pt.y), NULL); }
cv::Mat L0Smoothing(cv::Mat Im, double lambda = 0.02, double kappa = 2.0) { cv::Mat out(Im.rows, Im.cols, CV_32FC3); Matrix SR(Im.rows, Im.cols); Matrix SG(Im.rows, Im.cols); Matrix SB(Im.rows, Im.cols); for(int j = 0; j < Im.cols; ++j) { for(int i = 0; i < Im.rows; ++i) { cv::Vec3f& v1 = Im.at<cv::Vec3f>(i, j); SR(i, j) = v1[0]; SG(i, j) = v1[1]; SB(i, j) = v1[2]; } } double betamax = 1e5; Matrix fx(1, 2); fx(0, 0) = 1; fx(0, 1) = -1; Matrix fy(2, 1); fy(0, 0) = 1; fy(1, 0) = -1; Matrix sizeI2D(1, 2); sizeI2D(0, 0) = Im.rows; sizeI2D(0, 1) = Im.cols; Matrix2 otfFx = psf2otf(fx, sizeI2D); Matrix2 otfFy = psf2otf(fy, sizeI2D); Matrix otfFx2 = MatAbsPow2(otfFx); Matrix otfFy2 = MatAbsPow2(otfFy); Matrix2 Normin1R = fft2(SR); Matrix2 Normin1G = fft2(SG); Matrix2 Normin1B = fft2(SB); Matrix Denormin2 = otfFx2 + otfFy2; float beta = 2 * lambda; int count = 1; while(beta < betamax) { float lb = lambda / beta; Matrix Denormin = beta * Denormin2; MatAdd(Denormin, 1); Matrix hR = Matdiff(SR, 2); Matrix vR = Matdiff(SR, 1); Matrix hG = Matdiff(SG, 2); Matrix vG = Matdiff(SG, 1); Matrix hB = Matdiff(SB, 2); Matrix vB = Matdiff(SB, 1); Matrix Pos2Sum = MatPow2(hR) + MatPow2(vR) + MatPow2(hG) + MatPow2(vG) + MatPow2(hB) + MatPow2(vB); for(int j = 0; j < Im.cols; ++j) { for(int i = 0; i < Im.rows; ++i) { if(Pos2Sum(i, j) < lb) { hR(i, j) = 0; vR(i, j) = 0; hG(i, j) = 0; vG(i, j) = 0; hB(i, j) = 0; vB(i, j) = 0; } } } Matrix Normin2R = Matdiffinv(hR, 2) + Matdiffinv(vR, 1); Matrix Normin2G = Matdiffinv(hG, 2) + Matdiffinv(vG, 1); Matrix Normin2B = Matdiffinv(hB, 2) + Matdiffinv(vB, 1); Matrix2 FSR = (Normin1R + fft2(Normin2R) * beta) / Denormin; Matrix2 FSG = (Normin1G + fft2(Normin2G) * beta) / Denormin; Matrix2 FSB = (Normin1B + fft2(Normin2B) * beta) / Denormin; SR = ifft2(FSR); SG = ifft2(FSG); SB = ifft2(FSB); beta = beta * kappa; printf("."); for(uint i = 0; i < out.rows; ++i) { for(uint j = 0; j < out.cols; ++j) { cv::Vec3f& v1 = out.at<cv::Vec3f>(i, j); v1[0] = SR(i, j); v1[1] = SG(i, j); v1[2] = SB(i, j); } } cv::imshow("out", out); char filename[100]; sprintf(filename, "o%02d.png", count++); cv::Mat theout; out.convertTo(theout, CV_8UC3, 255); cv::imwrite(filename, theout); cv::waitKey(1); } for(uint j = 0; j < out.cols; ++j) { for(uint i = 0; i < out.rows; ++i) { cv::Vec3f& v1 = out.at<cv::Vec3f>(i, j); v1[0] = SR(i, j); v1[1] = SG(i, j); v1[2] = SB(i, j); } } return out; }
// function definition to create quadrants void drawQuadrants() { setcolor(LCYAN); // setting a color for the co-ordinate axes line(0,fy(0),X,fy(0)); // drawing the X-axis; fy(0)=480/2=240; line(fx(0),0,fx(0),Y); // drawing the Y-axis; fx(0)=640/2=320; }
__attribute__ ((noinline)) int main(){ uint64_t x = fx(), y = fy(); uint64_t z = x + y; return (z == 384); }
// Main code int main() { /**** Count to 10 in integers ****/ // Declare integer for loop counting int i; // Loop from 0 to 10, printing at each step for(i=0; i<10; i++) { printf("i= %d\n", i); } /**** Plot a function y=f(x) ****/ // Declare arrays of N real numbers float ax[N]; // x float ay[N]; // y float aylow[N]; // lower error in y float ayhigh[N]; // upper error in y // Set minimum and maximum for x float xmin = 0.0; float xmax = 10.0; // Assigning ax with N values for x between xmin and xmax for(i=0;i<N;i++) { ax[i] = xmin + (xmax-xmin)*(float)i/(float)(N-1); } // Fill ay using function fy for(i=0;i<N;i++) { ay[i] = fy(ax[i]); } // Fill aylow and ayhigh using sqrt(y) as the error for(i=0;i<N;i++) { aylow[i] = ay[i] - sqrt(ay[i]); ayhigh[i] = ay[i] + sqrt(ay[i]); } /**** Use pgplot to plot this function ****/ // cpgbeg starts a plotting page, in this case with 2x1 panels cpgbeg(0,"?",2,1); // sets colour: 1-black, 2-red, 3-green, 4-blue cpgsci(1); // sets line style: 1-solid, 2-dashed, 3-dot-dashed, 4-dotted cpgsls(1); // sets charachter height, larger number = bigger cpgsch(2.); // cpgpage() moves to the next panel cpgpage(); // sets the axes limits in the panel cpgswin(xmin,xmax,0.,100.); // draw the axes cpgbox("BCNST", 0.0, 0, "BCNST", 0.0, 0); // label the bottom axis cpgmtxt("B",2.,.5,.5,"x"); // label the left axis cpgmtxt("L",2.5,.5,.5,"f"); // connect N points in ax and ay with a line cpgline(N,ax,ay); // cpgpage() moves to the next panel cpgpage(); // sets the axes limits in the panel cpgswin(xmin,xmax,0.,100.); // draw the axes cpgbox("BCNST", 0.0, 0, "BCNST", 0.0, 0); // label the bottom axis cpgmtxt("B",2.,.5,.5,"x"); // label the left axis cpgmtxt("L",2.5,.5,.5,"f"); // draw N points in ax and ay // 17 - filled circles, 16 - filled squares, 13 - filled triangles cpgpt(N,ax,ay,17); // draw y error bars on the points cpgerry(N,ax,aylow,ayhigh,1.0); // close all pgplot applications cpgend(); // end program return 0; }
void testMatrixMatrixFunc() { typedef AMD::MatrixMatrixFunc<AMD::SymbolicMatrixMatlab, AMD::SymbolicScalarMatlab> MMFunc; typedef AMD::ScalarMatrixFunc<AMD::SymbolicMatrixMatlab, AMD::SymbolicScalarMatlab> SMFunc; std::string ans; AMD::SymbolicMatrixMatlab x("X",3,3); MMFunc fx(x,true); // a matrix variable AMD::SymbolicMatrixMatlab y("Y",3,3); MMFunc fy(y); // a matrix variable SMFunc func; ans = "Y'"; // d/dX trace(X*Y)=Y^T func = trace(fx*fy); assert(func.derivativeVal.getString()==ans); // d/dX trace(X^T*Y^T)=Y^T func = trace(transpose(fx)*transpose(fy)); assert(func.derivativeVal.getString()==ans); // d/dX trace((X*Y)^T)=Y^T func = trace(transpose(fx*fy)); assert(func.derivativeVal.getString()==ans); ans = "Y"; // d/dX trace(X*Y^T) = Y func = trace(fx*transpose(fy)); assert(func.derivativeVal.getString()==ans); // d/dX trace(Y*X^T) = Y func = trace(fy*transpose(fx)); assert(func.derivativeVal.getString()==ans); ans = "eye(3)"; // d/dX trace(X) = I func = trace(fx); assert(func.derivativeVal.getString()==ans); // d/dX trace(Y+X^T+Y) = I func = trace(fy+transpose(fx)+fy); assert(func.derivativeVal.getString()==ans); func = trace(fy*inv(fx)); ans = "(((-inv(X))*Y)*inv(X))'"; assert(func.derivativeVal.getString()==ans); assert(func.derivativeVal.getString()==ans); func = trace(fy-fx); ans = "(-eye(3))"; assert(func.derivativeVal.getString()==ans); func = logdet(fx); ans = "inv(X)'"; assert(func.derivativeVal.getString()==ans); func = logdet(transpose(fx)); assert(func.derivativeVal.getString()==ans); func = logdet(fy+fx); ans = "inv(Y+X)'"; assert(func.derivativeVal.getString()==ans); func = logdet(fy-fx); ans = "(-inv(Y-X))'"; assert(func.derivativeVal.getString()==ans); func = logdet(inv(transpose(fx))); ans = "(-inv(X)')"; assert(func.derivativeVal.getString()==ans); std::cout << "d/dX " << func.functionVal.getString() << " = " << func.derivativeVal.getString() << std::endl; }
//计算f(x)+f(y) int fxy(int x, int y) { return fx(x)+fy(y); }
int main() { typedef Kokkos::DefaultNode::DefaultNodeType Node; typedef KokkosExamples::EmptySparseKernel<void,Node> SOBASE; typedef SOBASE::graph<int,Node>::graph_type Graph; typedef SOBASE::bind_scalar<float>::other_type FloatOps; typedef FloatOps::matrix< float,int,Node>::matrix_type FMatrix; typedef SOBASE::bind_scalar<double>::other_type DoubleOps; typedef DoubleOps::matrix<double,int,Node>::matrix_type DMatrix; typedef Kokkos::MultiVector<double,Node> DoubleVec; typedef Kokkos::MultiVector<float,Node> FloatVec; std::cout << "Note, this class doesn't actually do anything. We are only testing that it compiles." << std::endl; // get a pointer to the default node Teuchos::RCP<Node> node = Kokkos::DefaultNode::getDefaultNode(); // create the graph G const int numRows = 5, numCols = 5; Teuchos::RCP<Graph> G = Teuchos::rcp(new Graph(numRows,numCols,node,Teuchos::null)); // create a double-valued matrix dM using the graph G Teuchos::RCP<DMatrix> dM = Teuchos::rcp(new DMatrix(G,Teuchos::null)); DoubleOps doubleKernel(node); // initialize it with G and dM DoubleOps::finalizeGraphAndMatrix(Teuchos::UNDEF_TRI,Teuchos::NON_UNIT_DIAG,*G,*dM,Teuchos::null); doubleKernel.setGraphAndMatrix(G,dM); // create double-valued vectors and initialize them DoubleVec dx(node), dy(node); // call the sparse kernel operator interfaces doubleKernel.multiply( Teuchos::NO_TRANS, 1.0, dx, dy); doubleKernel.multiply( Teuchos::NO_TRANS, 1.0, dx, 1.0, dy); doubleKernel.solve( Teuchos::NO_TRANS, dy, dx); // The Gauss-Seidel kernel asks the user to precompute the inverse // diagonal entries of the matrix (here, the vector D). We // demonstrate both sweep directions here. The local kernels don't // implement a "Symmetric" direction; Tpetra handles that. (This is // because for a matrix distributed over multiple processes, // symmetric Gauss-Seidel requires interprocess communication // between the forward and backward sweeps.) DoubleVec dd (node); doubleKernel.gaussSeidel (dy, dx, dd, 1.0, Kokkos::Forward); doubleKernel.gaussSeidel (dy, dx, dd, 1.0, Kokkos::Backward); // create a float-valued matrix fM using the graph G Teuchos::RCP<FMatrix> fM = Teuchos::rcp(new FMatrix(G,Teuchos::null)); // create a double-valued sparse kernel using the rebind functionality FloatOps floatKernel(node); // initialize it with G and fM FloatOps::finalizeMatrix(*G,*fM,Teuchos::null); floatKernel.setGraphAndMatrix(G,fM); // create float-valued vectors and initialize them FloatVec fx(node), fy(node); // call the sparse kernel operator interfaces floatKernel.multiply( Teuchos::NO_TRANS, 1.0f, fx, fy); floatKernel.multiply( Teuchos::NO_TRANS, 1.0f, fx, 1.0f, fy); floatKernel.solve( Teuchos::NO_TRANS, fy, fx); // Precomputed inverse diagonal entries of the sparse matrix. FloatVec fd (node); floatKernel.gaussSeidel (fy, fx, fd, (float) 1.0, Kokkos::Forward); floatKernel.gaussSeidel (fy, fx, fd, (float) 1.0, Kokkos::Backward); std::cout << "End Result: TEST PASSED" << std::endl; return 0; }
int main(int argc, char* argv[]) { int N; scanf("%d", &N); for (int s0 = 0; s0 < N; ++s0) { int num; scanf("%d", &num); int maxit; scanf("%d", &maxit); double eps; scanf("%lf", &eps); Equation eq(num); int n = eq.dim(); Vector x(n); for (int i = 1; i <= n; ++i) { double num; scanf("%lf", &num); x.setV(i, num); } Vector y0(n); eq.F(&x, &y0); double t = 1; double norm0 = y0.normInf(); for (int k = 1; k <= maxit; ++k) { eq.F(&x, &y0); double normy = y0.normInf(); SquareMatrix J(n); eq.jacobi(&x, &J); PMatrix P(n); J.PLUDecomposite(&P); if (!J.regular()) { printf("szingularis"); for (int i = 1; i <= n; ++i) { printf(" %.8lf", x.V(i)); } printf(" %.8lf\n", normy); break; } if (normy <= eps * (1 + norm0)) { printf("siker"); for (int i = 1; i <= n; ++i) { printf(" %.8lf", x.V(i)); } printf(" %.8lf %d\n", y0.normInf(), k - 1); break; } Vector dx(n); for (int i = 1; i <= n; ++i) { y0.setV(i, -y0.V(i)); } y0.leftMultiply(&P, &dx); J.solve(&dx); double xnorm = x.normInf(); bool br = false; for (int l = 0; l < 9; ++l) { Vector y(n); for (int i = 1; i <= n; ++i) { y.setV(i, x.V(i) + t * dx.V(i)); } Vector fy(n); eq.F(&y, &fy); if (fy.normInf() < normy) { if (l == 0) { t = (1.5 * t) > 1 ? 1 : (1.5 * t); } y.copyTo(&x); break; } t = t / 2; if (t < 1e-3) { br = true; break; } if (l == 8) { br = true; break; } } if (br) { printf("sikertelen"); for (int i = 1; i <= n; ++i) { printf(" %.8lf", x.V(i)); } printf(" %.8lf\n", normy); break; } if (k == maxit) { printf("maxit\n"); } } } return 0; }