예제 #1
0
파일: 10591.cpp 프로젝트: waiwai444/oj
int main()
{
	int i, c, tc, n, m;
	scanf("%d", &tc);
	visited[1] = happy[1] = true;
	for(c = 1; c <= tc; c++)
	{
		scanf("%d", &n);
		path.clear();
		m = n;
		if(m >= MAX)
			m = ssd(m);
		while(!visited[m])
		{
			visited[m] = true;
			path.push_back(m);
			m = ssd(m);
		}
		if(happy[m])
			for(i = 0; i < path.size(); i++)
				happy[path[i]] = happy[m];
		printf("Case #%d: %d is %s number.\n", c, n, happy[m] ? "a Happy" : "an Unhappy");
	}
	return 0;
}
예제 #2
0
파일: algo_x.c 프로젝트: RodrigoNieves/vlc
static inline int XDeint8x8DetectC( uint8_t *src, int i_src )
{
    int y, x;
    int ff, fr;
    int fc;

    /* Detect interlacing */
    fc = 0;
    for( y = 0; y < 7; y += 2 )
    {
        ff = fr = 0;
        for( x = 0; x < 8; x++ )
        {
            fr += ssd(src[      x] - src[1*i_src+x]) +
                  ssd(src[i_src+x] - src[2*i_src+x]);
            ff += ssd(src[      x] - src[2*i_src+x]) +
                  ssd(src[i_src+x] - src[3*i_src+x]);
        }
        if( ff < 6*fr/8 && fr > 32 )
            fc++;

        src += 2*i_src;
    }

    return fc < 1 ? false : true;
}
예제 #3
0
	virtual SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const {
		Common::String filename = generateGameStateFileName(target, slot);
		Common::ScopedPtr<Common::InSaveFile> in(g_system->getSavefileManager()->openForLoading(filename));
		if (!in)
			return SaveStateDescriptor();

		char buf[25];
		in->seek(0);
		in->read(buf, 24);
		buf[24] = 0;

		Common::String desc = buf;

		in->seek(TeenAgent::saveStateSize);
		if (!Graphics::checkThumbnailHeader(*in))
			return SaveStateDescriptor(slot, desc);

		SaveStateDescriptor ssd(slot, desc);

		//checking for the thumbnail
		if (Graphics::Surface *const thumb = Graphics::loadThumbnail(*in))
			ssd.setThumbnail(thumb);

		return ssd;
	}
