Michael Paluszek and

Stephanie Thomas

MATLAB Machine Learning

Michael Paluszek

New Jersey, USA

Stephanie Thomas

New Jersey, USA

Any source code or other supplementary materials referenced by the author in this text are available to readers at www.apress.com . For detailed information about how to locate your book’s source code, go to www.apress.com/source-code/mycopy . Readers can also access source code at SpringerLink in the Supplementary Material section for each chapter.

ISBN 978-1-4842-2249-2

e-ISBN 978-1-4842-2250-8

DOI 10.1007/978-1-4842-2250-8

Library of Congress Control Number: 2016963347

© Michael Paluszek, Stephanie Thomas 2017

This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.

Printed on acid-free paper

Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.

For Marilyn and Matt.

Introduction

Machine learning is becoming important in every discipline. It is used in engineering for autonomous cars. It is used in finance for predicting the stock market. Medical professionals use it for diagnoses. While many excellent packages are available from commercial sources and open-source repositories, it is valuable to understand how these algorithms work. Writing your own algorithms is valuable both because it gives you insight into the commercial and open-source packages and also because it gives you the background to write your own custom Machine Learning software specialized for your application.

MATLAB ®; had its origins for that very reason. Scientists who needed to do operations on matrices used numerical software written in FORTRAN. At the time, using computer languages required the user to go through the write-compile-link-execute process that was time consuming and error prone. MATLAB presented the user with a scripting language that allowed the user to solve many problems with a few lines of a script that executed instantaneously. MATLAB has built-in visualization tools that helped the user better understand the results. Writing MATLAB was a lot more productive and fun than writing FORTRAN.

The goal of MATLAB Machine Learning is to help all users harness the power of MATLAB to do a wide range of learning problems. This book has two parts. The first part, Chapters 13 , provides background on machine learning including learning control that is not often associated with machine intelligence. We coin the term “autonomous learning” to embrace all of these disciplines.

The second part of the book, Chapters 412 , shows complete MATLAB machine learning applications. Chapters 46 introduce the MATLAB features that make it easy to implement machine learning. The remaining chapters give examples. Each chapter provides the technical background for the topic and ideas on how you can implement the learning algorithm. Each example is implemented in a MATLAB script supported by a number of MATLAB functions.

The book has something for everyone interested in machine learning. It also has material that will allow people with interest in other technology areas to see how machine learning, and MATLAB, can help them solve problems in their areas of expertise.

