Using CppSim to Generate Neural Network Modules in Simulink using the simulink_neural_net_gen command

Similar documents
Integrating QuickBooks with TimePro

Upgrade Guide. Medtech Evolution General Practice. Version 1.9 Build (March 2018)

STIDistrict AL Rollover Procedures

Municode Website Instructions

User Guide. ACE Data Source. OnCommand Workflow Automation (WFA) Abstract PROFESSIONAL SERVICES

Upgrade Guide. Medtech Evolution Specialist. Version 1.11 Build (October 2018)

REFWORKS: STEP-BY-STEP HURST LIBRARY NORTHWEST UNIVERSITY

These tasks can now be performed by a special program called FTP clients.

1 Getting and Extracting the Upgrader

ROCK-POND REPORTING 2.1

BI Publisher TEMPLATE Tutorial

Using the Swiftpage Connect List Manager

1 Getting and Extracting the Upgrader

1 Getting and Extracting the Upgrader

Campuses that access the SFS nvision Windows-based client need to allow outbound traffic to:

Using the Swiftpage Connect List Manager

Oracle Universal Records Management Oracle Universal Records Manager Adapter for Documentum Installation Guide

istartsmart 3.5 Upgrade - Installation Instructions

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

User Guide. Document Version: 1.0. Solution Version:

RISKMAN REFERENCE GUIDE TO USER MANAGEMENT (Non-Network Logins)

Using SPLAY Tree s for state-full packet classification

Lab 0: Compiling, Running, and Debugging

Xilinx Answer Xilinx PCI Express DMA Drivers and Software Guide

WorldShip PRE-INSTALLATION INSTRUCTIONS: INSTALLATION INSTRUCTIONS: Window (if available) Install on a Single or Workgroup Workstation

CaseWare Working Papers. Data Store user guide

August 22, 2006 IPRO Tech Client Services Tip of the Day. Concordance and IPRO Camera Button / Backwards DB Link Setup

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Launching Xacta 360 Marketplace AMI Guide June 2017

Please contact technical support if you have questions about the directory that your organization uses for user management.

SAS Hot Fix Analysis, Download and Deployment Tool

SafeDispatch SDR Gateway for MOTOROLA TETRA

Project #1 - Fraction Calculator

DIVAR IP 3000 Field Installation Guide

Compliance Guardian 4. User Guide

INSTALLING CCRQINVOICE

Interfacing to MATLAB. You can download the interface developed in this tutorial. It exists as a collection of 3 MATLAB files.

TaiRox Mail Merge. Running Mail Merge

HPE AppPulse Mobile. Software Version: 2.1. IT Operations Management Integration Guide

Scroll down to New and another menu will appear. Select Folder and a new

Summary. Server environment: Subversion 1.4.6

Date: October User guide. Integration through ONVIF driver. Partner Self-test. Prepared By: Devices & Integrations Team, Milestone Systems

Gemini Intercom Quick Start Guide

Manual for installation and usage of the module Secure-Connect

InformationNOW Letters

Word 2007 The Ribbon, the Mini toolbar, and the Quick Access Toolbar

IFSP PDF Upload/Download Guidance

Copyrights and Trademarks

Quick Installation Guide

Outlook Web Application (OWA) Basic Training

INSERTING MEDIA AND OBJECTS

Dashboard Extension for Enterprise Architect

Little Green Button (LGB)

Verifone MX850 All-In-One Device: Before connecting the MX850 to your PC, the MX850 Driver CD will need to be installed.

Enabling Your Personal Web Page on the SacLink

AvePoint Pipeline Pro 2.0 for Microsoft Dynamics CRM

TECHNICAL REQUIREMENTS

LAB 7 (June 29/July 4) Structures, Stream I/O, Self-referential structures (Linked list) in C

I - EDocman Installation EDocman component EDocman Categories module EDocman Documents Module...2

Faculty Textbook Adoption Instructions

TRAINING GUIDE. Overview of Lucity Spatial

