Пример #1
0
void test_url()
{
	LogTraceLn();
	sample2(L"http://msdn.microsoft.com/vstudio/");
	sample2(L"mailto:[email protected]");
	sample2(L"file://C:\\AUTOEXEC.BAT");
	sample2(L"logger:///default?color=true;level=debug;prefix=full;target=console");
	sample2(L"logger:///module?name=default;color=true;level=debug;prefix=full;target=console");
}
Пример #2
0
// Implement the TestVariable action.  Triggers a TestEvent event on the result.
void MHOctetStrVar::TestVariable(int nOp, const MHUnion &parm, MHEngine *engine)
{
    parm.CheckType(MHUnion::U_String);
    int nRes = m_Value.Compare(parm.m_StrVal);
    bool fRes = false;

    switch (nOp)
    {
        case TC_Equal:
            fRes = nRes == 0;
            break;
        case TC_NotEqual:
            fRes = nRes != 0;
            break;
            /*  case TC_Less: fRes = nRes < 0; break;
                case TC_LessOrEqual: fRes = nRes <= 0; break;
                case TC_Greater: fRes = nRes > 0; break;
                case TC_GreaterOrEqual: fRes = nRes >= 0; break;*/
        default:
            MHERROR("Invalid comparison for string"); // Shouldn't ever happen
    }

    MHOctetString sample1(m_Value, 0, 10);
    MHOctetString sample2(parm.m_StrVal, 0, 10);
    MHLOG(MHLogDetail, QString("Comparison %1 %2 and %3 => %4").arg(TestToText(nOp))
          .arg(sample1.Printable()).arg(sample2.Printable()).arg(fRes ? "true" : "false"));
    engine->EventTriggered(this, EventTestEvent, fRes);
}
Пример #3
0
  void 
  RVolume::loadData(const std::vector<GLubyte>& inbuffer, size_t width, size_t height, size_t depth)
  {
    std::vector<GLubyte> voldata(4 * width * height * depth);
    
    std::vector<float>& histogram = _transferFunction->getHistogram();
    histogram = std::vector<float>(256, 0);
    
    for (int z(0); z < int(depth); ++z)
      for (int y(0); y < int(height); ++y)
	for (int x(0); x < int(width); ++x)
	  {
	    Vector sample1(inbuffer[coordCalc(x - 1, y, z, width, height, depth)],
			   inbuffer[coordCalc(x, y - 1, z, width, height, depth)],
			   inbuffer[coordCalc(x, y, z - 1, width, height, depth)]);
	    
	    Vector sample2(inbuffer[coordCalc(x + 1, y, z, width, height, depth)],
			   inbuffer[coordCalc(x, y + 1, z, width, height, depth)],
			   inbuffer[coordCalc(x, y, z + 1, width, height, depth)]);
	    
	    //Note, we store the negative gradient (we point down
	    //the slope)
	    Vector grad = sample1 - sample2;
	    
	    float nrm = grad.nrm();
	    if (nrm > 0) grad /= nrm;
	    
	    size_t coord = x + width * (y + height * z);
	    voldata[4 * coord + 0] = uint8_t((grad[0] * 0.5 + 0.5) * 255);
	    voldata[4 * coord + 1] = uint8_t((grad[1] * 0.5 + 0.5) * 255);
	    voldata[4 * coord + 2] = uint8_t((grad[2] * 0.5 + 0.5) * 255);
	    
	    GLubyte val = inbuffer[coordCalc(x, y, z, width, height, depth)];
	    voldata[4 * coord + 3] 
	      = val;

	    histogram[val] += 1;
	  }
    
    {
      float logMaxVal = std::log(*std::max_element(histogram.begin(), histogram.end()));
      float logMinVal = std::log(std::max(*std::min_element(histogram.begin(), histogram.end()), 1.0f));
      float normalization = 1.0 / (logMaxVal - logMinVal);

      for (std::vector<float>::iterator iPtr = histogram.begin();
	   iPtr != histogram.end(); ++iPtr)
	{
	  if (*iPtr == 0) *iPtr = 1.0;
	  *iPtr = (std::log(*iPtr) - logMinVal) * normalization;
	}
    }

    _data.init(width, height, depth);
    _data.subImage(voldata, GL_RGBA);
  }