Contents

  1. Part I Introduction to Machine Learning
    1. Chapter 1:​ An Overview of Machine Learning
      1. 1.​1 Introduction
      2. 1.​2 Elements of Machine Learning
        1. 1.​2.​1 Data
        2. 1.​2.​2 Models
        3. 1.​2.​3 Training
      3. 1.​3 The Learning Machine
      4. 1.​4 Taxonomy of Machine Learning
      5. 1.​5 Autonomous Learning Methods
        1. 1.​5.​1 Regression
        2. 1.​5.​2 NeuralNets
        3. 1.​5.​3 Support Vector Machines
        4. 1.​5.​4 Decision Trees
        5. 1.​5.​5 Expert System
      6. References
    2. Chapter 2:​ The History of Autonomous Learning
      1. 2.​1 Introduction
      2. 2.​2 Artificial Intelligence
      3. 2.​3 Learning Control
      4. 2.​4 Machine Learning
      5. 2.​5 The Future
      6. References
    3. Chapter 3:​ Software for Machine Learning
      1. 3.​1 Autonomous Learning Software
      2. 3.​2 Commercial MATLAB Software
        1. 3.​2.​1 MathWorks Products
        2. 3.​2.​2 Princeton Satellite Systems Products
      3. 3.​3 MATLAB Open-Source Resources
        1. 3.​3.​1 DeepLearn Toolbox
        2. 3.​3.​2 Deep Neural Network
        3. 3.​3.​3 MatConvNet
      4. 3.​4 Products for Machine Learning
        1. 3.​4.​1 R
        2. 3.​4.​2 scikit-learn
        3. 3.​4.​3 LIBSVM
      5. 3.​5 Products for Optimization
        1. 3.​5.​1 LOQO
        2. 3.​5.​2 SNOPT
        3. 3.​5.​3 GLPK
        4. 3.​5.​4 CVX
        5. 3.​5.​5 SeDuMi
        6. 3.​5.​6 YALMIP
      6. References
  2. Part II MATLAB Recipes for Machine Learning
    1. Chapter 4:​ Representation of Data for Machine Learning in MATLAB
      1. 4.​1 Introduction to MATLAB Data Types
        1. 4.​1.​1 Matrices
        2. 4.​1.​2 CellArrays
        3. 4.​1.​3 Data Structures
        4. 4.​1.​4 Numerics
        5. 4.​1.​5 Images
        6. 4.​1.​6 Datastore
        7. 4.​1.​7 Tall Arrays
        8. 4.​1.​8 Sparse Matrices
        9. 4.​1.​9 Tables andCategoricals
        10. 4.​1.​10 Large MAT-Files
      2. 4.​2 Initializing a Data Structure Using Parameters
        1. 4.​2.​1 Problem
        2. 4.​2.​2 Solution
        3. 4.​2.​3 How It Works
      3. 4.​3 Performing mapreduce on an Image Datastore
        1. 4.​3.​1 Problem
        2. 4.​3.​2 Solution
        3. 4.​3.​3 How It Works
      4. 4.​4 Creating a Table fromaFile
      5. Summary
    2. Chapter 5:​ MATLAB Graphics
      1. 5.​1 Two-Dimensional Line Plots
        1. 5.​1.​1 Problem
        2. 5.​1.​2 Solution
        3. 5.​1.​3 How It Works
      2. 5.​2 General 2D Graphics
        1. 5.​2.​1 Problem
        2. 5.​2.​2 Solution
        3. 5.​2.​3 How It Works
      3. 5.​3 Custom 2D Diagrams
        1. 5.​3.​1 Problem
        2. 5.​3.​2 Solution
        3. 5.​3.​3 How It Works
      4. 5.​4 Three-Dimensional Box
        1. 5.​4.​1 Problem
        2. 5.​4.​2 Solution
        3. 5.​4.​3 How It Works
      5. 5.​5 Draw a 3D Object with a Texture
        1. 5.​5.​1 Problem
        2. 5.​5.​2 Solution
        3. 5.​5.​3 How It Works
      6. 5.​6 General 3D Graphics
        1. 5.​6.​1 Problem
        2. 5.​6.​2 Solution
        3. 5.​6.​3 How It Works
      7. 5.​7 Building a Graphical User Interface
        1. 5.​7.​1 Problem
        2. 5.​7.​2 Solution
        3. 5.​7.​3 How It Works
      8. Summary
    3. Chapter 6:​ Machine Learning Examples in MATLAB
      1. 6.​1 Introduction
      2. 6.​2 Machine Learning
        1. 6.​2.​1 Neural Networks
        2. 6.​2.​2 Face Recognition
        3. 6.​2.​3 Data Classification
      3. 6.​3 Control
        1. 6.​3.​1 Kalman Filters
        2. 6.​3.​2 Adaptive Control
      4. 6.​4 Artificial Intelligence
        1. 6.​4.​1 Autonomous Driving and Target Tracking
    4. Chapter 7:​ Face Recognition with Deep Learning
      1. 7.​1 Obtain DataOnline:​ For Training a Neural Network
        1. 7.​1.​1 Problem
        2. 7.​1.​2 Solution
        3. 7.​1.​3 How It Works
      2. 7.​2 Generating Data for Training a Neural Net
        1. 7.​2.​1 Problem
        2. 7.​2.​2 Solution
        3. 7.​2.​3 How It Works
      3. 7.​3 Convolution
        1. 7.​3.​1 Problem
        2. 7.​3.​2 Solution
        3. 7.​3.​3 How It Works
      4. 7.​4 Convolution Layer
        1. 7.​4.​1 Problem
        2. 7.​4.​2 Solution
        3. 7.​4.​3 How It Works
      5. 7.​5 Pooling
        1. 7.​5.​1 Problem
        2. 7.​5.​2 Solution
        3. 7.​5.​3 How It Works
      6. 7.​6 Fully Connected Layer
        1. 7.​6.​1 Problem
        2. 7.​6.​2 Solution
        3. 7.​6.​3 How It Works
      7. 7.​7 Determining the Probability
        1. 7.​7.​1 Problem
        2. 7.​7.​2 Solution
        3. 7.​7.​3 How It Works
      8. 7.​8 Test the NeuralNetwork
        1. 7.​8.​1 Problem
        2. 7.​8.​2 Solution
        3. 7.​8.​3 How It Works
      9. 7.​9 Recognizing an Image
        1. 7.​9.​1 Problem
        2. 7.​9.​2 Solution
        3. 7.​9.​3 How It Works
      10. Summary
      11. Reference
    5. Chapter 8:​ Data Classification
      1. 8.​1 Generate Classification Test Data
        1. 8.​1.​1 Problem
        2. 8.​1.​2 Solution
        3. 8.​1.​3 How It Works
      2. 8.​2 Drawing Decision Trees
        1. 8.​2.​1 Problem
        2. 8.​2.​2 Solution
        3. 8.​2.​3 How It Works
      3. 8.​3 Decision Tree Implementation
        1. 8.​3.​1 Problem
        2. 8.​3.​2 Solution
        3. 8.​3.​3 How It Works
      4. 8.​4 Implementing a Decision Tree
        1. 8.​4.​1 Problem
        2. 8.​4.​2 Solution
        3. 8.​4.​3 How It Works
      5. 8.​5 Creating a Hand-Made Decision Tree
        1. 8.​5.​1 Problem
        2. 8.​5.​2 Solution
        3. 8.​5.​3 How It Works
      6. 8.​6 Training and Testing the Decision Tree
        1. 8.​6.​1 Problem
        2. 8.​6.​2 Solution
        3. 8.​6.​3 How It Works
      7. Summary
      8. Reference
    6. Chapter 9:​ Classification of Numbers Using Neural Networks
      1. 9.​1 Generate Test Images with Defects
        1. 9.​1.​1 Problem
        2. 9.​1.​2 Solution
        3. 9.​1.​3 How It Works
      2. 9.​2 Create the Neural Net Tool
        1. 9.​2.​1 Problem
        2. 9.​2.​2 Solution
        3. 9.​2.​3 How It Works
      3. 9.​3 Train a Network with One Output Node
        1. 9.​3.​1 Problem
        2. 9.​3.​2 Solution
        3. 9.​3.​3 How It Works
      4. 9.​4 Testing the Neural Network
        1. 9.​4.​1 Problem
        2. 9.​4.​2 Solution
        3. 9.​4.​3 How It Works
      5. 9.​5 Train a Network with Multiple Output Nodes
        1. 9.​5.​1 Problem
        2. 9.​5.​2 Solution
        3. 9.​5.​3 How It Works
      6. Summary
      7. References
    7. Chapter 10:​ Kalman Filters
      1. 10.​1 A State Estimator
        1. 10.​1.​1 Problem
        2. 10.​1.​2 Solution
        3. 10.​1.​3 How It Works
        4. 10.​1.​4 Conventional Kalman Filter
      2. 10.​2 Using the Unscented Kalman Filter for State Estimation
        1. 10.​2.​1 Problem
        2. 10.​2.​2 Solution
        3. 10.​2.​3 How It Works
      3. 10.​3 Using the UKF for Parameter Estimation
        1. 10.​3.​1 Problem
        2. 10.​3.​2 Solution
        3. 10.​3.​3 How It Works
      4. Summary
      5. References
    8. Chapter 11:​ Adaptive Control
      1. 11.​1 Self-Tuning:​ Finding the Frequency of an Oscillator
        1. 11.​1.​1 Problem
        2. 11.​1.​2 Solution
        3. 11.​1.​3 How It Works
      2. 11.​2 Model Reference Adaptive Control
        1. 11.​2.​1 Generating a Square Wave Input
        2. 11.​2.​2 Implement Model Reference Adaptive Control
        3. 11.​2.​3 Demonstrate MRAC for a Rotor
      3. 11.​3 Longitudinal Control of an Aircraft
        1. 11.​3.​1 Write the Differential Equations for the Longitudinal Motion of an Aircraft
        2. 11.​3.​2 Numerically Finding Equilibrium
        3. 11.​3.​3 Numerical Simulation of the Aircraft
        4. 11.​3.​4 Find a Limiting and Scaling function for a Neural Net
        5. 11.​3.​5 Find a Neural Net for the Learning Control
        6. 11.​3.​6 Enumerate All Sets of Inputs
        7. 11.​3.​7 Write a General Neural Net Function
        8. 11.​3.​8 Implement PID Control
        9. 11.​3.​9 Demonstrate PID control of Pitch for the Aircraft
        10. 11.​3.​10 Create the Neural Net for the Pitch Dynamics
        11. 11.​3.​11 Demonstrate the Controller in a Nonlinear Simulation
      4. 11.​4 Ship Steering:​ Implement Gain Scheduling for Steering Control of a Ship
        1. 11.​4.​1 Problem
        2. 11.​4.​2 Solution
        3. 11.​4.​3 How It Works
      5. Summary
      6. References
    9. Chapter 12:​ Autonomous Driving
      1. 12.​1 Modeling the Automobile Radar
        1. 12.​1.​1 Problem
        2. 12.​1.​2 How It Works
        3. 12.​1.​3 Solution
      2. 12.​2 Automobile Autonomous Passing Control
        1. 12.​2.​1 Problem
        2. 12.​2.​2 Solution
        3. 12.​2.​3 How It Works
      3. 12.​3 Automobile Dynamics
        1. 12.​3.​1 Problem
        2. 12.​3.​2 How It Works
        3. 12.​3.​3 Solution
      4. 12.​4 Automobile Simulation and the Kalman Filter
        1. 12.​4.​1 Problem
        2. 12.​4.​2 Solution
        3. 12.​4.​3 How It Works
      5. 12.​5 Perform MHT on the Radar Data
        1. 12.​5.​1 Problem
        2. 12.​5.​2 Solution
        3. 12.​5.​3 How It Works
        4. 12.​5.​4 Hypothesis Formation
        5. 12.​5.​5 Track Pruning
      6. Summary
      7. References
  3. Index

