Esempio n. 1
0
Marker::Marker()
{
    id = -1;

	int ids[4][5]=
    {
        {1,0,0,0,0},
        {1,0,1,1,1},
        {0,1,0,0,1},
        {0,1,1,1,0}
    };

	Pattern p1 = Pattern(4, vector<int>(5,2) );
	copyIntPat2Vec(ids,p1);
	g_marker_pattern.push_back(p1);

	int ids2[4][5]=
    {
        {0,0,0,1,1},
        {1,0,1,0,0},
        {1,1,1,1,1},
        {1,1,0,0,1}
    };
    
	Pattern p2 = Pattern(4, vector<int>(5,0) );
    copyIntPat2Vec(ids2,p2);
	g_marker_pattern.push_back(p2);
}
Esempio n. 2
0
CPatternManager::CPatternManager()
{
  m_patternList.push_back(Pattern("1101"));
  m_patternList.push_back(Pattern("1011"));
  //m_patternList.push_back(Pattern(ConstructTwoLinePattern("011", Utils::gGridSize - 2)));
  //m_patternList.push_back(Pattern(ConstructTwoLinePattern("101", Utils::gGridSize - 1)));
  //m_patternList.push_back(Pattern(ConstructTwoLinePattern("110", Utils::gGridSize)));
}
Esempio n. 3
0
void MLECounts::initialise(SNCBWCoCoInitialiser& cci, PatternCounts* patternCounts)
{
	Pattern skip = cci.classEncoder.buildpattern("{*}", false, false);

	Debug::getInstance() << DebugLevel::ALL << "### PatternCounts size: " << patternCounts->patternCounts.size() << std::endl;
	Debug::getInstance() << DebugLevel::ALL << "### MLE Counts size: " << mleCounts.size() << std::endl;

	for(int n = 1; n <= kORDER; ++n)
	{
		std::cout << "Extracting MLE set for " << n << "...";
		PatternSet<uint64_t> allPatterns = cci.trainPatternModel.extractset(n,n);
		std::cout << " done" << std::endl;

		long int countAllUnigrams = 0;
		if(n==1)
		{
			for(auto pattern: allPatterns)
			{
				countAllUnigrams += 1;
			}
			mleCounts[Pattern()] = 1.0/countAllUnigrams;
		}

		for(auto pattern : allPatterns)
		{
			Pattern context = (n==1) ? Pattern() : Pattern(pattern, 0, n-1);

			long int contextCount = 0;
			if(n==1)
			{
				contextCount = countAllUnigrams;
			} else
			{
				contextCount = patternCounts->get(context);
			}

			if(contextCount > 0)
			{
				double v = 1.0 * patternCounts->get(pattern) / contextCount;
//				if(v > 0.99)
//				{
//					mleCounts[pattern] = 0.99; //
//				}
				mleCounts[pattern] = v;
			} else
			{
				mleCounts[pattern] = CoCoInitialiser::epsilon;
			}
		}
	}
	Debug::getInstance() << DebugLevel::ALL << "### MLE Counts size: " << mleCounts.size() << std::endl;
}
Esempio n. 4
0
char *
menu_pattern(MENU *m)
{
	if (m) {
		if (Pattern(m)) {
			return (Pattern(m));
		} else {
			return ("");
		}
	} else {
		return (NULL);
	}
}
Esempio n. 5
0
double EntropyCounts::get(const Pattern& context,
		CoCoInitialiser * const cci) const
{
	if (context == cci->classEncoder.buildpattern("{*}", false, false))
	{
		return emptyEntropy;
	}

	if (context == Pattern())
	{
		return emptyEntropy;
	}

	std::unordered_map<Pattern, double>::const_iterator iter = entropyCounts.find(context);

	if (iter != entropyCounts.end())
	{
		//double rv = 1.0 + std::abs(1.0 / (1.0 - iter->second) - 2);
		double rv = 1.0 + std::abs(1.0 / (iter->second - 0.75));
		// is iter->second normal? if it's 1, then it's 1.0/0.0 -> boom
		if(!std::isnormal(rv))
		{
			return emptyEntropy;
		}
		return rv;
	} else
	{
		return emptyEntropy;
	}
}
Esempio n. 6
0
int main(int argc, char * argv[])
{
  if (argc != 2)
    {
      fprintf(stderr, "Usage: grep pattern\n\n"
              "Reads stdin, searches 'pattern', writes to stdout\n");
      return 2;
    }
  try
    {
      RegEx Pattern(argv[1]);
      int count = 0;
      char buffer[1024];

      while (fgets(buffer, sizeof(buffer), stdin))
        if (Pattern.Search(buffer))
          fputs(buffer, stdout),
            count++;
      return count == 0;
    }
  catch (const char * ErrorMsg)
    {
      fprintf(stderr, "error in regex '%s': %s\n", argv[1], ErrorMsg);
      return 2;
    }
}
Esempio n. 7
0
bool ImageResourceLoader::IsPatternAccepted(const std::string pattern) const
{
    auto temp = pattern;
    std::transform(temp.begin(), temp.end(), temp.begin(), ::tolower);

    return Pattern().find(temp) != std::string::npos;
}
Esempio n. 8
0
void PostScriptView::MinGS (ostream& out) {
    Brush(out);
    FgColor(out);
    BgColor(out);
    Pattern(out);
    Transformation(out);
}
Esempio n. 9
0
Pattern Pattern::getRandom(unsigned int width, double fraction) {
	std::vector<bool> ranvec;
	for (unsigned int i = 0; i < width; i++) {
		ranvec.push_back(common::Maths::getRandomBool(fraction));
	}
	assert(ranvec.size() == width);
	return Pattern(ranvec);
}
void ConfigDialog::slot_patternChanged(int index)
{
   _pattern = Pattern(index);

   if(      index == SymCircles)    _ui->image->setPixmap(QPixmap(":pattern/circles.png"));
   else if (index == AsymCircles)   _ui->image->setPixmap(QPixmap(":pattern/acircles_pattern.png"));
   else if (index == Chessboard)    _ui->image->setPixmap(QPixmap(":pattern/chess_pattern.png"));
}
DWORD WardenLoaderHack::PatchWardenLoader()
{
	// LoadWardenModule thunk: (можно найти по референсу на "Warden.cpp"/"WardenLoader.cpp")
	// 51            |PUSH ECX                                ; /pOldProtect
	// FF76 08       |PUSH DWORD PTR DS:[ESI+8]               ; |NewProtect
	// 50            |PUSH EAX                                ; |Size
	// 53            |PUSH EBX                                ; |Address
	// FF15 BC329A01 |CALL DWORD PTR DS:[<&KERNEL32.VirtualPr ; \KERNEL32.VirtualProtect <<-- change( call dword ptr[vp_addr], call imm32 wa_hook )
	// F646 08 F0    |TEST BYTE PTR DS:[ESI+8],F0
	// 74 11         |JZ SHORT 016DBE9C
	// FF75 08       |PUSH DWORD PTR SS:[EBP+8]               ; /Size
	// 53            |PUSH EBX                                ; |Base
	// FF15 EC349A01 |CALL DWORD PTR DS:[<&KERNEL32.GetCurren ; |[KERNEL32.GetCurrentProcess
	// 50            |PUSH EAX                                ; |hProcess
	// FF15 B8329A01 |CALL DWORD PTR DS:[<&KERNEL32.FlushInst ; \KERNEL32.FlushInstructionCache
	// FF45 D4       |INC DWORD PTR SS:[EBP-2C]
	// 8B55 E4       |MOV EDX,DWORD PTR SS:[EBP-1C]
	// EB BA         \JMP SHORT 016DBE5E


	PBYTE	bCode = (PBYTE) "\xE8\x90\x90\x90\x90\x90\x90"; // call
	Scanner::TPattern Pattern( "\x51\xFF\x76\x08\x50\x53\xFF\x15\x00\x00\x00\x00\xF6\x46\x08\xF0\x74\x11\xFF\x75\x08\x53\xFF\x15\x00\x00\x00\x00\x50\xFF\x15",
		"x8?4x12?4x3");

	DWORD dwProc = (DWORD) Scanner::ScanMem( &Pattern );
	if ( dwProc )
	{
#ifdef _DEBUG
		Logger::OutLog("WARDEN: LoadWardenModule thunk:0x%.8X, patching...\r\n", dwProc );
#endif
		DWORD dwProcChangeOffset = dwProc+6;
		*((PDWORD)(bCode+1)) = (DWORD)&WardenLoader_hook - ((DWORD)dwProcChangeOffset+5);
		if ( Patcher::Instance()->MakePatch( (PBYTE)dwProcChangeOffset, bCode, 6 ) ) 
		{
#ifdef _DEBUG
			Logger::OutLog("WARDEN: LoadWardenModule patched at 0x%.8X (6 bytes)\r\n", dwProcChangeOffset);
#endif
			return dwProc;
		}
	}
	else
	{
#ifdef _DEBUG
		Logger::OutLog("WARDEN: LoadWardenModule thunk not found\r\n");
#endif
	}
	return NULL;

}
Esempio n. 12
0
bool SoyTime::FromString(const std::string& String)
{
	std::regex Pattern("T?([0-9]+)$" );
	std::smatch Match;
	if ( !std::regex_match( String, Match, Pattern ) )
		return false;
	
	//	extract long long
	auto IntegerStr = Match[1].str();
	auto Time = std::stoll( IntegerStr );
	if ( Time < 0 )
		return false;
	mTime = Time;
	return true;
}
Esempio n. 13
0
bool LoanAssumption::MatchPattern(const QString& Pat) const
{
    Q_D(const LoanAssumption);
	if (Pat.isEmpty())return false;
	QString Pattern("(?:");
    if (QRegularExpression(d->m_ScenarioName).isValid())
        Pattern += "(?:\\b" + d->m_ScenarioName + "\\b)";
    for (auto i = d->m_Aliases.constBegin(); i != d->m_Aliases.constEnd(); ++i)
		Pattern +="|(?:\\b" + *i + "\\b)";
	Pattern += ')';
	if (Pattern == "(?:)")
        return false;
    QRegularExpression MatchFinder(Pattern, QRegularExpression::CaseInsensitiveOption);
    Q_ASSERT(MatchFinder.isValid());
	return MatchFinder.match(Pat).hasMatch();
}
  void goalCB()
  {
    ROS_INFO("%s: Received new goal", action_name_.c_str());

    typedef boost::shared_ptr<const turtlebot_actions::FindFiducialGoal> GoalPtr;
    GoalPtr goal = as_.acceptNewGoal();

    cv::Size grid_size(goal->pattern_width,goal->pattern_height);
    detector_.setPattern(grid_size, goal->pattern_size, Pattern(goal->pattern_type));

    ros::Duration(1.0).sleep();
    //subscribe to the image topic of interest
    std::string image_topic = goal->camera_name + "/image_rect";
    sub_ = it_.subscribeCamera(image_topic, 1, &FindFiducialAction::detectCB, this);

    pub_timer_ = nh_.createTimer(tf_listener_.getCacheLength() - ros::Duration(1.0), boost::bind(&FindFiducialAction::timeoutCB, this, _1),true);
  }
