Thursday, August 28, 2014

We will be reviewing some simple random walk theorems. We will look at the amount of time that a SSRW is positive. If the random walk is at zero, it takes an even number of steps in either direction to return to zero.
We will look at the distribution when the random walk is positive. We can take an example with coin tosses. When we toss a coin, the probability that the number of heads equals k in 2n coin tosses is maximum when k = n . What we are saying is that we know for sure we can exceed the number of tails when the number of heads and the number of tails are equal. If we wanted to maximize the number for one outcome, we would have to choose the value 0 or 2n for the remainder.  Since we mentioned earlier that the probability a random walk reaches a certain count can be derived from the probabilities from the outcomes of the states from the distribution, we can express the random walk probabilities in terms of  the counts of the probabilities for the individual states. 

Tuesday, August 26, 2014

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Test
{
    public static void Main()
    {
        char[,] wordSearch = new char [3,3] { {'B', 'O', 'B'}, {'B', 'O', 'B'}, {'B', 'O', 'B'} };
        var wordList = new List<string>() { "BOB", "BOX", "COB" };
        printWordsInMaze(wordSearch, 3, 3, wordList);
    }
   
    public static void printWordsInMaze(char[,] wordSearch, int row, int col, List<string> wordList)
    {
        string[ ] directions = {"LR", "RL", "U", "D", "DUL", "DUR", "DDL","DDR"};
    for (int i = 0; i < col; i++)
    for (int j = 0; j < row; j++)
    {
        char letter = wordSearch[i,j];
          string pattern;
           List<string> candidates = wordList;
      
          int start = i;
          int end = j;
          foreach (var direction in directions)
          {
              int r = i;
              int c = j;
              pattern = String.Empty;
              switch (direction)
             {
                            case "LR":
                              while (c < col) { pattern += wordSearch[r,c]; c++;}
                              printMatchingWord(start, end, pattern, candidates, direction);
                            break;

                            case "RL":
                              while (c >= 0) { pattern+= wordSearch[r,c]; c--;}
                              printMatchingWord(start, end,pattern, candidates, direction);
                            break;

                            case "U":
                              while (r >= 0) { pattern += wordSearch[r,c]; r--;}
                              printMatchingWord(start, end,pattern, candidates, direction);
                            break;

                            case "D":
                              while (r < col) { pattern += wordSearch[r,c]; r++;}
                              printMatchingWord(start, end, pattern, candidates, direction);
                            break;

                            case "DUL" :
                              while (r >= 0 && c >= 0) { pattern += wordSearch[r,c]; r--; c--;}
                              printMatchingWord(start, end, pattern, candidates, direction);
                            break;

                            case "DUR" :
                              while (r >= 0 && c < col) { pattern += wordSearch[r,c]; r--; c++;}
                              printMatchingWord(start, end, pattern, candidates, direction);
                            break;

                            case "DDL" :
                              while (c >= 0 && r < col) { pattern += wordSearch[r,c]; c--; r++;}
                              printMatchingWord(start, end,pattern, candidates, direction);
                            break;

                            case "DDR" :
                              while (r < col && c < row) { pattern += wordSearch[r,c]; r++; c++;}
                              printMatchingWord(start, end, pattern, candidates, direction);
                            break;
               }
               //i = start;
               //j = end;
              }
         }
    }
   
private static void printMatchingWord(int i, int j, string pattern, List<string> candidates, string direction)
{
                                  foreach (var word in candidates)
                                  {
                                      Console.WriteLine("Pattern={0},word={1}", pattern, word);
                                       if (pattern.StartsWith(word))
                                        Console.WriteLine ("Word = {0} at row = {1} and col = {2} and direction = {3}", word, i,j, direction);
                                }
}

}

  • Success time: 0.06 memory: 33936 signal:0
    Pattern=BOB,word=BOB
    Word = BOB at row = 0 and col = 0 and direction = LR
    Pattern=BOB,word=BOX
    Pattern=BOB,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BBB,word=BOB
    Pattern=BBB,word=BOX
    Pattern=BBB,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BOB,word=BOB
    Word = BOB at row = 0 and col = 0 and direction = DDR
    Pattern=BOB,word=BOX
    Pattern=BOB,word=COB
    Pattern=OB,word=BOB
    Pattern=OB,word=BOX
    Pattern=OB,word=COB
    Pattern=OB,word=BOB
    Pattern=OB,word=BOX
    Pattern=OB,word=COB
    Pattern=O,word=BOB
    Pattern=O,word=BOX
    Pattern=O,word=COB
    Pattern=OOO,word=BOB
    Pattern=OOO,word=BOX
    Pattern=OOO,word=COB
    Pattern=O,word=BOB
    Pattern=O,word=BOX
    Pattern=O,word=COB
    Pattern=O,word=BOB
    Pattern=O,word=BOX
    Pattern=O,word=COB
    Pattern=OB,word=BOB
    Pattern=OB,word=BOX
    Pattern=OB,word=COB
    Pattern=OB,word=BOB
    Pattern=OB,word=BOX
    Pattern=OB,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BOB,word=BOB
    Word = BOB at row = 0 and col = 2 and direction = RL
    Pattern=BOB,word=BOX
    Pattern=BOB,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BBB,word=BOB
    Pattern=BBB,word=BOX
    Pattern=BBB,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BOB,word=BOB
    Word = BOB at row = 0 and col = 2 and direction = DDL
    Pattern=BOB,word=BOX
    Pattern=BOB,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BOB,word=BOB
    Word = BOB at row = 1 and col = 0 and direction = LR
    Pattern=BOB,word=BOX
    Pattern=BOB,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BB,word=BOB
    Pattern=BB,word=BOX
    Pattern=BB,word=COB
    Pattern=BB,word=BOB
    Pattern=BB,word=BOX
    Pattern=BB,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BO,word=BOB
    Pattern=BO,word=BOX
    Pattern=BO,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BO,word=BOB
    Pattern=BO,word=BOX
    Pattern=BO,word=COB
    Pattern=OB,word=BOB
    Pattern=OB,word=BOX
    Pattern=OB,word=COB
    Pattern=OB,word=BOB
    Pattern=OB,word=BOX
    Pattern=OB,word=COB
    Pattern=OO,word=BOB
    Pattern=OO,word=BOX
    Pattern=OO,word=COB
    Pattern=OO,word=BOB
    Pattern=OO,word=BOX
    Pattern=OO,word=COB
    Pattern=OB,word=BOB
    Pattern=OB,word=BOX
    Pattern=OB,word=COB
    Pattern=OB,word=BOB
    Pattern=OB,word=BOX
    Pattern=OB,word=COB
    Pattern=OB,word=BOB
    Pattern=OB,word=BOX
    Pattern=OB,word=COB
    Pattern=OB,word=BOB
    Pattern=OB,word=BOX
    Pattern=OB,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BOB,word=BOB
    Word = BOB at row = 1 and col = 2 and direction = RL
    Pattern=BOB,word=BOX
    Pattern=BOB,word=COB
    Pattern=BB,word=BOB
    Pattern=BB,word=BOX
    Pattern=BB,word=COB
    Pattern=BB,word=BOB
    Pattern=BB,word=BOX
    Pattern=BB,word=COB
    Pattern=BO,word=BOB
    Pattern=BO,word=BOX
    Pattern=BO,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BO,word=BOB
    Pattern=BO,word=BOX
    Pattern=BO,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BOB,word=BOB
    Word = BOB at row = 2 and col = 0 and direction = LR
    Pattern=BOB,word=BOX
    Pattern=BOB,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BBB,word=BOB
    Pattern=BBB,word=BOX
    Pattern=BBB,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BOB,word=BOB
    Word = BOB at row = 2 and col = 0 and direction = DUR
    Pattern=BOB,word=BOX
    Pattern=BOB,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=OB,word=BOB
    Pattern=OB,word=BOX
    Pattern=OB,word=COB
    Pattern=OB,word=BOB
    Pattern=OB,word=BOX
    Pattern=OB,word=COB
    Pattern=OOO,word=BOB
    Pattern=OOO,word=BOX
    Pattern=OOO,word=COB
    Pattern=O,word=BOB
    Pattern=O,word=BOX
    Pattern=O,word=COB
    Pattern=OB,word=BOB
    Pattern=OB,word=BOX
    Pattern=OB,word=COB
    Pattern=OB,word=BOB
    Pattern=OB,word=BOX
    Pattern=OB,word=COB
    Pattern=O,word=BOB
    Pattern=O,word=BOX
    Pattern=O,word=COB
    Pattern=O,word=BOB
    Pattern=O,word=BOX
    Pattern=O,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BOB,word=BOB
    Word = BOB at row = 2 and col = 2 and direction = RL
    Pattern=BOB,word=BOX
    Pattern=BOB,word=COB
    Pattern=BBB,word=BOB
    Pattern=BBB,word=BOX
    Pattern=BBB,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=BOB,word=BOB
    Word = BOB at row = 2 and col = 2 and direction = DUL
    Pattern=BOB,word=BOX
    Pattern=BOB,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    Pattern=B,word=BOB
    Pattern=B,word=BOX
    Pattern=B,word=COB
    
