Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
25 views13 pages

Intelligence Lab

The document provides installation instructions and guidance on creating a classifier application using the IntelligenceLab 7.5 software, including the setup of components in Delphi and C++ Builder. It details the use of the TSLCRealBuffer class for data handling and basic operations, along with code examples for implementing a Naive Bayes classifier. The document also outlines how to visualize the classification results on a bitmap canvas.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views13 pages

Intelligence Lab

The document provides installation instructions and guidance on creating a classifier application using the IntelligenceLab 7.5 software, including the setup of components in Delphi and C++ Builder. It details the use of the TSLCRealBuffer class for data handling and basic operations, along with code examples for implementing a Naive Bayes classifier. The document also outlines how to visualize the classification results on a bitmap canvas.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

www.openwire.

org
www.mitov.com

Copyright Boian Mitov 2004 - 2014


Index
Installation...................................................................................................................................................3
Where is InstrumentLab?............................................................................................................................3
Creating classifier application.....................................................................................................................3
Using the TSLCRealBuffer in C++ Builder and Visual C++...................................................................10
Distributing your application...................................................................................................................13
Deploying your 32 bit application with the IPP DLLs.............................................................................13
Deploying your 64 bit application............................................................................................................13

November 13, 2014 -2- IntelligenceLab 7.5


Installation
InstrumentLab comes with an installation program. Just start the installation by double-
clicking on the Setup.exe file and follow the installation instructions.

Where is InstrumentLab?
After the installation, start your Delphi or C++ Builder.
Scroll the Component Palette, until you see the last three tabs:

If the installation was successful, they should be named “Signal Lab”, “UserLab”, and
“InstrumentLab”. On the SignalLab palette you will have only a subset of the SignalLab
components. SignalLab is a separated product, and will not be shipped as full with
InstrumentLab.

Only the following components of SignalLab will be available:

Creating classifier application


From the Delphi/C++Builder menu select | File | New | Application |.

An empty form will appear on the screen.

November 13, 2014 -3- IntelligenceLab 7.5


From the “Component Palette” select the “Standard” tab:

From the tab select and drop on the form a TButton component.
- TButton

From the “Component Palette” select the “Additional” tab:

select and drop on the form a TImage:


- TImage

From the “Component Palette” select the “Intelligence Lab” tab:

From the tab select and drop on the form a TILNaiveBayes component.
- TILNaiveBayes

Select the Button1 and in the “Object Inspector” change the Caption of the Button1 to
“Run”:

Double-click on the Button1:

November 13, 2014 -4- IntelligenceLab 7.5


If you are using Delphi add the highlighted code to the Button1Click event in the
Unit1.pas file:
procedure TForm1.Button1Click(Sender: Tobject);
var
ATrainingData : ISLRealMatrixBuffer;
AResposes : ISLRealBuffer;
ATestData : ISLRealBuffer;
I : Integer;
J : Integer;
pt : Tpoint;

begin
ATrainingData := TSLRealMatrixBuffer.CreateSize( 150, 2 );
AResposes := TSLRealBuffer.CreateSize( 150 );

Image1.Picture.Bitmap.Width := 500;
Image1.Picture.Bitmap.Height := 500;

for I := 0 to 50 - 1 do
begin
AResposes[ I ] := 1;
ATrainingData[ I, 0 ] := Random( 250 );
ATrainingData[ I, 1 ] := Random( 200 );
end;

for I := 50 to 100 - 1 do
begin
AResposes[ I ] := 2;

November 13, 2014 -5- IntelligenceLab 7.5


ATrainingData[ I, 0 ] := 300 + Random( 199 );
ATrainingData[ I, 1 ] := 100 + Random( 200 );
end;

for I := 100 to 150 - 1 do


begin
AResposes[ I ] := 3;
ATrainingData[ I, 0 ] := Random( 300 );
ATrainingData[ I, 1 ] := 300 + Random( 199 );
end;

ILNaiveBayes1.Train( ATrainingData, AResposes, False );

ATestData := TSLRealBuffer.CreateSize( 2 );
for I := 0 to 500 - 1 do
for J := 0 to 500 - 1 do
begin
ATestData[ 1 ] := I;
ATestData[ 0 ] := J;
ILNaiveBayes1.Predict( ATestData );
end;

// display the original training samples


for i := 0 to 150 div 3 - 1 do
begin
pt.x := Round( ATrainingData[ I, 0 ]);
pt.y := Round( ATrainingData[ I, 1 ]);