UiPath Automation. Walkthrough. Walkthrough Calculate Client Security Hash

1on1 Sales Manager Tool. User Guide

Exercise 4: Working with tabular data Exploring infant mortality in the 1900s

OASIS SUBMISSIONS FOR FLORIDA: SYSTEM FUNCTIONS

LiveEngage and Microsoft Dynamics Integration Guide Document Version: 1.0 September 2017

InformationNOW Letters

Trimble Survey GNSS Firmware Version 4.81 (July 2013)

Medtech Evolution. Installation Guide

Demand Forecasting. For. Microsoft Dynamics 365 for Operations. Technical Guide. Release 7.1. December 2017

SmartPass User Guide Page 1 of 50

3 AXIS STAGE CONTROLLER

Australian Statistics API Specification

IMPORTING INFOSPHERE DATA ARCHITECT MODELS INFORMATION SERVER V8.7

ClassFlow Administrator User Guide

Programming Project: Building a Web Server

FollowMe. FollowMe. Q-Server Quick Integration Guide. Revision: 5.4 Date: 11 th June Page 1 of 26

Adverse Action Letters

BMC Remedyforce Integration with Bomgar Remote Support

Exporting and Importing the Blackboard Vista Grade Book

TN How to configure servers to use Optimise2 (ERO) when using Oracle

SeaLinx Guide. Table of Contents

USO RESTRITO. SNMP Agent. Functional Description and Specifications Version: 1.1 March 20, 2015

BMC Remedyforce Integration with Remote Support

Wave IP 4.5. CRMLink Desktop User Guide

Admin Report Kit for Exchange Server

Guidelines for Installing HI 1734-WS Faceplates

Tips For Customising Configuration Wizards

InformationNOW Letters

UiPath Automation. Walkthrough. Walkthrough Calculate Client Security Hash

softpanel generic installation and operation instructions for nanobox products

Getting Started with the SDAccel Environment on Nimbix Cloud

$ARCSIGHT_HOME/current/user/agent/map. The files are named in sequential order such as:

UBC BLOGS NSYNC PLUGIN

The Login Page Designer

Installing Photran with Eclipse (MinGW or Cygwin)

HW4 Software version 3. Device Manager and Data Logging LOG-RC Series Data Loggers

MySqlWorkbench Tutorial: Creating Related Database Tables

Stealing passwords via browser refresh

Transcription:

Using CppSim t Generate Neural Netwrk Mdules in Simulink using the simulink_neural_net_gen cmmand Michael H. Perrtt http://www.cppsim.cm June 24, 2008 Cpyright 2008 by Michael H. Perrtt All rights reserved. Table f Cntents Intrductin... 1 Imprting the Example... 1 Highlights f Example... 4 A. Schematic f Neural Nde... 4 B. Overall Netwrk Tplgy... 5 C. Specificatin f Netwrk Intercnnectin... 6 D. Running the Example in Matlab/Simulink... 9 Specificatin f the Neural Net Intercnnectin... 12 Intrductin CppSim ffers a cnvenient way f realizing neural netwrks by using a graphical envirnment t create the neural nde and files t specify the cnnectivity between the ndes and the verall input and utput f the netwrk. CppSim creates all f the interface cde that is needed t turn the resulting neural net int a Simulink S-Functin blck. Given that the user has access t a suitable C++ cmpiler (such as Micrsft Visual C++), the S-Functin cde is cmpiled by the user and the blck can then be used within Simulink. Imprting the Example T explain the basic peratin f using the simulink_neural_net_gen: cmmand in CppSim, we will wrk thrugh an example. It is assumed that the user has installed CppSim n their cmputer (dwnladed frm http://www.cppsim.cm), dwnladed the file neural_net_example.tar.gz frm http://www.cppsim.cm, and has als installed a suitable C++ cmpiler fr Matlab mex and S- functin cmpilatin (such as Micrsft Visual C++). Fr issues related t installatin and general use f CppSim, please refer t the CppSim Primer available at http://www.cppsim.cm. Als, ne shuld nte that Micrsft prvides a free Express versin f their C++ cmpiler that can be used t cmpile mex files in Matlab. Please see the link http://www.mathwrks.cm/matlabcentral/fileexchange/22689 fr details. 1

