/************************************************************************/

//  Programming #2

//

//  List below are function prototypes of new functions given  or required

//                                  to be implemented in model.cpp for Programming #2

//

/************************************************************************/

 

 

 

int take1SampleFrom1PrSpace(double prTable[], int sizeOfTable);

/************************************************************************/

//Given the probabilities (of sizeOfTable elements) stored in prTable,

//                try to randomly take a sample out of sizeOfTable elements

//                according to the probabilities of sizeOfTable elements;

//Return the index of the non-deterministically sampled element.

/************************************************************************/

//This function is actually already implemented in model.cpp.

//                However, if you choose to implement this function on your own from scratch

//                you'll get an extra point.

/************************************************************************/

 

 

void getKeyboardProbabilityTable(char charToType, double prTable[]);

/************************************************************************/

//

//Given the character to type (charToType)

//                (assuming that the 1D keyboard of 26 keys is used),

//                (assuming that prTable[] for storing 26 prbabilities),

//                calculate pr(charGenerated = 'a' | charToType),

//                calculate pr(charGenerated = 'b' | charToType),

//                ...

//                calculate pr(charGenerated = 'z' | charToType), and

// store these probabilities in the array prTable.

/************************************************************************/

                 

 

char typeOneChar(char charToType);

/************************************************************************/

//Simulate the keyboard model:

//Given the charToType, simulate what character may actually be typed

//                when the user trying to type charToType and return it as the result.

/************************************************************************/

 

 

void typeOneWord(char word[], char output[], bool traceON = false, int maxOutput=100);

/************************************************************************/

//Simulate the combination of the spelling model and the keyboard model:

//Given a word stored in the word array, simulate what may actually

//                be typed and store the result in the output array.

//maxOutput specifies the capacity limit of the output array.

//When traceON is true, extra outputs are provided as traces.

/************************************************************************/

 

 

/************************************************************************/

// Also see below how option A in the main function in demo.cpp

//                                  call typeOneChar and typeOneWord to simulate the typing behavior

/************************************************************************/

 

/*

 

int main()

{

                  ...

                  ...

 

                  case 'A': case 'a'://

                                    {

                                                      displayParametersKbModel();

                                                      displayParametersSpellingModel();

 

                                                      char charToType;

                                                      cout << endl << "Now give me a character to type for 10 times:";

                                                      cin >> charToType;

 

                                                      for (int i=0; i<10; i++)

                                                      {               

                                                                        cout << endl << "[" << i+1 << "]: get \"" << typeOneChar(charToType)

                                                                                           << "\" while trying to type \"" << charToType << "\"" << endl << endl << endl;

                                                      }

 

                                                      char word[21];

                                                      char output[101];

                 

                                                      cout << endl << "Now give me a word (up to 20 characters) to type (10 times):";

                                                      cin >> word;

 

                                                      for (int i=0; i<10; i++)

                                                      {

                                                                        typeOneWord(word, output, true);

                                                                        cout << endl << "[" << i+1 << "]: get \"" << output

                                                                                           << "\" while trying to type \"" << word << "\"" << endl << endl << endl;

                                                      }

 

                                    }

                                    endOfService("[Simulation of typing behavior.]");

 

                                    ....

*/

 

 

/************************************************************************/

// Also note that we change all the global parameters variables to the double type.

/************************************************************************/

//******************************************************************************

//

//  Parameter settings for the Spelling model

//

//******************************************************************************

 

double prSpRepeat = 0.2;

//The probability of repeating the current cognitive state again as the next state

//we make it 0.2 initially, but you can try different values to see the effects.

 

double prSpMoveOn = 0.8;

//The probability of moving from the current cognitive state to other states

//      as the next state

//we make it 0.8 initially, but you can try different values to see the effects.

 

double spDegenerateTransitionDistancePower = 2;

//The likelihood of moving from the cognitive state of typing some character in a word

//to the next cognitive state is proportion to the inverse of

//(spDegenerateTransitionDistancePower) to the

//(the distance between the current state to the next state)th power.

//In the setting of the original spelling model in the project,

//we make it 2, but you can try different values to see the effects.

 

double spDegenerateInitialStateDistancePower = 2;

//The likelihood of some character in a word as the initial cognitive state

//is proportion to the inverse of

//(spDegenerateInitialStateDistancePower) to the

//(the position of the character in the word)th power.

//In the setting of the original spelling model in the project,

// spDegenerateInitialStateDistancePower and spDegenerateTransitionDistancePower

//have the same value, but you can make them different to see the effects

//By default, we make it 2, but you can try different values to see the effects.

 

//******************************************************************************

//******************************************************************************

//

//  Parameter settings for the keyboard model

//

//******************************************************************************

//******************************************************************************

 

double prKbHit = 0.6;

//The probability that you want to type a character and you do successfully make it

//In the setting of the original keyboard model in the project,

//we make it 0.9, but you can try different values to see the effects.

 

double prKbMiss = 0.4;

//The sum of probabilities that you want to type a character but end in touching

//a different character.

//we make it 0.1, but you can try different values to see the effects.

 

//*******************************************************

//Note that prKbHit + prKbMiss should always equal 1

//*******************************************************

 

//In the setting of the original keyboard model in the project,

//we make it 0.2, but you can try different values to see the effects.

 

 

double kbDegenerateDistancePower = 2;

//The likelihood you want to type a character but end in touching a different character

//is proportion to the inverse of

//(kbDegenerateDistancePower) raised to the (distance between them) th power

//In the setting of the original keyboard model in the project,

//we make it 2, but you can try different constants to see the effects.