Exemplo n.º 1
0
/**
 * Tests the KerDenSOM
 * Parameter: _som        The KerDenSom to test
 * Parameter: _examples   The training set of examples
 */
double KerDenSOM::test(const FuzzyMap& _som, const TS& _examples) const
{

    // Defines verbosity level
    int verbosity = listener->getVerbosity();
    if (verbosity)
    {
        listener->OnReportOperation((std::string) "\nEstimating quantization error....\n");
        listener->OnInitOperation(_examples.size());
    }


    /* Scan all data entries */
    double qerror = 0.0;
    for (size_t i = 0; i < _examples.size(); i++)
    {
        SomIn& theBest = _som.fuzzyTest(i); // get the best
        qerror += euclideanDistance(theBest, _examples.theItems[i]);
        if (verbosity)
        {
            int tmp = (int)((_examples.size() * 5) / 100);
            if ((tmp == 0) && (i != 0))
                tmp = i;
            else
                tmp = 1;
            if ((i % tmp) == 0)
                listener->OnProgress(i);
        }
    }
    if (verbosity)
        listener->OnProgress(_examples.size());
    return (qerror / (double) _examples.size());

}
Exemplo n.º 2
0
typename ucs4_convert_impl::enableif<TD, typename TS::value_type>::type unicode_cast(const TS& source)
//TD unicode_cast(const TS& source)
{
	using namespace ucs4_convert_impl;
	typedef typename convert_impl<typename TD::value_type>::type t_impl_writer;
	typedef typename convert_impl<typename TS::value_type>::type t_impl_reader;
	typedef typename std::back_insert_iterator<TD> t_outputitor;
	typedef typename TS::const_iterator t_inputitor;

	TD res;
	try
	{
		t_outputitor inserter(res);
		iteratorwriter<t_outputitor> dst(inserter);
		t_inputitor i1 = source.begin();
		t_inputitor i2 = source.end();

		while(i1 != i2) {
			t_impl_writer::write (dst, t_impl_reader::read(i1, i2));
		}
	}
	catch(utf8::invalid_utf8_exception&)
	{
		// TODO: use a ERR_.. stream but i dont know whether i can so to in header easily.
		std::cerr << "Failed to convert a string from " << t_impl_reader::get_name() << " to " << t_impl_writer::get_name() << "\n";
		return res;
	}
	return res;
}
Exemplo n.º 3
0
int main()
{
	char szError[cbErrMax];
	EC ec;
	PDB* ppdb = PDB::Open("001.PDB", pdbWrite, 0, &ec, szError);

	assert(ppdb);
	DBI* pdbi = ppdb->OpenDBI(pdbWrite, "<target>");
	assert(pdbi);
	TS ts = pdbi->OpenTpi(pdbWrite);
	assert(ts);

	struct {
		unsigned short	len;
		unsigned short	leaf;
		unsigned long	signature;
		unsigned long	age;
		unsigned char	name[9];
	} typeUseTypeServer = {
		20,	
		LF_TYPESERVER,
		123456789,
		1,
		"\x07""002.PDB"
	};

	struct {
		unsigned short	reclen;	
		unsigned short	rectyp;	
		CV_uoff32_t 	off;
		unsigned short	seg;
		CV_typ_t		typind;	
		unsigned char	name[5];
	} aSymbol = {
		16,
		S_GDATA32,
		0,
		0,
		0,
		"\x03""ABC"
	};

	Mod* pmod = pdbi->OpenMod(ts, 1, "<mod>");
	assert(pmod->AddTypes((PB)&typeUseTypeServer, 20));
	for (TI ti = 0x1000; ti < 0x12e0; ti++) {
		aSymbol.typind = ti;
		assert(pmod->AddSymbols((PB)&aSymbol, 16));
	}
	pmod->Commit();
	pmod->Close();

	ts->Commit();
	ts->Close();
	ppdb->Commit();
	pdbi->Close();
	ppdb->Commit();
	ppdb->Close();

	return 0;
}
Exemplo n.º 4
0
		void ins(TS& ts, const char* s, const char* p, const char* o) {
			TupleT t;
			t.set(0, (block_data_t*)const_cast<char*>(s));
			t.set(1, (block_data_t*)const_cast<char*>(p));
			t.set(2, (block_data_t*)const_cast<char*>(o));
			ts.insert(t);
		}