Image1.Picture.Bitmap.Canvas.Pen.Color := clRed;
Image1.Picture.Bitmap.Canvas.Brush.Color := clRed;
Image1.Picture.Bitmap.Canvas.Ellipse( pt.x - 2, pt.y - 2, pt.x +
2, pt.y + 2 );

pt.x := Round( ATrainingData[ I + 50, 0 ]);


pt.y := Round( ATrainingData[ I + 50, 1 ]);

Image1.Picture.Bitmap.Canvas.Pen.Color := clLime;
Image1.Picture.Bitmap.Canvas.Brush.Color := clLime;
Image1.Picture.Bitmap.Canvas.Ellipse( pt.x - 2, pt.y - 2, pt.x +
2, pt.y + 2 );

pt.x := Round( ATrainingData[ I + 100, 0 ]);


pt.y := Round( ATrainingData[ I + 100, 1 ]);

Image1.Picture.Bitmap.Canvas.Pen.Color := clBlue;
Image1.Picture.Bitmap.Canvas.Brush.Color := clBlue;
Image1.Picture.Bitmap.Canvas.Ellipse( pt.x - 2, pt.y - 2, pt.x +
2, pt.y + 2 );
end;

end;

November 13, 2014 -6- IntelligenceLab 7.5


If you are using C++ Builder add the highlighted code to the Button1Click event in
the Unit1.cpp file:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TSLCRealMatrixBuffer ATrainingData( 150, 2 );
TSLCRealBuffer AResposes( 150 );

Image1->Picture->Bitmap->Width = 500;
Image1->Picture->Bitmap->Height = 500;

for( int i = 0; i < 50; i ++ )


{
AResposes[ i ] = 1;
ATrainingData[ i ][ 0 ] = rand() % 250;
ATrainingData[ i ][ 1 ] = rand() % 200;
}

for( int i = 50; i < 100; i ++ )


{
AResposes[ i ] = 2;
ATrainingData[ i ][ 0 ] = 300 + rand() % 200;
ATrainingData[ i ][ 1 ] = 100 + rand() % 200;
}

for( int i = 100; i < 150; i ++ )


{
AResposes[ i ] = 3;
ATrainingData[ i ][ 0 ] = rand() % 300;
ATrainingData[ i ][ 1 ] = 300 + rand() % 200;
}

ILNaiveBayes1->Train( ATrainingData, AResposes, false );

TSLCRealBuffer ATestData( 2 );

for( int i = 0; i < 500; i ++ )


for( int j = 0; j < 500; j ++ )
{
ATestData[ 1 ] = i;
ATestData[ 0 ] = j;
ILNaiveBayes1->Predict( ATestData );
}

// display the original training samples


for( int i = 0; i < 150 / 3; i ++ )
{
TPoint pt;
pt.x = ATrainingData[ i ][ 0 ] + 0.5;
pt.y = ATrainingData[ i ][ 1 ] + 0.5;

Image1->Picture->Bitmap->Canvas->Pen->Color = clRed;
Image1->Picture->Bitmap->Canvas->Brush->Color = clRed;
Image1->Picture->Bitmap->Canvas->Ellipse( pt.x - 2, pt.y - 2,
pt.x + 2, pt.y + 2 );

pt.x = ATrainingData[ i + 50 ][ 0 ] + 0.5;

November 13, 2014 -7- IntelligenceLab 7.5


pt.y = ATrainingData[ i + 50 ][ 1 ] + 0.5;

Image1->Picture->Bitmap->Canvas->Pen->Color = clLime;
Image1->Picture->Bitmap->Canvas->Brush->Color = clLime;
Image1->Picture->Bitmap->Canvas->Ellipse( pt.x - 2, pt.y - 2,
pt.x + 2, pt.y + 2 );

pt.x = ATrainingData[ i + 100 ][ 0 ] + 0.5;


pt.y = ATrainingData[ i + 100 ][ 1 ] + 0.5;

Image1->Picture->Bitmap->Canvas->Pen->Color = clBlue;
Image1->Picture->Bitmap->Canvas->Brush->Color = clBlue;
Image1->Picture->Bitmap->Canvas->Ellipse( pt.x - 2, pt.y - 2,
pt.x + 2, pt.y + 2 );
}

Select the ILNaiveBayes1 on the form:

In the “Object Inspector” select the events tab and double click on the OnResult event:

November 13, 2014 -8- IntelligenceLab 7.5