Пример #4
0
int main() {
	//MessageInt message(&actor, &actor, 0);
	//gqueue.enqueue(&message);

	//actor.start();
	sample2();
	//sendWaitSample();
	//threadRing();
	return 0;

}
Пример #5
0
int samples()
{

    int status = 0;

    status = sample1();
    if (status != 0) return status;

    status = sample2();
    if (status != 0) return status;

    return 0;

}
Пример #6
0
int main() {
	// 🐨 has unicode codepoint U+1F428 (http://emojipedia.org/koala/)
	// according to UTF-8, we have to store 1 11110100 00101000:
	// [1111]0000 [10]011111 [10]010000 [10]101000
	// 4 bytes for koala!
	String sample1("🐨 коала emoji"); // 13 user-perceived characters (http://utf8everywhere.org/)
	String sample2(sample1); // copy constructor
	std::string sample3(sample1.str);
	std::cout << sample1.size << " " << sample3.length() << '\n'; // 21 21
	size_t len = 0;
	char *s = sample1.str;
	while (*s) len += (*s++ & 0xc0) != 0x80; // UTF-8 — count all bytes that do not match 10xxxxxx
	std::cout << len << '\n'; // 13
	return 0;
}
Пример #7
0
 valarray<bool> add_pseudocount(const valarray<bool>& sample1,int pseudocount) {
   valarray<bool> sample2(sample1.size() + 2*pseudocount);
   
   int i=0;
   for(int j=0;j<pseudocount;i++,j++)
     sample2[i] = true;
   
   for(int j=0;j<sample1.size();i++,j++)
     sample2[i] = sample1[j];
   
   for(int j=0;j<pseudocount;i++,j++)
     sample2[i] = false;
   
   return sample2;
 }
Пример #8
0
int main (int argc, char ** argv)
{
    FILE * file;
    int iarg=1 ;

    if( argc < 2 || strstr(argv[1],"-help") != NULL ) {      /* RWCox */
        printf("Usage:  mpegtoppm [-prefix ppp] file.mpg\n"
               "Writes files named 'ppp'000001.ppm, etc.\n" ) ;
        exit(0) ;
    }

    while( iarg < argc && argv[iarg][0] == '-' ) {  /* RWCox: options */
        if( strncmp(argv[iarg],"-c",2) == 0 ) {
            docount = 1 ;
            ++iarg ;
            continue ;
        }

        if( strncmp(argv[iarg],"-p",2) == 0 ) {
            prefix = argv[++iarg] ;
            ++iarg ;
            continue ;
        }
    }

    if( iarg < argc ) {
        file = fopen (argv[iarg], "rb");
        if (!file) {
            fprintf (stderr, "Could not open file %s\n", argv[iarg]);
            exit (1);
        }
    } else
        file = stdin;

    sample2 (file);

    if( docount && count > 0 ) {  /* RWCox */
        char filename[1000] = "\0" ;
        FILE *fp ;
        if( prefix != NULL ) strcpy(filename,prefix) ;
        strcat(filename,"COUNT") ;
        fp = fopen (filename, "wb");
        fprintf(fp,"%d\n",count) ;
        fclose(fp) ;
    }

    return 0;
}
Пример #9
0
int main (int argc, char ** argv)
{
    FILE * mpgfile;

    if (argc > 1) {
	mpgfile = fopen (argv[1], "rb");
	if (!mpgfile) {
	    fprintf (stderr, "Could not open file \"%s\".\n", argv[1]);
	    exit (1);
	}
    } else
	mpgfile = stdin;

    sample2 (mpgfile);

    return 0;
}
Пример #10
0
int main(int argc, char** argv)
{
	Poco::MongoDB::Connection connection("localhost", 27017);

	sample1(connection);
	sample2(connection);
	sample3(connection);
	sample4(connection);
	sample5(connection);
	sample6(connection);
	sample7(connection);
	sample8(connection);
	sample9(connection);
	sample10(connection);
	sample11(connection);
	sample12(connection);
	sample13(connection);

	return 0;
}
Пример #11
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    srand(time(NULL));

    DataSet sample("../sample_datasets/wine");
    DataSet sample2("../sample_datasets/winequality_white");

    std::string attributeNames[] = {"kolor", "kwaskowatość"};
    std::list<std::string> attributes(attributeNames, attributeNames + sizeof(attributeNames) / sizeof(attributeNames[0]));
    DataSet test(attributes);
    //kolor: 0 żółty 1.2  1 zielony 2
    for(int i = 0; i < 256; ++i)
    {
        if(i % 4 == 0)
        {
            //słodkie zielone jabłko: kolor [1.0 1.5] kwaskowatość[0.1;0.4]
            std::vector<float> attrs(2);
            attrs[0] = randFloat(1.0f, 1.5f);
            attrs[1] = randFloat(.1f, .4f);
            test.addInstance(DataSet::DataInstance(attrs, 0));
        }
        if(i % 4 == 1)
        {
            //banan: kolor [0.5;1.1] kwaskowatość[0.0 0.1]
            std::vector<float> attrs(2);
            attrs[0] = randFloat(.5f, 1.1f);
            attrs[1] = randFloat(0.0f, 0.1f);
            test.addInstance(DataSet::DataInstance(attrs, 1));
        }
        if(i % 4 == 2)
        {
            //kiwi: kolor [1.5;2.0] kwaskowatość[0.3;0.8]
            std::vector<float> attrs(2);
            attrs[0] = randFloat(1.5f, 2.0f);
            attrs[1] = randFloat(.3f, .8f);
            test.addInstance(DataSet::DataInstance(attrs, 2));
        }
        if(i % 4 == 3)
        {
            //ananas: kolor [0.0;0.8] kwaskowatość[0.3 0.9]
            std::vector<float> attrs(2);
            attrs[0] = randFloat(0.0f, 0.8f);
            attrs[1] = randFloat(.3f, .9f);
            test.addInstance(DataSet::DataInstance(attrs, 3));
        }
    }
    
    DataSet trainingData, testData;
