MPDL
Computing Research Methods Multi-Perspective Digital Library

Guests are welcome to view our materials. To subscribe, edit, view raw markup, etc., you'll need to register for an account. Accounts are free (and will always be free) - your involvement helps us directly and indirectly (by demonstrating that our work matters to our funders...) StartingPoints has more info.
MPDL

Introduction:

In this Agent Syntax Lab we have rovered on the aspects of Row and Column Major Arrays and its usage pertaining the Python Language and also the scientific aspects of Row and Column Major.Then we saw the Python code for agentsyntaxlab and then we solved the questions 7.1 and 7.2 accordingly.

Wampus World:

The Wumpus world is a grid of squares surrounded by walls, where each square can contain agents and objects. The agent (you) always starts in the lower left corner, a square that will be labeled [1,1]. The agent's task is to find the gold, return to [1,1] and climb out of the cave.

To specify the agent's task, we specify its percepts, actions, and goals. In the Wumpus World, these are as follows:

In the square containing the wumpus and in the directly (not diagonally) adjacent square the agent will perceive a stench

In the squares directly adjacent to a pit, the agent will perceive a breeze.

In the square where the gold is, the agent will perceive a glitter.

When an agent walks into a wall, it will perceive a bump.

When the wumpus is killed, it gives out a woeful scream that can be perceived anywhere in the cave.

There are actions to go right, left, up, and down. In addition, the action Grab can be used to pick up the gold, if it is in the same square as the agent. The action Shoot can be used to fire an arrow in a straight line in the direction the agent is facing. The arrow continues until it either hits and kills the wumpus or hits the wall. The agent only has one arrow, so only the first Shoot action has any effect. Finally the action Climb is used to leave the cave; it is effective only when the agent is in the start square.

The agent dies a miserable death if it enters a square containing a pit or a live wumpus. It is safe (but smelly) to enter a square with a dead wumpus.

The agent's goal is to find the gold and bring it back to the start as quickly as possible, without getting killed. To be precise, 100 points are awarded for climbing out of the cave while carrying the gold, but there is a 1-point penalty for each action taken, and a 1000-point penalty for getting killed.

The locations of the gold and the wumpus are chosen randomly.

Each square other than the start can be a pit, with a probability of 0.2.

In most environments there is a way for the agent to safely retrieve the gold. In some environments, the agent must choose between going home empty-handed or taking a chance that could lead to death or to the gold. And in about 21% of the environments (the ones where the gold is in a pit or surrounded by pits), there is no way the agent can get a positive score. Sometimes life is just unfair

Row Major v/s Column Major Arrays

Row-major order and column-major order describe methods for storing multidimensional arrays in linear memory. Row-major order is used in C; column-major order is used in Fortran and Matlab.

Row-major order

In row-major storage, a multidimensional array in linear memory is accessed such that rows are stored one after the other. It is the approach used by the C programming language as well as many other languages, with the notable exceptions of Fortran and MATLAB.

The array of 1 2 3 4 5 6

Would find the array laid-out in linear memory as: 1 2 3 4 5 6

The difference in offset from one column to the next is 1 and from one row to the next is 3. The linear offset from the beginning of the array to any given element A[row][column] can then be computed as:

offset = row*NUMCOLS + column

Column Major order

Column-major order is a similar method of flattening arrays onto linear memory, but the columns are listed in sequence. The programming languages Fortran and MATLAB use column-major ordering.

The array of 1 2 3 4 5 6

If stored in linear memory with column-major order would look like the following:

1 4 2 5 3 6

With columns listed first. The memory offset could then be computed as:

offset = row + column*NUMROWS

where NUMROWS represents the number of rows in the array—in this case, 2.

Then What is Python?

Two-dimensional (i.e. rank 2) Python Numeric arrays are indexed "row-column": the first index gives the row number and the second index gives the column number. Thus, array A[i,j] gives the element in the row i and column j of rank 2 array A. Python uses Numeric array[] function to store matrices just like C. Hence Python uses row major ordering.

7.1

The following are Task Environment Properties

Observable Deterministic Episodic or Sequential Dynamic or Static Static or Discrete Agents
Fully Deterministic Episodic Dynamic Continous Multiple

Observable: The agents sensors is fully observable and give access to the complete state of the environmnet at each point in time that is the cameras where as wumpum world is partially observable, as it has only local perception and also because it does not have the information of the full environment.

Deterministic or Stochastic: The other state of the environment is deterministic since the agents view of the environment is determined by the current state also moreover action executed by the agent.Wumpum World is also deterministic, as its outcome can be completely determined by the current state and action performed.

Episodic or Sequential: The agents choice of action in each time is episodic which depends only on that episode where wumpus world not episodic since its actions is sequentially decided.

Static or Dynamic: The environment for the agent is static since it is predefined and set for ready to use,also the wumpus world is static since it is unchanged.

