<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to compile ANN arduino code to mbed compiler using nRF51822</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/33397/how-to-compile-ann-arduino-code-to-mbed-compiler-using-nrf51822</link><description>Hello world.. 
 please solve my problem.. 
 I wanna to implement this arduino code.. 
 
 with this output.. 
 
 and convert to this mbed compiler, like this one.. 
 
 but there are several message problem like this one, 
 
 so please help me soon, this</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 16 Apr 2018 14:43:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/33397/how-to-compile-ann-arduino-code-to-mbed-compiler-using-nrf51822" /><item><title>RE: How to compile ANN arduino code to mbed compiler using nRF51822</title><link>https://devzone.nordicsemi.com/thread/128511?ContentTypeID=1</link><pubDate>Mon, 16 Apr 2018 14:43:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5de283d3-8d4a-4bda-84e2-8ea3644ae1f6</guid><dc:creator>mantap</dc:creator><description>&lt;p&gt;yah.. I know it, if your kindness, perhaps u can help me..&lt;br /&gt;but there are several progress that I using KNN for nRF51822..&lt;br /&gt;here there are...&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/33411/knn-using-c-for-nrf51822-any-suggestion-for-this-output" rel="noopener noreferrer" target="_blank"&gt;#KNNask1&lt;/a&gt; and&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/33396/how-to-convert-arduino-code-to-mbed-online-compiler-using-nrf51822" rel="noopener noreferrer" target="_blank"&gt;#KNNask2&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;please if you kind to help me w/ mbed compiler&lt;br /&gt;because I think code using c++ program good for nRF51 that using mbed compiler..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compile ANN arduino code to mbed compiler using nRF51822</title><link>https://devzone.nordicsemi.com/thread/128509?ContentTypeID=1</link><pubDate>Mon, 16 Apr 2018 14:40:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b0cc0427-f976-4114-88ea-3e9d1f417543</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;Did you know there are &lt;a href="https://github.com/sandeepmistry/arduino-nRF5" rel="noopener noreferrer" target="_blank"&gt;Arduino Libs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;available for NRF5x devices? MBED uses totally different syntax for many things, you&amp;#39;d need to understand the code first in order to be able to translate it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compile ANN arduino code to mbed compiler using nRF51822</title><link>https://devzone.nordicsemi.com/thread/128339?ContentTypeID=1</link><pubDate>Sat, 14 Apr 2018 23:02:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b30dd445-5f85-4866-94cc-f65dc9495969</guid><dc:creator>mantap</dc:creator><description>&lt;p&gt;thanks for answering..&lt;/p&gt;
&lt;p&gt;and how about this problem that show error message..&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Error: Identifier &amp;quot;analogRead&amp;quot; is undefined in &amp;quot;main.cpp&amp;quot;, Line: 64, Col: 15
Error: Identifier &amp;quot;randomSeed&amp;quot; is undefined in &amp;quot;main.cpp&amp;quot;, Line: 64, Col: 4
Error: This declaration has no storage class or type specifier in &amp;quot;main.cpp&amp;quot;, Line: 95, Col: 6
Error: Variable &amp;quot;pc&amp;quot; has already been defined in &amp;quot;main.cpp&amp;quot;, Line: 95, Col: 6
Error: Explicit type is missing (&amp;quot;int&amp;quot; assumed) in &amp;quot;main.cpp&amp;quot;, Line: 96, Col: 6
Error: Expected a declaration in &amp;quot;main.cpp&amp;quot;, Line: 98, Col: 6
Error: Expected a declaration in &amp;quot;main.cpp&amp;quot;, Line: 177, Col: 6
Error: This declaration has no storage class or type specifier in &amp;quot;main.cpp&amp;quot;, Line: 199, Col: 6
...
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;this is my mbed code..&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;math.h&amp;gt;
#include &amp;lt;mbed.h&amp;gt;
Serial pc(USBTX, USBRX);
const int PatternCount = 10;
const int InputNodes = 7;
const int HiddenNodes = 8;
const int OutputNodes = 4;
const float LearningRate = 0.3;
const float Momentum = 0.9;
const float InitialWeightMax = 0.5;
const float Success = 0.0004;

//const byte Input[PatternCount][InputNodes] =
const char Input[PatternCount][InputNodes] = 
{
  { 1, 1, 1, 1, 1, 1, 0 },  // 0
  { 0, 1, 1, 0, 0, 0, 0 },  // 1
  { 1, 1, 0, 1, 1, 0, 1 },  // 2
  { 1, 1, 1, 1, 0, 0, 1 },  // 3
  { 0, 1, 1, 0, 0, 1, 1 },  // 4
  { 1, 0, 1, 1, 0, 1, 1 },  // 5
  { 0, 0, 1, 1, 1, 1, 1 },  // 6
  { 1, 1, 1, 0, 0, 0, 0 },  // 7 
  { 1, 1, 1, 1, 1, 1, 1 },  // 8
  { 1, 1, 1, 0, 0, 1, 1 }   // 9
}; 

