void RMP::solve() { m_solver->solve(); m_energyHF = m_solver->getEnergy(); m_AOI = m_solver->getQmatrix(); m_fockEnergy = m_solver->getFockEnergy()(0); m_C = m_solver->getCoeff()(0); // temp1, temp2, temp3 are temporary fields used to get from // Atomic Orbital Integrals to Molecular Orbital Integrals field<mat> temp1(m_matDim, m_matDim); field<mat> temp2(m_matDim, m_matDim); field<mat> temp3(m_matDim, m_matDim); // orbitalIntegral = <ij|g|ab> for (int i = 0; i < m_matDim; i++){ for (int j = 0; j < m_matDim; j++){ temp1(i,j) = zeros(m_matDim, m_matDim); temp2(i,j) = zeros(m_matDim, m_matDim); temp3(i,j) = zeros(m_matDim, m_matDim); m_MOI(i,j) = zeros(m_matDim, m_matDim); } } // Transform from Atomic Orbital Integrals to Molecular Orbital Integrals if (m_perturbOrder > 1){ //#ifdef RUN_MPI // clock_t begin = clock(); //#endif AOItoMOI(temp1, m_AOI, m_C, 0); AOItoMOI(temp2, temp1, m_C, 1); AOItoMOI(temp3, temp2, m_C, 2); AOItoMOI(m_MOI, temp3, m_C, 3); //#ifdef RUN_MPI // clock_t end = clock(); // int my_rank; // MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); // cout << "Proc " << my_rank << ": Time AOI to MOI: " << (double(end - begin))/CLOCKS_PER_SEC << endl; //#endif } if (m_perturbOrder == 1){ } else if (m_perturbOrder == 2){ calc2OrderPerturb(); } else if (m_perturbOrder == 3){ calc2OrderPerturb(); calc3OrderPerturb(); } else { cout << "Error: " << m_perturbOrder << " order perturbation theory not implemented." << endl; exit(EXIT_FAILURE); } }
bool FileBasedIpc::Close() { std::auto_ptr<Semaphore> temp0(sems[0]); std::auto_ptr<Semaphore> temp1(sems[1]); std::auto_ptr<Semaphore> temp2(sems[2]); std::auto_ptr<Semaphore> temp3(sems[3]); bool result = true; for(size_t i = 0; i < 4; i++) { if(sems[i] != NULL) { if(status_ == PARENT) { if(!sems[i]->Destroy()) { result &= false; } } sems[i] = NULL; } } for(size_t i = 0; i < 2; i++) { if(files_[i] != NULL) { if(fclose(files_[i]) != 0) { result &= false; } files_[i] = NULL; } } return result; }
virtual void run() { // let all threads start at the same time startBarrier->block(); ossim_uint32 idx = 0; for(idx = 0; idx < m_numberOfPointsToQuery; ++idx) { ossim_float32 t = static_cast<double>(rand())/static_cast<double>(RAND_MAX); ossim_float32 centerx = 10000.0*t; ossim_float32 centery = 10000.0*t; ossimPolyArea2d polyArea1(ossimDrect(centerx-1000,centery-1000,centerx+2000,centery+2000)); ossimPolyArea2d polyArea2(ossimDrect(centerx-500,centery-500,centerx+2000,centery+2000)); ossimPolyArea2d temp1 = polyArea1&polyArea2; ossimPolyArea2d temp2 = polyArea1+polyArea2; ossimPolyArea2d temp3(polyArea1); ossimPolyArea2d temp4(polyArea2); temp3+=temp1; temp4&=temp3; // ossimGpt gpt(m_minLat + yt*m_latDelta, m_minLon + xt*m_lonDelta); } // let all threads end at the same time endBarrier->block(); }
TEST(Test_Container_SharedRabundVector, Constructors) { TestSharedRabundVector test; SharedRAbundVector noGroup; EXPECT_EQ(noGroup.getNumBins(), 0); EXPECT_EQ(noGroup.getNumSeqs(), 0); EXPECT_EQ(noGroup.getMaxRank(), 0); EXPECT_EQ(noGroup.getGroup(), ""); SharedRAbundVector noGroup2(10); EXPECT_EQ(noGroup2.getNumBins(), 10); EXPECT_EQ(noGroup2.getNumSeqs(), 0); EXPECT_EQ(noGroup2.getMaxRank(), 0); EXPECT_EQ(noGroup2.getGroup(), ""); vector<int> abunds(10, 5); SharedRAbundVector noGroup3(abunds, 5, 10, 50); EXPECT_EQ(noGroup3.getNumBins(), 10); EXPECT_EQ(noGroup3.getNumSeqs(), 50); EXPECT_EQ(noGroup3.getMaxRank(), 5); EXPECT_EQ(noGroup3.getGroup(), ""); SharedRAbundVector noGroup4(abunds); EXPECT_EQ(noGroup4.getNumBins(), 10); EXPECT_EQ(noGroup4.getNumSeqs(), 50); EXPECT_EQ(noGroup4.getMaxRank(), 5); EXPECT_EQ(noGroup4.getGroup(), ""); SharedRAbundVector noGroup5(noGroup4); EXPECT_EQ(noGroup5.getNumBins(), 10); EXPECT_EQ(noGroup5.getNumSeqs(), 50); EXPECT_EQ(noGroup5.getMaxRank(), 5); EXPECT_EQ(noGroup5.getGroup(), ""); ifstream in; Utils util; util.openInputFile(test.sharedFile, in); util.getline(in); //gobble headers SharedRAbundVector temp(in); EXPECT_EQ(temp.getNumBins(), 58); EXPECT_EQ(temp.getNumSeqs(), 20); EXPECT_EQ(temp.getMaxRank(), 5); EXPECT_EQ(temp.getGroup(), "F003D000"); SharedRAbundVector temp2(in); EXPECT_EQ(temp2.getNumBins(), 58); EXPECT_EQ(temp2.getNumSeqs(), 18); EXPECT_EQ(temp2.getMaxRank(), 3); EXPECT_EQ(temp2.getGroup(), "F003D002"); int numBins; string label, groupN; in >> label >> groupN >> numBins; SharedRAbundVector temp3(in, label, groupN, numBins); EXPECT_EQ(temp3.getNumBins(), 58); EXPECT_EQ(temp3.getNumSeqs(), 18); EXPECT_EQ(temp3.getMaxRank(), 5); EXPECT_EQ(temp3.getGroup(), "F003D004"); in.close(); }
bool Tringle::isPointOutTringle (const Point& p) const { Tringle temp1 (first, second, p); Tringle temp2 (second, third, p); Tringle temp3 (third, first, p); if (temp1.square() + temp2.square() + temp3.square() == this->square()) return false; return true; }
PS2Sprite3D::PS2Sprite3D(): conversionMatrix(Matrix4x4::IDENTITY) { Vector4 temp1(-1,-1,0,1); Vector4 temp2(1,-1,0,1); Vector4 temp3(1,1,0,1); Vector4 temp4(-1,1,0,1); Initialise(temp1, temp2, temp3, temp4); }
Machine::Machine() { std::shared_ptr<stack_t> temp1(new stack_t); std::shared_ptr<stack_t> temp2(new stack_t); std::shared_ptr<stack_t> temp3(new stack_t); D = nullptr; S = temp1; E = temp2; C = temp3; }
/** * @author YAO Wei, JIA Pei * @version 2010-05-20 * @brief Find the best offset for one point * @param ioShape Input and output - the input and output shape * @param iImg Input - image to be fitted * @param oImages Output - the output images * @param iLev Input - current pyramid level * @param PClose Input - percentage of converged points. Say, 0.9 means if 90% of the points * are judged as converged, the iteration of this pyramid can stop * @param epoch Input - the maximum iteration times * @param profdim Input - dimension used during fitting. For example, the trained data could be 4D, but the user may only use 1D * @note Refer to "AAM Revisited, page 34, figure 13", particularly, those steps. */ void VO_FittingASMNDProfiles::PyramidFit( VO_Shape& ioShape, const cv::Mat& iImg, std::vector<cv::Mat>& oImages, unsigned int iLev, float PClose, unsigned int epoch, unsigned int profdim, bool record) { VO_Shape tempShape = ioShape; int nGoodLandmarks = 0; float PyrScale = pow(2.0f, (float) (iLev) ); const int nQualifyingDisplacements = (int)(this->m_VOASMNDProfile->m_iNbOfPoints * PClose); for(unsigned int iter = 0; iter < epoch; iter++) { this->m_iIteration++; // estimate the best ioShape by profile matching the landmarks in this->m_VOFittingShape nGoodLandmarks = VO_FittingASMNDProfiles::UpdateShape( this->m_VOASMNDProfile, iImg, tempShape, this->m_vShape2DInfo, this->m_VOASMNDProfile->m_vvMeanNormalizedProfile[iLev], this->m_VOASMNDProfile->m_vvvCVMInverseOfSg[iLev], 3, profdim); // conform ioShape to the shape model this->m_VOASMNDProfile->VO_CalcAllParams4AnyShapeWithConstrain( tempShape, this->m_MatModelAlignedShapeParam, this->m_fScale, this->m_vRotateAngles, this->m_MatCenterOfGravity ); tempShape.ConstrainShapeInImage(iImg); if(record) { // If we get better fitting result, record this fitting result cv::Mat temp3 = cv::Mat(this->m_ImageInput.size(), this->m_ImageInput.type(), this->m_ImageInput.channels()); cv::Mat temp3ROI = temp3(cv::Range (0, (int)(this->m_ImageInput.rows/PyrScale) ), cv::Range (0, (int)(this->m_ImageInput.cols/PyrScale) ) ); cv::resize(this->m_ImageInput, temp3ROI, temp3ROI.size()); VO_Fitting2DSM::VO_DrawMesh(tempShape / this->m_fScale2, this->m_VOASMNDProfile, temp3); oImages.push_back(temp3); } // the fitting result is good enough to stop the iteration if(nGoodLandmarks > nQualifyingDisplacements) break; } ioShape = tempShape; }
void Machine::toDump() { Dump *temp_D = D; D = new Dump; D->D = temp_D; D->S = S; D->E = E; D->C = C; std::shared_ptr<stack_t> temp1(new stack_t); std::shared_ptr<stack_t> temp2(new stack_t); std::shared_ptr<stack_t> temp3(new stack_t); S = temp1; E = temp2; C = temp3; }
void Board::InitialiseLines() // Oh dear. { float zbase = 400; { Vector4 temp1(-390, 800, 1060 + zbase, 1); Vector4 temp2(-60, 800, 1060 + zbase, 1); Vector4 temp3(-60, 800, 1040 + zbase, 1); Vector4 temp4(-390, 800, 1040 + zbase, 1); boardlines[0].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(60, 800, 1060 + zbase, 1); Vector4 temp2(390, 800, 1060 + zbase, 1); Vector4 temp3(390, 800, 1040 + zbase, 1); Vector4 temp4(60, 800, 1040 + zbase, 1); boardlines[1].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(460, 800, 990 + zbase, 1); Vector4 temp2(460, 800, 660 + zbase, 1); Vector4 temp3(440, 800, 660 + zbase, 1); Vector4 temp4(440, 800, 990 + zbase, 1); boardlines[2].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(460, 800, 540 + zbase, 1); Vector4 temp2(460, 800, 210 + zbase, 1); Vector4 temp3(440, 800, 210 + zbase, 1); Vector4 temp4(440, 800, 540 + zbase, 1); boardlines[3].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(60, 800, 160 + zbase, 1); Vector4 temp2(390, 800, 160 + zbase, 1); Vector4 temp3(390, 800, 140 + zbase, 1); Vector4 temp4(60, 800, 140 + zbase, 1); boardlines[4].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-390, 800, 160 + zbase, 1); Vector4 temp2(-60, 800, 160 + zbase, 1); Vector4 temp3(-60, 800, 140 + zbase, 1); Vector4 temp4(-390, 800, 140 + zbase, 1); boardlines[5].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-460, 800, 540 + zbase, 1); Vector4 temp2(-440, 800, 540 + zbase, 1); Vector4 temp3(-440, 800, 210 + zbase, 1); Vector4 temp4(-460, 800, 210 + zbase, 1); boardlines[6].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-460, 800, 990 + zbase, 1); Vector4 temp2(-440, 800, 990 + zbase, 1); Vector4 temp3(-440, 800, 660 + zbase, 1); Vector4 temp4(-460, 800, 660 + zbase, 1); boardlines[7].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-240, 800, 910 + zbase, 1); Vector4 temp2(-60, 800, 910 + zbase, 1); Vector4 temp3(-60, 800, 890 + zbase, 1); Vector4 temp4(-240, 800, 890 + zbase, 1); boardlines[8].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(60, 800, 910 + zbase, 1); Vector4 temp2(240, 800, 910 + zbase, 1); Vector4 temp3(240, 800, 890 + zbase, 1); Vector4 temp4(60, 800, 890 + zbase, 1); boardlines[9].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(290, 800, 840 + zbase, 1); Vector4 temp2(310, 800, 840 + zbase, 1); Vector4 temp3(310, 800, 660 + zbase, 1); Vector4 temp4(290, 800, 660 + zbase, 1); boardlines[10].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(290, 800, 540 + zbase, 1); Vector4 temp2(310, 800, 540 + zbase, 1); Vector4 temp3(310, 800, 360 + zbase, 1); Vector4 temp4(290, 800, 360 + zbase, 1); boardlines[11].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(60, 800, 310 + zbase, 1); Vector4 temp2(240, 800, 310 + zbase, 1); Vector4 temp3(240, 800, 290 + zbase, 1); Vector4 temp4(60, 800, 290 + zbase, 1); boardlines[12].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-240, 800, 310 + zbase, 1); Vector4 temp2(-60, 800, 310 + zbase, 1); Vector4 temp3(-60, 800, 290 + zbase, 1); Vector4 temp4(-240, 800, 290 + zbase, 1); boardlines[13].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-290, 800, 540 + zbase, 1); Vector4 temp2(-310, 800, 540 + zbase, 1); Vector4 temp3(-310, 800, 360 + zbase, 1); Vector4 temp4(-290, 800, 360 + zbase, 1); boardlines[14].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-290, 800, 840 + zbase, 1); Vector4 temp2(-310, 800, 840 + zbase, 1); Vector4 temp3(-310, 800, 660 + zbase, 1); Vector4 temp4(-290, 800, 660 + zbase, 1); boardlines[15].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-90, 800, 760 + zbase, 1); Vector4 temp2(-60, 800, 760 + zbase, 1); Vector4 temp3(-60, 800, 740 + zbase, 1); Vector4 temp4(-90, 800, 740 + zbase, 1); boardlines[16].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(60, 800, 760 + zbase, 1); Vector4 temp2(90, 800, 760 + zbase, 1); Vector4 temp3(90, 800, 740 + zbase, 1); Vector4 temp4(60, 800, 740 + zbase, 1); boardlines[17].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(140, 800, 690 + zbase, 1); Vector4 temp2(150, 800, 690 + zbase, 1); Vector4 temp3(150, 800, 660 + zbase, 1); Vector4 temp4(140, 800, 660 + zbase, 1); boardlines[18].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(140, 800, 540 + zbase, 1); Vector4 temp2(150, 800, 540 + zbase, 1); Vector4 temp3(150, 800, 510 + zbase, 1); Vector4 temp4(140, 800, 510 + zbase, 1); boardlines[19].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(60, 800, 460 + zbase, 1); Vector4 temp2(90, 800, 460 + zbase, 1); Vector4 temp3(90, 800, 440 + zbase, 1); Vector4 temp4(60, 800, 440 + zbase, 1); boardlines[20].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-90, 800, 460 + zbase, 1); Vector4 temp2(-60, 800, 460 + zbase, 1); Vector4 temp3(-60, 800, 440 + zbase, 1); Vector4 temp4(-90, 800, 440 + zbase, 1); boardlines[21].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-160, 800, 540 + zbase, 1); Vector4 temp2(-140, 800, 540 + zbase, 1); Vector4 temp3(-140, 800, 510 + zbase, 1); Vector4 temp4(-160, 800, 510 + zbase, 1); boardlines[22].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-160, 800, 690 + zbase, 1); Vector4 temp2(-140, 800, 690 + zbase, 1); Vector4 temp3(-140, 800, 660 + zbase, 1); Vector4 temp4(-160, 800, 660 + zbase, 1); boardlines[23].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-10, 800, 840 + zbase, 1); Vector4 temp2(10, 800, 840 + zbase, 1); Vector4 temp3(10, 800, 810 + zbase, 1); Vector4 temp4(-10, 800, 810 + zbase, 1); boardlines[24].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-10, 800, 990 + zbase, 1); Vector4 temp2(10, 800, 990 + zbase, 1); Vector4 temp3(10, 800, 960 + zbase, 1); Vector4 temp4(-10, 800, 960 + zbase, 1); boardlines[25].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(210, 800, 610 + zbase, 1); Vector4 temp2(240, 800, 610 + zbase, 1); Vector4 temp3(240, 800, 590 + zbase, 1); Vector4 temp4(210, 800, 590 + zbase, 1); boardlines[26].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(360, 800, 610 + zbase, 1); Vector4 temp2(390, 800, 610 + zbase, 1); Vector4 temp3(390, 800, 590 + zbase, 1); Vector4 temp4(360, 800, 590 + zbase, 1); boardlines[27].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-10, 800, 390 + zbase, 1); Vector4 temp2(10, 800, 390 + zbase, 1); Vector4 temp3(10, 800, 360 + zbase, 1); Vector4 temp4(-10, 800, 360 + zbase, 1); boardlines[28].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-10, 800, 240 + zbase, 1); Vector4 temp2(10, 800, 240 + zbase, 1); Vector4 temp3(10, 800, 210 + zbase, 1); Vector4 temp4(-10, 800, 210 + zbase, 1); boardlines[29].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-390, 800, 610 + zbase, 1); Vector4 temp2(-360, 800, 610 + zbase, 1); Vector4 temp3(-360, 800, 590 + zbase, 1); Vector4 temp4(-390, 800, 590 + zbase, 1); boardlines[30].Initialise(temp1, temp2, temp3, temp4); } { Vector4 temp1(-240, 800, 610 + zbase, 1); Vector4 temp2(-210, 800, 610 + zbase, 1); Vector4 temp3(-210, 800, 590 + zbase, 1); Vector4 temp4(-240, 800, 590 + zbase, 1); boardlines[31].Initialise(temp1, temp2, temp3, temp4); } }
void Board::Initialise() { float zbase = 400; // Variable to store how deep in the z axis the object is based. Vector4 temp1(-600, 800, 1200 + zbase, 1); Vector4 temp2(600, 800, 1200 + zbase, 1); Vector4 temp3(600, 800, 0 + zbase, 1); Vector4 temp4(-600,800,0 + zbase,1); top.Initialise(temp1, temp2, temp3, temp4); // Set individual vertex locations for the top face of the board Vector4 col1(70,50,4,1); Vector4 col2(92,67,5,1); Vector4 col3(102,75,6,1); Vector4 col4(119,77,0,1); Vector4 col5(69, 25, 18, 1); top.SetColours(col1, col2, col2, col3); // Set individual colour values of each of those vertices Vector4 temp5(-600, 800, 0 + zbase, 1); Vector4 temp6(600, 800, 0 + zbase, 1); Vector4 temp7(600, 1000, 0 + zbase, 1); Vector4 temp8(-600,1000, 0 + zbase,1); // Individual vertices for the front face Vector4 temp9(-800, 1000, 1200 + zbase + 300, 1); Vector4 temp10(800, 1000, 1200 + zbase + 300, 1); Vector4 temp11(800, 1000, 100, 1); Vector4 temp12(-800, 1000, 100,1); // Individual vertices for the base face table.Initialise(temp9, temp10, temp11, temp12); table.SetColours(col5, col5, col5, col5); // Set to one mat colour, no shading. Vector4 temp13(-600, 800, 1200 + zbase, 1); Vector4 temp14(-600, 800, 0 + zbase, 1); Vector4 temp15(-600, 1000, 0 + zbase, 1); Vector4 temp16(-600, 1000, 1200 + zbase, 1); // Set individual vertices for the left face Vector4 temp17(600, 800, 0 + zbase, 1); Vector4 temp18(600, 800, 1200 + zbase, 1); Vector4 temp19(600, 1000, 1200 + zbase, 1); Vector4 temp20(600, 1000, 0 + zbase, 1); // Set individual vertices for the right face sides[0].Initialise(temp5, temp6, temp7, temp8); sides[1].Initialise(temp13, temp14, temp15, temp16); sides[2].Initialise(temp17, temp18, temp19, temp20); sides[3].Initialise(temp2, temp1, temp16, temp19); // Use known vertices to initialise the side faces sides[0].SetColours(col3, col4, col4, col2); sides[1].SetColours(col1, col2, col2, col1); sides[2].SetColours(col2, col1, col1, col2); sides[3].SetColours(col4, col4, col4, col4); // Then set the colours float positionLocations[24][2] = {{-450, 1050 + zbase}, //1 An array holding the centre locations {-300, 900 + zbase}, //2 of each of the positions where pieces {-150, 750 + zbase}, //3 can be placed. { 0 , 750 + zbase}, //4 { 150, 750 + zbase}, //5 { 300, 900 + zbase}, //6 { 450, 1050 + zbase}, //7 { 0 , 900 + zbase}, //8 { 0 , 1050 + zbase}, //9 {-450, 600 + zbase}, //10 {-300, 600 + zbase}, //11 {-150, 600 + zbase}, //12 {-450, 150 + zbase}, //13 {-300, 300 + zbase}, //14 {-150, 450 + zbase}, //15 { 0 , 150 + zbase}, //16 { 0 , 300 + zbase}, //17 { 0 , 450 + zbase}, //18 { 450, 150 + zbase}, //19 { 300, 300 + zbase}, //20 { 150, 450 + zbase}, //21 { 450, 600 + zbase}, //22 { 300, 600 + zbase}, //23 { 150, 600 + zbase}}; //24 for (int i = 0; i < 24; i++) { boardpositions[i].Initialise(positionLocations[i][0], positionLocations[i][1]); // Create the individual graphical representations } // (class Position) and put in array for easy drawing. InitialiseLines(); // Ugly function to draw each and every line on the // board with individual hand-placed vertices. SetupMills(); // Set up the mills (groups of three) with pointers to the positions // as alternate referencing option }
bool BlacklistTest(CDlgMain* dlg,CURL* curl,thread_status* this_struct) { dlg->console+=_T("\r\n*Retrieving Blacklist record."); dlg->UpdateData(FALSE); ScrollToBottom(dlg); CURLcode result; CString temp = _T("q="); CString temp2; temp+=dlg->res_domain;//GetDomain(dlg->settings->server_address); //temp+=_T("&check=check"); SetCurlUrl(curl,"http://www.blacklistalert.org/"); CleanData(this_struct); result = curl_easy_perform(curl); //<input type=hidden name="PHPSESSID" value="1885fc88a84fee781f38ef97da59386f"> int af = FindStr(this_struct->data,"name=\"PHPSESSID\" value=\"",0); int af2 = FindStr(this_struct->data,"\">",af); CString sess = CharToString(MidStr(this_struct->data,af+24,af2)); temp+=_T("&PHPSESSID=")+sess; curl_easy_setopt(curl, CURLOPT_POSTFIELDS, StringToChar(temp)); SetCurlUrl(curl,"http://www.blacklistalert.org/"); CleanData(this_struct); result = curl_easy_perform(curl); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, ""); if((this_struct->data==NULL)) { //dlg->MessageBox(_T("Unable to retrieve blacklist records")); dlg->result_blacklistednum = _T("?"); dlg->console+=_T("\r\nUnable to get Blacklist record."); dlg->UpdateData(FALSE); ScrollToBottom(dlg); } else { int pos1 = FindStr(this_struct->data,"(Alphabetic order):</b><br>",0); int pos1end = FindStr(this_struct->data,"<hr>",pos1+10); int pos2 = FindStr(this_struct->data,"(Alphabetic order)</b><br>",pos1end); int pos2end = FindStr(this_struct->data,"<hr>",pos2+10); if((pos1==-1)||(pos1end==-1)||(pos2==-1)||(pos2end==-1)) { dlg->result_blacklistednum = _T("?"); dlg->result_blacklist = _T("?"); dlg->console+=_T("\r\nUnable to get Blacklist record."); dlg->UpdateData(FALSE); ScrollToBottom(dlg); } else { int pos4 = 0, pos5 = 0, pos6 = pos1+26, pos7 = 0, pos8 = 0, pos9 = 0; bool ok; bool no_result; int c_ok = 0; int c_listed = 0; int count = 0; int index = 0; while((pos4!=-1)&&(pos6<pos2end)) // < !!!!!!!!!!!!!!!!!!! { pos4 = FindStr(this_struct->data,"<br>",pos6); if(pos4==pos1end-4) pos4 = FindStr(this_struct->data,"<br>",pos2+26); else if(pos4==pos2end-4) break; pos5 = FindStr(this_struct->data,"<font color=",pos4); temp = MidStr(this_struct->data,pos4+4,pos5-1); index = dlg->blacklist.InsertItem(dlg->blacklist.GetItemCount(),temp); pos6 = FindStr(this_struct->data,">",pos5+5); pos7 = FindStr(this_struct->data,"</em>",pos6); pos8 = FindStr(this_struct->data,"href=\"",pos6); pos9 = FindStr(this_struct->data,"\">",pos8); // is blacklsited or not ok = (strcmp((const char*)MidStr(this_struct->data,pos5+12,pos6),"green")==0); no_result = (strcmp((const char*)MidStr(this_struct->data,pos5+12,pos6),"magenta")==0); if(ok) { dlg->blacklist.SetItemText(index,1,_T("OK")); c_ok++; } else if(no_result) { dlg->blacklist.SetItemText(index,1,_T("NO RESULT")); } else { dlg->blacklist.SetItemText(index,1,_T("LISTED")); c_listed++; if(pos8<pos7) { CString temp3(MidStr(this_struct->data,pos8+6,pos9)); dlg->blacklist.SetItemText(index,2,temp3); } } count++; temp.Format(_T("%d"),c_listed); temp2.Format(_T("%d"),count); temp+=_T("/"); temp+=temp2; dlg->result_blacklistednum = temp; dlg->UpdateData(FALSE); } if(c_listed) dlg->result_blacklist = _T("YES"); else dlg->result_blacklist = _T("NO"); dlg->console+=_T("\r\nSuccess."); dlg->UpdateData(FALSE); ScrollToBottom(dlg); } } return true; }
// compute the log likelihood and its gradient w.r.t. theta int dtq::compGrad(void) { // remember, everything here is for equispaced data // we'll save the non-equispaced case for our scala + spark code :) if ((! haveData) || (! haveMyh)) return 1; if (spi<1) return 1; loglikmat = arma::zeros(ltvec-1,numts); if (spi==1) // special case { } else { // strategy: precompute and store common elements in Mats and Cubs // compute gradf and gradg at all spatial grid points arma::mat gradfy = arma::zeros(ylen,curtheta.n_elem); arma::mat gradgy = arma::zeros(ylen,curtheta.n_elem); this->gradFGyvec(gradfy, gradgy); // ompute gradf and gradg at all the data points arma::cube gradfdata = arma::zeros(curtheta.n_elem, (ltvec-1), numts); arma::cube gradgdata = arma::zeros(curtheta.n_elem, (ltvec-1), numts); this->gradFGdata(gradfdata, gradgdata); // initialize cubes to store all states and adjoints, // at all internal time points (spi-1), // for each pair of time series points (ltvec-1), // and at all spatial grid points (ylen) arma::cube dtqcube = arma::zeros(ylen,(ltvec-1),(spi-1)); arma::cube adjcube = arma::zeros(ylen,(ltvec-1),(spi-1)); // temporary matrix to store the initial state, phatinit arma::mat phatinit = arma::zeros(ylen,(ltvec-1)); // cube to store the gradient of the initial state w.r.t. theta arma::cube phatgrad = arma::zeros(ylen,(ltvec-1),curtheta.n_elem); // build the big matrix of initial conditions // and the gradients of those initial conditions! this->phatinitgrad(phatinit, phatgrad, gradfdata, gradgdata); dtqcube.slice(0) = phatinit; // propagate states forward in time by (spi-2) steps if (spi >= 3) for (int i=1; i<=(spi-2); i++) dtqcube.slice(i) = myk * prop * dtqcube.slice(i-1); // now multiply on the left by the Gamma vectors const arma::vec muvec = yvec + fy*myh; const arma::vec sigvec = gy*sqrt(myh); arma::cube allgamma = arma::zeros(ylen,numts,(ltvec-1)); for (int j=0; j<(ltvec-1); j++) { for (int l=0; l<numts; l++) { allgamma.slice(j).col(l) = myk*gausspdf((*odata)(j+1,l),muvec,sigvec); loglikmat(j,l) = log(arma::dot(allgamma.slice(j).col(l),dtqcube.slice(spi-2).col(j))); } } // std::cout << loglikmat << '\n'; // initialize the adjoint calculation for (int j=0; j<(ltvec-1); j++) for (int l=0; l<numts; l++) adjcube.slice(spi-2).col(j) += allgamma.slice(j).col(l) / exp(loglikmat(j,l)); // propagate adjoints backward in time by (spi-2) steps arma::sp_mat transprop = prop.t(); if (spi >= 3) for (int i=(spi-2); i>=1; i--) adjcube.slice(i-1) = myk * transprop * adjcube.slice(i); // stuff that we need for a bunch of gradients gradloglik = arma::zeros(curtheta.n_elem); arma::vec gvecm1 = arma::pow(gy,-1); arma::vec gvecm2 = arma::pow(gy,-2); arma::vec gvecm3 = arma::pow(gy,-3); // actual gradient calculation // proceed element-wise through theta_i for (int i=0; i<curtheta.n_elem; i++) { arma::vec temp1 = gvecm2 % gradfy.col(i); arma::vec temp2 = gvecm1 % gradgy.col(i); arma::vec temp3 = (1.0/myh)*gvecm3 % gradgy.col(i); arma::sp_mat::const_iterator start = prop.begin(); arma::sp_mat::const_iterator end = prop.end(); arma::umat dkdtloc(2, prop.n_nonzero); arma::vec dkdtval(prop.n_nonzero); unsigned int dkdtc = 0; for (arma::sp_mat::const_iterator it = start; it != end; ++it) { dkdtloc(0,dkdtc) = it.row(); dkdtloc(1,dkdtc) = it.col(); dkdtc++; } #pragma omp parallel for for (unsigned int dkdtcount=0; dkdtcount < prop.n_nonzero; dkdtcount++) { unsigned int orow = dkdtloc(0,dkdtcount); unsigned int ocol = dkdtloc(1,dkdtcount); double comval = yvec(orow) - muvec(ocol); dkdtval(dkdtcount) = myk*(prop.values[dkdtcount])*( comval*temp1(ocol) - temp2(ocol) + temp3(ocol)*comval*comval ); } arma::sp_mat dkdtheta(dkdtloc, dkdtval, ylen, ylen, false, true); // implement formula (22) from the DSAA paper // need gradient of Gamma{F-1} double tally = 0.0; #pragma omp parallel for reduction(+:tally) for (int j=0; j<(ltvec-1); j++) { tally += arma::dot(phatgrad.slice(i).col(j),adjcube.slice(0).col(j)); } #pragma omp parallel for collapse(2) reduction(+:tally) for (int j=0; j<(ltvec-1); j++) for (int l=0; l<numts; l++) { double xi = (*odata)((j+1),l); arma::vec gammagrad = (xi-muvec) % temp1; gammagrad += arma::pow(xi-muvec,2) % temp3; gammagrad -= temp2; gammagrad = gammagrad % allgamma.slice(j).col(l); tally += arma::dot(gammagrad,dtqcube.slice(spi-2).col(j)) / exp(loglikmat(j,l)); } // we have tested and found that the dot product is better than the // triple matrix product here, i.e., it is worth taking the transpose // arma::mat dkdtheta = dkdthetatrans.t(); #pragma omp parallel for collapse(2) reduction(+:tally) for (int j=0; j<(ltvec-1); j++) for (int l=0; l<(spi-2); l++) { tally += arma::dot((dkdtheta*dtqcube.slice(l).col(j)),adjcube.slice(l+1).col(j)); } gradloglik(i) = tally; } } haveLoglik = true; haveGradloglik = true; return 0; }
void Pyramid::createBlobs() { for(int octaveIndex = 0; octaveIndex < octaves.size(); octaveIndex++){ //Разность гаусианов for(int levelIndex = 0; levelIndex < octaves.at(octaveIndex).getLevelsCount() - 1; levelIndex++){ for(int x = 0; x < octaves.at(octaveIndex).getLevel(levelIndex).getImage().getWidth(); x++){ for(int y = 0; y < octaves.at(octaveIndex).getLevel(levelIndex).getImage().getHeight(); y++){ octaves.at(octaveIndex).getLevel(levelIndex).getImage().setPixel(x,y, octaves.at(octaveIndex).getLevel(levelIndex+1).getImage().getPixel(x,y)-octaves.at(octaveIndex).getLevel(levelIndex).getImage().getPixel(x,y)); } } } octaves.at(octaveIndex).getLevels().pop_back(); for(int firstLevelIndex = 1; firstLevelIndex < octaves.at(octaveIndex).getLevelsCount() - 1; firstLevelIndex++){ std::vector<IntrestingPoint> blobs; Image temp1(octaves[octaveIndex].getLevel(firstLevelIndex).getImage()); Image temp2(octaves[octaveIndex].getLevel(firstLevelIndex+1).getImage()); Image temp3(octaves[octaveIndex].getLevel(firstLevelIndex-1).getImage()); for(int x = 1; x < temp1.getWidth()-1; x++){ for(int y = 1; y <temp1.getHeight()-1; y++){ double extremumValue = temp1.getPixel(x,y); bool max = true; bool min = true; if(temp1.getPixel(x-1, y+1) >= extremumValue || temp2.getPixel(x-1, y+1) >= extremumValue || temp3.getPixel(x-1, y+1) >= extremumValue) { max = false; } if(temp1.getPixel(x, y+1) >= extremumValue || temp2.getPixel(x, y+1) >= extremumValue || temp3.getPixel(x, y+1) >= extremumValue) { max = false; } if(temp1.getPixel(x+1, y+1) >= extremumValue || temp2.getPixel(x+1, y+1) >= extremumValue || temp3.getPixel(x+1, y+1) >= extremumValue) { max = false; } if(temp1.getPixel(x-1, y) >= extremumValue || temp2.getPixel(x-1, y) >= extremumValue || temp3.getPixel(x-1, y) >= extremumValue) { max = false; } if(temp2.getPixel(x, y) >= extremumValue || temp3.getPixel(x, y) >= extremumValue) { max = false; } if(temp1.getPixel(x+1, y) >= extremumValue || temp2.getPixel(x+1, y) >= extremumValue || temp3.getPixel(x+1, y) >= extremumValue) { max = false; } if(temp1.getPixel(x-1, y-1) >= extremumValue || temp2.getPixel(x-1, y-1) >= extremumValue || temp3.getPixel(x-1, y-1) >= extremumValue) { max = false; } if(temp1.getPixel(x, y-1) >= extremumValue || temp2.getPixel(x, y-1) >= extremumValue || temp3.getPixel(x, y-1) >= extremumValue) { max = false; } if(temp1.getPixel(x+1, y-1) >= extremumValue || temp2.getPixel(x+1, y-1) >= extremumValue || temp3.getPixel(x+1, y-1) >= extremumValue) { max = false; } if(temp1.getPixel(x-1, y+1) <= extremumValue || temp2.getPixel(x-1, y+1) <= extremumValue || temp3.getPixel(x-1, y+1) <= extremumValue) { min = false; } if(temp1.getPixel(x, y+1) <= extremumValue || temp2.getPixel(x, y+1) <= extremumValue || temp3.getPixel(x, y+1) <= extremumValue) { min = false; } if(temp1.getPixel(x+1, y+1) <= extremumValue || temp2.getPixel(x+1, y+1) <= extremumValue || temp3.getPixel(x+1, y+1) <= extremumValue) { min = false; } if(temp1.getPixel(x-1, y) <= extremumValue || temp2.getPixel(x-1, y) <= extremumValue || temp3.getPixel(x-1, y) <= extremumValue) { min = false; } if(temp2.getPixel(x, y) <= extremumValue || temp3.getPixel(x, y) <= extremumValue) { min = false; } if(temp1.getPixel(x+1, y) <= extremumValue || temp2.getPixel(x+1, y) <= extremumValue || temp3.getPixel(x+1, y) <= extremumValue) { min = false; } if(temp1.getPixel(x-1, y-1) <= extremumValue || temp2.getPixel(x-1, y-1) <= extremumValue || temp3.getPixel(x-1, y-1) <= extremumValue) { min = false; } if(temp1.getPixel(x, y-1) <= extremumValue || temp2.getPixel(x, y-1) <= extremumValue || temp3.getPixel(x, y-1) <= extremumValue) { min = false; } if(temp1.getPixel(x+1, y-1) <= extremumValue || temp2.getPixel(x+1, y-1) <= extremumValue || temp3.getPixel(x+1, y-1) <= extremumValue) { min = false; } if(max || min){ IntrestingPoint blob( x, y, extremumValue, octaveIndex, firstLevelIndex, octaves.at(octaveIndex).getLevel(firstLevelIndex).getSigma(), sqrt(2)*(octaves.at(octaveIndex).getLevel(firstLevelIndex).getSigma() * (double)pow(2,octaveIndex)) ); double harris = octaves.at(octaveIndex).getLevel(firstLevelIndex).getImage().harrisForPoint(blob); if(harris > 0.00001){ blobs.push_back(blob); } } } } octaves.at(octaveIndex).getLevel(firstLevelIndex).getImage().setPoints(blobs); } } }
void BPTree::insertNonleaf(Node node,Value key,PtrType pointer) { if (node.getNodePtr() == root) { Node newNode(dbName,indexName,tableInstance,n); vector<Value> keyList; Value temp1(_TYPE_INT,node.getNodePtr()); Value temp2(_TYPE_INT,pointer); keyList.push_back(temp1); keyList.push_back(key); keyList.push_back(temp2); newNode.set(keyList); root = newNode.getNodePtr(); //把根节点的更改写入磁盘 int firstBlock = bfm->getIndexBlocks(indexName)[0];//获取开始的块 Node rootNode(dbName,firstBlock,indexName,tableInstance,n); Value temp3(_TYPE_INT,root); vector<Value> temp4; temp4.push_back(temp3); rootNode.set(temp4); } else { Node parentNode(dbName,findParentNode(node.getNodePtr()),indexName,tableInstance,n); if (parentNode.getCount() < n) { vector<Value> keyList = parentNode.getInfo();//只读键值对 if (isLess(key,keyList[0])) { Value tempPtr(_TYPE_INT,pointer); keyList.insert(keyList.begin()+1,tempPtr); keyList.insert(keyList.begin()+1,key); } else { for (int i = (keyList.size() - 1 - 1); i >= 0; i-=2) { if (isLessEqual(keyList.at(i),key)) { Value tempPtr(_TYPE_INT,pointer); keyList.insert(keyList.begin() + i+2,tempPtr);//TODO:最后一个会怎么样? keyList.insert(keyList.begin() + i+2,key); break; } } } parentNode.set(keyList); } else//分裂ParentNode { //排序 vector<Value> keyList = parentNode.getInfo();//只读键值对 if (isLess(key,keyList[0])) { Value tempPtr(_TYPE_INT,pointer); keyList.insert(keyList.begin()+1,tempPtr); keyList.insert(keyList.begin()+1,key); } else { for (int i = (keyList.size() - 1 - 1); i >= 0; i-=2) { if (isLessEqual(keyList.at(i),key)) { Value tempPtr(_TYPE_INT,pointer); keyList.insert(keyList.begin() + i+2,tempPtr);//TODO:最后一个会怎么样? keyList.insert(keyList.begin() + i+2,key); break; } } } //赋值元素到该到的地方 int breakPoint = 0; if (n % 2 == 0) breakPoint = (n /2); else breakPoint = ((n / 2) + 1); vector<Value> temp; temp.push_back(keyList[0]); int j = 1; for (int i = 1; i < breakPoint; i++) { temp.push_back(keyList[j]); temp.push_back(keyList[++j]); } parentNode.set(temp); Value newK = keyList[++j]; vector<Value> temp2; for (int i = j + 1; i < keyList.size(); i++) { temp2.push_back(keyList[i]); } Node newNode(dbName,indexName,tableInstance,n); newNode.set(temp2); insertNonleaf(parentNode,newK,newNode.getNodePtr()); } } }
// 색1 색2 색1 색2 색1 색2 void Take_Copter(Mat Cam, Mat Cam2, Copter& cop) { pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; Mat YUV_PIC3; Mat Pic2_col1(cop.Picture3.rows,cop.Picture3.cols,CV_8UC1); Mat Pic2_col2(cop.Picture3.rows,cop.Picture3.cols,CV_8UC1); Mat temp3(cop.Picture3.rows,cop.Picture3.cols,CV_8UC1); Mat temp4(cop.Picture3.rows,cop.Picture3.cols,CV_8UC1); Mat temp5(cop.Picture3.rows,cop.Picture3.cols,CV_8UC1); Mat temp6(cop.Picture3.rows,cop.Picture3.cols,CV_8UC1); cvtColor(cop.Picture3,YUV_PIC3,CV_RGB2YCrCb); vector<Mat> yuv; Mat Corr_1_1;//색1 Mat Corr_1_2;//색1 Mat Corr_2_1;//색2 Mat Corr_2_2;//색2 int corr_size_X =0; int corr_size_Y =0; Mat Result; double min,max; Point Copter_point; for(int i=0; i<V_BUFFER_SIZE; i++) { cop.prev_cx[i] = -5000; cop.prev_cy[i] = -5000; } if(cop.find_mode == true){ cop.find_mode = false; matchTemplate(Cam,cop.Pic_Binary1,Corr_1_1,CV_TM_CCOEFF_NORMED); matchTemplate(Cam2,cop.Pic_Binary2,Corr_1_2,CV_TM_CCOEFF_NORMED); if(Corr_1_1.rows<Corr_1_2.rows) { corr_size_Y = Corr_1_1.rows; } else { corr_size_Y = Corr_1_2.rows; } if(Corr_1_1.cols<Corr_1_2.cols) { corr_size_X = Corr_1_1.cols; } else { corr_size_X = Corr_1_2.cols; } resize(Corr_1_1,Corr_1_1,Size(corr_size_X,corr_size_Y),0,0,INTER_CUBIC); resize(Corr_1_2,Corr_1_2,Size(corr_size_X,corr_size_Y),0,0,INTER_CUBIC); Result = (0.6*Corr_1_1)+(0.6*Corr_1_2); } else { cop.find_mode = true; split(YUV_PIC3,yuv); threshold(yuv[0],yuv[0],cop.Y_MAX,255,THRESH_TOZERO_INV); threshold(yuv[0],Pic2_col1,cop.Y_MIN,255,THRESH_BINARY); threshold(yuv[1],yuv[1],cop.Cb_MAX,255,THRESH_TOZERO_INV); threshold(yuv[1],temp3,cop.Cb_MIN,255,THRESH_BINARY); threshold(yuv[2],yuv[2],cop.Cr_MAX,255,THRESH_TOZERO_INV); threshold(yuv[2],temp4,cop.Cr_MIN,255,THRESH_BINARY); bitwise_and(Pic2_col1,temp3,temp3); bitwise_and(temp3,temp4,Pic2_col1); split(YUV_PIC3,yuv); threshold(yuv[0],yuv[0],cop.Y_MAX2,255,THRESH_TOZERO_INV); threshold(yuv[0],Pic2_col2,cop.Y_MIN2,255,THRESH_BINARY); threshold(yuv[1],yuv[1],cop.Cb_MAX2,255,THRESH_TOZERO_INV); threshold(yuv[1],temp5,cop.Cb_MIN2,255,THRESH_BINARY); threshold(yuv[2],yuv[2],cop.Cr_MAX2,255,THRESH_TOZERO_INV); threshold(yuv[2],temp6,cop.Cr_MIN2,255,THRESH_BINARY); bitwise_and(Pic2_col2,temp5,temp5); bitwise_and(temp5,temp6,Pic2_col2); matchTemplate(Cam,Pic2_col1,Corr_2_1,CV_TM_CCOEFF_NORMED); matchTemplate(Cam2,Pic2_col2,Corr_2_2,CV_TM_CCOEFF_NORMED); if(Corr_2_1.rows<Corr_2_2.rows) { corr_size_Y = Corr_2_1.rows; } else { corr_size_Y = Corr_2_2.rows; } if(Corr_2_1.cols<Corr_2_2.cols) { corr_size_X = Corr_2_1.cols; } else { corr_size_X = Corr_2_2.cols; } resize(Corr_2_1,Corr_2_1,Size(corr_size_X,corr_size_Y),0,0,INTER_CUBIC); resize(Corr_2_2,Corr_2_2,Size(corr_size_X,corr_size_Y),0,0,INTER_CUBIC); Result = (0.6*Corr_2_1)+(0.6*Corr_2_2); } // imshow("3",Pic2_col2); // imshow("2",Pic2_col1); // imshow("1",Result); minMaxLoc(Result,&min,&max,NULL,&Copter_point); cop.width = 3*(cop.Pic_Binary2.cols); cop.height =3*(cop.Pic_Binary2.rows); cop.x = Copter_point.x-(cop.width/3); cop.y = Copter_point.y-(cop.height/3); Reposition_minus(cop); pthread_mutex_lock(&mutex);// =========* resize(cop.Copter_Layer,cop.Copter_Layer,Size(cop.width,cop.height),0,0,INTER_NEAREST); if(cop.number == 1) cop.Copter_Layer = Cam_Image(Rect(cop.x , cop.y , cop.width , cop.height ) ); else if(cop.number == 2) cop.Copter_Layer = Cam_Image(Rect(cop.x,cop.y,cop.width,cop.height)); pthread_mutex_unlock(&mutex);// ==========* }
CFX_PtrArray* CBC_ReedSolomonDecoder::RunEuclideanAlgorithm( CBC_ReedSolomonGF256Poly* a, CBC_ReedSolomonGF256Poly* b, int32_t R, int32_t& e) { if (a->GetDegree() < b->GetDegree()) { CBC_ReedSolomonGF256Poly* temp = a; a = b; b = temp; } CBC_ReedSolomonGF256Poly* rsg1 = a->Clone(e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> rLast(rsg1); CBC_ReedSolomonGF256Poly* rsg2 = b->Clone(e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> r(rsg2); CBC_ReedSolomonGF256Poly* rsg3 = m_field->GetOne()->Clone(e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> sLast(rsg3); CBC_ReedSolomonGF256Poly* rsg4 = m_field->GetZero()->Clone(e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> s(rsg4); CBC_ReedSolomonGF256Poly* rsg5 = m_field->GetZero()->Clone(e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> tLast(rsg5); CBC_ReedSolomonGF256Poly* rsg6 = m_field->GetOne()->Clone(e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> t(rsg6); while (r->GetDegree() >= R / 2) { CBC_AutoPtr<CBC_ReedSolomonGF256Poly> rLastLast = rLast; CBC_AutoPtr<CBC_ReedSolomonGF256Poly> sLastLast = sLast; CBC_AutoPtr<CBC_ReedSolomonGF256Poly> tLastlast = tLast; rLast = r; sLast = s; tLast = t; if (rLast->IsZero()) { e = BCExceptionR_I_1IsZero; BC_EXCEPTION_CHECK_ReturnValue(e, NULL); } CBC_ReedSolomonGF256Poly* rsg7 = rLastLast->Clone(e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> rTemp(rsg7); r = rTemp; CBC_ReedSolomonGF256Poly* rsg8 = m_field->GetZero()->Clone(e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> q(rsg8); int32_t denominatorLeadingTerm = rLast->GetCoefficients(rLast->GetDegree()); int32_t dltInverse = m_field->Inverse(denominatorLeadingTerm, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); while (r->GetDegree() >= rLast->GetDegree() && !(r->IsZero())) { int32_t degreeDiff = r->GetDegree() - rLast->GetDegree(); int32_t scale = m_field->Multiply(r->GetCoefficients(r->GetDegree()), dltInverse); CBC_ReedSolomonGF256Poly* rsgp1 = m_field->BuildMonomial(degreeDiff, scale, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> build(rsgp1); CBC_ReedSolomonGF256Poly* rsgp2 = q->AddOrSubtract(build.get(), e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp(rsgp2); q = temp; CBC_ReedSolomonGF256Poly* rsgp3 = rLast->MultiplyByMonomial(degreeDiff, scale, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> multiply(rsgp3); CBC_ReedSolomonGF256Poly* rsgp4 = r->AddOrSubtract(multiply.get(), e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp3(rsgp4); r = temp3; } CBC_ReedSolomonGF256Poly* rsg9 = q->Multiply(sLast.get(), e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp1(rsg9); CBC_ReedSolomonGF256Poly* rsg10 = temp1->AddOrSubtract(sLastLast.get(), e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp2(rsg10); s = temp2; CBC_ReedSolomonGF256Poly* rsg11 = q->Multiply(tLast.get(), e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp5(rsg11); CBC_ReedSolomonGF256Poly* rsg12 = temp5->AddOrSubtract(tLastlast.get(), e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp6(rsg12); t = temp6; } int32_t sigmaTildeAtZero = t->GetCoefficients(0); if (sigmaTildeAtZero == 0) { e = BCExceptionIsZero; BC_EXCEPTION_CHECK_ReturnValue(e, NULL); } int32_t inverse = m_field->Inverse(sigmaTildeAtZero, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_ReedSolomonGF256Poly* rsg13 = t->Multiply(inverse, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> sigma(rsg13); CBC_ReedSolomonGF256Poly* rsg14 = r->Multiply(inverse, e); BC_EXCEPTION_CHECK_ReturnValue(e, NULL); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> omega(rsg14); CFX_PtrArray* temp = new CFX_PtrArray; temp->Add(sigma.release()); temp->Add(omega.release()); return temp; }
//write relation TEST(ParserAttList, ParAttList) { //CREATE TABLE species (kind VARCHAR(10)) PRIMARY KEY (kind); Token temp(Token::KEYWORD); temp.content = "CREATE"; tokens.push_back(temp); Token temp1(Token::KEYWORD); temp.content = "TABLE"; tokens.push_back(temp1); Token temp2(Token::VARIABLE); temp.content = "species"; tokens.push_back(temp2); Token temp3(Token::OPENPAREN); temp.content = "("; tokens.push_back(temp3); Token temp4(Token::VARIABLE); temp.content = "kind"; tokens.push_back(temp4); Token temp5(Token::KEYWORD); temp.content = "VARCHAR"; tokens.push_back(temp5); Token temp6(Token::OPENPAREN); temp.content = "("; tokens.push_back(temp6); Token temp7(Token::LITERAL); temp.content = "10"; tokens.push_back(temp7); Token temp8(Token::CLOSEPAREN); temp.content = ")"; tokens.push_back(temp8); Token temp9(Token::CLOSEPAREN); temp.content = ")"; tokens.push_back(temp9); Token temp10(Token::KEYWORD); temp.content = "PRIMARY"; tokens.push_back(temp10); Token temp11(Token::KEYWORD); temp.content = "KEY"; tokens.push_back(temp11); Token temp12(Token::OPENPAREN); temp.content = "("; tokens.push_back(temp12); Token temp13(Token::VARIABLE); temp.content = "kind"; tokens.push_back(temp13); Token temp14(Token::CLOSEPAREN); temp.content = ")"; tokens.push_back(temp14); pars.command(tokens); }
// u is used to denote this effect // v other effect // If nThisContexts == 1, then nGlobalFactors and Q_size must be 0 and // Q, globalSample, globalPostMean, globalPostVar, globalPriorVar and thisContext will not be touched. // If nOtherContexts == 1, then otherContext will not be touched. extern "C" void gaussianPosterior_2WayInteraction_2Levels( // OUTPUT double* localSample /* nLevelsThisEff x nLocalFactors x nThisContexts (u) */, double* globalSample /* nLevelsThisEff x nGlobalFactors (u_global) */, double* localPostMean /* NULL or nLevelsThisEff x nLocalFactors x nThisContexts: This is the posterior given the globalSample */, double* localPostVar /* NULL or nLevelsThisEff x nLocalFactors x nLocalFactors x nThisContexts: This is the posterior given the globalSample */, double* globalPostMean /* NULL or nLevelsThisEff x nGlobalFactors */, double* globalPostVar /* NULL or nLevelsThisEff x nGlobalFactors x nGlobalFactors */, //INPUT const int* option /*1: output sample, 2: output mean & var, 3: output sample & Mean & Var*/, const int* thisEffIndex /* nObs x 1 */, const int* otherEffIndex /* nObs x 1 */, const int* thisContext /* nObs x 1 */, const int* otherContext /* nObs x 1 */, const double* obs /* nObs x 1 */, const double* Q /* nLocalFactors x nGlobalFactors x nThisContexts */, const double* offset, /* NULL or nLevelsThisEff x nLocalFactors x nThisContexts */ const double* obsVar /* nObsVar x 1 */, const double* localPriorVar /* nThisContexts x 1 */, const double* globalPriorVar /* 1x1 */, const double* otherEff /* nLevelsOtherEff x nLocalFactors x nOtherContexts */, const int* nObs_, const int* nObsVar_ /* 1 or nObs */, const int* nLevelsThisEff_, const int* nThisContexts_, const int* nLevelsOtherEff_, const int* nOtherContexts_, const int* nLocalFactors_, const int* nGlobalFactors_, const int* nOffset_ /* 0 or nLevelsThisEff*nLocalFactors*nThisContexts */, const int* Q_size_ /* 1 or nLocalFactors*nGlobalFactors*nThisContexts */, const int* obsIndex, const int* oiStart, const int* oiNum, // OTHER const int* debug_, const int* verbose_ ){ int nObs=(*nObs_), nObsVar=(*nObsVar_), nLevelsThisEff=(*nLevelsThisEff_), nThisContexts=(*nThisContexts_), nLevelsOtherEff=(*nLevelsOtherEff_), nOtherContexts=(*nOtherContexts_), nLocalFactors=(*nLocalFactors_), nGlobalFactors=(*nGlobalFactors_), nOffset=(*nOffset_), Q_size=(*Q_size_), debug=(*debug_), verbose=(*verbose_); if(nObsVar != 1 && nObsVar != nObs) STOP1("nObsVar = %d", nObsVar); if(nThisContexts == 1 && nGlobalFactors != 0) STOP1("nThisContexts = 1, but nGlobalFactors = %d", nGlobalFactors); if(nThisContexts == 1 && Q_size != 0) STOP1("nThisContexts = 1, but Q_size = %d", Q_size); if(Q_size != 1 && Q_size != nLocalFactors*nGlobalFactors*nThisContexts) STOP1("Q_size = %d", Q_size); if(Q_size == 1 && Q[0] != 1 && Q[0] != 0) STOP1("Q = ", Q[0]); int outputMeanVar, drawSample; if(*option == 1){ outputMeanVar = 0; drawSample = 1; }else if(*option == 2){ outputMeanVar = 1; drawSample = 0; }else if(*option == 3){ outputMeanVar = 1; drawSample = 1; }else STOP1("Unknown option: %d", *option); // Initialize objects int max_nFactors = MAX(nLocalFactors, nGlobalFactors); int *num = (int*)Calloc(nThisContexts, int); // num[k]: #obs of user i in context k int N = (nThisContexts == 1 ? nLocalFactors : nGlobalFactors); Matrix_ColumnMajor temp1(max_nFactors, max_nFactors), temp2(max_nFactors, max_nFactors), temp3(max_nFactors, max_nFactors), globalMean(N,1), globalVar(N,N); Matrix_ColumnMajor *E_i = new Matrix_ColumnMajor[nThisContexts]; Matrix_ColumnMajor *S_i = new Matrix_ColumnMajor[nThisContexts]; Matrix_ColumnMajor *z_i = new Matrix_ColumnMajor[nThisContexts]; Matrix_ColumnMajor *Q_ = new Matrix_ColumnMajor[nThisContexts]; Matrix_ColumnMajor *Qt_ = new Matrix_ColumnMajor[nThisContexts]; for(int k=0; k<nThisContexts; k++){ E_i[k].resize(nLocalFactors, nLocalFactors); S_i[k].resize(nLocalFactors, nLocalFactors); z_i[k].resize(nLocalFactors, 1); if(Q_size > 1){ Q_[k].resize(nLocalFactors, nGlobalFactors); for(int a=0; a<nLocalFactors; a++) for(int b=0; b<nGlobalFactors; b++) Q_[k](a,b) = Q[C_3DA(a,b,k,nLocalFactors,nGlobalFactors)]; Qt_[k].transpose(Q_[k]); } } double *v_jk = (double*)Calloc(nLocalFactors, double); // o[ijk] = obs[ijk] - v[j,,k]' offset[i,,k] double *o; if(nOffset == 0){ o = (double*)obs; }else if(nOffset == nLevelsThisEff*nLocalFactors*nThisContexts){ o = (double*)Calloc(nObs, double); computeMultiResponseUV( o, offset, otherEff, thisEffIndex, otherEffIndex, thisContext, otherContext, nObs_, nLocalFactors_, nLevelsThisEff_, nThisContexts_, nLevelsOtherEff_, nOtherContexts_, debug_ ); for(int m=0; m<nObs; m++) o[m] = obs[m] - o[m]; }else STOP1("nOffset = %d", nOffset);