If you are using Delphi add the highlighted code to the ILNaiveBayes1Result event
in the Unit1.pas file:
procedure TForm1.ILNaiveBayes1Result(ASender: TObject; AFeatures:
ISLRealBuffer; AResult: TILNaiveBayesResult);
begin
case( Round( AResult.ResultClass )) of
1 : Image1.Picture.Bitmap.Canvas.Pixels[ Round( AFeatures[ 0 ] ),
Round( AFeatures[ 1 ] ) ] := RGB( 127, 0, 0 );
2 : Image1.Picture.Bitmap.Canvas.Pixels[ Round( AFeatures[ 0 ] ),
Round( AFeatures[ 1 ] ) ] := RGB( 0, 127, 0 );
3 : Image1.Picture.Bitmap.Canvas.Pixels[ Round( AFeatures[ 0 ] ),
Round( AFeatures[ 1 ] ) ] := RGB( 0, 0, 127 );
end;

end;

If you are using C++ Builder add the highlighted code to the ILNaiveBayes1Result
event in the Unit1.cpp file:
void __fastcall TForm1::ILNaiveBayes1Result(TObject *ASender, ISLRe-
alBuffer *AFeatures, TILNaiveBayesResult *AResult)
{
switch( (int)( AResult->ResultClass + 0.5 ))
{
case 1 : Image1->Picture->Bitmap->Canvas->Pixels[ AFeatures-
>Items[ 0 ] ][ AFeatures->Items[ 1 ] ] = (TColor)RGB( 127, 0, 0 );
break;
case 2 : Image1->Picture->Bitmap->Canvas->Pixels[ AFeatures-
>Items[ 0 ] ][ AFeatures->Items[ 1 ] ] = (TColor)RGB( 0, 127, 0 );
break;
case 3 : Image1->Picture->Bitmap->Canvas->Pixels[ AFeatures-
>Items[ 0 ] ][ AFeatures->Items[ 1 ] ] = (TColor)RGB( 0, 0, 127 );
break;
}
}

Compile and run the application.

November 13, 2014 -9- IntelligenceLab 7.5


Click on the “Run” button.
You should see the pixels classified in 3 groups:

You have just learned how to use IntelligenceLab classifier.

Using the TSLCRealBuffer in C++ Builder and Visual C++


The C++ Builder version of the library comes with a powerful data buffer class, called
TSLCRealBuffer.
The TSLCRealBuffer is capable of performing basic math operations over the data as
well as some basic signal processing functions. The data buffer also uses copy on write
algorithm improving dramatically the application performance.
The TSLCRealBuffer is an essential part of the SignalLab generators and filters, but it
can be used independently in your code.
You have seen already some examples of using TSLCRealBuffer in the previous
chapters. Here we will go into a little bit more details about how TSLCRealBuffer can be
used.
In order to use TSLCRealBuffer you must include SLCRealBuffer.h directly or indirectly
(trough another include file):
#include <SLCRealBuffer.h>

Once the file is included you can declare a buffer:


Here is how you can declare a 1024 samples buffer:
TSLCRealBuffer Buffer( 1024 );

November 13, 2014 -10- IntelligenceLab 7.5


Version 4.0 and up does not require the usage of data access objects. The data objects are
now obsolete and have been removed from the library.

You can obtain the current size of a buffer by calling the GetSize method:
Int ASize = Buffer.GetSize(); // Obtains the size of the buffers

You can resize (change the size of) a buffer:


Buffer.Resize( 2048 ); // Changes the size to 2048

You can set all of the elements (samples) of the buffer to a value:
Buffer.Set( 30 ); // Sets all of the elements to 30.

You can access individual elements (samples) in the buffer:


Buffer [ 5 ] = 3.7; // Sets the fifth elment to 3.7

Double AValue = Buffer [ 5 ]; // Assigns the fifth element to a vari-


able

You can obtain read, write or modify pointer to the buffer data:
const double *data = Buffer.Read() // Starts reading only
double *data = Buffer.Write()// Starts writing only
double *data = Buffer.Modify()// Starts reading and writing