Today we will be reviewing the Atom web standards. There is the Atom publishing format and the Atom syndication format. The latter is the XML language used to describe the Atom feeds. The former is the HTTP based protocol for creating and updating the web resources.Web feeds follow a publisher subscriber model. A web feed provider is usually a site owner that publishes resources in say xml format. Subscribers then use feed readers to view their content. Browsers typically support feed readers. One usage is say when bloggers keep track of each others posts via Atom feeds.
A feed can contain both data and metadata. It has  labeled content. It is usually timestamped to communicate the information on when it was created/updated. Each text element can be internationalized using xml:lang  The Atom format came after the RSS format which was struggling with backward compatibility. While RSS is still used by Apple and iTunes, the Atom format has been adopted widely by Google.
To provide a link to an Atom feed, we use the following in HTML:
<link href="atom.xml" type="application/atom+xml" rel="alternate" title="feedtitle" />
The feed is specified as  <feed xmlns="http://www.w3.org/2014/Atom"><metadata/><data/></feed>
.Net MVC webservers allow RSSResult ActionResult to be cached with an expiration time because it is just a file.
The iCalendar format is different from Atom in that it specifies a meeting request and tasks for sharing with a file and an extension named .ics. The content is specified in begin and end tags with the top level being vcalendar. The items are listed in key:value pairs and form a succint description of the meeting. It has syntax to specify the event/journal/free/busy time.
Flair is a javascript based application framework for Adobes AIR html+ajax SDK. Its an acronym for Framework Leveraged AIR. It can be used to specify a list of items say for example based on source ip of request as gathered from the request headers HTTP_X_FORWARDED_FOR and REMOTE_ADDR

