예제 #1
0
void ParityTest::runTest() {

    int sampling = getSampling();
    int evenCount = 0;
    int oddCount = 0;
    int array[sampling];
    ostringstream ss;

    for(int i = 0 ; i < getSampling() ; i++) {
        array[i] = getGenerator()->toGenerate();
        if ((array[i] % 2) == 0)
            evenCount++;
        else
            oddCount++;
    }

    ss << "Generator " << getGenerator()->getGeneratorName() << " gave me numbers:\n";
    for (int i = 0 ; i < sampling ; i++ ) {
        ss << array[i] << "   ";
        if ((i+1) % 5 == 0)
            ss << endl;
    }
    ss << "Numbers have:\n";
    ss << evenCount << " even numbers\n";
    ss << "and\n";
    ss << oddCount <<" odd numbers\n";
    ss << "Proportion even/odd is: \n";
    ss << (double) oddCount / (double) evenCount << endl;

    addInResultText(ss.str());

}
예제 #2
0
void test_rsc_encode(){
    int lm = 9;
    int** G = getGenerator();
    int* m = (int*) malloc(sizeof(int)*lm);
    double* Lu = (double*) malloc(sizeof(double)*(lm+2));
    double* Ly = (double*) malloc(sizeof(double)*2*(lm+2));

    for(int i  = 0 ; i < lm+2 ; ++i)
        Lu[i] = 0;

    for(int i = 0 ; i < lm ; ++i)
        m[i] = M[i];

    int* x = (int*) malloc(sizeof(int)*2*(lm+2));
//    int* x = rsc_encode(G,3,m,lm,1);
    rsc_encode(G,3,m,lm,1,x);

    for(int i = 0 ; i < 2; ++i){
        for(int j = 0 ; j < (lm+2) ; ++j){
            Ly[i+j*2] = x[i+j*2];
            printf("%d ",x[i+j*2]);
        }
        printf("\n");
    }

    delete2d<int>(G);
    free(x);
    free(m);
    free(x);
    free(Lu);
}
예제 #3
0
// OK
void test_trellis(){
    int** G = getGenerator();
    int Ns = 4;
    int ** pout = new2d<int>(Ns,4);
    int ** ps = new2d<int>(Ns,2) ;

    trellis(G,2,3,Ns,pout,ps);

    printf("pout:\n");
    for(int i = 0 ; i < Ns ; ++i){
        for(int j = 0 ; j < 4 ; ++j)
            printf("%d, ",pout[i][j]);
        printf("\n");
    }

    printf("pstate:\n");
    for(int i = 0 ; i < Ns ; ++i){
        for(int j = 0 ; j < 2 ; ++j)
            printf("%d, ",ps[i][j]);
        printf("\n");
    }

    delete2d<int>(G);
    delete2d<int>(pout);
    delete2d<int>(ps);

}
예제 #4
0
// OK
void test_intra(){
    int*** Y;
    double *** Ly;
    int *** map_out;
    int h = 288, w = 352, f = 5 ;
    int lm = h*w;
    int lu = lm+2;
    int snr = 0;
    int ** G = getGenerator();

    Y = yuv_read("stefan_cif.yuv",h,w,f);

    Ly = new3d<double>(f,PXL,2*lu);
    map_out = new3d<int>(f,PXL,lm);

    video_encode(Y,f,h,w,snr,G,Ly,map_out);

    double* PSNR = (double*) malloc(sizeof(double)*f);
//    direct_decode("stefan",Y,Ly,map_out,h,w,f,lu,G,PSNR);
    intra("stefan",Y,Ly,map_out,h,w,f,lu,G,PSNR);

    delete3d<double>(Ly);
    delete3d<int>(map_out);
    delete2d<int>(G);
    deleteY(Y);
}
예제 #5
0
// OK
void test_encode(){
    int*** Y;
    double *** Ly;
    int *** map_out;
    int h = 288, w = 352, f = 5 ;
    int lm = h*w;
    int lu = lm+2;

    Y = yuv_read("stefan_cif.yuv",h,w,f);

    Ly = new3d<double>(f,PXL,2*lu);
    map_out = new3d<int>(f,PXL,lm);

    video_encode(Y,f,h,w,0,getGenerator(),Ly,map_out);

    int cn=0 ,cp=0;
    for(int i = 0 ; i < 2*lu ; ++i){
        if(Ly[0][0][i]>0)
            cp++;
        else
            cn++;
    }
    printf("positive:%d and nagtive:%d\n",cp,cn);

    delete3d<double>(Ly);
    delete3d<int>(map_out);
    deleteY(Y);
}
예제 #6
0
void SeriesTest::runTest() {

  int sampling = getSampling();
  int array[sampling];
  int increaseCount = 0;
  int decreaseCount = 0;
  int maxIncreaseSerie = 0;
  int maxDecreaseSerie = 0;
  int nonStopIncreaseCount = 0;
  int nonStopDecreaseCount = 0;

  ostringstream ss;
  array[0] = getGenerator()->toGenerate();
  for(int i = 0 ; i < getSampling() - 1 ; i++){
    array[i+1] = getGenerator()->toGenerate();
    if (array[i] < array[i+1]){
      nonStopDecreaseCount = 0;
      increaseCount++;
      nonStopIncreaseCount++;
    }
    else {
      nonStopIncreaseCount = 0;
      decreaseCount++;
      nonStopDecreaseCount++;
    }
    if (nonStopIncreaseCount > maxIncreaseSerie)
      maxIncreaseSerie = nonStopIncreaseCount;
    if (nonStopDecreaseCount > maxDecreaseSerie)
      maxDecreaseSerie = nonStopDecreaseCount;
  }

  ss << "Generator " << getGenerator()->getGeneratorName() << " gave me numbers:\n";
  for (int i = 0 ; i < sampling ; i++ ){
    ss << array[i] << "   ";
    if ((i+1) % 5 == 0)
      ss << endl;
  }
  ss << "All increase cases: " << increaseCount << endl;
  ss << "All decrease cases: " << decreaseCount << endl;
  ss << "Max series:\n";
  ss << "inc: " << maxIncreaseSerie << endl;
  ss << "dec: " << maxDecreaseSerie << endl;
  addInResultText(ss.str());

}
    Point CylindricSurface::compute(double u, double v)
    {
        Point originOnGenerator = getGenerator()->compute(u);

        Point originOnDirector = getDirector()->compute(0);
        Point next = getDirector()->compute(v);
        Vector translator(originOnDirector, next);
        return originOnGenerator.translate(translator);
    }