//    test.getTrainingAndTestSets(0.1, trainingData, testData);
//    sample.getTrainingAndTestSets(0.1, trainingData, testData);
    sample2.getTrainingAndTestSets(0.1, trainingData, testData);

    //    RuleBase testRuleBase;
    //    {//jabłko
    //        FuzzySetContainer premises;
    //        premises.insert(TriangularFuzzySet(1.0, 1.25, 1.5), 0);
    //        premises.insert(TriangularFuzzySet(1.0, 1.25, 1.5), 1);
    //        testRuleBase.addRule(RuleBase::Rule(premises, TriangularFuzzySet(-0.1,0,0.1)));
    //    }
    //    {//banan
    //        FuzzySetContainer premises;
    //        premises.insert(TriangularFuzzySet(0.5, 1.0, 1.1), 0);
    //        premises.insert(TriangularFuzzySet(0.0, 0.05, 0.1), 1);
    //        testRuleBase.addRule(RuleBase::Rule(premises, TriangularFuzzySet(0.9,1,1.1)));
    //    }
    //    {//kiwi
    //        FuzzySetContainer premises;
    //        premises.insert(TriangularFuzzySet(1.5, 1.75, 2.0), 0);
    //        premises.insert(TriangularFuzzySet(0.3, 0.5, 0.8), 1);
    //        testRuleBase.addRule(RuleBase::Rule(premises, TriangularFuzzySet(1.9,2,2.1)));
    //    }
    //    {//ananas
    //        FuzzySetContainer premises;
    //        premises.insert(TriangularFuzzySet(0.0, 0.6, 0.8), 0);
    //        premises.insert(TriangularFuzzySet(0.3, 0.6, 0.9), 1);
    //        testRuleBase.addRule(RuleBase::Rule(premises, TriangularFuzzySet(2.9,3,3.1)));
    //    }

    float perf;
    //    FuzzyInferenceEngine engine(testRuleBase);
    //    engine.init();
    //    perf = engine.testPerformance(trainingData);
    //    std::cout<<"Performance on training data: "<<perf*100.0f<<'%'<<std::endl;
    //    perf = engine.testPerformance(testData);
    //    std::cout<<"Performance on test data: "<<perf*100.0f<<'%'<<std::endl;

    FuzzyRuleBaseCreator creator(trainingData);

    for(int i = 0; i < trainingData.getNumberOfAttributes(); ++i)
    {
        creator.setRegularPartitionForAttribute(i, 4);
        creator.setFunctionClassForAttribute(i, TriangularFuzzySet());
    }
    creator.setFunctionClassForClass(TriangularFuzzySet());
    creator.setRegularPartitionForClass(4);
    RuleBase learnedBase;
    creator.learnRules(learnedBase);
    FuzzyInferenceEngine engine2(learnedBase);
    engine2.init();
    perf = engine2.testPerformance(trainingData);
    std::cout<<"Performance on training data: "<<perf*100.0f<<'%'<<std::endl;
    perf = engine2.testPerformance(testData);
    std::cout<<"Performance on test data: "<<perf*100.0f<<'%'<<std::endl;

    QTimer::singleShot(0, &a, SLOT(quit()));
    return a.exec();
}
Пример #12
0
PWIZ_API_DECL void addMIAPEExampleMetadata(MSData& msd)
{
    msd.id = "urn:lsid:psidev.info:mzML.instanceDocuments.small_miape.pwiz";

    msd.cvs = defaultCVList(); // TODO: move this to Reader_Thermo

    FileContent& fc = msd.fileDescription.fileContent;
    fc.userParams.push_back(UserParam("ProteoWizard", "Thermo RAW data converted to mzML, with additional MIAPE parameters added for illustration"));

    // fileDescription

    SourceFilePtr sfp_parameters(new SourceFile("sf_parameters", "parameters.par", "file:///C:/example/"));
	sfp_parameters->set(MS_parameter_file);
    sfp_parameters->set(MS_SHA_1, "unknown");
    sfp_parameters->set(MS_no_nativeID_format);
    msd.fileDescription.sourceFilePtrs.push_back(sfp_parameters);

    Contact contact;
    contact.set(MS_contact_name, "William Pennington");
    contact.set(MS_contact_affiliation, "Higglesworth University");
    contact.set(MS_contact_address, "12 Higglesworth Avenue, 12045, HI, USA");
	contact.set(MS_contact_URL, "http://www.higglesworth.edu/");
	contact.set(MS_contact_email, "*****@*****.**");
    msd.fileDescription.contacts.push_back(contact);

    // paramGroupList

    ParamGroupPtr pgInstrumentCustomization(new ParamGroup);
    pgInstrumentCustomization->id = "InstrumentCustomization";
    pgInstrumentCustomization->set(MS_customization ,"none");
    msd.paramGroupPtrs.push_back(pgInstrumentCustomization);

    ParamGroupPtr pgActivation(new ParamGroup);
    pgActivation->id = "CommonActivationParams";
    pgActivation->set(MS_collision_induced_dissociation);
    pgActivation->set(MS_collision_energy, 35.00, UO_electronvolt);
    pgActivation->set(MS_collision_gas, "nitrogen"); 
    msd.paramGroupPtrs.push_back(pgActivation);

    // sampleList

    SamplePtr sample1(new Sample);
    sample1->id = "sample1";
    sample1->name = "Sample 1";
    msd.samplePtrs.push_back(sample1);

    SamplePtr sample2(new Sample);
    sample2->id = "sample2";
    sample2->name = "Sample 2";
    msd.samplePtrs.push_back(sample2);

    // instrumentConfigurationList

    for (vector<InstrumentConfigurationPtr>::const_iterator it=msd.instrumentConfigurationPtrs.begin(),
         end=msd.instrumentConfigurationPtrs.end(); it!=end; ++it)
    {
        for (size_t i=0; i < (*it)->componentList.size(); ++i)
        {
            Component& c = (*it)->componentList[i];
            if (c.type == ComponentType_Source)
                c.set(MS_source_potential, "4.20", UO_volt);
        }
    }
 
    // dataProcesingList

    ProcessingMethod procMIAPE;
    procMIAPE.order = 1;
    procMIAPE.softwarePtr = msd.softwarePtrs.back();
    procMIAPE.set(MS_deisotoping);
    procMIAPE.set(MS_charge_deconvolution);
    procMIAPE.set(MS_peak_picking);
    procMIAPE.set(MS_smoothing);
    procMIAPE.set(MS_baseline_reduction);
    procMIAPE.userParams.push_back(UserParam("signal-to-noise estimation", "none"));
    procMIAPE.userParams.push_back(UserParam("centroiding algorithm", "none"));
    procMIAPE.userParams.push_back(UserParam("charge states calculated", "none"));

    DataProcessingPtr dpMIAPE(new DataProcessing);
    msd.dataProcessingPtrs.push_back(dpMIAPE);
    dpMIAPE->id = "MIAPE example";
    dpMIAPE->processingMethods.push_back(procMIAPE);

    // acquisition settings
    
    ScanSettingsPtr as1(new ScanSettings("acquisition settings MIAPE example"));
    as1->sourceFilePtrs.push_back(sfp_parameters);

    Target t1;
    t1.userParams.push_back(UserParam("precursorMz", "123.456")); 
    t1.userParams.push_back(UserParam("fragmentMz", "456.789")); 
    t1.userParams.push_back(UserParam("dwell time", "1", "seconds")); 
    t1.userParams.push_back(UserParam("active time", "0.5", "seconds")); 
    
    Target t2;
    t2.userParams.push_back(UserParam("precursorMz", "231.673")); 
    t2.userParams.push_back(UserParam("fragmentMz", "566.328")); 
    t2.userParams.push_back(UserParam("dwell time", "1", "seconds")); 
    t2.userParams.push_back(UserParam("active time", "0.5", "seconds")); 

    as1->targets.push_back(t1);
    as1->targets.push_back(t2);
    msd.scanSettingsPtrs.push_back(as1);

    // run
    
    msd.run.samplePtr = sample1;

} // addMIAPEExampleMetadata()
Пример #13
0
int
main(int argc, char *argv[])
{
	std::cout << "\ncpp_samples: main: Init" << std::endl;

	A a = { NULL, 8 };

	std::cout << "\ncpp_samples: main: a.x: " << a.x << std::endl;
	std::cout << "cpp_samples: main: a.y: " << a.y << std::endl;

	SOA soa = { { 2, 4, 8, 1, 3 }, {{ 1, 4, 7, 9, 0, 4 }, { 8, 2, 9, 1, 6, 3 }} };

	std::cout << "\ncpp_samples: main: soa.a[0]: " << soa.a[0] << std::endl;
	std::cout << "cpp_samples: main: soa.a[1]: " << soa.a[1] << std::endl;
	std::cout << "cpp_samples: main: soa.a[2]: " << soa.a[2] << std::endl;
	std::cout << "cpp_samples: main: soa.a[3]: " << soa.a[3] << std::endl;
	std::cout << "cpp_samples: main: soa.a[4]: " << soa.a[4] << std::endl;
	std::cout << "cpp_samples: main: soa.b[0][2]: " << soa.b[0][2] << std::endl;
	std::cout << "cpp_samples: main: soa.b[1][1]: " << soa.b[1][1] << std::endl;
	std::cout << "cpp_samples: main: soa.b[0][3]: " << soa.b[0][3] << std::endl;
	std::cout << "cpp_samples: main: soa.b[1][5]: " << soa.b[1][5] << std::endl;
	std::cout << "cpp_samples: main: soa.b[0][3]: " << soa.b[0][3] << std::endl;

	C c = { 78, 126 };

	std::cout << "\ncpp_samples: main: c.x: " << c.x << std::endl;
	std::cout << "cpp_samples: main: c.y: " << c.y << std::endl;

	Box box1;
	Box box2;

	box1.setLength(43);
	box1.setWidth(83);
	box1.setHeight(91);

	box2.setLength(78);
	box2.setWidth(92);
	box2.setHeight(19);

	uint64_t volume = 0;

	volume = box1.getVolume();
	std::cout << "Volume: box1: " << volume << std::endl;

	volume = box2.getVolume();
	std::cout << "Volume: box2: " << volume << std::endl;


	RGBColour rgb1;
	RGBColour rgb2;

	rgb1.red = 83;
	rgb1.green = 10;
	rgb1.blue = 39;

	rgb2.red = 43;
	rgb2.green = 13;
	rgb2.blue = 71;

	std::cout << "Colour: box1: rgb1: Red: " << (short)rgb1.red << " Green: " << (short)rgb1.green << " Blue: " << (short)rgb1.blue << std::endl;

	std::cout << "Colour: box2: rgb2: Red: " << (short)rgb2.red << " Green: " << (short)rgb2.green << " Blue: " << (short)rgb2.blue << std::endl;

	sample2();

	sample3();

	sample4();

	return 0;
}