Sometimes you need a very fast way of accessing the buffer items. In this case, you can
obtain a direct pointer to the internal data buffer. The buffer is based on copy on write
technology for high performance. The mechanism is encapsulated inside the buffer, so
when working with individual items you don’t have to worry about it. If you want to
access the internal buffer for speed however, you will have to specify up front if you are
planning to modify the data or just to read it. The TSLCRealBuffer has 3 methods for
accessing the data Read(), Write(), and Modify (). Read() will return a constant pointer to
the data. You should use this method when you don’t intend to modify the data and just
need to read it. If you want to create new data from scratch and don’t intend to preserve
the existing buffer data, use Write(). If you need to modify the data you should use
Modify (). Modify () returns a non constant pointer to the data, but often works slower
than Read() or Write(). Here are some examples:
const double *pcData = Buffer.Read(); // read only data pointer

double Value = *pcData; // OK!


*pcData = 3.5; // Wrong!

double *pData = Buffer.Write(); // generic data pointer

double Value = *pData; // OK!


*pData = 3.5; // OK!

You can assign one buffer to another:


Buffer1 = Buffer2;

November 13, 2014 -11- IntelligenceLab 7.5


You can do basic buffer arithmetic:
TSLCRealBuffer Buffer1( 1024 );
TSLCRealBuffer Buffer2( 1024 );
TSLCRealBuffer Buffer3( 1024 );

Buffer1.Set( 20.5 );
Buffer2.Set( 5 );

Buffer3 = Buffer1 + Buffer2;


Buffer3 = Buffer1 - Buffer2;
Buffer3 = Buffer1 * Buffer2;
Buffer3 = Buffer1 / Buffer2;

In this example the elements of the Buffer3 will be result of the operation ( +,-,* or / )
between the corresponding elements of Buffer1 and Buffer2.
You can add, subtract, multiply or divide by constant:
// Adds 4.5 to each element of the buffer
Buffer1 = Buffer2 + 4.5;

// Subtracts 4.5 to each element of the buffer


Buffer1 = Buffer2 - 4.5;

// Multiplies the elements by 4.5


Buffer1 = Buffer2 * 4.5;

// Divides the elements by 4.5


Buffer1 = Buffer2 / 4.5;

You can do “in place” operations as well:


Buffer1 += Buffer2;
Buffer1 += 4.5;

Buffer1 -= Buffer2;
Buffer1 -= 4.5;

Buffer1 *= Buffer2;
Buffer1 *= 4.5;

Buffer1 /= Buffer2;
Buffer1 /= 4.5;

Those are just some of the basic buffer operations provided by SignalLab.
If you are planning to use some of the more advanced features of TSLCRealBuffer please
refer to the online help.
SignalLab also provides TSLCComplexBuffer and TSLCIntegerBuffer. They work
similar to the TSLCRealBuffer but are intended to be used with Complex and Integer
data. For more information on TSLCComplexBuffer and TSLCIntegerBuffer please refer
to the online help.

November 13, 2014 -12- IntelligenceLab 7.5


Distributing your application
Once you have finished the development of your application you most likely will need to
distribute it to other systems. In order for some IntelligenceLab built application to work,
you will have to include a set of DLL files together with the distribution. The necessary
files can be found under the [install path]\DLL directory( [install path] is the location
where the IntelligenceLab was installed). You can distribute them to the
[Windows]\System32 ([Windows]\SysWOW64 in 64 bit Windows) directory, or to the
distribution directory of your application( [Windows] is the Windows directory - usually
C:\WINNT or C:\WINDOWS ).
Not all of the components in the library require additional DLLs. Please check if the
DLLs are needed by the application before including them in the install.

Deploying your 32 bit application with the IPP DLLs


The compiled applications can be deployed to the target system by simply copying the
executable. The application will work, however the performance can be improved by also
copying the Intel IPP DLLs provided with the library.
The DLLs are under the [install path]\LabPacks\IppDLL\Win32 directory( [install path]
is the location where the library was installed).
In 32 bit Windows to deploy IPP, copy the files to the [Windows]\System32 directory on
the target system.
In 64 bit Windows to deploy IPP, copy the files to the [Windows]\SysWOW64 directory
on the target system.
[Windows] is the Windows directory - usually C:\WINNT or C:\WINDOWS
This will improve the performance of your application on the target system.

Deploying your 64 bit application


The current version of the library requires when deploying 64 bit applications, the Intel
IPP DLLs to be deployed as well.

The DLLs are under the [install path]\LabPacks\IppDLL\Win64 directory( [install path]
is the location where the library was installed).

To deploy IPP, copy the files to the [Windows]\System32 directory on the target system.
[Windows] is the Windows directory - usually C:\WINNT or C:\WINDOWS
This will improve the performance of your application on the target system.

November 13, 2014 -13- IntelligenceLab 7.5

You might also like