330 likes | 530 Views
Pattern Analysis and Machine Intelligence. A web service perspective. Overview. Why? What are web services? How do we deploy them? Design Issues Examples Word recognition Checkers. Why?. Take re-use to new heights Risk-free evaluation Customer installs only an ultra-thin client
E N D
Pattern Analysis and Machine Intelligence A web service perspective
Overview • Why? • What are web services? • How do we deploy them? • Design Issues • Examples • Word recognition • Checkers
Why? • Take re-use to new heights • Risk-free evaluation • Customer installs only an ultra-thin client • Service provider keeps valuable implementations on site • Customer subscribes to a service • Does not care how it is implemented • Implementations can be upgraded transparently • Quality of service can be monitored by service provider and customer
Web Service • A contractually defined behaviour • Implemented in any way • Used in any way • Usage governed by contract • Just like Java interfaces, except • Language independent • Web based
Web Services Client Application Service Implementation Language Specific Messages Language Neutral Messages Web Service
Web Service Components Service Implementation Web Application Server (e.g. Tomcat) Service Proxy Client Service Listener
Key Features • Language Neutral • Compositional • Should be able to construct more complex services from simpler ones • Configuration issues • Stateless versus state-based services
Web Services and Distributed Computing • Simple model for distributed computing • Call by value only • No call-backs • No remote references (other than URIs)
Hello SOAP World • Define this interface for Hello Service • Not necessary – but useful to decouple the service description from the implementation • Essential for Dynamic Proxy – see later package hello; public interface Hello { public String sayHelloTo(String name) }
Implementing the Service • In this case, the service is very simple: package hello; public class HelloImpl { // just to notify when tomcat loads the class static { System.out.println("Loaded HelloImpl.class"); } public String sayHelloTo(String name) { System.out.println("sayHelloTo(String name)"); return "Hello " + name + ", How are you doing?"; } }
DeploymentDescriptor.xml <isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment" id="urn:Hello"> <isd:provider type="java" scope="Application" methods="sayHelloTo"> <isd:java class="hello.HelloImpl" static="false"/> </isd:provider> </isd:service>
hello.ProxyClient.java package hello; import proxy.*; public class ProxyClient { public static void main(String[] args) throws Exception { Class[] interfaces = new Class[] {hello.Hello.class}; Hello hello = (Hello) Proxy.newInstance("urn:Hello",interfaces); System.out.println(hello.sayHelloTo("Simon")); } }
Design Issues • Type mappings i.e. • How do we encode/decode objects • XML-RPC and SOAP provide standard type-mappings for various primitives, arrays and collections • User-defined classes are trickier! • Take care to preserve language independence!
Example: Checkers Game Service • Service is to provide opponents to play checkers over the web • Client invokes service by sending player details • Service responds with details of opponent and the first move • Client then modifies a local copy of the board, makes a move and sends the move to the service • Repeat move exchange until game over
Example: Move Encoding • Zero effort is to use JSX • Java serialization to XML • BUT: compromises language independence • Preferred solution: customized type mapping • Note the difference:
Use Object Encoder via standard interface public static void main(String[] args) { SquareSequenceMove ssm = new SquareSequenceMove( new Square(0, 0), new Square(1, 1)); RemoteMoveRequest rmr = new RemoteMoveRequest( ssm, 2, false ); // XMLWriter out = new JSXWriter( // new PrintWriter( System.out ) ); XMLWriter out = new BoardWriter( new PrintWriter( System.out ) ); out.writeObject( rmr ); }
JSX Move Encoding <games.board.RemoteMoveRequest requestTime="1016535860883" toPlay="2" maximize="false"> <games.board.SquareSequenceMove obj-name="move"> <java.util.Vector obj-name="squares"> <games.board.Square x="0" y="0"/> <games.board.Square x="1" y="1"/> </java.util.Vector> </games.board.SquareSequenceMove> </games.board.RemoteMoveRequest>
Custom Move Encoding <RemoteMoveRequest> <toPlay> 2 </toPlay> <SquareSequenceMove> 0,0 1,1 </SquareSequenceMove> </RemoteMoveRequest>
More Design Issues • Problem decomposition • What services do we provide? • How do we allow clients to configure services? • How best to store the state of a configured service?
Pattern recognition servers • Reside at particular URLs • Can be trained on specified or supplied datasets • Can respond to recognition requests
Example Request • Recognize this word: • Given the dictionary at: • http://ace.essex.ac.uk/viadocs/dic/pygenera.txt • And the OCR training set at: • http://ace.essex.ac.uk/algoval/ocr/viadocs1.xml • Respond with your 10 best word hypotheses
1. MELISSOBLAPTES2. ENDOMMMASIS3. HETEROGRAPHIS4. TRICHOBAPTES5. HETEROCHROSIS6. PHLOEOGRAPTIS7. HETEROCNEPHES8. DRESCOMPOSIS9. MESOGRAPHE10.DIPSOCHARES Example Response
Issues • How general to make problem specs • Could set up separate problems for OCR and face recognition, or a single problem called ImageRecognition • How does the software effort scale?
Evolving a Checkers Player • What services can we identify?
Checkers Evolution Services • Game-playing • Service just provides an opponent • Low-level - still some work to do • Player evaluation • Client provides a player • Service evaluates quality of player
Static evaluator evaluation public interface StaticEvaluator { public double evaluate( int[][] board ); } • How good is my static evaluator? • Very interesting! • Which service is best at evaluating my static evaluator? • Do the details of the Minimax algorithm (e.g. depth) affect the evaluation service?
Other Evolutionary Services • Representational services: • Gene manipulation (mutation, crossover etc) • Phenotype mapping service • Creating evaluatable individuals from independently specified genomes • Algorithmic services • Random hill climber • ‘Standard’ GA • Guided local search?
Example Code public Mutable search( Mutatable current, int maxEvals, FitnessEvaluator evaluator) { fitness = evaluator.fitness( ((IntArrayGenotype) current).getIntArray() ); for (int i=0; i<maxEvals-1; i++) { Mutable child = current.mutate(); double childFitness = evaluator.fitness( ((IntArrayGenotype) child).getIntArray() ); if ( childFitness > fitness ) { current = child; fitness = childFitness; } } return current; }
Kernel Machines Kernel-based Classifier (e.g. SVM, RVM) Independent Web Services String Kernel
Software Scalability • Suppose we have: • A algorithms implemented in L languages • D datasets • P problems • E algorithm evaluators • How will our software effort scale with respect to these numbers?
Service Messages • In practice, the normal request/response pattern may not be the best • Some services could be slow • Need intermediate messages • Reckon I’ll be another few minutes • Or immediate response of a job URI
Conclusions • Excellent way to utilise networked computers for coarse-grained distributed computing • Imposes strict discipline • Main extra overhead is: • User-defined type-mappings (don’t always need these) • Configuring the service listeners • Deploying the service