예제 #8
0
fast_Ring<TNum,kdefs>::fast_Ring(	unsigned short _char, 
						unsigned short _epsPrec) : 	characteristic(_char),
											epsilon(_epsPrec), 
											generator(getGenerator())
{
	assert(TNum::wellDefined(characteristic));
	assert( epsilon <= 1 );
    assert( isGenerator(generator));
	init();
	assert( wellDefined() );
}
예제 #9
0
void
IsotropicSphereModel::doGenerate(Catalog& catalog)
{
  if (catalog.getType() != _catType)
  {
    std::stringstream ss;
    ss << "Generate failed. Model '" << ModelMapper::instance()->getKey(getType())
       << "'. Provided catalog type doesn't match requested one.";
    Exception exc(type::EXCEPTION_WARNING + type::EXCEPTION_MOD_NO_PREFIX,
                  ss.str(), PRETTY_FUNCTION);
    throw exc;
  }

  for (std::size_t i = 0; i < getNumberOfEntries(); ++i)
  {
    CatalogEntryGrbcat* entry = createEntry();
    entry->getCoordFlag() = 0.0;
    entry->getCoodinates().getX0() = _time(getGenerator());
    entry->getCoodinates().getX1() = 1.0;
    entry->getCoodinates().getX2() = _phi(getGenerator());
    entry->getCoodinates().getX3() = _theta(getGenerator());
    catalog.getEntries().push_back(entry);
  }
}
/*
 *  converts cartesian via points to joint space via points
 */