About the Authors and About the Technical Reviewer

About the Authors

A420697_1_En_BookFrontmatter_Figb_HTML.jpg

Michael Paluszek is president of Princeton Satellite Systems, Inc. (PSS) in Plainsboro, New Jersey. Mr. Paluszek founded PSS in 1992 to provide aerospace consulting services. He used MATLAB to develop the control system and simulation for the Indostar-1 geosynchronous communications satellite, resulting in the launch of Princeton Satellite Systems’ first commercial MATLAB toolbox, the Spacecraft Control Toolbox, in 1995. Since then he has developed toolboxes and software packages for aircraft, submarines, robotics, and nuclear fusion propulsion, resulting in Princeton Satellite Systems’ current extensive product line. He is currently leading a U.S. Army research contract for precision attitude control of small satellites and working with the Princeton Plasma Physics Laboratory on a compact nuclear fusion reactor for energy generation and space propulsion.

Prior to founding PSS, Mr. Paluszek was an engineer at GE Astro Space in East Windsor, NJ. At GE he designed the Global Geospace Science Polar despun platform control system and led the design of the GPS IIR attitude control system, the Inmarsat-3 attitude control systems, and the Mars Observer Delta-V control system, leveraging MATLAB for control design. Mr. Paluszek also worked on the attitude determination system for the DMSP meteorological satellites. Mr. Paluszek flew communication satellites on more than 12 satellite launches, including the GSTAR III recovery, the first transfer of a satellite to an operational orbit using electric thrusters. At Draper Laboratory Mr. Paluszek worked on the Space Shuttle, Space Station, and submarine navigation. His Space Station work included design of control moment gyro-based systems for attitude control.