Place the file neural_net_example.tar.gz in the directry c:/cppsim/imprt_exprt. Nte that we have assumed that the rt installatin directry fr CppSim is c:/cppsim in this case please mdify the abve directry lcatin if apprpriate. Open up Sue2 by clicking n its icn n the Windws Desktp. Within Sue2, select Library Manager under the Tls menu item as shwn in the figure belw: In the Library Manager windw that appears, click n the Imprt Library Tl buttn as shwn in the figure belw 2

In the Imprt CppSim Library windw that nw appears, yu shuld see neural_net_example.tar.gz appear as a Surce File/Library as shwn in the figure belw. If yu d nt see this file, it means that yu need t place it in the c:/cppsim/imprt_exprt directry. 3

Change the Destinatin Library t Neural_Net_Example as shwn in the figure belw. Once yu have dne s, yu need t re-click n the neural_net_example.tar.gz file t select it, and then push the Imprt buttn. After the mdules have been imprted, exit frm Sue2 and then restart it. Highlights f Example We will nw wrk thrugh the example that was cntained in the neural_net_example.tar.gz file. T cmplete this example, yu will need t have access t Matlab, Simulink, and an apprpriate C++ cmpiler fr cmpiling Matlab mex files and S-functins (such as Micrsft Visual C++ Versin 6 r later). A. Schematic f Neural Nde Within Sue2, click n the Library prtin f the Schematic Selectin Bx and chse Neural_Net_Example as shwn belw. 4

Click n the neurn_nde cell in the abve windw. The Sue2 schematic windw shuld nw appear as shwn belw. In the abve schematic, nte that there are three inputs (in_a, in_b, and in_c), tw utputs (ut1 and ut2), and tw parameters (gain1 and gain2). While we have chsen a very simple set f gain blcks and adders fr the nde shwn in the abve windw, ne can create neural ndes f arbitrary cmplexity. B. Overall Netwrk Tplgy The verall neural netwrk is cmpsed f the intercnnectin f the abve ndes with each ther, the verall input t the netwrk, and the verall utput f the netwrk. As shwn in the figure 5

belw, the number f input and utput elements is assumed t be the same as the number f ndes in the netwrk. The chice f intercnnectins between ndes, input, and utput, as well as their strength, are set accrding t files as will sn be discussed. The setting f parameter values fr each nde is als set accrding t a file. Nte that nde inputs as well as the verall utput elements can cnnect t an arbitrary number f nde utputs and input elements, and the strength settings can als be arbitrarily set. in[0] Nde 0 ut[0] in[1] Nde 1 ut[1] in[n] Nde N ut[n] where: N = num_ndes C. Specificatin f Netwrk Intercnnectin As ur starting pint in explaining the intercnnectin specificatin, let us examine the Simulatin File fr ur example. In the Sue2 windw, click n Tls and then the CppSim Simulatin menu item as shwn in the figure belw. 6

Within the CppSim Simulatin windw that appears, click n Edit Sim File buttn as shwn in the figure belw. 7