Discrete or Continuous: The enviornment for the agent is always continous since can do multiple times at same or different time where as wumpus world is discrete, as its percepts and actions are clearly defined.

Single Agent or Multiple Agent: In this type of environment we can see only multiple agents where as wumpus world is single agent.

7.2

KB:

W1. There must be a wumpus in either [1, 3] or [2, 2] (W1,3 ^ ¬W2,2) v (¬W1,3 ^ W2,2)

(Stench in [1, 2])

W2. There cannot be a wumpus in [2, 2] or [3, 1]. ¬W2,2 ^ ¬W3,1

(No stench in [2,1]

W3. The wumpus is in [1, 3], and not in [2, 2] or [3, 1]. W1,3 ^ ¬W2,2 ^ ¬W3,1

(W1 and W2)

P1. There must be a pit in [2, 2] or [3, 1] or both. P2,2 ^ P3,1

(Breeze in [2, 1])

P2. There cannot be a pit in [1, 3] or [2, 2]. ¬P1,3 ^ ¬P2,2

(No breeze in [1, 2])

P3. There is a pit in [3, 1] and no pit in [1, 3] or [2, 2]. P3,1 ^ ¬P1,3 ^ ¬P2,2

(P4 and P5)

Wumpus in [1,3], [2,2],or [3,1] pit in [1,3] pit in [2,2] pit in [3,1] W3 is true P3 is true KB is true alpha2= There is no pit in [2,2] alpha3 = There is a wumpus in [1,3]
no 0 0 0 0 0 0 1 0
no 0 0 1 0 1 0 1 0
no 0 1 0 0 0 0 0 0
no 0 1 1 0 0 0 0 0
no 1 0 0 0 0 0 1 0
no 1 0 1 0 0 0 1 0
no 1 1 0 0 0 0 0 0
no 1 1 1 0 0 0 0 0
[1,3] 0 0 0 1 0 0 1 1
[1,3] 0 0 1 1 1 1 1 1
[1,3] 0 1 0 1 0 0 0 1
[1,3] 0 1 1 1 0 0 0 1
[1,3] 1 0 0 1 0 0 1 1
[1,3] 1 0 1 1 0 0 1 1
[1,3] 1 1 0 1 0 0 0 1
[1,3] 1 1 1 1 0 0 0 1
[2,2] 0 0 0 0 0 0 1 0
[2,2] 0 0 1 0 1 0 1 0
[2,2] 0 1 0 0 0 0 0 0
[2,2] 0 1 1 0 0 0 0 0
[2,2] 1 0 0 0 0 0 1 0
[2,2] 1 0 1 0 0 0 1 0
[2,2] 1 1 0 0 0 0 0 0
[2,2] 1 1 1 0 0 0 0 0
[3,1] 0 0 0 0 0 0 1 0
[3,1] 0 0 1 0 1 0 1 0
[3,1] 0 1 0 0 0 0 0 0
[3,1] 0 1 1 0 0 0 0 0
[3,1] 1 0 0 0 0 0 1 0
[3,1] 1 0 1 0 0 0 1 0
[3,1] 1 1 0 0 0 0 0 0
[3,1] 1 1 1 0 0 0 0 0

Conclusions: Since α2 is true in every model (row) where the KB is true (W3 and P3 are true),(KB |= α2). It can be concluded that α2 = “There is no pit in [2,2].” Since α3 is true in every model (row) where the KB is true (W3 and P3 are true),(KB |= α3). It can be concluded that α3 = “There is a wumpus in [1,3

Proposition:

This is a statement that is either true or false like 1 or 0 that is binary data. For example, L[i,j,t] is a proposition; the proposition symbol in this case is L[i,j,t]. This sentence says that agent, at time t was in the [i,j] square.

Atomic Sentences:

Is basically short compact sentences that lack bridge words that form compound sentences, and therefore cannot be compound in nature.Atomic Sentence is a string of symbols which can represent an elementary sentence.In other words, an atomic sentence is an atomic formula containing no variables, which effectivly means that atomic sentences contains no logical connectives, variables or quantifiers. In terms of Agents Syntax, at any time instance t, Grab[t]

Complex Sentences:

Complex sentences involve combining two sentences of unequal value - one sentence is dependent on the other for its full meaning.A complex sentence has an independent clause joined by one or more dependent clauses. In terms of Agent Syntax, Gold[i][j] /\ Grab[t] means, there is gold in the square [i][j] and agent grabs it at time [t] where as in terms of Artificial Intelligence, Complex sentences are Atomic Sentences connected using logical connectives.

Conjuncts and Conjunctions:

A conjunct is an adjunct that adds information to the sentence that not considered part of the propositional content but which connects the sentence with previous parts of the discourse. In terms of Agent Syntax, a sentence whose main conective is /\ is caled a conjunction and the to connected statements are called conjuncts For example: Gold[i][j] /\ Grab[t] is a conjuction and Gold[i][j], Grab[t] are Conjucts.

Disjuncts and Disjunctions:

A disjunction uses the key word "or", so it is true as long as one side is true, but false when both sides are false. It is same as Conjucts and conjuctions, instead of using /\ if we use \/, it becomes a disjunctions. For Example:(Gold[i][j] \/ Grab[t]) is disjunction and Gold[i][j], Grab[t] are disjuncts.

Implication:

It is known as if-then statement or refers to implies where as in terms of Agent syntax W[1,2] => S[1,3] for example, (L[1,1,t] ∧ Breeze[t]) ⇒ (P[2,1] ∨ P[1,2]) This sentence states that if at time t agent is in square [1,1] and it senses a Breeze, then one the squares directly adjacent to it ([2,1] or [1,2]) has a Pit.

Premise or Antecedent:

In the above example (L[1,1,t] ∧ Breeze[t]) is the premise/antecedent

Biconditional:

Is a logical operator connecting two statements to assert that is an "if and only if" statement, A if and only if B where A is a antecedent and B is a consequent). In terms of Agent Syntax, a breeze will be perceived in [1,2] if and only if there is a pit in [1,1], [2,2], or [1,3].

Sound:

Inference processes derives true conclusions given true premises. Is also algorithm is sound if it derives only entailed sentences.

Sound Rules Of Inference

  • Here are some examples of sound rules of inference
  • A rule is sound if its conclusion is true whenever the premise is true
  • Each can be shown to be sound using a truth table
    RULE   PREMISE   CONCLUSION
    Modus Ponens   A, A -> B   B
    And Introduction   A, B   A ∧ B
    And Elimination   A ∧ B   A
    Double Negation   ¬¬A   A
    Unit Resolution   A V B, ¬B   A
    Resolution   A V B, ¬B V C   A V C

Valid:

A sentence is valid if it is true is all models. For example,(Breeze[1,1]) ⇔ (P[2,1] ∨ P[1,2]) is a valid sentence because it is true in all models of Wumpus World

Satisfiable:

A sentence is satisfiable if it is true or statisfies the conditions in some model. For example, ¬W[1,1] ∨ ¬W[2,1] is satisfiable in all models of Wumpus World. ¬W[2,1] is satisfiable in all models where square does not have a Wumpu

Unit Resolution and Resolution:

An inference rule (such as Modus Ponens or And-Elimination); For example, ¬W[1,1] ∨ ¬W[1,3] is given, and we also know there is a Wumpus in [1,3] (¬W[1,3] is false), then there is no Wumpus in [1,1] (¬W[1,1] is true).

Resolution:

The resolution implemented in Python:

Code Source : http://code.google.com/p/aima-python

def pl_resolution(KB, alpha):
    "Propositional Logic Resolution: say if alpha follows from KB. [Fig. 7.12]"
    clauses = KB.clauses + conjuncts(to_cnf(~alpha))
    new = set()
    while True:
        n = len(clauses)
        pairs = [(clauses[i], clauses[j])
                 for i in range(n) for j in range(i+1, n)]
        for (ci, cj) in pairs:
            resolvents = pl_resolve(ci, cj)
            if FALSE in resolvents: return True
            new = new.union(set(resolvents))
        if new.issubset(set(clauses)): return False
        for c in new:
            if c not in clauses: clauses.append(c)

def pl_resolve(ci, cj):
    """Return all clauses that can be obtained by resolving clauses ci and cj.
    >>> for res in pl_resolve(to_cnf(A|B|C), to_cnf(~B|~C|F)):
    ...    ppset(disjuncts(res))
    set([A, C, F, ~C])
    set([A, B, F, ~B])
    """
    clauses = []
    for di in disjuncts(ci):
        for dj in disjuncts(cj):
            if di == ~dj or ~di == dj:
                dnew = unique(removeall(di, disjuncts(ci)) + 
                              removeall(dj, disjuncts(cj)))
                clauses.append(NaryExpr('|', *dnew))
    return clauses

Conclusion:

All in all the in this agent syntax lab we came to know about wampus world and agents and others.We touched all the examples and went to every details of the lab and explained each and every part of it.I can say that i am learing some verygood things in this lab and also got familiar with python coding.Also this lab has helped in easy going with interaction design class.

r1 - 20 Nov 2008 - 21:32:30 - BipinBitlaa
Guests are welcome to view our materials. To subscribe, edit, view raw markup, etc., you'll need to register for an account. Accounts are free (and will always be free) - your involvement helps us directly and indirectly (by demonstrating that our work matters to our funders...) StartingPoints has more info.
This site is powered by the TWiki collaboration platformCopyright 1999-2009 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Ahatwiki? Send feedback Syndicate this site RSSATOM