机器学习算法——SVM(Support Vector Machine)分类

目录

对于线性可分样本

对于近似线性可分样本 

对于线性不可分样本

多分类问题


基于课程《地学大数据与人工智能》课的学习笔记。

从sklearn导入数据datasets

同时也需要导入svm里的SVC,用于实现支持向量机(SVM)算法

DecisionBoundaryDisplay,用于样本向量用于分区,注意此处需要更新sklearn版本到最新版本。

import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.svm import SVC
from sklearn.inspection import DecisionBoundaryDisplay

定义函数,该函数用于绘制超平面和支持面。

#Plot the decision function for a 2D SVC
def plot_SVC_decision_function(model, ax=None, plot_support=True):
    if ax is None:
        ax = plt.gca()
    xlim = ax.get_xlim()
    ylim = ax.get_ylim()
 
    # create grid to evaluate model
    x = np.linspace(xlim[0], xlim[1], 30)
    y = np.linspace(ylim[0], ylim[1], 30)
    Y, X = np.meshgrid(y, x)
    xy = np.vstack([X.ravel(), Y.ravel()]).T
    P = model.decision_function(xy).reshape(X.shape)
 
    # plot decision boundary and margins
    ax.contour(X, Y, P, colors='k', levels=[-1, 0, 1],
               alpha=0.5, linestyles=['-', '--', '-'], linewidths=1)
 
    # plot support vectors
    if plot_support:
        ax.scatter(model.support_vectors_[:, 0],
                   model.support_vectors_[:, 1],
                   s=300, linewidth=1, facecolors='none')
 
    ax.set_xlim(xlim)
    ax.set_ylim(ylim)

对于线性可分样本

make_blobs用于生成图,n_samples 样本数设置为100,n_features 特征数量设置为2,centers为样本的堆,设置为2,cluster_std为标准差,设置为0.5,用于衡量数据间的离散程度。 random_state=0

# 线性可分样本
# 生成样本数据
X,y=datasets.make_blobs(n_samples=100, n_features=2, centers=2, cluster_std=0.5, random_state=0)
plt.figure()
plt.scatter(X[:,0], X[:,1], c=y, s=20, marker='o', cmap='bwr')
plt.xlabel('$x_1$')
plt.ylabel('$x_2$')
plt.colorbar()

运行该段代码,结果如图:

 

 训练模型

利用SVC函数生成训练模型,kernel为核函数,linear为线性核函数。

# 训练模型
model=SVC(kernel='linear')
model.fit(X,y)

 运行定义的plot_SVC_decision_function函数,绘制支持面和支持面向量以及超平面。

# 绘制支持面与支持向量
plot_SVC_decision_function(model)
plt.scatter(model.support_vectors_[:,0], model.support_vectors_[:,1], marker='o', facecolors='none', edgecolors='k', s=80)

结果如图:

 

 对于近似线性可分样本 

# # 近似线性可分样本
# # 生成样本数据
X,y=datasets.make_blobs(n_samples=100, n_features=2, centers=2, cluster_std=1, random_state=0)
plt.figure()
plt.scatter(X[:,0], X[:,1], c=y, s=20, marker='o', cmap='bwr')
plt.xlabel('$x_1$')
plt.ylabel('$x_2$')
plt.colorbar()

运行结果如图:

可以看出,近似线性可分样本中,有部分向量点交叉,不能线性可分。 

 生成训练模型并绘制支持面和支持向量,其中选用线性核函数,系数C为10。(C的取值可以通过尝试,笔者在此也是试出来的,该值较为良好)

# # 训练模型
model=SVC(kernel='linear', C=10)
model.fit(X,y)

# # 绘制支持面与支持向量
plot_SVC_decision_function(model)
plt.scatter(model.support_vectors_[:,0], model.support_vectors_[:,1], marker='o', facecolors='none', edgecolors='k', s=80)

 运行该段代码,得到以下结果:

 可以看出少数支持向量在支持面之间,即为软间隔SVM模型,运行部分样本犯错。

对于线性不可分样本

# # 线性不可分样本
# # 生成样本数据
X,y=datasets.make_circles(100, factor=0.2, noise=0.1, random_state=0)
plt.figure()
plt.scatter(X[:,0], X[:,1], c=y, s=20, marker='o', cmap='bwr')
plt.xlabel('$x_1$')
plt.ylabel('$x_2$')
plt.colorbar()

运行结果如图:

 可以看出该样本明显是线性不可分,故必须使用核函数。

核函数的作用是使样本的特征向量空间映射到更高维的特征向量空间,从而在“更高维”的空间使该样本能够线性(近似)可分

同上述生成模型:

# # 训练模型
model=SVC(kernel='rbf', C=10)
model.fit(X,y)

# # 绘制支持面与支持向量
plot_SVC_decision_function(model)
plt.scatter(model.support_vectors_[:,0], model.support_vectors_[:,1], marker='o', facecolors='none', edgecolors='k', s=80)

运行得到结果如图: 

 可以看出,通过核函数,样本从线性不可分变到“高维”空间线性可分,采用硬间隔SVM模型。

以上是采用SVM用于二分类问题,同时也可以利用SVM实现多分类问题。

多分类问题

能够实现二分类,多分类就是一级一级二分类实现,较为简单易理解。

利用sklearn中自带的函数能够实现,(以下展示是3分类问题),读者可以自行尝试,只需更改centers的值,此处取3。其余参数值说明见上文~

代码如下: 

# # 多分类样本
# # 生成样本数据
X,y=datasets.make_blobs(n_samples=150, n_features=2, centers=3, cluster_std=0.5, random_state=0)