Mr. Paluszek received his bachelor’s degree in electrical engineering and master’s and engineer’s degrees in aeronautics and astronautics from the Massachusetts Institute of Technology. He is the author of numerous papers and has over a dozen U.S. patents. Mr. Paluszek is the coauthor of “MATLAB Recipes” published by Apress.

A420697_1_En_BookFrontmatter_Figc_HTML.jpg

Stephanie Thomas is vice president of Princeton Satellite Systems, Inc. in Plainsboro, New Jersey. She received her bachelor’s and master’s degrees in aeronautics and astronautics from the Massachusetts Institute of Technology in 1999 and 2001, respectively. Ms. Thomas was introduced to PSS’ Spacecraft Control Toolbox for MATLAB during a summer internship in 1996 and has been using MATLAB for aerospace analysis ever since. In her nearly 20 years of MATLAB experience, she has developed many software tools including the Solar Sail Module for the Spacecraft Control Toolbox; a proximity satellite operations toolbox for the Air Force; collision monitoring Simulink blocks for the Prisma satellite mission; and launch vehicle analysis tools in MATLAB and Java. She has developed novel methods for space situation assessment such as a numeric approach to assessing the general rendezvous problem between any two satellites implemented in both MATLAB and C++. Ms. Thomas has contributed to PSS’ Attitude and Orbit Control textbook, featuring examples using the Spacecraft Control Toolbox (SCT), and has written many software user guides. She has conducted SCT training for engineers from diverse locales such as Australia, Canada, Brazil, and Thailand and has performed MATLAB consulting for NASA, the Air Force, and the European Space Agency. Ms. Thomas is the coauthor of MATLAB Recipes published by Apress. In 2016, Ms. Thomas was named a NASA NIAC Fellow for the project “Fusion-Enabled Pluto Orbiter and Lander.”

