Accord in C++/cli

306 views
Skip to first unread message

sp

unread,
Aug 17, 2012, 5:37:48 AM8/17/12
to accor...@googlegroups.com
Hi all,

I'm trying to use Accord.Net in c++/cli.

Did anyone try it ?

I have translated the simple example depicted in the getting started page into c++/cli code. (see the original program written in c# here: http://code.google.com/p/accord/wiki/GettingStarted)

It all seems okay, however I'm getting some annoying error message which saying: cannot convert parameter 2 from 'cli::array<Type,dimension> ^' to 'cli::array<Type,dimension> ^'

please see also the attached screen-shots.

I just don't get it since it's the same parameter...

Any idea ?

thanks in advanced!
[Please Excuse My English.:)]

ScreenShot655.jpg
ScreenShot657.jpg

César

unread,
Aug 17, 2012, 8:42:02 AM8/17/12
to accor...@googlegroups.com
Hi there,
 
I suspect you are getting this error because the SequentialMinimalOptimization constructor expects an int[] array as the second parameter. Please try changing the type of the _outputs array from cli::array<double,1> to cli::array<int,1>.
 
Please let me know if it works!
 
Best regards,
Cesar

sp

unread,
Aug 17, 2012, 8:54:01 AM8/17/12
to accor...@googlegroups.com
Cesar, thanks of your answer.

Unfortunately this didn't solve the problem, please see the attached:
(BTW, the input and not the output is the second parameter)
ScreenShot661.jpg
ScreenShot660.jpg

César

unread,
Aug 17, 2012, 12:26:58 PM8/17/12
to accor...@googlegroups.com
Hi,
 
Here is a working example. The problem was that the second parameter was expected to be a jagged array; completely overlooked that. Hope it helps this time.
 
Best regards,
Cesar
 
 
// cpp_test.cpp : main project file.

#include "stdafx.h"

using namespace cli;
using namespace System;
using namespace Accord::MachineLearning::VectorMachines;
using namespace Accord::MachineLearning::VectorMachines::Learning;
using namespace Accord::Math;
using namespace Accord::Statistics::Kernels;

int main(array<System::String ^> ^args)
{
   
KernelSupportVectorMachine^ ksvm = gcnew KernelSupportVectorMachine(gcnew Gaussian(), 2);

   
// Example XOR problem
    array
<array<double>^>^ inputs =
   
{
        gcnew array
<double> { 0, 0 }, // 0 xor 0: 1 (label +1)
        gcnew array
<double> { 0, 1 }, // 0 xor 1: 0 (label -1)
        gcnew array
<double> { 1, 0 }, // 1 xor 0: 0 (label -1)
        gcnew array
<double> { 1, 1 }  // 1 xor 1: 1 (label +1)
   
};

   
// Dichotomy SVM outputs should be given as [-1;+1]
    array
<int>^ outputs =
   
{
       
1, -1, -1, 1
   
};

   
SequentialMinimalOptimization^ smo = gcnew SequentialMinimalOptimization(ksvm, inputs, outputs);

   
double error = smo->Run();

   
return 0;
}


 

sp

unread,
Aug 17, 2012, 3:24:03 PM8/17/12
to accor...@googlegroups.com
Working indeed!

thank you very much!
Reply all
Reply to author
Forward
0 new messages