//const byte Target[PatternCount][OutputNodes] =
const char Target[PatternCount][OutputNodes] = 
{
  { 0, 0, 0, 0 },  
  { 0, 0, 0, 1 }, 
  { 0, 0, 1, 0 }, 
  { 0, 0, 1, 1 }, 
  { 0, 1, 0, 0 }, 
  { 0, 1, 0, 1 }, 
  { 0, 1, 1, 0 }, 
  { 0, 1, 1, 1 }, 
  { 1, 0, 0, 0 }, 
  { 1, 0, 0, 1 } 
};

int i, j, p, q, r;
int ReportEvery1000;
int RandomizedIndex[PatternCount];
long  TrainingCycle;
float Rando;
float Error;
float Accum;


float Hidden[HiddenNodes];
float Output[OutputNodes];
float HiddenWeights[InputNodes+1][HiddenNodes];
float OutputWeights[HiddenNodes+1][OutputNodes];
float HiddenDelta[HiddenNodes];
float OutputDelta[OutputNodes];
float ChangeHiddenWeights[InputNodes+1][HiddenNodes];
float ChangeOutputWeights[HiddenNodes+1][OutputNodes];

int main()
{
  pc.baud(9600);
  randomSeed(analogRead(3));
  ReportEvery1000 = 1;
  for( p = 0 ; p &amp;lt; PatternCount ; p++ ) 
  {    
    RandomizedIndex[p] = p ;
  }
  
  void loop ()
  {



    for( i = 0 ; i &amp;lt; HiddenNodes ; i++ ) 
    {    
        for( j = 0 ; j &amp;lt;= InputNodes ; j++ ) 
        { 
            ChangeHiddenWeights[j][i] = 0.0 ;
            Rando = float(random(100))/100;
            HiddenWeights[j][i] = 2.0 * ( Rando - 0.5 ) * InitialWeightMax ;
        }
    }

    for( i = 0 ; i &amp;lt; OutputNodes ; i ++ ) 
    {    
        for( j = 0 ; j &amp;lt;= HiddenNodes ; j++ ) 
        {
            ChangeOutputWeights[j][i] = 0.0 ;  
            Rando = float(random(100))/100;        
            OutputWeights[j][i] = 2.0 * ( Rando - 0.5 ) * InitialWeightMax ;
        }
    }
    pc.printf(&amp;quot;Initial/Untrained Outputs: \n&amp;quot;);
    toTerminal();

    for( TrainingCycle = 1 ; TrainingCycle &amp;lt; 2147483647 ; TrainingCycle++) 
    {    

        for( p = 0 ; p &amp;lt; PatternCount ; p++) 
        {
            q = random(PatternCount);
            r = RandomizedIndex[p] ; 
            RandomizedIndex[p] = RandomizedIndex[q] ; 
            RandomizedIndex[q] = r ;
        }
        Error = 0.0 ;

        for( q = 0 ; q &amp;lt; PatternCount ; q++ ) 
        {    
            p = RandomizedIndex[q];

            for( i = 0 ; i &amp;lt; HiddenNodes ; i++ ) 
            {    
                Accum = HiddenWeights[InputNodes][i] ;
                for( j = 0 ; j &amp;lt; InputNodes ; j++ ) 
                {
                    Accum += Input[p][j] * HiddenWeights[j][i] ;
                }
                Hidden[i] = 1.0/(1.0 + exp(-Accum)) ;
            }


            for( i = 0 ; i &amp;lt; OutputNodes ; i++ ) 
            {    
                Accum = OutputWeights[HiddenNodes][i] ;
                for( j = 0 ; j &amp;lt; HiddenNodes ; j++ ) 
                {
                    Accum += Hidden[j] * OutputWeights[j][i] ;
                }
                Output[i] = 1.0/(1.0 + exp(-Accum)) ;   
                OutputDelta[i] = (Target[p][i] - Output[i]) * Output[i] * (1.0 - Output[i]) ;   
                Error += 0.5 * (Target[p][i] - Output[i]) * (Target[p][i] - Output[i]) ;
            }


            for( i = 0 ; i &amp;lt; HiddenNodes ; i++ ) 
            {    
                Accum = 0.0 ;
                for( j = 0 ; j &amp;lt; OutputNodes ; j++ ) 
                {
                    Accum += OutputWeights[i][j] * OutputDelta[j] ;
                }
                HiddenDelta[i] = Accum * Hidden[i] * (1.0 - Hidden[i]) ;
            }




            for( i = 0 ; i &amp;lt; HiddenNodes ; i++ ) 
            {     
                ChangeHiddenWeights[InputNodes][i] = LearningRate * HiddenDelta[i] + Momentum * ChangeHiddenWeights[InputNodes][i] ;
                HiddenWeights[InputNodes][i] += ChangeHiddenWeights[InputNodes][i] ;
                for( j = 0 ; j &amp;lt; InputNodes ; j++ ) 
                { 
                    ChangeHiddenWeights[j][i] = LearningRate * Input[p][j] * HiddenDelta[i] + Momentum * ChangeHiddenWeights[j][i];
                    HiddenWeights[j][i] += ChangeHiddenWeights[j][i] ;
                }
            }


            for( i = 0 ; i &amp;lt; OutputNodes ; i ++ ) 
            {    
                ChangeOutputWeights[HiddenNodes][i] = LearningRate * OutputDelta[i] + Momentum * ChangeOutputWeights[HiddenNodes][i] ;
                OutputWeights[HiddenNodes][i] += ChangeOutputWeights[HiddenNodes][i] ;
                for( j = 0 ; j &amp;lt; HiddenNodes ; j++ ) 
                {
                    ChangeOutputWeights[j][i] = LearningRate * Hidden[j] * OutputDelta[i] + Momentum * ChangeOutputWeights[j][i] ;
                    OutputWeights[j][i] += ChangeOutputWeights[j][i] ;
                }
            }
     }


    ReportEvery1000 = ReportEvery1000 - 1;
    if (ReportEvery1000 == 0)
    { 
      pc.printf (&amp;quot;TrainingCycle: &amp;quot;);
      pc.printf (&amp;quot;%i&amp;quot;,(int16_t)TrainingCycle);
      pc.printf (&amp;quot;  Error = &amp;quot;);
      pc.printf (&amp;quot;%i\n&amp;quot;,(int16_t)Error, 5);

      toTerminal();

      if (TrainingCycle==1)
      {
        ReportEvery1000 = 999;
      }
        else
      {
        ReportEvery1000 = 1000;
      }
    }    

    if( Error &amp;lt; Success ) break ;  
  } 
    pc.printf (&amp;quot;TrainingCycle: &amp;quot;);
    pc.printf (&amp;quot;%i&amp;quot;,(int16_t)TrainingCycle);
    pc.printf (&amp;quot;  Error = &amp;quot;);
    pc.printf (&amp;quot;%i\n&amp;quot;,(int16_t)Error, 5);

    toTerminal();

    pc.printf (&amp;quot;Training Set Solved!\n&amp;quot;);
    pc.printf (&amp;quot;--------\n&amp;quot;);   
    ReportEvery1000 = 1;
    }
}  