Monday, August 25, 2014

In this post, we describe an application that does a time series inverted search on computer logs that are described as raw text, timestamp, host, source and source type. We call these events and we keep them in a table. The events are stored in a table in a SQL database with a clustered index on the time-stamp. The application is a .Net Web API application that connects to the table over entity framework or any object-relational mapping library. The Web API application exposes an API to post the events into the server and an API to do search over the events. When the events are posted into the table, they are sorted by their time. When the search is executed by the table, the time range is used to select the events and returned to the user as search results. Code is being written at http://github.com/ravibeta/csharpexamples/SplunkLite.Net 

Sunday, August 24, 2014

In the previous post, we mentioned Markov chains and a closed communicating class. If we have a Markov chain with transition matrix P and fix n transitions from the overall N, then the Markov chain with transition matrix Pn has exactly the same closed communicating classes. Recall that each single-element set from the states is a closed communicating class and by definition a closed communicating class has all the states that the origin leads to. A general Markov chain can have an infinite number of communicating classes. This is something we see from sets and relations. When we visualize the topological structure of a Markov chain, we will see closed communicating classes that have no arrows for communication and arrows between two non-closed communicating classes that are in the same direction. If we remove the non-closed communicating classes, we can get disjoint closed communicating classes.
If we have an irreducible chain where all the states form a single closed communicating class, we can further simplify the behavior of the chain by noticing that if the chain is in one set it can move to only a few other sets. For example, if we take the set with four communicating classes, the diagonal states will transition to the opposite. This we say has a period of two. A triangular three communicating class will have a period of three. The numbers two and three are indicative of a divisor in the communicating classes. If an integer n divides m and the reflexive state transitions are possible with n transitions, then its possible with m transitions. So, whether it is possible to return to i in m steps can be decided by one of the integer divisors of m. The period of the state is defined as the greatest common divisor of all natural numbers n with such that it is possible to return to i in n steps. A state i is called aperiodic if it can be returned to only one step.

Saturday, August 23, 2014

The topological structure of a Markov chain can be represented as a digraph and denoted by a pair (V,E ) with V being the vertices and E being the edges of the graph. The graph of a chain refers to the structure of the process that does not depend on the exact values of the transition probabilities but only on which of them are positive. We say that a state i leads to state j if, starting from i the chain will visit j at some finite time.
We denote this by i ~ j and it is equivalent to stating the probability for some final state j after n iterations starting from i is greater than zero. This relation is reflexive. In fact for all the states in the event space, we can have probabilities between pairs to be greater than zero.
This relation is also transitive. If we can reach state j from i and k from j then it implies that there is a chain possible from i to k .
If it's a symmetric relationship which means that there is a chain from i to j and j to i then we can say that i communicates with j.
The communication relationship is an equivalence relation which means it is symmetric, reflexive and transitive. Equivalence classes also called as communicating classes partition the space. The communicating class corresponding to state i is, by definition the set of all states that communicate with i.
Two communicating classes are either identical or completely disjoint.
A communicating class is said to be closed when all the states belong to the communicating class. Closed communicating classes are particularly important because they decompose the chain into smaller more manageable parts.The single element state i is essential if it belongs to closed communicating class. Otherwise the state is inessential. If all the states communicate with all others, then the chain is considered irreducible.

Friday, August 22, 2014

Today we will continue to discuss Skorokhod theorem. Recall that the theorem mentions the stopping time in terms of a probability from the distribution.  The simpler case was the symmetrical random walk but Skorokhod embedding theorem works even better for the distribution. Moreover we use it for describing a random walk with a new random variable that can take values above a value a and below b.