# # 训练模型
model=SVC(kernel='linear')
model.fit(X,y)

# # 绘制支持面与支持向量
DecisionBoundaryDisplay.from_estimator(model, X)
plt.scatter(X[:,0], X[:,1], c=y, s=20, marker='o', cmap='rainbow')
plt.scatter(model.support_vectors_[:,0], model.support_vectors_[:,1], marker='o', facecolors='none', edgecolors='k', s=80)
plt.xlabel('$x_1$')
plt.ylabel('$x_2$')

运行结果如图:

  • 6
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PART I: VXBUS FUNDAMENTALS 1 Getting Started with Device Driver Development .................................... 3 1.1 About Device Drivers ..................................................................................................... 3 1.2 About this Documentation ............................................................................................ 4 1.2.1 Intended Audience ........................................................................................... 4 1.2.2 Navigating this Manual .................................................................................. 4 Experienced VxWorks Device Driver Developers ........................................ 4 Novice VxWorks Device Driver Developers ................................................. 5 1.2.3 Documentation Conventions .......................................................................... 5 1.3 Additional Documentation Resources ....................................................................... 6 2 VxBus and VxBus Device Drivers ............................................................. 7 2.1 Introduction ...................................................................................................................... 7 2.2 About VxBus ................................................................................................................... 7 2.3 VxBus Device Drivers ................................................................................................... 8 2.4 Design Goals ................................................................................................................... 11 2.4.1 Performance ....................................................................................................... 11 2.4.2 Maintenance and Readability .......................................................................... 11 2.4.3 Ease of Configuration ....................................................................................... 12 2.4.4 Performance Testing ......................................................................................... 12 2.4.5 Code Size ............................................................................................................ 12 3 Device Driver Fundamentals ..................................................................... 13 3.1 Introduction ...................................................................................................................... 13 3.2 Driver Classes ................................................................................................................. 14 VxBus Device Driver Developer's Guide, 6.9 iv 3.2.1 General Classes .................................................................................................. 14 Serial Drivers .................................................................................................... 14 Storage Drivers ................................................................................................. 14 Network Interface Drivers .............................................................................. 15 Non-Volatile RAM Drivers ............................................................................. 15 Timer Drivers .................................................................................................... 16 DMA Controller Drivers ................................................................................. 16 Bus Controller Drivers ..................................................................................... 16 USB Drivers ....................................................................................................... 17 Interrupt Controller Drivers ........................................................................... 17 Multifunction Drivers ...................................................................................... 17 Remote Processing Element Drivers ............................................................. 18 Console Drivers ................................................................................................ 18 Resource Drivers .............................................................................................. 19 3.2.2 Other Classes .................................................................................................... 19 3.3 Driver Organization ....................................................................................................... 19 3.3.1 File Location ...................................................................................................... 20 Wind River Drivers ........................................................................................... 20 Third-Party Drivers .......................................................................................... 20 3.3.2 Sample Driver Files: wrsample ....................................................................... 21 3.3.3 Required Files ................................................................................................... 21 Driver Source File ............................................................................................. 22 Component Description File ........................................................................... 24 Driver Configuration Stub Files ..................................................................... 29 README File .................................................................................................... 31 Device Driver Makefiles .................................................................................. 31 3.4 VxBus Driver Methods .................................................................................................. 33 3.4.1 Representing Driver Methods in the Documentation ................................ 33 3.4.2 Parts of a Driver Method ................................................................................. 33 3.4.3 Calling Driver Methods ................................................................................... 34 3.4.4 Advertising Driver Methods .......................................................................... 35 3.4.5 Driver Method Limitations ............................................................................. 36 3.5 Driver Run-time Life Cycle .......................................................................................... 36 3.5.1 Driver Initialization Sequence ........................................................................ 36 Making Assumptions About Initialization Order ....................................... 37 Early in the Boot Process ................................................................................. 37 sysHwInit( ), PLB, and Hardware Discovery ............................................... 37 Driver Registration ........................................................................................... 38 Driver Initialization Phase 1 ........................................................................... 38 Kernel Startup ................................................................................................... 39 Driver Initialization Phase 2 ........................................................................... 39 Driver Initialization Phase 3 ........................................................................... 39 3.5.2 Invoking a Driver Method .............................................................................. 39 3.5.3 Run-time Operation ......................................................................................... 39 Contents v Unloading a Driver .......................................................................................... 40 Removing a Device from the System ............................................................ 40 Dissociating a Device from a Driver .............................................................. 40 3.5.4 Handling a System Shutdown Notification ................................................. 41 3.5.5 Handling Late Driver Registration ................................................................ 41 3.5.6 Driver Registration Order Considerations ................................................... 42 3.5.7 Driver-to-Device Matching and Hardware Availability ............................. 42 PLB ..................................................................................................................... 43 Other Bus Types ................................................................................................ 43 3.6 Services Available to Drivers ....................................................................................... 44 3.6.1 Configuration .................................................................................................... 44 Determining Driver Configuration Information ......................................... 45 Responding to Changes in Device Parameters ............................................ 47 3.6.2 Memory Allocation .......................................................................................... 47 Allocating Memory During System Startup ................................................ 48 Allocating Memory During Normal System Operation ............................. 49 Intermixing Memory Allocation Methods within a Single Driver ........... 49 3.6.3 Non-Volatile RAM Support ............................................................................. 49 3.6.4 Hardware Access .............................................................................................. 50 Finding the Address of the Hardware Registers ......................................... 50 Reading and Writing to the Hardware Registers ........................................ 51 Special Requirements for Hardware Register Access ................................. 53 VxBus Version Considerations ........................................................................ 53 3.6.5 Interrupt Handling ........................................................................................... 54 Overview of Interrupt Handling .................................................................... 54 Interrupt Indexes .............................................................................................. 54 Dynamic Interrupt Handling .......................................................................... 55 Minimizing Work Performed Within an ISR ................................................ 56 3.6.6 Synchronization ................................................................................................ 57 Task-Level Synchronization ............................................................................ 57 Interrupt-Level Synchronization .................................................................... 58 3.6.7 Direct Memory Access (DMA) ....................................................................... 59 vxbDmaBufLib .................................................................................................. 60 DMA Considerations ........................................................................................ 60 Allocating External DMA Engines ................................................................ 63 3.6.8 Atomic Operators ............................................................................................. 65 3.7 BSP Configuration ......................................................................................................... 66 3.7.1 Requirements for PLB Devices ....................................................................... 67 3.7.2 Configuring Device Parameters in the BSP .................................................. 68 3.8 SMP Considerations ...................................................................................................... 69 3.8.1 Lack of Implicit Locking ................................................................................. 69 VxBus Device Driver Developer's Guide, 6.9 vi 3.8.2 True Task-to-Task Contention ......................................................................... 70 3.8.3 Interrupt Routing ............................................................................................. 70 3.8.4 Deferring Interrupt Processing ...................................................................... 71 3.9 Device Memory Mapping in 64-Bit Devices .............................................................. 72 3.10 Physical-to-Virtual Address Translations in 64-Bit VxWorks ................................. 73 3.10.1 64-bit Changes to the Memory Management Model ................................... 73 3.10.2 Porting Drivers That Rely on Physical-to-Virtual Address Translations .. 74 Transfer Using Descriptors .............................................................................. 74 Strategies When Order is Unpredictable ....................................................... 75 4 Development Strategies ............................................................................. 77 4.1 Introduction ...................................................................................................................... 77 4.2 Writing New VxBus Drivers ........................................................................................ 77 4.2.1 Creating the VxBus Infrastructure ................................................................. 78 Writing Driver Source Files ............................................................................. 78 Writing Header Files (Optional) .................................................................... 78 Writing the Component Description File (CDF) .......................................... 78 Writing the Configuration Stub Files ............................................................ 79 Verifying the Infrastructure ............................................................................ 80 4.2.2 Modifying the BSP (Optional) ........................................................................ 80 4.2.3 Adding Debug Code ........................................................................................ 81 4.2.4 Adding the VxBus Driver Methods ............................................................... 81 4.2.5 Removing Global Variables ............................................................................ 82 4.3 VxBus Show Routines ................................................................................................... 83 4.3.1 Available Show Routines ................................................................................ 83 vxBusShow( ) ..................................................................................................... 83 vxbDevStructShow( ) ........................................................................................ 85 vxbDevPathShow( ) .......................................................................................... 86 4.3.2 PCI Show Routines .......................................................................................... 86 pciDevShow( ) ................................................................................................... 87 vxbPciDeviceShow( ) ........................................................................................ 87 vxbPciHeaderShow( ) ....................................................................................... 88 vxbPciFindDeviceShow( ) ................................................................................ 89 vxbPciFindClassShow( ) ................................................................................... 89 vxbPciConfigTopoShow( ) ............................................................................... 90 4.3.3 Using Show Routines from Software ............................................................ 91 4.3.4 Configuring Show Routines into VxWorks .................................................. 93 4.4 Debugging ....................................................................................................................... 94 4.4.1 Configuring Show Routines ........................................................................... 94 Contents vii 4.4.2 Deferring Driver Registration ........................................................................ 95 4.4.3 Including Debug Code .................................................................................... 95 4.4.4 Confirming Register Access ............................................................................ 96 4.4.5 Increasing the Size of HWMEM_POOL ........................................................ 96 4.4.6 Confirming Device and Driver Name Matches ........................................... 96 5 Driver Release Procedure .......................................................................... 99 5.1 Introduction ..................................................................................................................... 99 5.2 Driver Source Location .................................................................................................. 100 5.3 Driver-Specific Directories ............................................................................................ 101 5.4 Driver Installation and the README File ................................................................ 102 5.5 Driver Packaging ............................................................................................................ 103 5.6 Driver Release Procedure ............................................................................................. 104 PART II: DEVICE DRIVER PORTING 6 Class-Specific Driver Development .......................................................... 107 6.1 About VxBus Driver Classes ........................................................................................ 107 6.2 Before You Begin ............................................................................................................. 107 6.3 About the Class-Specific Driver Documentation ..................................................... 108 7 Bus Controller Drivers ................................................................................ 109 7.1 Introduction ..................................................................................................................... 109 7.2 Overview .......................................................................................................................... 109 7.3 VxBus Driver Methods .................................................................................................. 111 7.3.1 {busCtlrDevCfgRead}( ) ................................................................................... 111 7.3.2 {busCtlrCfgRead}( ) ........................................................................................... 112 7.3.3 {busCtlrDevCfgWrite}( ) ................................................................................... 113 7.3.4 {busCtlrCfgWrite}( ) .......................................................................................... 113 7.3.5 {busCtlrDevCtlr}( ) ............................................................................................ 114 7.3.6 {busCtlrAccessOverride}( ) .............................................................................. 115 Override for (*busCfgRead)( ) ......................................................................... 115 Override for (*busCfgWrite)( ) ........................................................................ 116 Override for (*vxbDevControl)( ) ................................................................... 116 VxBus Device Driver Developer's Guide, 6.9 viii 7.3.7 {busCtlrCfgInfo}( ) ............................................................................................. 116 7.3.8 {busCtlrBaseAddrCvt}( ) .................................................................................. 117 7.3.9 {vxbDevRegMap}( ) ........................................................................................... 117 Specifying a Predefined Transaction Type ..................................................... 119 Providing a New Transaction Type ............................................................... 120 7.3.10 {vxbIntDynaVecProgram}( ) ............................................................................. 122 7.4 Header Files ..................................................................................................................... 122 7.5 BSP Configuration .......................................................................................................... 123 7.5.1 PCI Configuration ............................................................................................ 124 7.5.2 PCI Autoconfiguration .................................................................................... 124 7.6 Available Utility Routines ............................................................................................ 125 7.6.1 PCI Configuration ............................................................................................ 125 7.6.2 PCI Autoconfiguration ..................................................................................... 126 7.6.3 vxbBusAnnounce( ) ........................................................................................... 126 7.6.4 vxbPciBusTypeInit( ) ......................................................................................... 127 7.7 Initialization .................................................................................................................... 127 7.7.1 Initialization Example ..................................................................................... 128 vxbBusAnnounce( ) ........................................................................................... 129 vxbDeviceAnnounce( ) ..................................................................................... 130 vxbDevStructAlloc( ) ........................................................................................ 130 vxbDevStructFree( ) .......................................................................................... 130 7.8 Debugging ........................................................................................................................ 130 8 Direct Memory Access Drivers .................................................................. 131 8.1 Introduction ..................................................................................................................... 131 8.2 Overview ........................................................................................................................... 131 8.3 VxBus Driver Methods ................................................................................................... 132 8.3.1 {vxbDmaResourceGet}( ) .................................................................................. 132 8.3.2 {vxbDmaResourceRelease}( ) ........................................................................... 133 8.3.3 {vxbDmaResDedicatedGet}( ) .......................................................................... 133 8.4 Header Files ...................................................................................................................... 133 8.5 BSP Configuration .......................................................................................................... 134 8.6 Available Utility Routines ............................................................................................. 134 8.7 Initialization ..................................................................................................................... 134 Contents ix 8.8 DMA System Structures and Routines ....................................................................... 134 8.8.1 (*dmaRead)( ) ..................................................................................................... 135 8.8.2 (*dmaReadAndWait)( ) ..................................................................................... 135 8.8.3 (*dmaWrite)( ) .................................................................................................... 135 8.8.4 (*dmaWriteAndWait)( ) .................................................................................... 136 8.8.5 (*dmaCancel)( ) .................................................................................................. 136 8.8.6 (*dmaPause)( ) ................................................................................................... 136 8.8.7 (*dmaResume)( ) ................................................................................................ 136 8.8.8 (*dmaStatus)( ) ................................................................................................... 136 8.9 Debugging ....................................................................................................................... 137 9 I2C Drivers ................................................................................................... 139 9.1 Introduction ...................................................................................................................... 139 9.2 Overview ........................................................................................................................... 139 9.3 VxBus Driver Methods ................................................................................................... 140 9.4 Header Files ...................................................................................................................... 141 9.5 BSP Configuration .......................................................................................................... 141 9.6 Initialization ..................................................................................................................... 143 9.7 Implementing Driver Service Routines ...................................................................... 144 (*VXB_I2C_LOCK_BUS_FUNC)( ) ................................................................. 145 (*VXB_I2C_UNLOCK_BUS_FUNC)( ) ........................................................... 145 (*VXB_I2C_START_FUNC)( ) .......................................................................... 145 (*VXB_I2C_STOP_FUNC)( ) ............................................................................ 146 (*VXB_I2C_READ_FUNC)( ) ........................................................................... 146 (*VXB_I2C_WRITE_FUNC)( ) ......................................................................... 146 (*VXB_I2C_DEV_READ)( ) .............................................................................. 147 (*VXB_I2C_DEV_WRITE)( ) ............................................................................ 147 9.8 Device Driver ................................................................................................................... 148 9.8.1 Generic I2C Devices .......................................................................................... 149 10 Interrupt Controller Drivers ........................................................................ 151 10.1 Introduction ..................................................................................................................... 151 10.2 Overview .......................................................................................................................... 152 Interrupt Identification .................................................................................... 152 Interrupt Controller Driver Responsibilities ................................................. 152 Interrupt Controller Configurations ............................................................... 153 Dynamic Vectors ................................................................................................ 153 Interrupt Controller Drivers and Multiprocessing ....................................... 154 VxBus Device Driver Developer's Guide, 6.9 x 10.3 VxBus Driver Methods .................................................................................................. 154 10.3.1 Basic Methods .................................................................................................... 154 {vxbIntCtlrAlloc}( ) ............................................................................................ 154 {vxbIntCtlrFree}( ) ............................................................................................. 155 {vxbIntCtlrConnect}( ) ...................................................................................... 155 {vxbIntCtlrDisconnect}( ) ................................................................................. 155 {vxbIntCtlrEnable}( ) ......................................................................................... 156 {vxbIntCtlrDisable}( ) ........................................................................................ 156 10.3.2 Dynamic Vector Methods ................................................................................ 156 {vxbIntDynaVecConnect}( ) ............................................................................. 156 10.3.3 Multiprocessor Methods ................................................................................. 157 {vxbIntCtlrIntReroute}( ) .................................................................................. 157 {vxbIntCtlrCpuReroute}( ) .............................................................................. 157 {vxIpiControlGet}( ) .......................................................................................... 157 10.4 Header Files ...................................................................................................................... 158 vxbIntrCtlr.h ....................................................................................................... 158 vxbIntCtlrLib.h .................................................................................................. 158 10.5 BSP Configuration .......................................................................................................... 158 10.5.1 Interrupt Input Table ........................................................................................ 159 10.5.2 Dynamic Vector Table ....................................................................................... 160 10.5.3 CPU Routing Table ............................................................................................ 162 10.5.4 Interrupt Priority ............................................................................................... 163 10.5.5 Crossbar Routing Table .................................................................................... 163 10.6 Available Utility Routines ............................................................................................. 164 10.6.1 intCtlrHwConfGet( ) ......................................................................................... 165 10.6.2 intCtlrISRAdd( ) ................................................................................................ 165 10.6.3 intCtlrISRDisable( ) ........................................................................................... 165 10.6.4 intCtlrISREnable( ) ............................................................................................ 166 10.6.5 intCtlrISRRemove( ) .......................................................................................... 166 10.6.6 intCtlrPinFind( ) ................................................................................................ 166 10.6.7 intCtlrTableArgGet( ) ........................................................................................ 166 10.6.8 intCtlrTableFlagsGet( ) ..................................................................................... 166 10.6.9 intCtlrTableIsrGet( ) .......................................................................................... 166 10.6.10 intCtlrHwConfShow( ) ..................................................................................... 166 10.6.11 intCtlrTableCreate( ) ......................................................................................... 167 10.6.12 intCtlrTableFlagsSet( ) ...................................................................................... 167 10.6.13 intCtlrTableUserSet( ) ....................................................................................... 167 10.6.14 VXB_INTCTLR_ISR_CALL( ) ......................................................................... 167 10.6.15 VXB_INTCTLR_PINENTRY_ENABLED( ) ................................................... 167 Contents xi 10.6.16 VXB_INTCTLR_PINENTRY_ALLOCATED( ) ............................................. 167 10.6.17 Dispatch Routines ............................................................................................. 168 vxbIntDynaCtlrInputInit( ) .............................................................................. 168 vxbIntDynaVecProgram( ) ............................................................................... 168 vxbIntDynaVecErase( ) ..................................................................................... 169 10.7 Initialization ..................................................................................................................... 169 10.8 Interrupt Controller Topologies and Hierarchies ..................................................... 169 10.9 Interrupt Priority ............................................................................................................. 170 10.10 ISR Dispatch .................................................................................................................... 171 10.11 Managing Dynamic Interrupt Vectors ........................................................................ 173 Configuring Dynamic Vectors Using the Service Driver Routines ............ 174 Configuring Dynamic Vectors in the BSP ..................................................... 174 Programming Dynamic Vectors ...................................................................... 175 Determining Dynamic Vector Values ............................................................ 175 10.12 Internal Representation of Interrupt Inputs .............................................................. 176 10.13 Multiprocessor Issues with VxWorks SMP ................................................................ 177 10.13.1 Routing Interrupt Inputs to Individual CPUs .............................................. 177 10.13.2 Interprocessor Interrupts ................................................................................. 178 10.13.3 Limitations in Multiprocessor Systems .......................................................... 182 10.14 Debugging ........................................................................................................................ 182 11 Multifunction Drivers .................................................................................. 185 11.1 Introduction ...................................................................................................................... 185 11.2 Overview ........................................................................................................................... 185 11.3 VxBus Driver Methods ................................................................................................... 186 11.4 Header Files ...................................................................................................................... 186 11.5 BSP Configuration .......................................................................................................... 186 11.6 Available Utility Routines ............................................................................................. 187 vxbDevStructAlloc( ) ........................................................................................ 187 vxbDeviceAnnounce( ) ..................................................................................... 187 vxbDevRemovalAnnounce( ) .......................................................................... 187 vxbDevStructFree( ) .......................................................................................... 188 vxbBusAnnounce( ) ........................................................................................... 188 11.7 Initialization ..................................................................................................................... 188 11.8 Device Interconnections ................................................................................................ 188 VxBus Device Driver Developer's Guide, 6.9 xii 11.8.1 Interleaved Registers ........................................................................................ 188 11.8.2 Shared Resources ............................................................................................... 189 11.8.3 Other Interactions ............................................................................................. 190 11.9 Logical Location of Subordinate Devices ................................................................... 190 11.10 Debugging ........................................................................................................................ 190 12 Network Drivers .......................................................................................... 191 12.1 Introduction ...................................................................................................................... 191 12.1.1 Terminology ....................................................................................................... 191 12.1.2 Networking Overview ..................................................................................... 192 Seven Layer OSI Model .................................................................................... 192 Transmission Media and VxWorks ................................................................. 192 Protocols ............................................................................................................. 193 12.2 Network Interface Drivers ............................................................................................. 193 12.2.1 Network Interface Driver Overview .............................................................. 193 IPNET-Native Drivers ...................................................................................... 193 Functional Modules .......................................................................................... 194 Network Driver Interrupts ............................................................................. 195 12.2.2 VxBus Driver Methods for Network Interface Drivers .............................. 196 {muxDevConnect}( ) ......................................................................................... 196 {muxDevConnect2}( ) ....................................................................................... 197 {vxbDrvUnlink}( ) .............................................................................................. 199 {miiMediaUpdate}( ) ......................................................................................... 199 {miiRead}( ) ........................................................................................................ 200 {miiWrite}( ) ........................................................................................................ 201 12.2.3 Header Files for Network Interface Drivers ................................................. 201 12.2.4 BSP Configuration for Network Interface Drivers ...................................... 202 12.2.5 Available Utility Routines for Network Interface Drivers ......................... 203 MUX Interactions .............................................................................................. 203 Job Queueing ..................................................................................................... 204 Buffer Management .......................................................................................... 205 DMA Support .................................................................................................... 209 PHY and MII bus interactions ......................................................................... 210 12.2.6 Initialization for Network Interface Drivers ................................................ 212 12.2.7 MUX: Connecting to Networking Code ........................................................ 212 12.2.8 jobQueueLib: Deferring ISRs ........................................................................... 213 12.2.9 Working with Ipcom_pkt Packets ................................................................... 214 Supporting Scatter-Gather with IPNET-Native Drivers .............................. 217 12.2.10 netBufLib: Transferring Data with M_BLKs ................................................ 218 12.2.11 Protocol Impact on Drivers .............................................................................. 220 Contents xiii 12.2.12 Other Network Interface Driver Issues .......................................................... 232 Receive Handling Method ............................................................................... 233 Receive Stall Handling ..................................................................................... 240 12.2.13 Debugging Network Interface Drivers .......................................................... 241 Using VxBus Show Routines ........................................................................... 241 Deferring Driver Registration ......................................................................... 241 Pairing with a PHY instance ............................................................................ 242 Stress Testing ...................................................................................................... 242 Netperf Test Suite .............................................................................................. 243 Interrupt Validation .......................................................................................... 243 Additional Tests ................................................................................................. 243 12.3 PHY Drivers ...................................................................................................................... 249 12.3.1 PHY Driver Overview ...................................................................................... 250 PHY Device Probing and Discovery .............................................................. 250 MAC and MII Bus Relationship ...................................................................... 251 Generic PHY Driver Support ........................................................................... 252 Generic TBI Driver Support ............................................................................. 252 12.3.2 VxBus Driver Methods for PHY Drivers ....................................................... 253 Upper Edge Methods ........................................................................................ 253 Lower Edge Methods ....................................................................................... 253 12.3.3 Header Files for PHY Drivers ......................................................................... 255 12.3.4 BSP Configuration for PHY Drivers ............................................................... 255 12.3.5 Available Utility Routines for PHY Drivers .................................................. 255 Upper Edge Utility Routines ........................................................................... 256 Lower Edge Utility Routines ........................................................................... 256 12.3.6 Initialization for PHY Drivers ......................................................................... 257 12.3.7 Debugging PHY Drivers .................................................................................. 257 12.4 Wireless Ethernet Drivers .............................................................................................. 258 12.5 Hierarchical END Drivers ............................................................................................. 258 13 Non-Volatile RAM Drivers .......................................................................... 259 13.1 Introduction ...................................................................................................................... 259 NVRAM Drivers and TrueFFS ........................................................................ 259 13.2 Non-Volatile RAM Drivers ........................................................................................... 260 13.2.1 NVRAM Driver Overview ............................................................................... 260 13.2.2 VxBus Driver Methods for NVRAM Drivers ................................................ 260 {nonVolGet}( ) .................................................................................................... 260 {nonVolSet}( ) ..................................................................................................... 261 13.2.3 Header Files ....................................................................................................... 261 13.2.4 BSP Configuration for NVRAM Drivers ....................................................... 261 VxBus Device Driver Developer's Guide, 6.9 xiv 13.2.5 Utility Routines for NVRAM Drivers ............................................................ 262 13.2.6 Initialization for NVRAM Drivers .................................................................. 262 13.2.7 NVRAM Block Sizes ......................................................................................... 262 13.2.8 Stacking NVRAM Instances ............................................................................ 263 13.2.9 Debugging NVRAM Drivers ........................................................................... 263 13.3 Flash File System Support with TrueFFS ................................................................... 263 13.3.1 TrueFFS Overview ............................................................................................. 264 Core Layer .......................................................................................................... 264 MTD Layer ........................................................................................................ 264 Socket Layer ....................................................................................................... 264 Flash Translation Layer .................................................................................... 265 13.3.2 TrueFFS Driver Development Process ........................................................... 265 Using MTD-Supported Flash Devices ........................................................... 265 Writing MTD Components .............................................................................. 269 Socket Drivers .................................................................................................... 276 Flash Translation Layer .................................................................................... 282 14 RapidIO Drivers ........................................................................................... 297 14.1 Introduction ...................................................................................................................... 297 14.2 Overview ........................................................................................................................... 297 14.3 VxBus Driver Methods ................................................................................................... 299 {vxbRapidIoCtlrInfoGet}( ) .............................................................................. 299 {sharedMemSupportAPIGet}( ) ....................................................................... 300 {vxbMsgApiGet}( ) ............................................................................................ 300 14.4 Header Files ...................................................................................................................... 301 14.5 BSP Configuration .......................................................................................................... 301 RapidIO Bus Controller Driver ....................................................................... 301 Virtual Message Network Device Driver ....................................................... 301 14.6 Initialization ..................................................................................................................... 302 Phase 1 ................................................................................................................ 302 Phase 2 ................................................................................................................ 302 Phase 3 ................................................................................................................ 303 14.7 Implementing Driver Service Routines ...................................................................... 303 RapidIO Bus Controller Driver ....................................................................... 303 Message Controller Driver ............................................................................... 307 15 Resource Drivers ........................................................................................ 311 15.1 Introduction ...................................................................................................................... 311 Contents xv 15.2 Overview ........................................................................................................................... 311 15.3 VxBus Driver Methods ................................................................................................... 312 15.4 Header Files ...................................................................................................................... 312 15.5 BSP Configuration .......................................................................................................... 312 15.6 Available Utility Routines ............................................................................................. 313 15.7 Initialization ..................................................................................................................... 313 15.8 Debugging ........................................................................................................................ 313 16 Serial Drivers ............................................................................................... 315 16.1 Introduction ...................................................................................................................... 315 16.2 Overview ........................................................................................................................... 315 16.3 VxBus Driver Methods ................................................................................................... 316 16.3.1 {sioChanGet}( ) ................................................................................................... 316 16.3.2 {sioChanConnect}( ) .......................................................................................... 317 16.4 Header Files ...................................................................................................................... 317 16.5 BSP Configuration .......................................................................................................... 318 16.6 Available Utility Routines ............................................................................................. 318 16.7 Initialization ..................................................................................................................... 318 16.8 Polled Mode Versus Interrupt-Driven Mode ............................................................. 318 16.9 SIO_CHAN and SIO_DRV_FUNCS ............................................................................ 319 16.10 WDB ................................................................................................................................... 321 16.10.1 WDB and Kernel Initialization ........................................................................ 321 16.11 Serial Drivers, Initialization, and Interrupts ............................................................. 321 16.11.1 WDB and Interrupts ......................................................................................... 322 16.11.2 Initialization Order and Interrupts ................................................................. 322 16.11.3 Initialization Order ........................................................................................... 323 16.12 Debugging ........................................................................................................................ 323 17 SPI Drivers ................................................................................................... 325 17.1 Introduction ...................................................................................................................... 325 17.2 Overview ........................................................................................................................... 325 VxBus Device Driver Developer's Guide, 6.9 xvi 17.3 VxBus Driver Methods ................................................................................................... 326 17.4 Header Files ...................................................................................................................... 326 17.5 BSP Configuration .......................................................................................................... 327 17.6 Initialization ..................................................................................................................... 328 17.7 Implementing Driver Service Routines ...................................................................... 329 17.8 Device Driver ................................................................................................................... 329 17.8.1 SPI_EEPROM ..................................................................................................... 330 17.8.2 SPI Flash ............................................................................................................. 330 18 Storage Drivers ........................................................................................... 333 18.1 Introduction ...................................................................................................................... 333 18.2 Overview ........................................................................................................................... 333 Updates in VxWorks 6.9, Update Pack 2, Service Pack 1 ............................ 334 Updates in VxWorks 6.9, Update Pack 3, Service Pack 3 ............................ 334 18.3 VxBus Driver Methods ................................................................................................... 335 18.4 Header Files ...................................................................................................................... 335 18.5 BSP Configuration .......................................................................................................... 336 18.6 Available Utility Routines ............................................................................................. 336 erfHandlerRegister( ) and erfHandlerUnregister( ) ..................................... 336 erfEventRaise( ) ................................................................................................. 336 xbdAttach( ) ....................................................................................................... 336 bio_done( ) .......................................................................................................... 337 18.7 Initialization ..................................................................................................................... 337 18.8 Interface with VxWorks File Systems ......................................................................... 337 18.8.1 Device Creation ................................................................................................. 337 ERF Registration ................................................................................................ 338 Advertisement of XBD Methods ..................................................................... 338 ERF New Device Notification ......................................................................... 339 18.8.2 Processing ........................................................................................................... 340 xbd_request processing .................................................................................... 340 18.8.3 Event Reporting ................................................................................................. 341 18.9 Writing New Storage Drivers ........................................................................................ 342 18.10 Writing New SD/MMC/SDIO host controller Drivers ............................................ 343 18.11 Device Driver ................................................................................................................... 344 Contents xvii 19 Timer Drivers ............................................................................................... 345 19.1 Introduction ...................................................................................................................... 345 19.2 Overview ........................................................................................................................... 345 19.3 VxBus Driver Methods ................................................................................................... 346 19.4 Header Files ...................................................................................................................... 349 19.5 BSP Configuration .......................................................................................................... 349 19.6 Available Utility Routines ............................................................................................. 349 19.7 Initialization ..................................................................................................................... 349 19.8 Data Structure Layout ..................................................................................................... 350 19.9 Implementing Driver Service Routines ...................................................................... 351 19.9.1 (*timerAllocate)( ) .............................................................................................. 351 19.9.2 (*timerRelease)( ) ............................................................................................... 351 19.9.3 (*timerRolloverGet)( ) ....................................................................................... 352 19.9.4 (*timerCountGet)( ) ........................................................................................... 352 19.9.5 (*timerDisable)( ) ............................................................................................... 353 19.9.6 (*timerEnable)( ) ................................................................................................ 354 19.9.7 (*timerISRSet)( ) ................................................................................................. 354 19.9.8 (*timerEnable64)( ) ............................................................................................ 355 19.9.9 (*timerRolloverGet64)( ) ................................................................................... 355 19.9.10 (*timerCountGet64)( ) ....................................................................................... 356 19.10 Integrating a Timer Driver ............................................................................................ 357 19.10.1 VxWorks System Clock .................................................................................... 357 19.10.2 VxWorks Auxiliary Clock ................................................................................ 359 19.10.3 VxWorks Timestamp Driver ............................................................................ 360 19.11 Debugging ........................................................................................................................ 361 19.12 SMP Considerations ....................................................................................................... 361 20 USB Drivers ................................................................................................. 363 20.1 Introduction ...................................................................................................................... 363 20.2 Wind River USB Overview ............................................................................................ 363 20.2.1 USB Host Stack Drivers .................................................................................... 364 VxBus Model Drivers ....................................................................................... 364 Other Host Drivers ............................................................................................ 364 VxBus Device Driver Developer's Guide, 6.9 xviii 20.2.2 USB Target Stack ............................................................................................... 364 20.3 Host Controller and Root Hub Class Drivers ............................................................ 365 20.3.1 VxBus Driver Methods ..................................................................................... 365 20.3.2 Header Files ....................................................................................................... 365 20.3.3 BSP Configuration ............................................................................................. 366 20.3.4 Available Utility Routines ................................................................................ 367 20.3.5 Initialization ....................................................................................................... 367 20.3.6 Debugging .......................................................................................................... 368 21 Other Driver Classes .................................................................................. 371 21.1 Introduction ...................................................................................................................... 371 21.2 Overview ........................................................................................................................... 371 21.3 VxBus Driver Methods ................................................................................................... 372 21.4 Header Files ...................................................................................................................... 373 21.5 BSP Configuration .......................................................................................................... 373 21.6 Available Utility Routines ............................................................................................. 373 21.7 Initialization ..................................................................................................................... 373 21.8 Debugging ........................................................................................................................ 374 PART III: DEVICE DRIVER PORTING 22 Legacy Drivers and Migration ................................................................... 377 22.1 Migration Overview ....................................................................................................... 377 22.2 Legacy Driver Overview ................................................................................................ 377 23 Migrating to VxBus ..................................................................................... 379 23.1 Overview ........................................................................................................................... 379 23.2 Available Resources ........................................................................................................ 379 Template Drivers ............................................................................................... 379 23.3 Porting an Existing VxWorks Driver to VxBus .......................................................... 380 23.3.1 Verifying Your Hardware and Driver Code .................................................. 380 23.3.2 Creating the VxBus Infrastructure ........
MSL 即 Microsoft Library 是 DOS 版的 "WinHelp",也就是现代版 Help Viewer 的始祖。 安装目录下有个 ini 文件,用来指定图书的路径,它即是目录。 文件来源自 http://wdl2.winworldpc.com/Abandonware%20SDKs/Microsoft Programmer's Library 1.3.7z Microsoft Programmer's Library 1.3.iso 这就是 DOS 版的 MSDN!使用 DOSBOX 就可以运行此库。此库含一大古董级MS官方编程参考材料,主要针对 Windows 3.0 平台,真可谓之应用尽有: MS Windows 3.0 SDK Guide to Programming MS Windows 3.0 SDK Install. & Update Guide MS Windows 3.0 SDK Programmer's Reference Vol. 1 MS Windows 3.0 SDK Programmer's Reference Vol. 2 MS Windows 3.0 SDK Tools MS Windows 3.0 SDK Articles All MS Windows 3.0 SDK Manuals MS Windows 3.0 DDK Install. & Update Guide MS Windows 3.0 DDK Adaptation Guide MS Windows 3.0 DDK Virtual Device Adapt. Guide MS Windows 3.0 DDK Printer & Font Kit All MS Windows 3.0 DDK Manuals MS Online User's Guide Programming MS Windows MS Windows Sample Code MS KnowledgeBase - MS Windows 以及 Options => Library 菜单下提供的 9 个重要的参考资料,其中就有 C 和 MASM 这些重要的参考资料。这些是已安装的目录部分,鉴于 MASM 的重要性,特将其添加到压缩包内,免CD运行: Windows References OS/S References Network References MS-DOS References MS Systems Journal Hardware References C References MASM References BASIC References Pascal References FORTUAN References 其中 C References 和 MASM References 包含: Installing and Using MS MASM 6.0 MS MASM 6.0 Reference MS MASM 6.0 Programmer's Guide MS MASM 6.0 White Paper QuickAssembler 2.01 Programmer's Guide MS Mixed-Language Programming Guide CodeView & Utilities User's Guide MS Editor User's Guide MS OnLine User's Guide MASM Sample Code MS KnowledgeBase - MASM MS C 6.0 Advanced Programming Techniques MS C 6.0 Installing and Using the P.D.S. MS C 6.0 Reference MS C 6.0 Run-Time Library Reference MS C 6.0 Developer's Toolkit Reference QuickC 2.5 Tool Kit QuickC 2.5 C for Yourself QuickC 2.5 Up and Running QuickC 2.5 Update MS Professional
这段代码主要是根据用户选择的 SVM 算法类型,建立相应的 SVM 模型,并使用训练集数据进行训练,并对训练集和测试集进行预测。 首先,根据选择的 SVM 类型,判断需要使用哪个 SVM 模型进行训练。如果选择了线性 SVM(choice=1),则使用 svm_bi.SVM(svm_bi.linear_kernel) 建立模型;如果选择了非线性 SVM(choice=2),则可以选择使用 svm_bi.SVM(svm_bi.gaussian_kernel) 或 svm_bi.SVM(svm_bi.sigmoid_kernel) 建立模型;如果选择了多分类 SVM(choice=3),则使用 svm_multi.SVM_Multi() 建立模型;如果选择了 sklearn SVM(choice=4),则使用 sklearn.svm.SVC(kernel='sigmoid') 建立模型。 然后,根据选择的 SVM 模型类型,使用训练集数据进行训练,并对训练集和测试集进行预测。如果选择的是 sklearn SVM 模型,则使用 model4.fit(x1_x2_train, t_train) 对模型进行训练,并使用 model4.predict(x1_x2_train) 和 model4.predict(x1_x2_test) 对训练集和测试集进行预测;如果选择的是 SVM(linear、gaussian 或 sigmoid kernel)模型,则使用 model.train(data_train) 对模型进行训练,并使用 model(x1_x2_train) 和 model(x1_x2_test) 对训练集和测试集进行预测。如果选择的是多分类 SVM 模型,则使用 model3.train(data_train) 对模型进行训练,并使用 model3(x1_x2_train) 和 model3(x1_x2_test) 对训练集和测试集进行预测。 最后,根据选择的 SVM 模型类型,返回预测结果 pred_train 和 pred_test,以及支持向量 support_vec。如果选择的是 SVM(linear、gaussian 或 sigmoid kernel)模型或多分类 SVM 模型,返回的支持向量 support_vec 非空,否则为空。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值