In the Simulatin File Emacs windw that appears, as shwn belw, ntice the tp_param: and simulink_neural_net_get: cmmands which are circled. There are several details that will be imprtant in understanding hw t set parameter values and intercnnectins. In the tp_param: statement, ntice the rder f parameters is gain1 and gain2, which is the key characteristic f interest. The values f the parameter settings, in this case gain1=1e3 and gain2=1e6, are f n cnsequence since they will be verwritten by the settings specified in a file. In the simulink_neural_net_gen: statement, there are many settings t cnsider. The first thing t nte is that the values f these settings are smetimes specified as?, which indicates that the value must be specified in the Simulink blck that will be created. This is advantageus in cases where several Simulink blcks will be instantiated and there is a desire t change such settings between these blcks. In cases where the settings will remain cnstant acrss different blcks, the value shuld be set in the statement belw and nt by using the? symbl. As an example, the intercnnectins and intercnnectin strengths fr the verall utput are specified in the file ut.dat, and the intercnnectins and intercnnectin strengths fr input in_a in each nde are specified in the file in_a.dat, whereas the parameter setting file will be specified in the Simulink blck. Further explanatin is merited f the specificatins ut1=1 ut2=2. Fr ndes with mre than ne utput, a number designatin is required fr each utput in rder t identify it in 8

the intercnnectin file. The number designatin must prceed in integer increments starting at value 1, as seen in the abve specificatin. Anther item f interest is Ts, which crrespnds t the time step value that will be applied t each nde when simulating it in Simulink. Nte that the statement f Ts: 1/1e6, which is specified earlier in the Sim File shwn belw, is ignred when creating the Simulink blck fr the verall neural net. D. Running the Example in Matlab/Simulink We will nw run the example in Matlab/Simulink. It is assumed that yu have already installed an apprpriate C++ cmpiler n yur system t supprt mex and S-Functin cmpilatin in Matlab. An example f an apprpriate cmpiler is Micrsft Visual C++. It is als assumed that yu are wrking with a reasnable recent versin f Matlab (i.e., Matlab 7.0 and abve). Start up Matlab and then perfrm the fllwing peratins at its cmmand line: 9

addpath( c:\cppsim\cppsimshared\hspicetlbx ) cd c:\cppsim\simruns\neural_net_example\neurn_nde The first f the abve cmmands adds Matlab cmmands fr running and cmpiling CppSim blcks within Matlab. The secnd f the abve cmmands sets the current Matlab directry t the apprpriate place t run and cmpile the cell neurn_nde int a neural netwrk that will then be embedded within a crrespnding Simulink blck. As yu wrk with different base ndes and their crrespnding netwrks, yu will need t change this directry. In general, the wrking directry will be: c:\cppsim\simruns\library_name\cell_name. In this case, LIBRARY_NAME is Neural_Net_Example, and the CELL_NAME is neurn_nde. Nw that yu are in the apprpriate directry, run the fllwing cmmand in Matlab: cppsim2simulink This cmmand generates the C++ cde crrespnding t the netwrk and then cmpiles it int a Simulink S-functin. The Matlab windw shuld nw appear similar t the figure shwn belw. Nte the listing f parameters as circled belw each f these crrespnd t the settings that were marked as? in the simulatin file described in the previus sub-sectin. The rder f these parameters will be imprtant when defining the Simulink blck, as discussed belw. It is imprtant t nte that cppsim2simulink must be rerun each time the CppSim Simulatin File is changed r the nde schematic (ie.., fr neurn_nde in this case) is altered. It des nt need t be re-run when yu change the cntents f the files that designate intercnnectins and parameter values fr the netwrk. 10

Nw run the fllwing cmmand in Matlab: create_tables This cmmand generates files that are used t specify the intercnnectin f the netwrk. We will discuss this functin in further detail in the next sectin. Nw start up Simulink frm Matlab, and pen the Simulink file test_neurn.mdl (which is lcated in c:\cppsim\simruns\neural_net_example\neurn_nde). Yu shuld see the system shwn in the figure belw. Duble-click n the neurn_nde_s cmpnent. Yu shuld see the windw shwn belw. Nte the S-functin parameters, which crrespnd t the Simulink Blck parameters discussed n the previus page: Ts=1e-8, num_ndes=3, param_file= param.dat, in_b_file= in_b.dat 11