Exemplo n.º 5
0
		void init_ts() {
		#if !INQP_TEST_USE_BLOCK
			debug_->debug("its0");

			#if VECTOR_STATIC_OUTSOURCE
				container.set_data(tuple_data_);
			debug_->debug("its1");
				container.set_size(VECTOR_STATIC_SIZE);
			#endif
			debug_->debug("its2");
			#if STATIC_DICTIONARY_OUTSOURCE
				dictionary.set_data(dict_data_);
			#endif

			debug_->debug("its3");
			dictionary.init(debug_);
			debug_->debug("its4");
			ts.init(&dictionary, &container, debug_);
		#else
			block_memory_.physical().init();
			delay(1000);
			block_memory_.init();
			block_allocator_.init(&block_memory_, debug_);
			container.init(&block_allocator_, debug_);
			dictionary.init(&block_allocator_, debug_);
		#endif
			debug_->debug("its5");
		}
Exemplo n.º 6
0
		void init_ts() {
		#if !INQP_TEST_USE_BLOCK
			dictionary.init(debug_);
			ts.init(&dictionary, &container, debug_);
		#else
			block_memory_.physical().init();
			delay(1000);
			block_memory_.init();
			block_allocator_.init(&block_memory_, debug_);
			container.init(&block_allocator_, debug_);
			dictionary.init(&block_allocator_, debug_);
		#endif
			
			//debug_->debug("tsi don");
		}
Exemplo n.º 7
0
		UINT32 SendOB(DataSet::const_iterator Begin, DataSet::const_iterator End)
		{	
			UINT32 sentlength=0;
			typedef TypeFromVR<VR_OB>::Type Type;
			
			Tag tag = Begin->first;
			int fragments=dataset_.count(tag);

			Enforce(ts_.isEncapsulated() || (1==fragments),"Only encoded data can have multiple image fragments.");

			if(1==fragments)//just send the data
			{
				const Type& ByteVector = Begin->second.Get<Type>();
				sentlength += WriteLengthAndVR((UINT32)ByteVector.size(),VR_OB);
				buffer_.AddVector(ByteVector);
				sentlength += ByteVector.size();
			}
			else	//send the data as a series of fragments as defined in Part5 Annex 4
			{
				sentlength += WriteLengthAndVR(UNDEFINED_LENGTH,VR_OB);

				//send empty offset table - not supported.

				buffer_ << TAG_ITEM;
				sentlength += sizeof(Tag);
				buffer_ << UINT32(0x00);//no offset table.
				sentlength += sizeof(UINT32);

				for(;Begin!=End;Begin++)
				{
					buffer_ << TAG_ITEM;
					sentlength += sizeof(Tag);
					const Type& ByteVector = Begin->second.Get<Type>();
					buffer_ << UINT32(ByteVector.size());
					sentlength += sizeof(UINT32);
					buffer_.AddVector(ByteVector);
					sentlength += ByteVector.size();
				}

				buffer_ << TAG_SEQ_DELIM_ITEM;
				sentlength += sizeof(Tag);
				buffer_ << UINT32(0x00);			
				sentlength += sizeof(UINT32);
			}
			return sentlength;
		}
Exemplo n.º 8
0
		void debug_ts() {
			for(TS::iterator iter = ts.begin(); iter != ts.end(); ++iter) {
				debug_->debug("(%s %s %s)", (char*)iter->get(0), (char*)iter->get(1), (char*)iter->get(2));
				for(int i = 0; i < 1000; i++) ;
			}
		}
Exemplo n.º 9
0
void f() {
    TS<int> ts;
    ts.m();
}