AI class homework 4: Difference between revisions

From John's wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 5: Line 5:
== Logic ==
== Logic ==


{{#ev:youtubehd|WP_97aspqrc}}
<youtube>WP_97aspqrc</youtube>


Note: Select whether the logical sentences are always true (T), always false (F), or sometimes true sometimes false depending on the values of the variables (?).
=== Note ===
 
Select whether the logical sentences are always true (T), always false (F), or sometimes true sometimes false depending on the values of the variables (?).
 
=== Code ===
 
I used the following code to solve this question.
 
  function print( line ) { WScript.StdOut.WriteLine( line ); }
  function implies( p, q ) {
    if ( p === true && q === false ) { return false; }
    return true;
  }
  function a( smoke, fire ) {
    return implies( smoke, fire ) === ( smoke || ! fire );
  }
  function b( smoke, fire ) {
    return implies( smoke, fire ) === implies( ! smoke, ! fire );
  }
  function c( smoke, fire ) {
    return implies( smoke, fire ) === implies( ! fire, ! smoke );
  }
  function d( big, dumb ) {
    return big || dumb || implies( big, dumb );
  }
  function e( big, dumb ) {
    return ( big && dumb ) === ! ( ! big || ! dumb );
  }
  function check_t() { return true; }
  function check_f() { return false; }
  function check_d( a ) { return a; }
  function test( label, f ) {
 
    var results = { "true": 0, "false": 0 };
    var iter = function( p1, p2 ) {
      var t = f( p1, p2 );
      results[ t.toString() ]++;
    }
    iter( false, false );
    iter( false, true  );
    iter( true , false );
    iter( true , true  );
    if ( results[ "true" ] === 4 ) {
      print( label + " all true." );
    }
    else if ( results[ "false" ] === 4 ) {
      print( label + " all false." );
    }
    else {
      print( label + " depends." );
    }
  }
  test( "a", a );
  test( "b", b );
  test( "c", c );
  test( "d", d );
  test( "e", e );
  test( "check t", check_t );
  test( "check f", check_f );
  test( "check d", check_d );
 
=== Answer ===
 
<youtube>XFR1231H0M0</youtube>


== More Logic ==
== More Logic ==


{{#ev:youtubehd|P_eu1YFp9Z8}}
<youtube>P_eu1YFp9Z8</youtube>


Note:
=== Note ===


Select whether the logical sentence correctly encode the english sentence (check-mark), incorrectly encode the english sentence (X), or not a legitimate sentence in first-order logic (Err).
Select whether the logical sentence correctly encode the english sentence (check-mark), incorrectly encode the english sentence (X), or not a legitimate sentence in first-order logic (Err).
Line 32: Line 121:


The fourth statement is missing a ) at the end.
The fourth statement is missing a ) at the end.
=== Answer ===
<youtube>SiZtjEaLiE8</youtube>


== Vacuum World ==
== Vacuum World ==


{{#ev:youtubehd|wsfXrIhDhJ0}}
<youtube>wsfXrIhDhJ0</youtube>


Note:
=== Note ===


The image represents belief states of the two-room vacuum world. In this version there are no percepts/sensors, the actions are all deterministic, and the environment is static. In the initial state you have no information about which state you are in. Your goal is to be in the leftmost of the two squares and have both squares cleaned up.
The image represents belief states of the two-room vacuum world. In this version there are no percepts/sensors, the actions are all deterministic, and the environment is static. In the initial state you have no information about which state you are in. Your goal is to be in the leftmost of the two squares and have both squares cleaned up.
Line 44: Line 137:


Select yes if the sequence is guaranteed to always reach the goal or no if it is not.
Select yes if the sequence is guaranteed to always reach the goal or no if it is not.
=== Answer ===
<youtube>FhowsCKPJCE</youtube>


== More Vacuum World ==
== More Vacuum World ==


{{#ev:youtubehd|2H4NJg8Iiaw}}
<youtube>2H4NJg8Iiaw</youtube>


Note:
=== Note ===


This problem deals with a version of the two-room vacuum world where there is local sensing, dynamic dirt generation, and stochastic movement actions. Local sensing means after any action you get information about the room you are in (left or right) and whether there is dirt in that room, but no information about dirt in the other room. The world is dynamic, which means dirt can spontaneously appear in either room after an action is performed except when the robot has performed a suck action, in which case the room where the suck action has been performed will have no dirt. Left and right moves are stochastic because they can sometimes fail, for example, the robot might not move right even if the move right action is chosen. The suck action is deterministic so it will always succeed in removing dirt.
This problem deals with a version of the two-room vacuum world where there is local sensing, dynamic dirt generation, and stochastic movement actions. Local sensing means after any action you get information about the room you are in (left or right) and whether there is dirt in that room, but no information about dirt in the other room. The world is dynamic, which means dirt can spontaneously appear in either room after an action is performed except when the robot has performed a suck action, in which case the room where the suck action has been performed will have no dirt. Left and right moves are stochastic because they can sometimes fail, for example, the robot might not move right even if the move right action is chosen. The suck action is deterministic so it will always succeed in removing dirt.
Line 55: Line 152:
Given we start in the leftmost location and that location is clean (i.e. we start in either belief state 5 or 7), select the set of belief states we have after performing a move right action.
Given we start in the leftmost location and that location is clean (i.e. we start in either belief state 5 or 7), select the set of belief states we have after performing a move right action.


== Move Vacuum World ==
=== Answer ===
 
<youtube>Z6QNCiMIR1I</youtube>
 
== More Vacuum World ==
 
<youtube>i5XMOLw6CGE</youtube>
 
=== Note ===
 
Assume we have the same belief states that we had at the end of problem 4. We now sense that we are in the right most square and the square is dirty. Click on all the belief states given this percept.
 
=== Answer ===
 
<youtube>QHPs9m5qE9A</youtube>
 
== More Vacuum World ==
 
<youtube>x93ewPQhIQc</youtube>
 
=== Note ===
 
Assume we have belief states two and six. We perform a suck action. Select the belief states we have after performing the suck action.


{{#ev:youtubehd|i5XMOLw6CGE}}
=== Answer ===


Note: Assume we have the same belief states that we had at the end of problem 4. We now sense that we are in the right most square and the square is dirty. Click on all the belief states given this percept.
<youtube>984YVReF6Do</youtube>


== More Vacuum World ==
== More Vacuum World ==


{{#ev:youtubehd|x93ewPQhIQc}}
<youtube>RW-l7JWDtYQ</youtube>


Note: Assume we have belief states two and six. We perform a suck action. Select the belief states we have after performing the suck action.
=== Note ===


== Move Vacuum World ==
Assume we have the same belief states that we had at the end of problem 6. We now sense that we are in the right most square and the square is clean. Select the belief states we have after sensing.


{{#ev:youtubehd|RW-l7JWDtYQ}}
=== Answer ===


Note: Assume we have the same belief states that we had at the end of problem 6. We now sense that we are in the right most square and the square is clean. Select the belief states we have after sensing.
<youtube>mPk9fV8RZ3g</youtube>


== Monkey and Bananas ==
== Monkey and Bananas ==


{{#ev:youtubehd|rCGAgc9smZg}}
<youtube>rCGAgc9smZg</youtube>


Note:
=== Note ===


Given the plan written in red on the upper right piece of paper and the initial state described at the very bottom of the screen, select the statements that will be true in the final state after performing the plan starting in the initial state.  
Given the plan written in red on the upper right piece of paper and the initial state described at the very bottom of the screen, select the statements that will be true in the final state after performing the plan starting in the initial state.  
Line 88: Line 207:


It is intentional for the bananas to remain high.
It is intentional for the bananas to remain high.
=== Answer ===
<youtube>rZtBR-d0H5Y</youtube>


== Situation Calculus ==
== Situation Calculus ==


{{#ev:youtubehd|eeDwEYxWCTA}}
<youtube>eeDwEYxWCTA</youtube>
 
=== Note ===


The domain for this problem is a combination lock with 4 digits. There are two actions
The domain for this problem is a combination lock with 4 digits. There are two actions
Line 102: Line 227:
* Poss(action, situation) - possible to perform action in a given situation
* Poss(action, situation) - possible to perform action in a given situation
* X - the correct combination
* X - the correct combination
=== Answer ===
<youtube>2oZexvl5fVU</youtube>

Latest revision as of 23:48, 14 April 2018

These are my notes for homework 4 of the AI class.

Homework

Logic

Note

Select whether the logical sentences are always true (T), always false (F), or sometimes true sometimes false depending on the values of the variables (?).

Code

I used the following code to solve this question.

 function print( line ) { WScript.StdOut.WriteLine( line ); }

 function implies( p, q ) {
   if ( p === true && q === false ) { return false; }
   return true;
 }

 function a( smoke, fire ) {

   return implies( smoke, fire ) === ( smoke || ! fire );

 }

 function b( smoke, fire ) {

   return implies( smoke, fire ) === implies( ! smoke, ! fire );

 }

 function c( smoke, fire ) {

   return implies( smoke, fire ) === implies( ! fire, ! smoke );

 }

 function d( big, dumb ) {

   return big || dumb || implies( big, dumb );

 }

 function e( big, dumb ) {

   return ( big && dumb ) === ! ( ! big || ! dumb );

 }

 function check_t() { return true; }
 function check_f() { return false; }
 function check_d( a ) { return a; }

 function test( label, f ) {
 
   var results = { "true": 0, "false": 0 };

   var iter = function( p1, p2 ) {

     var t = f( p1, p2 );

     results[ t.toString() ]++;

   }

   iter( false, false );
   iter( false, true  );
   iter( true , false );
   iter( true , true  );

   if ( results[ "true" ] === 4 ) {
     print( label + " all true." );
   }
   else if ( results[ "false" ] === 4 ) {
     print( label + " all false." );
   }
   else {
     print( label + " depends." );
   }
 }

 test( "a", a );
 test( "b", b );
 test( "c", c );
 test( "d", d );
 test( "e", e );

 test( "check t", check_t );
 test( "check f", check_f );
 test( "check d", check_d );

Answer

More Logic

Note

Select whether the logical sentence correctly encode the english sentence (check-mark), incorrectly encode the english sentence (X), or not a legitimate sentence in first-order logic (Err).

English Sentences and the lines with the corresponding logical sentences:

Paris and Nice are both in France.

Corresponding translations on lines 1 and 2.

There is a country that borders Iran and Syria'

Corresponding translations on lines 3 and 4.

No two bordering countries can have the same map color.

Corresponding translations on lines 5 and 6.

The fourth statement is missing a ) at the end.

Answer

Vacuum World

Note

The image represents belief states of the two-room vacuum world. In this version there are no percepts/sensors, the actions are all deterministic, and the environment is static. In the initial state you have no information about which state you are in. Your goal is to be in the leftmost of the two squares and have both squares cleaned up.

Click on the shortest sequence of actions (L, R, or S) that take you from the initial state to the goal state (determining the initial and goal states are part of the problem).

Select yes if the sequence is guaranteed to always reach the goal or no if it is not.

Answer

More Vacuum World

Note

This problem deals with a version of the two-room vacuum world where there is local sensing, dynamic dirt generation, and stochastic movement actions. Local sensing means after any action you get information about the room you are in (left or right) and whether there is dirt in that room, but no information about dirt in the other room. The world is dynamic, which means dirt can spontaneously appear in either room after an action is performed except when the robot has performed a suck action, in which case the room where the suck action has been performed will have no dirt. Left and right moves are stochastic because they can sometimes fail, for example, the robot might not move right even if the move right action is chosen. The suck action is deterministic so it will always succeed in removing dirt.

Given we start in the leftmost location and that location is clean (i.e. we start in either belief state 5 or 7), select the set of belief states we have after performing a move right action.

Answer

More Vacuum World

Note

Assume we have the same belief states that we had at the end of problem 4. We now sense that we are in the right most square and the square is dirty. Click on all the belief states given this percept.

Answer

More Vacuum World

Note

Assume we have belief states two and six. We perform a suck action. Select the belief states we have after performing the suck action.

Answer

More Vacuum World

Note

Assume we have the same belief states that we had at the end of problem 6. We now sense that we are in the right most square and the square is clean. Select the belief states we have after sensing.

Answer

Monkey and Bananas

Note

Given the plan written in red on the upper right piece of paper and the initial state described at the very bottom of the screen, select the statements that will be true in the final state after performing the plan starting in the initial state.

Clarifications:

  • The effect on ClimbUp should be: On(Monkey, b) and !Height(Monkey, Low) and Height(Monkey, High)
  • There should also be an additional precondition at Push action, add: At(b, x), where b = box.

Thanks to Naran Bayanbat for these clarifications.

It is intentional for the bananas to remain high.

Answer

Situation Calculus

Note

The domain for this problem is a combination lock with 4 digits. There are two actions

  1. dial any combination into the lock, where the result is the lock opening if the right combination (X) is dialed
  2. push a lock button (L) which makes the lock, locked

Select the axioms that correctly encode the situation.

Notation:

  • Poss(action, situation) - possible to perform action in a given situation
  • X - the correct combination

Answer