By: Jordan Hofstaedter. Make random outputs from inputs that actually make sense. If we let the computer produce random letters in English, chances are.

Slides:



Advertisements
Similar presentations
Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
Advertisements

© 2004 Goodrich, Tamassia Hash Tables1  
Design and Implementation* Objective: To design and implement a program for a relatively small yet reasonably complicated problem. To introduce and review.
Markov Chain Algorithm in Perl Yu-Chung Chau CS 265.
CSC 4630 Meeting 9 February 14, 2007 Valentine’s Day; Snow Day.
1 CSCI-2400 Models of Computation. 2 Computation CPU memory.
Dictionaries and Hash Tables1  
Chapter 20 Thinking Big: Functions. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Anatomy of a Function Functions are packages for.
Chapter 2: Algorithm Discovery and Design
Program Design and Development
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
Strings. Sentences in English are implemented as strings in the C language. Computations involving strings are very common. E.g. – Is string_1 the same.
Simple Program Design Third Edition A Step-by-Step Approach
Lists in Python.
 2006 Pearson Education, Inc. All rights reserved Arrays.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
Invitation to Computer Science, Java Version, Second Edition.
MCB 5472 Assignment #6: HMMER and using perl to perform repetitive tasks February 26, 2014.
CHAPTER 07 Arrays and Vectors (part I). OBJECTIVES 2 In this part you will learn:  To use the array data structure to represent a set of related data.
Scripting Languages Diana Trandab ă ț Master in Computational Linguistics - 1 st year
CSE 143 Lecture 11 Maps Grammars slides created by Alyssa Harding
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
Introduction to Awk Awk is a convenient and expressive programming language that can be applied to a wide variety of computing and data manipulation tasks.
1 Analysis of Algorithms CS 105 Introduction to Data Structures and Algorithms.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
1 Content-Aware Device Benchmarking Methodology/Terminology (draft-ietf-bmwg-ca-bench-meth-00) BMWG Meeting IETF-82 Taipei November 2011 Mike Hamilton.
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
5 1 Data Files CGI/Perl Programming By Diane Zak.
LIN Unix Lecture 7 Hana Filip. LIN Text Processing Command Line Utility Programs (cont.) sed LAST WEEK wc sort tr uniq awk TODAY join paste.
Computing Science 1P Large Group Tutorial: Lab Exam & Class Test Simon Gay Department of Computing Science University of Glasgow 2006/07.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
UNIT 5.  The related activities of sorting, searching and merging are central to many computer applications.  Sorting and merging provide us with a.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Hashing 1 Hashing. Hashing 2 Hashing … * Again, a (dynamic) set of elements in which we do ‘search’, ‘insert’, and ‘delete’ n Linear ones: lists, stacks,
By: Robert Apeldorn.  Generate statistical random texts that can be read well  Allow for the output texts to be created quickly regardless the size.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
1 Content-Aware Device Benchmarking Methodology/Terminology (draft-ietf-bmwg-ca-bench-meth-01) BMWG Meeting IETF-83 Paris March 2012 Mike Hamilton
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Recursively Enumerable and Recursive Languages
Special Methods in Java. Mathematical methods The Math library is extensive, has many methods that you can call to aid you in your programming. Math.pow(double.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Markov Chain Algorithm in Perl Michael Conway CS 265 May 4, 2011.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
CSC 4630 Perl 3 adapted from R. E. Beck. Problem But we worked on it first: Input: Read from a text file named in a command line argument Output: List.
Lecture 06: Theory of Automata:08 Finite Automata with Output.
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 8.
CSC 212 – Data Structures Lecture 28: More Hash and Dictionaries.
Engineering Innovation Center
Hash Tables in C Louis Manco.
The backslash is used to escape characters that are used in Python
Encryption and Decryption
Design and Implementation*
Lists in Python Outputting lists.
Markov-Chain Algorithm In Perl
Loop problem Write a method printLetters that prints each letter from a word separated by commas. For example, the call: printLetters("Atmosphere") should.
Programming Logic and Design Fifth Edition, Comprehensive
Hashing.
Presentation transcript:

By: Jordan Hofstaedter

Make random outputs from inputs that actually make sense. If we let the computer produce random letters in English, chances are it will be incoherent sentences made up of incoherent words xptmxgn xusaja afqnzgxl lhidlwcd rjdjuvpydrlwnjy If we weigh letters by their frequency of appearance in English text, it’s not much better idtefoae tcs trder jcii ofdslnqetacp t ola Finally words chosen at random from a dictionary won’t make much sense either polydactyl equatorial splashily jowl verandah circumscribe The Markov chain algorithm outputs randomly by choosing a suffix that follows the prefix in a coherent input

Set W1 and W2 to the first two words in the text Print W1 and W2 Loop Randomly choose W3, one of the successors of prefix W1,W2 in the text Print W3 Replace W1 and W2 by W2 and W3 Repeat loop

Suppose we have the text: “Show your flowcharts and conceal your tables and I will be mystified. Show your tables and your flowcharts will be obvious.” (end) Input Prefix:Suffix words that follow: Show yourFlowcharts or tables your flowchartsand or will flowcharts andconceal flowcharts willbe your tablesand or and will bemystified. or obvious. be mystified.Show be obvious.(end)

Uses associative and anonymous arrays and string handling Associative arrays are convenient packing of a hash table Subscripts are arbitrary strings or numbers or comma- separated lists of them Anonymous arrays used to keep track of suffixes Used in place of a third subscript Special characters needed: $ for for indexed array, use [ ] brackets to index Use { } brackets to index hashes

# markov.pl: markov chain algorithm for 2-word prefixes $MAXGEN = 10000; $NONWORD = "\n"; $w1 = $w2 = $NONWORD; # initial state while (<>) { # read each line of input foreach (split) { $_); # THIS LINE PUSHES NEW SUFFIX ONTO THE END OF THE ARRAY ($w1, $w2) = ($w2, $_);# multiple assignment } $NONWORD); # add tail $w1 = $w2 = $NONWORD; for ($i = 0; $i < $MAXGEN; $i++) { $suf = $statetab{$w1}{$w2};# array reference, $r is number of elems exit if (($t = $suf->[$r]) eq $NONWORD); print "$t\n"; ($w1, $w2) = ($w2, $t);# advance chain }

+ Shorter and more concise + Scripting languages are good for experimental programming, prototypes and production if run-time is not a big issue - Harder to handle prefixes that are not exactly two words, such as hyphenated words - Less clearer than in implementations in other languages

Kernighan, Brian W., and Rob Pike. The Practice of Programming (Addison-Wesley Professional Computing Series). New York: Addison-Wesley Professional, Print.