vector<ColumnVector> TrajectoryController::getJSPoints(
		vector<ColumnVector>& cartesianList) {

	vector<ColumnVector> jsPoints;
	ColumnVector cartesian(6), currentQ(6), previousQ(6), joint(6);
	Generator* gen = getGenerator(cartesianList);
	if (gen != NULL) {
		currentQ = 0;
		joint = 0;

		// - convert ith cartesian to thetas
		// - if conditions satisfied, add point in path.
		for (int i = 0; i <= PNT_SAMPLES; i++) {
			double k = ((i * 1.0) / PNT_SAMPLES);

			//			cout << k << endl;
			//get xyz and orientation from generator for time k.
			cartesian = gen->getPosition(k);
			//			cout << "cart c " << cartesian.as_row();
			Quaternion quat = gen->getOrientation(k);
			cartesian.resize_keep(6);
			Matrix R = quat.R();
			cartesian.Rows(4, 6) = irpy(R);

			//			cout << cartesian.AsRow() << endl;
			//			cout << quat << endl;

			//add the joint solution if it exists
			if (kineSolver->getBestSolution(cartesian, currentQ, joint)) {
				//				cout << "cartesian " << cartesian.AsRow() << endl;
				//				cout << "joint " << joint.AsRow() << endl;
				jsPoints.push_back(joint);
				currentQ = joint;
			} else {
				//path has to be rejected
				cout << cartesian.AsRow()
						<< " : Via point out of workspace. Path rejected."
						<< endl;
				jsPoints.clear();
				break;
			}
		}
	}
	return jsPoints;
}
예제 #11
0
void
Manager::processSingle(FetchedInfoScholarship &fis,
                       Database &db)
{
    HtmlGenBase* generator = getGenerator(fis.m_URL);
    assert (generator != NULL);
    
    generator->process(fis);
    
    const HtmlResult& result = generator->getHtmlResult();
    
    if (result.getDeadline().get() != NULL)
    {
        // write to files
        const std::string& full_html_code = result.getFullHtmlCode();
        std::string full_path = result.getTitle().getFileLocation(result.getDeadline());
        
        std::ofstream html_file(full_path.c_str());
        if (html_file.is_open())
        {
            html_file << full_html_code;
            html_file.close();
            
            // insert to database
            const Title& title = result.getTitle();
            const StorageVec st = db.getStorages();
            std::size_t index = title.classifiedIndex();
            StoragePtr s = st[index];
            
            db.insert(s, result.getDeadline(), fis.m_Title, fis.m_URL, true /* is_new */);
            //db.showDatabase();
        }
        else
        {
            DBGERR(__FUNCTION__ << ": Cannot write to file \"" << full_path << "\"!")
        }
    }
    
    // clean up
    delete generator;
    generator = NULL;
}
/**
 * Creates a SymmetryElement from a SymmetryOperation
 *
 * As detailed in the class description, the method checks whether there is
 * already a prototype SymmetryElement for the provided SymmetryOperation. If
 * not, it tries to find an appropriate generator and uses that to create
 * the prototype. Then it returns a clone of the prototype.
 *
 * @param operation :: SymmetryOperation for which to generate the element.
 * @return SymmetryElement for the supplied operation.
 */
SymmetryElement_sptr SymmetryElementFactoryImpl::createSymElement(
    const SymmetryOperation &operation) {
  std::string operationIdentifier = operation.identifier();

  SymmetryElement_sptr element = createFromPrototype(operationIdentifier);

  if (element) {
    return element;
  }

  AbstractSymmetryElementGenerator_sptr generator = getGenerator(operation);

  if (!generator) {
    throw std::runtime_error("Could not process symmetry operation '" +
                             operationIdentifier + "'.");
  }

  insertPrototype(operationIdentifier, generator->generateElement(operation));

  return createFromPrototype(operationIdentifier);
}
예제 #13
0
 void set_var(elem &result, int v) const         { result = getGenerator(); }