About the Technical Reviewer

Jonah Lissner is a Research Scientist advancing PhD and DSc programs, scholarships, applied projects and academic journal publications in Theoretical Physics, Power Engineering, Complex Systems, Metamaterials, Geophysics, and Computation Theory. He has strong cognitive ability in empiricism and scientific reason for the purpose of hypothesis building, theory learning, mathematical and axiomatic modeling and testing for abstract problem-solving. His Dissertations, Research Publications and Projects, CV, Journals, Blog, Novels, System are listed at http://Lissnerresearch.weebly.com .

A420697_1_En_BookFrontmatter_Figd_HTML.jpg

Joseph MuellerDr. specializes in control systems and trajectory optimization. For his doctoral thesis, he developed optimal ascent trajectories for stratospheric airships. His active research interests include robust optimal control, adaptive control, applied optimization and planning for decision support systems, and intelligent systems to enable autonomous operations of robotic vehicles.

Prior to joining SIFT in early 2014, Dr. Mueller worked at Princeton Satellite Systems for 13 years. In that time, he served as the principal investigator for eight Small Business Innovative Research contracts for NASA, Air Force, Navy and MDA. He has developed algorithms for optimal guidance and control of both formation flying spacecraft and high altitude airships, and developed a course of action planning tool for DoD communication satellites.

In support of a research study for NASA Goddard Space Flight Center in 2005, Dr. Mueller developed the Formation Flying Toolbox for Matlab, a commercial product that is now used at NASA, ESA, and several universities and aerospace companies around the world.

In 2006, Dr. Mueller developed the safe orbit guidance mode algorithms and software for the Swedish Prisma mission, which has successfully flown a 2-spacecraft formation flying mission since it launch in 2010.

Dr. Mueller also serves as an adjunct professor in the Aerospace Engineering & Mechanics Department at the University of Minnesota, Twin Cities campus.

Derek Surka has over 20 years of professional experience in the aerospace field, specializing in space situational awareness, guidance, navigation, and control, distributed system autonomy, and formation flying. Mr. Surka has applied his expertise in astrodynamics, data fusion, estimation and control systems, and software development to over 20 satellites and payloads for a variety of military, civil, and commercial space customers. Mr. Surka is an active runner and triathlete and is a former National Mixed Curling Champion.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.48.204