void toTerminal()
{

  for( p = 0 ; p &amp;lt; PatternCount ; p++ ) { 
    pc.printf (&amp;quot;  Training Pattern: &amp;quot;);
    pc.printf (&amp;quot;%i\n&amp;quot;,(int16_t)p);      
    pc.printf (&amp;quot;  Input &amp;quot;);
    for( i = 0 ; i &amp;lt; InputNodes ; i++ ) {
      pc.printf (&amp;quot;%i,%i&amp;quot;,(int16_t)Input[p][i],(int16_t)DEC);
      pc.printft (&amp;quot; &amp;quot;);
    }
    pc.printf (&amp;quot;  Target &amp;quot;);
    for( i = 0 ; i &amp;lt; OutputNodes ; i++ ) {
      pc.printf (&amp;quot;%i,%i&amp;quot;,(int16_t)Input[p][i],(int16_t)DEC);
      Serial.print (&amp;quot; &amp;quot;);
    }
/******************************************************************
* Compute hidden layer activations
******************************************************************/

    for( i = 0 ; i &amp;lt; HiddenNodes ; i++ ) {    
      Accum = HiddenWeights[InputNodes][i] ;
      for( j = 0 ; j &amp;lt; InputNodes ; j++ ) {
        Accum += Input[p][j] * HiddenWeights[j][i] ;
      }
      Hidden[i] = 1.0/(1.0 + exp(-Accum)) ;
    }

/******************************************************************
* Compute output layer activations and calculate errors
******************************************************************/

    for( i = 0 ; i &amp;lt; OutputNodes ; i++ ) {    
      Accum = OutputWeights[HiddenNodes][i] ;
      for( j = 0 ; j &amp;lt; HiddenNodes ; j++ ) {
        Accum += Hidden[j] * OutputWeights[j][i] ;
      }
      Output[i] = 1.0/(1.0 + exp(-Accum)) ; 
    }
    pc.printf (&amp;quot;  Output &amp;quot;);
    for( i = 0 ; i &amp;lt; OutputNodes ; i++ ) {       
      pc.printf (&amp;quot;%i&amp;quot;,Output[i], 5);
      pc.printf (&amp;quot; &amp;quot;);
    }
  }


}

&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compile ANN arduino code to mbed compiler using nRF51822</title><link>https://devzone.nordicsemi.com/thread/128329?ContentTypeID=1</link><pubDate>Sat, 14 Apr 2018 11:59:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da9c5e33-e784-4cd2-9daf-5aca62e794b3</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;Take a few beginners lessons for C/C++ or read a book, either language is not self-explanarory.&lt;/p&gt;
&lt;p&gt;Even a C novice should recognize that &amp;quot;byte&amp;quot; is not a known type for the compiler. Try using &amp;quot;char&amp;quot; or &amp;quot;unsigned char&amp;quot;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>