예제 #14
0
파일: random.cpp 프로젝트: Marvin182/mr
int integer(int lowerBound, int upperBound) {
	// Creating the distribution is very cheap, only generator creation is expensive (=> static std::mt19937)
	std::uniform_int_distribution<int> dist{lowerBound, upperBound};
	return dist(getGenerator());
}
예제 #15
0
int main(int argc,char* argv[]){

    startRandom();

    // control SNR step
    const double s_snr = -0.5;
    const double step = 0.02;
    const int snr_size = 500;

    // control the certain Frame and the bp
    int frame = 2;
    int t_lvl = 0;
    double _snr = 0;
    if(argc >= 3 )
        _snr = strtod(argv[2],NULL);

    if(argc >= 4)
        frame = strtod(argv[3],NULL);

    if(argc >= 5)
        t_lvl = strtod(argv[4],NULL);

    // for video encode
    const int puncture = 0;                     // puncture or not
    const double rate = 1/(double)(2-puncture);       // code rate
    const double a = 1;                         // Fading amplitude. a=1 -> AWGN channel
    double EbN0,L_c,sigma;

    // for basical info
    char buffer[50];
    const int h = __HEIGHT, w = __WIDTH, f = frame+1 ;
    const int lm = h*w;
    const int lu = lm+(G_L-1);
    int ** G = getGenerator();
    double * Ly = (double*) malloc(sizeof(double)*2*lu);
    int*** Y = new3d<int>(f,h,w);
    int* map_out = (int*) malloc(sizeof(int)*lm);

    double* Lu = (double*) malloc(sizeof(double)*lu);
    for(int i=0; i<lu ;++i)
        Lu[i] = 0;

    // pstate, pout
    const int Ns = pow(2,G_L-1);
    int ** pout = new2d<int>(Ns,4);
    int ** pstate = new2d<int>(Ns,2) ;
    double* Le1 = (double*)malloc(sizeof(double)*lu);
    double* Le2 = (double*)malloc(sizeof(double)*lu);

    trellis(G,G_N,G_L,Ns,pout,pstate);

    // frame buffer
    int*** imgr_bp = new3d<int>(PXL,h,w);
    double** Lu_c = new2d<double>(PXL,lu);  //channel decoder output

    // buffer for Ia, Ie
    double* Le = (double*) malloc(sizeof(double)*lm);
    double* Ia_pc = (double*) malloc(sizeof(double)*snr_size);
    double* Ie_pc = (double*) malloc(sizeof(double)*snr_size);
    int idx = 0;
    double tmp_sum = 0, tmp ;

    // read YUV
    sprintf(buffer,"%s_cif.yuv",argv[1]);
    yuv_read(buffer,h,w,f,Y,NULL,NULL);

//  video_encode(Y,f,h,w,_snr,G,Ly,map_out) for frame and t_lvl
    EbN0 = pow(10,_snr/10);      // convert Eb/N0[dB] to normal number
    L_c = 4*a*EbN0*rate;           // reliability value of the channel
    sigma = 1/sqrt(2*rate*EbN0);   // standard deviation of AWGN noise

    int* x = (int*) malloc(sizeof(int)*2*lu);
    img2bp_frame(Y[frame],h,w,imgr_bp);
    random_sequence(0,lm-1,map_out);
    rsc_encode(G,G_L,imgr_bp[t_lvl],map_out,w,lm,1,x);

    for(int i = 0 ; i < 2*lu ; ++i)
        Ly[i] = 0.5*L_c*((2*x[i] - 1)+ sigma*gaussian_noise());

    printf("processing ...%2.2f%%\n",0);
    for(double snr = s_snr; idx < snr_size ; snr+=step, idx++ , tmp_sum=0){
        printf("\tprocessing ...%2.2f%%\n",100*(snr-s_snr)/step/snr_size);
        // encode
        EbN0 = pow(10,snr/10);      // convert Eb/N0[dB] to normal number
        L_c = 4*a*EbN0*rate;           // reliability value of the channel
        sigma = 1/sqrt(2*rate*EbN0);   // standard deviation of AWGN noise

//        img2bp_frame(Y[frame],h,w,imgr_bp);
        for(int i = 0 ; i < lm ; ++i){
            tmp = (2*imgr_bp[t_lvl][map_out[i]/w][map_out[i]%w] - 1);
            Lu[i] = 0.5*L_c*( tmp + sigma*gaussian_noise());
            tmp_sum+=log2(1 + exp(-Lu[i]*tmp));
        }

        Ia_pc[idx] = 1 - tmp_sum/lm;

        // decode
        computeLe(Lu,Le1,Le2,lu);
        logmap(Ns, lu, 1, Ly, Le1, Le2, pstate, pout, Lu_c[t_lvl]);

        for(int i = 0 ; i < lm ; ++i)
            Le[map_out[i]] = Lu_c[t_lvl][i] - Lu[i];

        tmp_sum = 0;
        for(int i=0; i < lm ; ++i)
            tmp_sum+=log2(1 + exp(-Le[i]*(2*imgr_bp[t_lvl][i/w][i%w]-1)));

        Ie_pc[idx] = 1 - tmp_sum/lm;

    }
    printf("\r100%% completed!\n");

    FILE *file = fopen("output/exit_curve_pc.txt","a+");

    fprintf(file,"============================\n%s:SNR=%lf, frame#%d,bp#%d\nIa=\n",argv[1],_snr,frame+1,t_lvl+1);
    for(int i = 0 ; i < snr_size ; ++i)
        fprintf(file,"%lf,",Ia_pc[i]);
    fprintf(file,"\nIe=\n");
    for(int i = 0 ; i < snr_size ; ++i)
        fprintf(file,"%lf,",Ie_pc[i]);
    fprintf(file,"\n\n");

    fclose(file);

    write_pc_for_matlab(Ia_pc,Ie_pc,snr_size);

    // free memory
    free(Ly);
    free(map_out);
    delete2d<int>(G);
    deleteY(Y);

    delete3d<int>(imgr_bp);
    delete2d<double>(Lu_c);
    delete2d<int>(pstate);
    delete2d<int>(pout);

    free(Le);
    free(Lu);
    free(Le1);
    free(Le2);

    free(Ia_pc);
    free(Ie_pc);
    free(x);
}
예제 #16
0
 void set_var(ElementType &result, int v) const         { result = getGenerator(); }
/**
 * @brief This method is provided for convenience.
 *
 * It behaves exactly like the above function. It just calls fromString to get the type
 * reperesentation of the string.
 *
 * @param type               the type of the password generator
 * @param additionalArgument see class documentation.
 * @return a pointer to the created PasswordGenerator object. This object must be
 *         delected by the caller.
 * @exception std::invalid_argument if a wrong \p type is specified or if the argument
 *                                  is invalid
 */
PasswordGenerator* PasswordGeneratorFactory::getGenerator(const QString    &type,
                                                          const QString    &additionalArgument)
    throw (std::invalid_argument)
{
    return getGenerator(fromString(type), additionalArgument);
}