예제 #4
0
TEST(TestSSD, Dev)
{
    tdv::ImageReader readerL("../../res/tsukuba_L.png");
    tdv::ImageReader readerR("../../res/tsukuba_R.png");
    tdv::FloatConv fconvl, fconvr;
    tdv::RGBConv rconvl, rconvr;

    tdv::SSDDev ssd(16);

    fconvl.input(readerL.output());
    fconvr.input(readerR.output());

    ssd.inputs(fconvl.output(), fconvr.output());

    readerL.update();
    readerR.update();
    fconvl.update();
    fconvr.update();
    ssd.update();

    tdv::DSIMem dsi;
    ASSERT_TRUE(ssd.output()->read(&dsi));

    EXPECT_EQ(384, dsi.dim().width());
    EXPECT_EQ(288, dsi.dim().height());
    EXPECT_EQ(16, dsi.dim().depth());
}
예제 #5
0
int
App::Main()
{
    FNET_SignalShutDown::hookSignals();
    // would like to turn off FNET logging somehow
    if (_argc < 3) {
        fprintf(stderr, "usage: %s <listenspec> <connectspec> [verbose]\n", _argv[0]);
        return 1;
    }
    bool verbose = (_argc > 3) && (strcmp(_argv[3], "verbose") == 0);

    FRT_Supervisor supervisor;
    RPCProxy       proxy(supervisor, _argv[2], verbose);

    supervisor.GetReflectionManager()->Reset();
    supervisor.SetSessionInitHook(FRT_METHOD(RPCProxy::HOOK_Init), &proxy);
    supervisor.SetSessionDownHook(FRT_METHOD(RPCProxy::HOOK_Down), &proxy);
    supervisor.SetSessionFiniHook(FRT_METHOD(RPCProxy::HOOK_Fini), &proxy);
    supervisor.SetMethodMismatchHook(FRT_METHOD(RPCProxy::HOOK_Mismatch),
                                     &proxy);
    supervisor.Listen(_argv[1]);
    FNET_SignalShutDown ssd(*supervisor.GetTransport());
    supervisor.Main();
    return 0;
}
예제 #6
0
sp_session *SpotifySession::get(abort_callback & p_abort) {
	SpotifySessionData ssd(p_abort, this);
	InitOnceExecuteOnce(&initOnce,
		makeSpotifySession,
		&ssd,
		NULL);
	return getAnyway();
}
예제 #7
0
TEST(TestSSD, WithDynCPU)
{
    tdv::SSDDev ssd(128);
    tdv::DynamicProgCPU dp;
    runStereoTest(
        "../../res/tsukuba512_L.png",
        "../../res/tsukuba512_R.png",
        "tsukuba_ssddynprogcpu.png",
        &ssd, &dp);
}
예제 #8
0
TEST(TestSSD, WithMedianWTA)
{
    tdv::SSDDev ssd(155);
    tdv::WTADev wta;

    runStereoTest(
        "../../res/tsukuba512_L.png",
        "../../res/tsukuba512_R.png",
        "tsukuba_medianssdwta.png",
        &ssd, &wta, true);
}
예제 #9
0
TEST(TestSSD, WithWTA)
{
    tdv::SSDDev ssd(128);
    tdv::WTADev wta;

    runStereoTest(
        "../../res/tsukuba512_L.png",
        "../../res/tsukuba512_R.png",
        "tsukuba_ssdwta.png",
        &ssd, &wta);
}
예제 #10
0
//------------------------------------------------------------------------------
void GmatSavePanel::OnScript(wxCommandEvent &event)
{
   wxString title = "Object Script";
   // open separate window to show scripts?
   if (mObject != NULL)
   {
      title = "Scripting for ";
      title += mObject->GetName().c_str();
   }
   ShowScriptDialog ssd(this, -1, title, mObject);
   ssd.ShowModal();
}
예제 #11
0
//! YY TODO: Now prefer to keep the algorithm clear, so it is highly inefficient. To improve latter. 
QuantLib::Matrix PCA::doPCA(const QuantLib::Matrix& originalMatrix, size_t reducedRank, bool normalizeDiagonal) // YY TODO: change it to boost::optional<bool>
{
	size_t fullRank = originalMatrix.rows(); 

	assert(fullRank > reducedRank);

	//! decompose the original matrix
	QuantLib::SymmetricSchurDecomposition ssd(originalMatrix);  // here it check if the matrix is squared, symetric.
	QuantLib::Array eigenvalues = ssd.eigenvalues();
	QuantLib::Matrix eigenvectors = ssd.eigenvectors();

	assert(checkEigenvalue(eigenvalues, reducedRank));

	//! construct the reducedRank matrix	   

	QuantLib::Array D(reducedRank);
	for(size_t i=0; i<D.size(); ++i)
	{
		D[i] = std::sqrt(eigenvalues[i]);
	}
	//! normalize the diagonal of the reducedRank matrix.
	QuantLib::Array diagonalNormalizeFactor(fullRank);
	if(normalizeDiagonal)
	{
		for(size_t i=0; i<fullRank; ++i)
		{
			diagonalNormalizeFactor[i] = 0.0;
			for(size_t j=0; j<reducedRank; ++j)
			{
				diagonalNormalizeFactor[i] += eigenvalues[j]*eigenvectors[i][j]*eigenvectors[i][j];
			}
			diagonalNormalizeFactor[i] = sqrt(diagonalNormalizeFactor[i]);
		}
	}
	else
	{
		for(size_t i=0; i<fullRank; ++i)
		{
			diagonalNormalizeFactor[i] = 1.0;
		}
	}

	QuantLib::Matrix U(fullRank,reducedRank,0.0);
	for(size_t i=0; i<fullRank; ++i)
	{
		for(size_t j=0; j<reducedRank; ++j)
		{
			U[i][j] = eigenvectors[i][j]*D[j]/diagonalNormalizeFactor[i];
		}
	}

	return U;
}
예제 #12
0
CcLgmPiecewise::CcLgmPiecewise(
    const std::vector<boost::shared_ptr<
        LgmFxParametrization<LgmFxPiecewiseSigma> > > &fxParametrizations,
    const std::vector<
        boost::shared_ptr<LgmParametrization<LgmPiecewiseAlphaConstantKappa> > >
        &lgmParametrizations,
    const Matrix &correlation)
    : CcLgmParametrization<CcLgmPiecewise, LgmFxPiecewiseSigma,
                           LgmPiecewiseAlphaConstantKappa>(fxParametrizations,
                                                           lgmParametrizations),
      correlation_(correlation), n_(fxParametrizations.size()) {
    QL_REQUIRE(correlation_.rows() == 2 * n_ + 1 &&
                   correlation_.columns() == 2 * n_ + 1,
               "correlation matrix is "
                   << correlation_.rows() << " x " << correlation_.columns()
                   << ", expected " << (2 * n_ + 1) << " x " << (2 * n_ + 1));

    for (Size i = 0; i < correlation_.rows(); ++i) {
        for (Size j = 0; j < i; ++j) {
            QL_REQUIRE(correlation_[i][j] == correlation_[j][i],
                       "correlation matrix is not symmetric");
            QL_REQUIRE(correlation_[i][j] >= -1 && correlation_[i][j] <= 1,
                       "correlation matrix contains elements outside [-1,1]");
        }
        QL_REQUIRE(
            close_enough(correlation_[i][i], 1.0),
            "correlation matrix contains diagonal elements not equal to 1");
    }

    SymmetricSchurDecomposition ssd(correlation_);
    for (Size i = 0; i < ssd.eigenvalues().size(); ++i) {
        QL_REQUIRE(ssd.eigenvalues()[i] >= 0.0,
                   "correlation matrix has negative eigenvalue @"
                       << i << ": " << ssd.eigenvalues()[i]);
    }

    std::vector<Time> allTimes;
    for (Size i = 0; i < fxParametrizations.size(); ++i) {
        allTimes.insert(allTimes.end(), fxParametrizations[i]->times().begin(),
                        fxParametrizations[i]->times().end());
    }
    for (Size i = 0; i < lgmParametrizations.size(); ++i) {
        allTimes.insert(allTimes.end(), lgmParametrizations[i]->times().begin(),
                        lgmParametrizations[i]->times().end());
    }

    boost::shared_ptr<Integrator> simpson =
        boost::make_shared<SimpsonIntegral>(1E-10, 100);

    setIntegrator(
        boost::make_shared<PiecewiseIntegral>(simpson, allTimes, true));
}
void ssd(Vid* vid, Mat* out)
{
    int nf = vid->nf;
    IplImage** imgs = vid->imgs;

    printf("Computing SSDs\n");
    for (int j = 0; j < nf; j++)
    {
        for (int i = j + 1; i < nf; i++)
        {
            double v = ssd(imgs[i], imgs[j]);
            set_mat(out, i, j, v);
            set_mat(out, j, i, v);
        }
        
        set_mat(out, j, j, 0.0);
    }
}
예제 #14
0
void SelfSimDescriptor::compute(const Mat& img, vector<float>& descriptors, Size winStride,
                                const vector<Point>& locations) const
{
    CV_Assert( img.depth() == CV_8U );

    winStride.width = std::max(winStride.width, 1);
    winStride.height = std::max(winStride.height, 1);
    Size gridSize = getGridSize(img.size(), winStride);
    int i, nwindows = locations.empty() ? gridSize.width*gridSize.height : (int)locations.size();
    int border = largeSize/2 + smallSize/2;
    int fsize = (int)getDescriptorSize();
    vector<float> tempFeature(fsize+1);
    descriptors.resize(fsize*nwindows + 1);
    Mat ssd(largeSize, largeSize, CV_32F), mappingMask;
    computeLogPolarMapping(mappingMask);

#if 0 //def _OPENMP
    int nthreads = cvGetNumThreads();
    #pragma omp parallel for num_threads(nthreads)
#endif
    for( i = 0; i < nwindows; i++ )
    {
        Point pt;
        float* feature0 = &descriptors[fsize*i];
        float* feature = &tempFeature[0];
        int x, y, j;

        if( !locations.empty() )
        {
            pt = locations[i];
            if( pt.x < border || pt.x >= img.cols - border ||
                pt.y < border || pt.y >= img.rows - border )
            {
                for( j = 0; j < fsize; j++ )
                    feature0[j] = 0.f;
                continue;
            }
        }
        else
            pt = Point((i % gridSize.width)*winStride.width + border,
                       (i / gridSize.width)*winStride.height + border);

        SSD(img, pt, ssd);

        // Determine in the local neighborhood the largest difference and use for normalization
        float var_noise = 1000.f;
        for( y = -1; y <= 1 ; y++ )
            for( x = -1 ; x <= 1 ; x++ )
                var_noise = std::max(var_noise, ssd.at<float>(largeSize/2+y, largeSize/2+x));

        for( j = 0; j <= fsize; j++ )
            feature[j] = FLT_MAX;

        // Derive feature vector before exp(-x) computation
        // Idea: for all  x,a >= 0, a=const.   we have:
        //       max [ exp( -x / a) ] = exp ( -min(x) / a )
        // Thus, determine min(ssd) and store in feature[...]
        for( y = 0; y < ssd.rows; y++ )
        {
            const schar *mappingMaskPtr = mappingMask.ptr<schar>(y);
            const float *ssdPtr = ssd.ptr<float>(y);
            for( x = 0 ; x < ssd.cols; x++ )
            {
                int index = mappingMaskPtr[x];
                feature[index] = std::min(feature[index], ssdPtr[x]);
            }
        }

        var_noise = -1.f/var_noise;
        for( j = 0; j < fsize; j++ )
            feature0[j] = feature[j]*var_noise;
        Mat _f(1, fsize, CV_32F, feature0);
        cv::exp(_f, _f);
    }
}
예제 #15
0
int main(int argc, char** argv)
{
	QuadParams params(argc, argv);

	// open output file for writing
	FILE* fout;
	if (NULL == (fout=fopen(params.outname, "w"))) {
		fprintf(stderr, "Could not open %s for writing\n", params.outname);
		exit(1);
	}

	try {

		// open memory file for vcov
		ogu::MemoryFile vcov_mf(params.vcovname);
	
		// parse the vcov matrix
		ogp::MatrixParser mp;
		mp.parse(vcov_mf.length(), vcov_mf.base());
		if (mp.nrows() != mp.ncols())
			throw ogu::Exception(__FILE__,__LINE__,
								 "VCOV matrix not square");
		// and put to the GeneralMatrix
		GeneralMatrix vcov(mp.nrows(), mp.ncols());
		vcov.zeros();
		for (ogp::MPIterator it = mp.begin(); it != mp.end(); ++it)
			vcov.get(it.row(), it.col()) = *it;
	
		// calculate the factor A of vcov, so that A*A^T=VCOV
		GeneralMatrix A(vcov.numRows(), vcov.numRows());
		SymSchurDecomp ssd(vcov);
		ssd.getFactor(A);

		// construct Gauss-Hermite quadrature
		GaussHermite ghq;
		// construct Smolyak quadrature
		int level = params.max_level;
		SmolyakQuadrature sq(vcov.numRows(), level, ghq);

		printf("Dimension:                %d\n", vcov.numRows());
		printf("Maximum level:            %d\n", level);
		printf("Total number of nodes:    %d\n", sq.numEvals(level));

		// put the points to the vector
		std::vector<Vector*> points;
		for (smolpit qit = sq.start(level); qit != sq.end(level); ++qit)
			points.push_back(new Vector((const Vector&)qit.point()));
		// sort and uniq
		OrderVec ordvec;
		std::sort(points.begin(), points.end(), ordvec);
		std::vector<Vector*>::iterator new_end = std::unique(points.begin(), points.end());
		for (std::vector<Vector*>::iterator it = new_end; it != points.end(); ++it)
			delete *it;
		points.erase(new_end, points.end());

		printf("Duplicit nodes removed:   %lu\n", (unsigned long) (sq.numEvals(level)-points.size()));

		// calculate weights and mass
		double mass = 0.0;
		std::vector<double> weights;
		for (int i = 0; i < (int)points.size(); i++) {
			weights.push_back(std::exp(-points[i]->dot(*(points[i]))));
			mass += weights.back();
		}

		// calculate discarded mass
		double discard_mass = 0.0;
		for (int i = 0; i < (int)weights.size(); i++)
			if (weights[i]/mass < params.discard_weight)
				discard_mass += weights[i];

		printf("Total mass discarded:     %f\n", discard_mass/mass);
	
		// dump the results
		int npoints = 0;
		double upscale_weight = 1/(mass-discard_mass);
		Vector x(vcov.numRows());
		for (int i = 0; i < (int)weights.size(); i++)
			if (weights[i]/mass >= params.discard_weight) {
				// print the upscaled weight
				fprintf(fout, "%20.16g", upscale_weight*weights[i]);
				// multiply point with the factor A and sqrt(2)
				A.multVec(0.0, x, std::sqrt(2.), *(points[i]));
				// print the coordinates
				for (int j = 0; j < x.length(); j++)
					fprintf(fout, " %20.16g", x[j]);
				fprintf(fout, "\n");
				npoints++;
			}

		printf("Final number of points:   %d\n", npoints);

		fclose(fout);

	} catch (const SylvException& e) {
		e.printMessage();
		return 1;
	} catch (const ogu::Exception& e) {
		e.print();
		return 1;
	}

	return 0;
}
예제 #16
0
파일: xyuv.c 프로젝트: zoominla/x264
static void xyuv_detect( int *pi_width, int *pi_height )
{
    static const int pi_size[][2] = {
        {128, 96},
        {160,120},
        {320,244},
        {320,288},

        /* PAL */
        {176,144},  // QCIF
        {352,288},  // CIF
        {352,576},  // 1/2 D1
        {480,576},  // 2/3 D1
        {544,576},
        {640,576},  // VGA
        {704,576},  // D1
        {720,576},  // D1

        /* NTSC */
        {176,112},  // QCIF
        {320,240},  // MPEG I
        {352,240},  // CIF
        {352,480},  // 1/2 D1
        {480,480},  // 2/3 D1
        {544,480},
        {640,480},  // VGA
        {704,480},  // D1
        {720,480},  // D1

        /* */
        {0,0},
    };
    int i_max;
    int i_size_max;
    uint8_t *pic;
    int i;

    *pi_width = 0;
    *pi_height = 0;

    /* Compute size max */
    for( i_max = 0, i_size_max = 0;
            pi_size[i_max][0] != 0 && pi_size[i_max][1] != 0; i_max++ ) {
        int s = pi_size[i_max][0] * pi_size[i_max][1] * 3 / 2;

        if( i_size_max < s )
            i_size_max = s;
    }

    /* Temporary buffer */
    i_size_max *= 3;
    pic = malloc( i_size_max );

    fprintf( stderr, "guessing size for:\n" );
    for( i = 0; i < xyuv.i_yuv; i++ ) {
        int j;
        int i_read;
        double dbest = 255*255;
        int    i_best = i_max;
        int64_t t;

        fprintf( stderr, " - %s\n", xyuv.yuv[i].name );

        i_read = fread( pic, 1, i_size_max, xyuv.yuv[i].f );
        if( i_read < 0 )
            continue;

        /* Check if file size is at least compatible with one format
         * (if not, ignore file size)*/
        fseek( xyuv.yuv[i].f, 0, SEEK_END );
        t = ftell( xyuv.yuv[i].f );
        fseek( xyuv.yuv[i].f, 0, SEEK_SET );
        for( j = 0; j < i_max; j++ ) {
            const int w = pi_size[j][0];
            const int h = pi_size[j][1];
            const int s = w * h * 3 / 2;

            if( t % s == 0 )
                break;
        }
        if( j == i_max )
            t = 0;


        /* Try all size */
        for( j = 0; j < i_max; j++ ) {
            const int w = pi_size[j][0];
            const int h = pi_size[j][1];
            const int s = w * h * 3 / 2;
            double dd;

            int x, y, n;
            int64_t d;

            /* To small */
            if( i_read < 3*s )
                continue;
            /* Check file size */
            if( ( t > 0 && (t % s) != 0  ) ) {
                fprintf( stderr, "  * %dx%d ignored (incompatible file size)\n", w, h );
                continue;
            }


            /* We do a simple ssd between 2 consecutives lines */
            d = 0;
            for( n = 0; n < 3; n++ ) {
                uint8_t *p;

                /* Y */
                p = &pic[n*s];
                for( y = 0; y < h-1; y++ ) {
                    for( x = 0; x < w; x++ )
                        d += ssd( p[x] - p[w+x] );
                    p += w;
                }

                /* U */
                p = &pic[n*s+w*h];
                for( y = 0; y < h/2-1; y++ ) {
                    for( x = 0; x < w/2; x++ )
                        d += ssd( p[x] - p[(w/2)+x] );
                    p += w/2;
                }

                /* V */
                p = &pic[n*s+5*w*h/4];
                for( y = 0; y < h/2-1; y++ ) {
                    for( x = 0; x < w/2; x++ )
                        d += ssd( p[x] - p[(w/2)+x] );
                    p += w/2;
                }
            }
            dd = (double)d / (3*w*h*3/2);
            fprintf( stderr, "  * %dx%d d=%f\n", w, h, dd );

            if( dd < dbest ) {
                i_best = j;
                dbest = dd;
            }
        }

        fseek( xyuv.yuv[i].f, 0, SEEK_SET );

        if( i_best < i_max ) {
            fprintf( stderr, "  -> %dx%d\n", pi_size[i_best][0], pi_size[i_best][1] );
            *pi_width = pi_size[i_best][0];
            *pi_height = pi_size[i_best][1];
        }
    }

    free( pic );
}