Esempio n. 15
0
int
set_menu_format(MENU *m, int rows, int cols)
{
	if (rows < 0 || cols < 0) {
		return (E_BAD_ARGUMENT);
	}
	if (m) {
		if (Posted(m)) {
			return (E_POSTED);
		}
		if (rows == 0) {
			rows = FRows(m);
		}
		if (cols == 0) {
			cols = FCols(m);
		}

		/* The pattern buffer is allocated after items have been */
		/* connected */
		if (Pattern(m)) {
			IthPattern(m, 0) = '\0';
			Pindex(m) = 0;
		}

		FRows(m) = rows;
		FCols(m) = cols;
		Cols(m) = min(cols, Nitems(m));
		Rows(m) = (Nitems(m)-1) / cols + 1;
		Height(m) = min(rows, Rows(m));
		Top(m) = 0;
		Current(m) = IthItem(m, 0);
		SetLink(m);
		_scale(m);
	} else {
		if (rows > 0) {
			FRows(Dfl_Menu) = rows;
		}
		if (cols > 0) {
			FCols(Dfl_Menu) = cols;
		}
	}
	return (E_OK);
}
Esempio n. 16
0
File: Assgn.C Progetto: Henry/PatMat
int main()
{
    // assigment on match
    string vowel;
    Pattern p1 = Any("aeiou") * vowel;
    tst.validate(p1, "Hello", true);
    tst.validate_assign(p1, vowel, "e");

    // immediate assigment
    string nonv;
    Natural pos;
    Pattern p2 = Setcur(pos) & 'l' % nonv & Abort();
    tst.validate(p2, "Hello", false);
    tst.validate_assign(p2, nonv, "l");

    // assign on match & replace w/ value from match
    string sss;
    string subject1("hello");
    string subject2("goodbye");

    Pattern p3 = Pattern("good") * sss;
    tst.validate(p3, subject1, false);

    p3(subject2) = "<b>" + sss + "</b>";
    tst.validate_assign(p3, subject2, "<b>good</b>bye");

    // test "delayed evaluation" of string value
    MyStringObj s;
    Pattern p4 = "H" & vowel & +s;
    s.set("ll");  // AFTER p4 creation
    string subject("Hello");
    string r("");

    tst.validate(p4, subject, r, true);
    tst.validate_assign(p4, subject, "o");

    return tst.state();
}
DWORD RunScriptHack::PatchRunScript()
{
	/*
		33C9          XOR ECX,ECX
		56            PUSH ESI
		390D A8BA5F01 CMP DWORD PTR DS:[15FBAA8],ECX
		74 44         JE SHORT 01309A84
		83FA 22       CMP EDX,22
	*/

	PBYTE	bCode = (PBYTE) "\xEB"; // JMP SHORT
	Scanner::TPattern Pattern( "\x33\xC9\x56\x39\x0D\xFF\xFF\xFF\xFF\x74\x44\x83\xFA\x22", "x5?4x5");

	DWORD dwProc = (DWORD) Scanner::ScanMem( &Pattern );
	if ( dwProc )
	{
		DWORD dwProcChangeOffset = dwProc+9;

#ifdef _DEBUG
		Logger::OutLog("Script_RunScript proc:0x%.8X, patching...\r\n", dwProc );
#endif
		if ( Patcher::Instance()->MakePatch( (PBYTE)dwProcChangeOffset, bCode, 1 ) ) 
		{
#ifdef _DEBUG
			Logger::OutLog("Script_RunScript patched at 0x%.8X (1 bytes)\r\n", dwProcChangeOffset);
#endif
			return dwProcChangeOffset;
		}
	}
	else
	{
#ifdef _DEBUG
		Logger::OutLog("Script_RunScript proc not found\r\n");
#endif
	}
	return NULL;

}
Esempio n. 18
0
int
_match(MENU *m, char c, ITEM **current)
{
	int i, j;
	int found;
	/*
	 * Indicates search has cycled past the current item.  If the current
	 * item is matched after cycled is true then NO_MATCH results.
	 */
	int cycled;

	/* If a backspace is encountered then search backward from the */
	/* current item.  Otherwise, search forward from the current item. */

	i = Index(*current);
	if (c && c != '\b') {		/* c could be null */
		if (Pindex(m)+1 > MaxName(m)) {
			return (E_NO_MATCH);
		}
		IthPattern(m, Pindex(m)) = c;
		IthPattern(m, ++Pindex(m)) = '\0';
		if (--i < 0) {
			i = Nitems(m)-1;
		}
	}

	j = i;
	found = FALSE;
	cycled = FALSE;

	do {
		if (c == '\b') {
			if (--i < 0) {
				i = Nitems(m)-1;
			}
		} else {
			if (++i >= Nitems(m)) {
				i = 0;
			}
		}
		if (substr(m, Pattern(m), Name(IthItem(m, i)))) {
			found = TRUE;
			break;
		}
		cycled = TRUE;
	} while (i != j);

	if (found) {
		if (i == Index(*current) && cycled) {
			return (E_NO_MATCH);
		}
		*current = IthItem(m, i);
	} else {
		if (c && c != '\b') {
			Pindex(m) -= 1;
			IthPattern(m, Pindex(m)) = '\0';
		}
		return (E_NO_MATCH);
	}
	return (E_OK);
}
Esempio n. 19
0
/* 濁点は全て無視されるので注意 */
unsigned char MultiByteWord(unsigned char hi, unsigned char low, char* qualify=NULL) {
	int pos = 0;
	if (hi == 0x82 && LRANGE(0x9f,0xf1)) {
		return AssignHiraKaku(low, 1, qualify);			/* ひらがな */

	} else if (hi == 0x83 && LRANGE(0x40,0x96)) {
		return AssignHiraKaku(low, 0, qualify);	/* カタカナ */

	} 
	Pattern(0x89, 0x7e, 0x5f)	/* 円 */
	Pattern(0x81, 0x60, 0xd0)	/* 波 */
	Pattern(0x81, 0x5b, 0x90)	/* 長音 */
	Pattern(0x81, 0x40, 0x81)	/* 句点 */
	Pattern(0x81, 0x41, 0x84) /* 読点 */
	Pattern(0x81, 0x45, 0x85) /* 中黒 */
	Pattern(0x81, 0x75, 0x82)	/* 「 */
	Pattern(0x81, 0x76, 0x83) /* 」 */
	Pattern(0x81, 0x79, 0xc2)	/* 【 */
	Pattern(0x81, 0x7a, 0xc3)	/* 】 */
	Pattern(0x81, 0xf4, 0xc5) /* 音符 */
	Pattern(0x81, 0xa1, 0xc4) /* 四角 */
	Pattern(0x81, 0x63, 0xfe)	/* …… */
	Pattern(0x81, 0x40, 0x40) /* 全角空白 */

	return 0xc0;	// なんかおかしいときは-1を返す
}
Esempio n. 20
0
EntropyCounts::EntropyCounts(SNCBWCoCoInitialiser& cci, PatternCounts* patternCounts)
{
	initialise(cci, patternCounts);
	emptyEntropy = get(Pattern());
}
Esempio n. 21
0
void EntropyCounts::initialise(SNCBWCoCoInitialiser& cci, PatternCounts* patternCounts)
{
	Pattern previousPrefix = Pattern();
	double llh = 0;
	long int sum = 0;

	std::vector<long int> added_patterns;
	for(int n = 1; n <= kORDER; ++n)
	{
		PatternSet<uint64_t> allPatterns = cci.trainPatternModel.extractset(n,n);
		std::cout << "Done extracting entropy set for " << n << std::endl;

		std::set<Pattern, PatternComp> ordered_patterns;

		for(auto pattern : allPatterns)
		{
			ordered_patterns.insert(pattern);
		}

		//


		for(auto pattern: ordered_patterns)
		{
			Pattern context = pattern.size() == 1 ? Pattern() : Pattern(pattern, 0, n-1);
			if(context != previousPrefix)
			{
				double entropySum = 0; // maybe this isn't a great idea?
				for(auto count : added_patterns)
				{
					double mle = 1.0*count/sum;
					if(!std::isnormal(mle))
					{
						mle = CoCoInitialiser::epsilon;
					}
					entropySum += mle * log(mle);
				}

//					std::string::size_type n = previousPrefix.tostring(cci.classDecoder).find("justify");
//					if(n != std::string::npos)
//					{
//						std::cout << "\t\tFound " << added_patterns.size() << " elements"
//								<< " for the context: " << previousPrefix.tostring(cci.classDecoder)
//								<< " with sum: " << sum
//								<< " resulting in entropy: " << -entropySum
//								<<   std::endl;
//					}

				entropyCounts[previousPrefix] = -entropySum;

				sum = 0;
				added_patterns = std::vector<long int>();
				previousPrefix = context;
			}

			long int count = patternCounts->get(pattern);

			sum += count;
			added_patterns.push_back(count);
		}
	}

	V = get(Pattern());
}
Esempio n. 22
0
 rep(jj, Hex::kBoardSizeAligned) {
     uint kk = ii * Hex::kBoardSizeAligned + jj;
     patterns[kk] = Pattern(kk, 0, ii, jj);
 }