Click n OK in the abve windw, and then start the Simulink simulatin. The scpe windws shuld appear as shwn belw (nce they are aut-scaled). Specificatin f the Neural Net Intercnnectin Nw that we have run thrugh the highlights f the example, we will fcus ur attentin n details relating t specificatin f the intercnnectin f the ndes t frm the verall neural netwrk. This specificatin is perfrmed thrugh files whse names are specified in either the CppSim Simulatin File r as Simulink Blck parameters (i.e., when? is used t specify the value f the parameter within the CppSim Simulatin File, as discussed earlier in this dcument). In general, yu will need ne file fr each input and utput that are specified in the nde schematic (i.e., in_a, in_b, in_c and ut1, ut2 in this case) and ne file t designate parameter values fr each nde. We will nw cver the frmat f these files in this sectin. Assuming yu have just run the example frm the previus sectin, type the fllwing cmmand in Matlab: 12

edit create_tables Yu shuld see an edit windw similar t what is shwn belw, which displays the create_tables.m Matlab script. In the abve Matlab script, yu will ntice that there are tw custm functins that are used thrughut the script: save_param_t_file() and save_t_file(). This functins are defined at the end f the script, and simply stre the cntents f the input matrix t a crrespnding ASCII file. Fr large matrices, ne may need t write faster versins f these functins since they are relatively slw in their executin speed. Fr small matrices as discussed nw, these scripts shuld be sufficient. The first matrix that is saved crrespnds t the parameters f the nde. These parameters are specified in the tp_param: statement f the CppSim Simulatin File, as shwn n page 8. Fr this example, recall that this statement was: tp_param: gain1=1e3 gain2=1e6 As mentined earlier, the actual values (i.e., 1e3 and 1e6) are ignred, and nly the rder is f cnsequence (i.e., gain1, gain2). In examining the Matlab script abve, ntice that each nde is fed tw parameter values (i.e., [3 10]). Specifically, given the abve tp_param: statement, this translates t setting gain1=3, gain2=10 fr each nde. While each nde is fed the same parameter values in this particular example, they can be arbitrarily set fr each nde in practice. 13

In general, the parameter matrix shuld appear as fllws: Nde 0 Nde 1 param 0 param 1... param M-1 param 0 param 1... param M-1 Nde N-1 param 0 param 1... param M-1 Nte that we have assumed that there are M parameters in this case, and num_ndes = N. The secnd matrix that is saved crrespnds t the input signal in_a. In this case, three values are specified fr each nde (i.e., [0 0 1.0]). In general, these values may be different fr each nde, and fllw the fllwing template: in_x f Nde 0 in_x f Nde 1 sig_type sig_num strength sig_type sig_num strength... sig_type sig_num strength sig_type sig_num strength... in_x f Nde N-1 sig_type sig_num strength sig_type sig_num strength... sig_type: takes n values 0, 1, 2, which crrespnd t the verall input, utput1 f the nde, utput2 f the nde, etc. sig_num: takes n values 0, 1, num_ndes. strength: takes n a real value representing the strength f this cnnectin. Example: [sig_type sig_num strength] = [0 2 1.0] crrespnds t a cnnectin frm element 2 f the verall input with strength 1.0 Example: [sig_type sig_num strength] = [1 0 2.0] crrespnds t a cnnectin frm utput1 f nde 0 with strength 2.0 Example: [sig_type sig_num strength sig_type sig_num strength] = [0 1-1.5 2 1.5] crrespnds t a cnnectin frm element 1 f the verall input with strength -1.5 added t a cnnectin frm utput2 f nde 1 with strength 0.5 Nte that yu can define as many cnnectins per nde as yu like, but the verall matrix must be square. Therefre, if yu want t have less cnnectins fr a particular nde cmpared t ther ndes that have mre cnnectins, simply set the difference in cnnectins t have strength 0. The last matrix that is saved crrespnds t the verall utput f the neural netwrk. The frmat f the matrix is the same as that used fr inputs, namely: 14

Out 0 Out 1 sig_type sig_num strength sig_type sig_num strength... sig_type sig_num strength sig_type sig_num strength... Out N-1 sig_type sig_num strength sig_type sig_num strength... 15