topic
stringlengths
1
63
text
stringlengths
1
577k
Array y NIL
Amigo, Tenes razon con respecto al Next de columna. Asi como pones el ejemplo si funciona, pero fijate que es diferente al mio, ya que uso un vector redimencionado, de ultima si me haces el favor, copia este codigo ( ahora le pongo el next que faltaba) y probalo. Gracias. [code:2a7c5tdh]function main() LOCAL aVector:= {} LOCAL nFila:= 0 LOCAL nColumna:= 0 PUBLIC aMatriz:= {} FOR nFila:= 1 TO 10 aVector:={} ASize( aVector, 4) AAdd( aMatriz, aVector ) NEXT nFila for nFila:= 1 to 10 for nColumna:= 1 to 4 if aMatriz[ nFila ][ nColumna ] == NIL ? "es nil", nFila, nColumna // Renglon A else ? "Fila", nFila, ; "Columna", nColumna,; "valor", aMatriz[ nFila ][ nColumna ] endif nColumna next nFila return ( nil )[/code:2a7c5tdh]
Array y NIL
Probado !!! Asi como lo enviaste, ya salen todos los elementos en NIL !!!! Acerca de lo otro, es igual, puedes cambiar el numero de elementos de cada nivel, segun lo necesites, el detalle seria, si lo vas a definir desde el inicio o sobre la marcha. Te comento, por que yo uso en muchos browses, la informacion desde arrays y en algunos casos desde las dbfs, aplicando arreglos de varios niveles. Saludos
Array y NIL
ok, gracias pibe. No me da a mi, voy a ver que pasa.
ArrayIncrFilter
How can I cancel the filter using ArrayIncrFilter and restore the standard view of xBrowse?
ArrayIncrFilter
Did you try this? [code=fw:1awglq6g]<div class="fw" id="{CB}" style="font-family: monospace;">oBrw:<span style="color: #000000;">ArrayIncrFilter</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">''</span><span style="color: #000000;">&#41;</span></div>[/code:1awglq6g] then try this, [b:1awglq6g]but only for temporary testing[/b:1awglq6g]: [code=fw:1awglq6g]<div class="fw" id="{CB}" style="font-family: monospace;">oBrw:<span style="color: #000000;">lIncrFilter</span>:=.f.</div>[/code:1awglq6g] [quote="ORibeiro":1awglq6g]How can I cancel the filter using ArrayIncrFilter and restore the standard view of xBrowse?[/quote:1awglq6g]
ArrayIncrFilter
I tried it, but it does not work. Do you have other idea?
ArrayIncrFilter
oBrw:Seek( "" ) clears the filter and displays the full array
ArrayIncrFilter
Rao, I tried it but does not work too.
ArrayIncrFilter
You wrote little information. What information are you filtering on the browse? How did you define the browse lines? addRow or SetArray ... if I'm not mistaken, you can not restore the rows because they have been removed (you can easily check this by debugging your system and browse instance). Then you have to reassign with [b:3sl7n1vw]oBrw:setArray(...)[/b:3sl7n1vw] If you filled the browse with [b:3sl7n1vw]addRow[/b:3sl7n1vw] then you should make a copy of [b:3sl7n1vw]oBrw:arrayData[/b:3sl7n1vw] before the filter. In my browse (in another tool), I show normal or just deleted lines, alternate doing reassignments. [quote="ORibeiro":3sl7n1vw] Do you have other idea?[/quote:3sl7n1vw]
ArrayIncrFilter
[quote:10jdi9zz]if I'm not mistaken, you can not restore the rows because they have been removed (you can easily check this by debugging your system and browse instance). Then you have to reassign with oBrw:setArray(...) [/quote:10jdi9zz] XBrowse's incremental filter does not remove any lines. They are all there. User sees only the filtered lines.
ArrayIncrFilter
[quote="ORibeiro":3n10ec9m]Rao, I tried it but does not work too.[/quote:3n10ec9m] This has to work, if I understood your requirement correctly. Here is a sample: [code=fw:3n10ec9m]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #00C800;">function</span> Incfilter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> oDlg, oBrw, oFont<br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> aData<br /><br />&nbsp; &nbsp;USE CUSTOMER<br />&nbsp; &nbsp;aData := FW_DbfToArray<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"FIRST,LAST,CITY"</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;CLOSE CUSTOMER<br /><br />&nbsp; &nbsp;<span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">FONT</span> oFont <span style="color: #0000ff;">NAME</span> <span style="color: #ff0000;">"TAHOMA"</span> <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">0</span>,<span style="color: #000000;">-14</span><br />&nbsp; &nbsp;<span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">DIALOG</span> oDlg <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">700</span>,<span style="color: #000000;">500</span> <span style="color: #0000ff;">PIXEL</span> TRUEPIXEL <span style="color: #0000ff;">FONT</span> oFont<br /><br />&nbsp; &nbsp;@ <span style="color: #000000;">60</span>,<span style="color: #000000;">20</span> <span style="color: #0000ff;">XBROWSE</span> oBrw <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">-20</span>,<span style="color: #000000;">-20</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oDlg ;<br />&nbsp; &nbsp; &nbsp; DATASOURCE aData <span style="color: #0000ff;">AUTOCOLS</span> HEADERS <span style="color: #ff0000;">"First"</span>, <span style="color: #ff0000;">"Last"</span>, <span style="color: #ff0000;">"City"</span> ;<br />&nbsp; &nbsp; &nbsp; CELL LINES NOBORDER AUTOSORT FOOTERS<br /><br />&nbsp; &nbsp;WITH OBJECT oBrw<br />&nbsp; &nbsp; &nbsp; :<span style="color: #000000;">lIncrFilter</span> &nbsp; := .t.<br />&nbsp; &nbsp; &nbsp; <span style="color: #B900B9;">// :lSeekWild &nbsp;:= .t. &nbsp;// optional</span><br />&nbsp; &nbsp; &nbsp; :<span style="color: #000000;">aCols</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">bFooter</span> &nbsp;:= <span style="color: #000000;">&#123;</span> || <span style="color: #ff0000;">"Records : "</span> + Str<span style="color: #000000;">&#40;</span> oBrw:<span style="color: #000000;">nLen</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span><br />&nbsp; &nbsp; &nbsp; <span style="color: #B900B9;">//</span><br />&nbsp; &nbsp; &nbsp; :<span style="color: #000000;">CreateFromCode</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;END<br /><br />&nbsp; &nbsp;@ <span style="color: #000000;">20</span>,<span style="color: #000000;">20</span> <span style="color: #0000ff;">SAY</span> oBrw:<span style="color: #000000;">oSeek</span> <span style="color: #0000ff;">VAR</span> oBrw:<span style="color: #000000;">cSeek</span> <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">150</span>,<span style="color: #000000;">20</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oDlg <span style="color: #0000ff;">COLOR</span> CLR_HRED, CLR_YELLOW <span style="color: #0000ff;">UPDATE</span><br /><br />&nbsp; &nbsp;@ <span style="color: #000000;">10</span>,<span style="color: #000000;">200</span> <span style="color: #0000ff;">BTNBMP</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Clear Filter"</span> <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">200</span>,<span style="color: #000000;">40</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oDlg FLAT ;<br />&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">ACTION</span> <span style="color: #000000;">&#40;</span> oBrw:<span style="color: #000000;">Seek</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">""</span> <span style="color: #000000;">&#41;</span>, oBrw:<span style="color: #000000;">SetFocus</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp;<span style="color: #0000ff;">ACTIVATE</span> <span style="color: #0000ff;">DIALOG</span> oDlg <span style="color: #0000ff;">CENTERED</span><br />&nbsp; &nbsp;<span style="color: #0000ff;">RELEASE</span> <span style="color: #0000ff;">FONT</span> oFont<br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br />&nbsp;</div>[/code:3n10ec9m] Pressing any key incrementally sets filter. Pressing backspace clears the filter. At any stage, clicking the button "clear filter" clears the filter.
ArrayIncrFilter
Rao, What is wrong in this code? [code=fw:1rxybe16]<div class="fw" id="{CB}" style="font-family: monospace;"><br />*********************************************************************************************<br /><span style="color: #00C800;">static</span> <span style="color: #00C800;">function</span> Sample2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #B900B9;">// With ArrayIncFilter()</span><br />*********************************************************************************************<br />   <span style="color: #00C800;">local</span> oDlg, oBrw, oFont, oBold<br />   <span style="color: #00C800;">local</span> n<br />   <span style="color: #00C800;">local</span> aData<br /><br />   USE CUSTOMER <span style="color: #00C800;">NEW</span> SHARED<br />   aData := FW_DbfToArray<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"FIRST,LAST,CITY,HIREDATE,SALARY"</span> <span style="color: #000000;">&#41;</span><br />   CLOSE CUSTOMER<br /><br />   <span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">FONT</span> oFont <span style="color: #0000ff;">NAME</span> <span style="color: #ff0000;">"TAHOMA"</span> <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">0</span>,<span style="color: #000000;">-12</span><br />   <span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">FONT</span> oBold <span style="color: #0000ff;">NAME</span> <span style="color: #ff0000;">"TAHOMA"</span> <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">0</span>,<span style="color: #000000;">-12</span> BOLD<br /><br />   <span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">DIALOG</span> oDlg <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">800</span>,<span style="color: #000000;">500</span> <span style="color: #0000ff;">PIXEL</span> TRUEPIXEL ;<br />      <span style="color: #0000ff;">FONT</span> oFont <span style="color: #0000ff;">TITLE</span> FWVERSION + <span style="color: #ff0000;">" : Bar Get"</span><br /><br />   @ <span style="color: #000000;">110</span>,<span style="color: #000000;">20</span> <span style="color: #0000ff;">XBROWSE</span> oBrw <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">-20</span>,<span style="color: #000000;">-20</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oDlg ;<br />      DATASOURCE aData <span style="color: #0000ff;">AUTOCOLS</span> CELL LINES NOBORDER FASTEDIT<br /><br />   <span style="color: #B900B9;">// Relevant Code</span><br />   <span style="color: #00C800;">for</span> n := <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">&#40;</span> oBrw:<span style="color: #000000;">aCols</span> <span style="color: #000000;">&#41;</span><br />      WITH OBJECT oBrw:<span style="color: #000000;">aCols</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span><br />         <span style="color: #00C800;">if</span>     ValType<span style="color: #000000;">&#40;</span>:<span style="color: #000000;">Value</span><span style="color: #000000;">&#41;</span> = <span style="color: #ff0000;">'C'</span><br />            :<span style="color: #000000;">uBarGetVal</span> := uValBlank<span style="color: #000000;">&#40;</span>Space<span style="color: #000000;">&#40;</span> :<span style="color: #000000;">nDataLen</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />         elseif ValType<span style="color: #000000;">&#40;</span>:<span style="color: #000000;">Value</span><span style="color: #000000;">&#41;</span> = <span style="color: #ff0000;">'N'</span>    <span style="color: #B900B9;">// 28-05-18: Ainda não consegui desenvolver o filtro para campos numéricos</span><br />            :<span style="color: #000000;">uBarGetVal</span> := <span style="color: #000000;">0.00</span><br />            :<span style="color: #000000;">cBarGetPic</span> := <span style="color: #ff0000;">'@E 99999.99'</span> <span style="color: #B900B9;">// NumPict( :nDataLen, :nDataDec )</span><br />         elseif ValType<span style="color: #000000;">&#40;</span>:<span style="color: #000000;">Value</span><span style="color: #000000;">&#41;</span> = <span style="color: #ff0000;">'D'</span><br />            :<span style="color: #000000;">uBarGetVal</span> := CTOD<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">""</span><span style="color: #000000;">&#41;</span><br />            :<span style="color: #000000;">cBarGetPic</span> := <span style="color: #ff0000;">'@D'</span><br />         <span style="color: #00C800;">endif</span><br />      END<br />   <span style="color: #00C800;">next</span><br />   oBrw:<span style="color: #000000;">bClrEdits</span>   := <span style="color: #000000;">&#123;</span> || <span style="color: #000000;">&#123;</span> CLR_BLACK, CLR_YELLOW <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span><br />   oBrw:<span style="color: #000000;">lIncrFilter</span> := .T.<br />   oBrw:<span style="color: #000000;">lGetBar</span>     := .T.<br />   <span style="color: #B900B9;">// End of Relevant Code</span><br /><br />   oBrw:<span style="color: #000000;">CreateFromCode</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br />   @ <span style="color: #000000;">10</span>,<span style="color: #000000;">20</span> <span style="color: #0000ff;">SAY</span> <span style="color: #ff0000;">"Gets under Headers. Entered values can be used"</span> + ;<br />      <span style="color: #ff0000;">"for filtering or any othe purpose"</span> + CRLF + ;<br />      <span style="color: #ff0000;">"Usage: oCol:uBarGetVal := Space( 10 ); oBrw:lGetBar := .t."</span> ;<br />      <span style="color: #0000ff;">SIZE</span> oDlg:<span style="color: #000000;">nWidth</span> - <span style="color: #000000;">40</span>,<span style="color: #000000;">40</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oDlg <span style="color: #0000ff;">CENTER</span><br /><br />   @ <span style="color: #000000;">60</span>, <span style="color: #000000;">20</span> <span style="color: #0000ff;">BTNBMP</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #000000;">&#123;</span> || <span style="color: #00C800;">If</span><span style="color: #000000;">&#40;</span> oBrw:<span style="color: #000000;">lGetBar</span>, <span style="color: #ff0000;">"Hide GetBar"</span>, <span style="color: #ff0000;">"ShowGetBar"</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> ;<br />      <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">100</span>,<span style="color: #000000;">40</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oDlg FLAT ;<br />      <span style="color: #0000ff;">ACTION</span> <span style="color: #000000;">&#40;</span> oBrw:<span style="color: #000000;">lGetBar</span> := ! oBrw:<span style="color: #000000;">lGetBar</span>, oBrw:<span style="color: #0000ff;">Refresh</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br /><br />   @ <span style="color: #000000;">60</span>,<span style="color: #000000;">140</span> <span style="color: #0000ff;">BTNBMP</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Set Filter"</span> ;<br />      <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">100</span>,<span style="color: #000000;">40</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oDlg FLAT ;<br />      <span style="color: #0000ff;">ACTION</span> xSetFilter<span style="color: #000000;">&#40;</span> oBrw <span style="color: #000000;">&#41;</span><br /><br />   @ <span style="color: #000000;">60</span>,<span style="color: #000000;">250</span> <span style="color: #0000ff;">BTNBMP</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Clear Filter"</span> ;<br />      <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">100</span>,<span style="color: #000000;">40</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oDlg FLAT ;<br />      <span style="color: #0000ff;">ACTION</span> <span style="color: #000000;">&#40;</span> oBrw:<span style="color: #000000;">Seek</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">""</span> <span style="color: #000000;">&#41;</span>, oBrw:<span style="color: #000000;">SetFocus</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #0000ff;">ACTIVATE</span> <span style="color: #0000ff;">DIALOG</span> oDlg <span style="color: #0000ff;">CENTERED</span><br />   <span style="color: #0000ff;">RELEASE</span> <span style="color: #0000ff;">FONT</span> oFont, oBold<br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br />*********************************************************************************************<br /><span style="color: #00C800;">static</span> <span style="color: #00C800;">function</span> xSetFilter<span style="color: #000000;">&#40;</span> oBrw <span style="color: #000000;">&#41;</span><br />*********************************************************************************************<br />   <span style="color: #00C800;">local</span> n, oCol, uVal, cType, cName:=<span style="color: #ff0000;">""</span><br />   <span style="color: #00C800;">for</span> n := <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">&#40;</span> oBrw:<span style="color: #000000;">aCols</span> <span style="color: #000000;">&#41;</span><br />      oCol := oBrw:<span style="color: #000000;">aCols</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span><br />      <span style="color: #00C800;">if</span> !Empty<span style="color: #000000;">&#40;</span> uVal := oCol:<span style="color: #000000;">uBarGetVal</span> <span style="color: #000000;">&#41;</span> <span style="color: #B900B9;">// Procura as colunas onde houve digitação no filtro</span><br />         cType := oCol:<span style="color: #000000;">cDataType</span><br />         cName := oCol:<span style="color: #000000;">cHeader</span><br />         <span style="color: #00C800;">do</span> <span style="color: #00C800;">case</span>                           <span style="color: #B900B9;">// Monta o filtro de acordo com o tipo da coluna</span><br />         <span style="color: #00C800;">case</span> cType == <span style="color: #ff0000;">'C'</span><br />            uVal    := Upper<span style="color: #000000;">&#40;</span> AllTrim<span style="color: #000000;">&#40;</span> uVal <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />         <span style="color: #00C800;">case</span> cType == <span style="color: #ff0000;">'D'</span><br />            uVal    := DTOC<span style="color: #000000;">&#40;</span> uVal <span style="color: #000000;">&#41;</span><br />         <span style="color: #00C800;">case</span> cType == <span style="color: #ff0000;">'N'</span><br />            uVal    := Alltrim<span style="color: #000000;">&#40;</span>Str<span style="color: #000000;">&#40;</span> uVal ,<span style="color: #000000;">18</span>,<span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />         <span style="color: #00C800;">endcase</span><br />         oBrw:<span style="color: #000000;">cFilterFld</span> := cName          <span style="color: #B900B9;">// seleciona a coluna que será ativado o filtro</span><br />         oBrw:<span style="color: #000000;">lSeekWild</span>  := .T.<br />         oBrw:<span style="color: #000000;">ArrayIncrFilter</span><span style="color: #000000;">&#40;</span> uVal <span style="color: #000000;">&#41;</span><br />      <span style="color: #00C800;">endif</span><br />   <span style="color: #00C800;">next</span><br />   oBrw:<span style="color: #0000ff;">Refresh</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   oBrw:<span style="color: #0000ff;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   oBrw:<span style="color: #000000;">SetFocus</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><span style="color: #00C800;">Return</span> <span style="color: #00C800;">nil</span><br />*********************************************************************************************<br />&nbsp;</div>[/code:1rxybe16]
ArrayIncrFilter
[code=fw:1cf8l9y3]<div class="fw" id="{CB}" style="font-family: monospace;"><br /><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"fivewin.ch"</span><br /><br /><span style="color: #00C800;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">local</span> oDlg, oBrw, oFont<br />   <span style="color: #00C800;">local</span> aData<br /><br />   USE CUSTOMER<br />   aData := FW_DbfToArray<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"FIRST,LAST,CITY"</span> <span style="color: #000000;">&#41;</span><br />   CLOSE CUSTOMER<br /><br />   <span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">FONT</span> oFont <span style="color: #0000ff;">NAME</span> <span style="color: #ff0000;">"TAHOMA"</span> <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">0</span>,<span style="color: #000000;">-14</span><br />   <span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">DIALOG</span> oDlg <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">700</span>,<span style="color: #000000;">500</span> <span style="color: #0000ff;">PIXEL</span> TRUEPIXEL <span style="color: #0000ff;">FONT</span> oFont<br /><br />   @ <span style="color: #000000;">60</span>,<span style="color: #000000;">20</span> <span style="color: #0000ff;">XBROWSE</span> oBrw <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">-20</span>,<span style="color: #000000;">-20</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oDlg ;<br />      DATASOURCE aData <span style="color: #0000ff;">AUTOCOLS</span> HEADERS <span style="color: #ff0000;">"First"</span>, <span style="color: #ff0000;">"Last"</span>, <span style="color: #ff0000;">"City"</span> ;<br />      CELL LINES NOBORDER AUTOSORT FOOTERS<br /><br />   WITH OBJECT oBrw<br />      :<span style="color: #000000;">aCols</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">bFooter</span>  := <span style="color: #000000;">&#123;</span> || <span style="color: #ff0000;">"Records : "</span> + Str<span style="color: #000000;">&#40;</span> oBrw:<span style="color: #000000;">nLen</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span><br />      <span style="color: #B900B9;">//</span><br />      :<span style="color: #000000;">uBarGetVals</span>   := Space<span style="color: #000000;">&#40;</span> <span style="color: #000000;">10</span> <span style="color: #000000;">&#41;</span><br />      :<span style="color: #000000;">bClrEdits</span>     := <span style="color: #000000;">&#123;</span> || <span style="color: #000000;">&#123;</span> CLR_BLACK, CLR_YELLOW <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span><br />      :<span style="color: #000000;">lBarGetOnKeys</span> := .t.<br />      :<span style="color: #000000;">lGetBar</span>       := .t.<br />      <span style="color: #B900B9;">//</span><br />      :<span style="color: #000000;">CreateFromCode</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   END<br /><br />   @ <span style="color: #000000;">10</span>, <span style="color: #000000;">20</span> <span style="color: #0000ff;">BTNBMP</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Set Filter"</span> <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">200</span>,<span style="color: #000000;">40</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oDlg FLAT ;<br />      <span style="color: #0000ff;">ACTION</span> <span style="color: #000000;">&#40;</span> xSetFilter<span style="color: #000000;">&#40;</span> oBrw <span style="color: #000000;">&#41;</span>, oBrw:<span style="color: #000000;">SetFocus</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br /><br />   @ <span style="color: #000000;">10</span>,<span style="color: #000000;">240</span> <span style="color: #0000ff;">BTNBMP</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Clear Filter"</span> <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">200</span>,<span style="color: #000000;">40</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oDlg FLAT ;<br />      <span style="color: #0000ff;">ACTION</span> <span style="color: #000000;">&#40;</span> xClearFilter<span style="color: #000000;">&#40;</span> oBrw <span style="color: #000000;">&#41;</span>, oBrw:<span style="color: #000000;">SetFocus</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #0000ff;">ACTIVATE</span> <span style="color: #0000ff;">DIALOG</span> oDlg <span style="color: #0000ff;">CENTERED</span><br />   <span style="color: #0000ff;">RELEASE</span> <span style="color: #0000ff;">FONT</span> oFont<br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">function</span> xSetFilter<span style="color: #000000;">&#40;</span> oBrw <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">local</span> cFilter  := <span style="color: #ff0000;">""</span><br />   <span style="color: #00C800;">local</span> oCol, c<br /><br />   <span style="color: #00C800;">for</span> each oCol in oBrw:<span style="color: #000000;">aCols</span><br />      <span style="color: #00C800;">if</span> !Empty<span style="color: #000000;">&#40;</span> oCol:<span style="color: #000000;">uBarGetVal</span> <span style="color: #000000;">&#41;</span><br />         c  := Upper<span style="color: #000000;">&#40;</span> AllTrim<span style="color: #000000;">&#40;</span> oCol:<span style="color: #000000;">uBarGetVal</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br /><span style="color: #B900B9;">//         c  := "'" + c + "' $ Upper( aRow[" + LTrim( Str( oCol:nArrayCol ) ) + "] )"</span><br />         c  := <span style="color: #ff0000;">"'"</span> + c + <span style="color: #ff0000;">"' $ Upper( cValToChar( aRow["</span> + LTrim<span style="color: #000000;">&#40;</span> Str<span style="color: #000000;">&#40;</span> oCol:<span style="color: #000000;">nArrayCol</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">"] ) )"</span> &nbsp;<span style="color: #B900B9;">// can be char,date,num</span><br />         <span style="color: #00C800;">if</span> !Empty<span style="color: #000000;">&#40;</span> cFilter <span style="color: #000000;">&#41;</span><br />            cFilter  += <span style="color: #ff0000;">" .AND. "</span><br />         <span style="color: #00C800;">endif</span><br />         cFilter  += c<br />      <span style="color: #00C800;">endif</span><br />   <span style="color: #00C800;">next</span><br /><br />   <span style="color: #00C800;">if</span> Empty<span style="color: #000000;">&#40;</span> cFilter <span style="color: #000000;">&#41;</span><br />      xClearFilter<span style="color: #000000;">&#40;</span> oBrw <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">else</span><br />      cFilter  := <span style="color: #ff0000;">"{ |c,aRow,oBrw| "</span> + cFilter + <span style="color: #ff0000;">" }"</span><br />      oBrw:<span style="color: #000000;">bFilterExp</span>  := &<span style="color: #000000;">&#40;</span> cFilter <span style="color: #000000;">&#41;</span><br />      oBrw:<span style="color: #000000;">ArrayIncrFilter</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"dummy"</span> <span style="color: #000000;">&#41;</span><br />      oBrw:<span style="color: #0000ff;">Refresh</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />      oBrw:<span style="color: #000000;">SetFocus</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">endif</span><br /><br /><span style="color: #00C800;">return</span> .t.<br /><br /><span style="color: #00C800;">function</span> xClearFilter<span style="color: #000000;">&#40;</span> oBrw <span style="color: #000000;">&#41;</span><br /><br />   AEval<span style="color: #000000;">&#40;</span> oBrw:<span style="color: #000000;">aCols</span>, <span style="color: #000000;">&#123;</span> |o| <span style="color: #00C800;">If</span><span style="color: #000000;">&#40;</span> o:<span style="color: #000000;">oBarGet</span> == <span style="color: #00C800;">nil</span>, <span style="color: #00C800;">nil</span>, o:<span style="color: #000000;">oBarGet</span>:<span style="color: #000000;">cText</span> := uValBlank<span style="color: #000000;">&#40;</span> o:<span style="color: #000000;">uBarGetVal</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">if</span> oBrw:<span style="color: #000000;">nLen</span> < Len<span style="color: #000000;">&#40;</span> oBrw:<span style="color: #000000;">aArrayData</span> <span style="color: #000000;">&#41;</span><br />      oBrw:<span style="color: #000000;">bKeyCount</span>    := <span style="color: #000000;">&#123;</span> || Len<span style="color: #000000;">&#40;</span> oBrw:<span style="color: #000000;">aArrayData</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span><br />      oBrw:<span style="color: #0000ff;">Refresh</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">endif</span><br />   oBrw:<span style="color: #000000;">SetFocus</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">return</span> .t.<br /> </div>[/code:1cf8l9y3]
ArrayIncrFilter
All this long code is not necessary. I made a small modification to my earlier sample. That is enough to handle all types
ArrayIncrFilter
Thanks a lot Rao. It´s completely fine with numeric and date field too. [code=fw:1odxq26j]<div class="fw" id="{CB}" style="font-family: monospace;"><br /><br />*********************************************************************************************<br /><span style="color: #00C800;">static</span> <span style="color: #00C800;">function</span> xSetFilter<span style="color: #000000;">&#40;</span> oBrw <span style="color: #000000;">&#41;</span><br />*********************************************************************************************<br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> oCol, uVal, cFilter:=<span style="color: #ff0000;">""</span><br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> each oCol in oBrw:<span style="color: #000000;">aCols</span><br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> !Empty<span style="color: #000000;">&#40;</span> uVal := oCol:<span style="color: #000000;">uBarGetVal</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">do</span> <span style="color: #00C800;">case</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">case</span> oCol:<span style="color: #000000;">cDataType</span> == <span style="color: #ff0000;">'C'</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uVal &nbsp; &nbsp;:= Upper<span style="color: #000000;">&#40;</span> AllTrim<span style="color: #000000;">&#40;</span> uVal <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cFilter := cFilter + iif<span style="color: #000000;">&#40;</span>!Empty<span style="color: #000000;">&#40;</span>cFilter<span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">".AND."</span>,<span style="color: #ff0000;">""</span><span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">'"'</span> + uVal + <span style="color: #ff0000;">'" $ Upper( aRow['</span> + AllTrim<span style="color: #000000;">&#40;</span>Str<span style="color: #000000;">&#40;</span> oCol:<span style="color: #000000;">nArrayCol</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">"] )"</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">case</span> oCol:<span style="color: #000000;">cDataType</span> == <span style="color: #ff0000;">'D'</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uVal &nbsp; &nbsp;:= DTOC<span style="color: #000000;">&#40;</span> uVal <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cFilter := cFilter + iif<span style="color: #000000;">&#40;</span>!Empty<span style="color: #000000;">&#40;</span>cFilter<span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">".AND."</span>,<span style="color: #ff0000;">""</span><span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">'"'</span> + uVal + <span style="color: #ff0000;">'" = DTOC( aRow['</span> + AllTrim<span style="color: #000000;">&#40;</span>Str<span style="color: #000000;">&#40;</span> oCol:<span style="color: #000000;">nArrayCol</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">"] )"</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">case</span> oCol:<span style="color: #000000;">cDataType</span> == <span style="color: #ff0000;">'N'</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uVal &nbsp; &nbsp;:= Alltrim<span style="color: #000000;">&#40;</span>Str<span style="color: #000000;">&#40;</span> uVal ,<span style="color: #000000;">18</span>,<span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cFilter := cFilter + iif<span style="color: #000000;">&#40;</span>!Empty<span style="color: #000000;">&#40;</span>cFilter<span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">".AND."</span>,<span style="color: #ff0000;">""</span><span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">'"'</span> + uVal + <span style="color: #ff0000;">'" = Alltrim(Str( aRow['</span> + Alltrim<span style="color: #000000;">&#40;</span>Str<span style="color: #000000;">&#40;</span> oCol:<span style="color: #000000;">nArrayCol</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> +<span style="color: #ff0000;">'] ,18,2))'</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">endcase</span><br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">endif</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span><br />&nbsp; &nbsp;<span style="color: #00C800;">if</span> Empty<span style="color: #000000;">&#40;</span> cFilter <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; xClearFilter<span style="color: #000000;">&#40;</span> oBrw <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">else</span><br />&nbsp; &nbsp; &nbsp; cFilter &nbsp;:= <span style="color: #ff0000;">"{ |c,aRow,oBrw| "</span> + cFilter + <span style="color: #ff0000;">" }"</span><br />&nbsp; &nbsp; &nbsp; oBrw:<span style="color: #000000;">bFilterExp</span> &nbsp;:= &<span style="color: #000000;">&#40;</span> cFilter <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; oBrw:<span style="color: #000000;">ArrayIncrFilter</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"dummy"</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; oBrw:<span style="color: #0000ff;">Refresh</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">endif</span><br />&nbsp; &nbsp;oBrw:<span style="color: #000000;">SetFocus</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><span style="color: #00C800;">Return</span> <span style="color: #00C800;">nil</span><br /><br /><br />&nbsp;</div>[/code:1odxq26j]
ArrayIncrFilter
Yes Rao, your code looks great. Thank you. I noticed that with a large array, the get fields become messy when the User scrolls quickly. So, Is it possible to refresh the get line when you place the cursor or click on some get field? Thanks.
ArrayIncrFilter
Amigo tengo este codigo funciona bien en la busqueda, pero quiero mostrar lo q escribo y no me funciona REDEFINE FOLDEREX oFld ID 99 OF oDlg ; PROMPT &vTitulo; //aPrompt; BITMAPS &vBitmap; TAB HEIGHT 35 ; DIALOGS &vDialogo; //aDialogo ; ON CHANGE (oSumaTotal:=0,oBrw[oFld:nOption]:RefreshFooters(),SumaSubtotal(oBrw,aData,oFld:nOption) ); TOP ALIGN &vFldBmp For I=1 To Len(oBrw) REDEFINE XBROWSE oBrw[I] ID 400 ; HEADERS "Descripcion","Cantidad","Pr.Neto","Sub-Total"; JUSTIFY .F.,.F.,.F.,.F.; FIELDSIZES 590, 70, 70, 80 ; PICTURES "@!",'99,999.99','999,999,999','999,999,999' ; DATASOURCE aData[I] FOOTERS AUTOSORT; LINES CELL cols{ 1,2,3,4 } OF oFld:aDialogs[ I ] oBrw[I]:nColDividerStyle := LINESTYLE_BLACK oBrw[I]:nRowDividerStyle := LINESTYLE_BLACK oBrw[I]:nMarqueeStyle := MARQSTYLE_HIGHLCELL oBrw[I]:lFastEdit := .T. oBrw[I]:nFreeze := 4 oBrw[I]:nHeaderLines := 2 oBrw[I]:lHScroll := .f. oBrw[I]:lVScroll := .F. oBrw[I]:bPastEof := {|| NewReg(aData,oBrw,oFld:nOption) } oBrw[I]:lFooter := .t. oBrw[I]:nFooterHeight := 35 // Altura del footer oBrw[I]:lIncrFilter := .T. oBrw[I]:lSeekWild := .T. oBrw[I]:nColSel := 1 For n := 1 to Len( oBrw[I]:aCols ) oCol := oBrw[I]:aCols[ n ] If n == 1 oCol:nEditType := EDIT_GET oCol:bOnPostEdit := { | oCol, xVal, nKey | If( nKey == VK_RETURN,aData[oFld:nOption][oBrw[oFld:nOption]:nArrayAt,1]:=xVal,) } oCol:bEditWhen := { || IF(aData[oFld:nOption][oBrw[oFld:nOption]:nArrayAt,6]=0,.T.,.F.) } ElseIf n == 2 oCol:nEditType := EDIT_GET oCol:bOnPostEdit := { | oCol, xVal, nKey | If( nKey == VK_RETURN,aData[oFld:nOption][oBrw[oFld:nOption]:nArrayAt,2]:=xVal,) } ElseIf n == 3 oCol:nEditType := EDIT_GET oCol:bOnPostEdit := { | oCol, xVal, nKey | If( nKey == VK_RETURN,aData[oFld:nOption][oBrw[oFld:nOption]:nArrayAt,3]:=xVal,) } oCol:bEditValid := { | oGet, oCol | (CargaPrecio(oGet,oBrw,aData,oFld:nOption)) } oCol:cFooter := 'Total' oCol:nFootStrAlign:= AL_CENTER ElseIf n ==4 oCol:bFooter := { || TRANSFORM( oSumaTotal,"999,999,999") } Endif next oFld:aDialogs[ I ]:bInit := {|| oBrw[I]:aCols[1]:SetOrder(), Eval(oBrw[I]:aCols[1]:bLClickHeader) } *** ESTO 3 NO ME FUNCIONAN PARA MOSTRAR LO Q BUSCO SE CAE * @ 20,20 SAY oBrw[I]:oSeek VAR oBrw[I]:cSeek SIZE 150,20 PIXEL OF oDlg COLOR CLR_HRED, CLR_YELLOW UPDATE * REDEFINE SAY oBrw[oFld:nOption]:oSeek PROMPT oBrw[oFld:nOption]:cSeek ID 103 OF oDlg:aDialogs[ I ] PICTURE "@S60!" UPDATE * @ 11,150 SAY oBrw[I]:oSeek PROMPT oBrw[I]:cSeek SIZE 200,10 PIXEL OF oFld:aDialogs[ I ] COLOR CLR_BLACK,CLR_YELLOW PICTURE '@!' Next Saludos
ArrayIncrFilter
[quote="jbrita":3jyr1umw] *** ESTO 3 NO ME FUNCIONAN PARA MOSTRAR LO Q BUSCO SE CAE * @ 20,20 SAY oBrw[I]:oSeek VAR oBrw[I]:cSeek SIZE 150,20 PIXEL OF oDlg COLOR CLR_HRED, CLR_YELLOW UPDATE * REDEFINE SAY oBrw[oFld:nOption]:oSeek PROMPT oBrw[oFld:nOption]:cSeek ID 103 OF oDlg:aDialogs[ I ] PICTURE "@S60!" UPDATE * @ 11,150 SAY oBrw[I]:oSeek PROMPT oBrw[I]:cSeek SIZE 200,10 PIXEL OF oFld:aDialogs[ I ] COLOR CLR_BLACK,CLR_YELLOW PICTURE '@!' Next Saludos[/quote:3jyr1umw] Prueba asi [code=fw:3jyr1umw]<div class="fw" id="{CB}" style="font-family: monospace;"><br />@ <span style="color: #000000;">11</span>,<span style="color: #000000;">150</span> <span style="color: #0000ff;">SAY</span> oBrw<span style="color: #000000;">&#91;</span>I<span style="color: #000000;">&#93;</span>:<span style="color: #000000;">oSeek</span> <span style="color: #0000ff;">VAR</span> oBrw<span style="color: #000000;">&#91;</span>I<span style="color: #000000;">&#93;</span>:<span style="color: #000000;">cSeek</span> <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">200</span>,<span style="color: #000000;">10</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oFld:<span style="color: #000000;">aDialogs</span><span style="color: #000000;">&#91;</span> I <span style="color: #000000;">&#93;</span> <span style="color: #0000ff;">COLOR</span> CLR_BLACK,CLR_YELLOW <span style="color: #0000ff;">PICTURE</span> <span style="color: #ff0000;">'@!'</span><br /> </div>[/code:3jyr1umw]
ArrayIncrFilter
Tampoco asi resulta: @ 11,150 SAY oBrw[I]:oSeek VAR oBrw[I]:cSeek SIZE 200,10 PIXEL OF oFld:aDialogs[ I ] COLOR CLR_BLACK,CLR_YELLOW PICTURE '@!' saludos
Arrays
Hola Amigos Es esto un Bug?, o qué hago mal Al 1er array “TabP” debo incluir algunos elementos, cada nueva linea esta basada en otro array “xTab”, con ciertas modificaciones. Esta es la rutina que al parecer es muy simple. #include "FiveWin.ch" function main() local TabP:={{"Z","Y","X","W"}} local xTab:={"A","B","C","D"} local z ,y, a:="" for z=1 to 3 xTab[1]:=str(z,1) xTab[3]:=str(z,1) AADD(TabP,xTab) y:=len(TabP) a:=a+str(y)+","+TabP[y,1]+TabP[y,2]+TabP[y,3]+TabP[y,4]+CRLF next ?"13",len(TabP),a &&' ok a:="" for z=1 to len(TabP) &&' aca ya esta mal a:=a+str(z)+","+TabP[z,1]+TabP[z,2]+TabP[z,3]+TabP[z,4]+CRLF next ?"18",a return El resultado hasta la linea 13 es éste y está bien, la 1ra y la 3ra columna tienen “1”,”2” ,”3” en los elementos adicionados de TabP. 2=> 1B1D 3=> 2B2D 4=> 3B3D inmediatamente después verifico todo el array TabP y las lineas que fueron adicionadas han sido cambiadas como una copia de la ultima linea adicionada, todas tienen “3” en la 1ra y 3ra columna 1=> ZYXW 2=> 3B3D 3=> 3B3D 4=> 3B3D es esto un problema de xHarbour? O qué hago mal?. Saludos y muchas gracias por la ayuda. Jorge Vargas
Arrays
Hola Amigos: A nadie le sucede esto? o hay algo que hago mal? gracias. Jorge Vargas
Arrays
debes usar la funcion aClone AADD(TabP,aclone(xTab) )
Arrays
Hola Patricio Muchas gracias por tu respuesta y la solucion. medio raro, pero funciona saludos Jorge <!-- s:lol: --><img src="{SMILIES_PATH}/icon_lol.gif" alt=":lol:" title="Laughing" /><!-- s:lol: -->
Arrays and tSBrowse
OK ... I found a work around, but still .... Using tSBrowse with an array. Initially it has x number of elements ( for example 10) and browsing them is no problem. Now, I wish to add another element, so I use AADD( ) and increase the array by one element. I now need to reposition the highlight to the new element so I do a oLbx:gobttom() ... but that doesn't necessarily get there ! The array elements are in natural order, not sorted. So, using the tSBrowse gobottom() method I would think should take me there ... Any thoughts ? For my work around, I count the number of array elements, and then use the GoPos( x, y ) method to go to the last array element. That seems to work. I'm using this to append elements to the array, and then they will be written to a database after editing is complete. <!-- s8) --><img src="{SMILIES_PATH}/icon_cool.gif" alt="8)" title="Cool" /><!-- s8) -->
Arrays and tSBrowse
Tim, may be this could work. [code:8puvit2i]oBrw&#58;bGoBottom &#58;= &#123; || oBrw&#58;nAt &#58;= len&#40; oBrw&#58;aArray &#41; &#125;[/code:8puvit2i] Regards, Detlef
Arrays and tSBrowse
[quote="TimStone":2j1bh7t2]using tSBrowse with an array. Initially it has x number of elements ( for example 10) and browsing them is no problem. Now, I wish to add another element, so I use AADD( ) and increase the array by one element. I now need to reposition the highlight to the new element so I do a oLbx:gobttom() ... but that doesn't necessarily get there ! The array elements are in natural order, not sorted. So, using the tSBrowse gobottom() method I would think should take me there ... Any thoughts ?[/quote:2j1bh7t2] Hi Tim: If you externally add an element to the array, must to add 1 to oBrw:nLen data, or use SetArray() method to refresh the array size and view. Regards. Manuel Mercado
Arrays en FastReport (SOLUCIONADO)
Amigos: Alguien que me ayude a entender cómo ligar el siguiente array a FastReport, tanto para diseñar el reporte como para la impresión ? aRegs[nRegs,nCols] Saludos
Arrays en FastReport (SOLUCIONADO)
Hola Armando... [code=fw:q4xerhl6]<div class="fw" id="{CB}" style="font-family: monospace;"><br />oFr:<span style="color: #000000;">SetUserDataSet</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"aMiArray"</span>,<span style="color: #ff0000;">"COLUMNA1;COLUMNA2;COLUMNA3;COLUMNA4"</span>,;<br />                     <span style="color: #000000;">&#123;</span>||np := <span style="color: #000000;">1</span><span style="color: #000000;">&#125;</span>, ;                   <span style="color: #B900B9;">//--> bGoTop</span><br />                     <span style="color: #000000;">&#123;</span>||np := np + <span style="color: #000000;">1</span><span style="color: #000000;">&#125;</span>, ;              <span style="color: #B900B9;">//--> bSkipPlus</span><br />                     <span style="color: #000000;">&#123;</span>||np := np - <span style="color: #000000;">1</span><span style="color: #000000;">&#125;</span>, ;              <span style="color: #B900B9;">//--> bSkipMinus</span><br />                     <span style="color: #000000;">&#123;</span>||np > Len<span style="color: #000000;">&#40;</span>aMiArray<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span>, ;        <span style="color: #B900B9;">//--> bCheckEOF</span><br />                     <span style="color: #000000;">&#123;</span>|aField|nCol := IIF<span style="color: #000000;">&#40;</span> aField == <span style="color: #ff0000;">"COLUMNA1"</span>   , <span style="color: #000000;">1</span>,;<br />                                      IIF<span style="color: #000000;">&#40;</span> aField == <span style="color: #ff0000;">"COLUMNA2"</span>   , <span style="color: #000000;">2</span>,;<br />                                      IIF<span style="color: #000000;">&#40;</span> aField == <span style="color: #ff0000;">"COLUMNA3"</span>   , <span style="color: #000000;">3</span>,;<br />                                      IIF<span style="color: #000000;">&#40;</span> aField == <span style="color: #ff0000;">"COLUMNA4"</span>   , <span style="color: #000000;">4</span>, <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>, aMiArray<span style="color: #000000;">&#91;</span>np, nCol<span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span></div>[/code:q4xerhl6] Espero te sirva... Saludos, Esteban.
Arrays en FastReport (SOLUCIONADO)
Esteban: Gracias por tu apoyo pero fijate que no doy pie con bola <!-- s:oops: --><img src="{SMILIES_PATH}/icon_redface.gif" alt=":oops:" title="Embarassed" /><!-- s:oops: --> mira tengo un array de la siguiente forma: aRegs[nReg,nCol] Imaginemos que tiene 5 registros (nReg = 5) y que cada registro tiene 4 campos (nCols = 4), cómo debería definir el código para pasarlo a FastReport y abrir el diseñador que me permita usar el array para formar el reporte ?? Saludos
Arrays en FastReport (SOLUCIONADO)
Armando... Es así como te lo escribí. En lo que escribí anteriormente lo que para tí es: "aRegs" para mí es: "aMiArray" Prueba y dime que resulta. Saludos, Esteban.
Arrays en FastReport (SOLUCIONADO)
Esteban: Tienes razón, ya lo logré, es muy sencillo !. Saludos y muchas gracias
Arrays en FastReport (SOLUCIONADO)
Esteban: He logrado incluir el ARRAY en FastReport y he usado sus elementos para constuir el reporte, mejor dicho la etiqueta, son etiquetas !. Perooo, no logro que me imprima más de una, lo que necesito es que me imprima una etiqueta por cada elemento (nRegs) del array. aRegs[nRegs,nCols] Saludos
Arrays en FastReport (SOLUCIONADO)
Hola Armando, En las bandas (Master,Detail, etc.) hay una propiedad: "RowCount" donde puedes ponerle en número que equivale a las veces que quieres visualizar/imprimir dicha la banda, en tu caso la longitud del array. Es decir no asocias la banda a un origen de datos recordset ó DBF. No se si te puede servir... Un saludo Ernesto
Arrays en FastReport (SOLUCIONADO)
Ernesto: Gracias por tu respuesta. Mira, tengo entendido que en el caso de una DBF o RecordSet la banda se imprime tantas veces como registros haya en el DBF o RecordSet. Tambien tengo entendido que en el caso de los Array sucede lo mismo, me parece que no puedo utilizar el RowCount porque en cada impresión la longitud del Array puede variar, mejor dicho varía, deduzco que algo me hace falta definir en el formato pero no doy con qué <!-- s:oops: --><img src="{SMILIES_PATH}/icon_redface.gif" alt=":oops:" title="Embarassed" /><!-- s:oops: --> Saludos
Arrays en FastReport (SOLUCIONADO)
Hola Armando, Si la longitud del array varía, puedes ponerlo asi: nLenArray:=len(aArray) oFr:SetProperty("MasterData1", "RowCount",nLenArray) Un saludo, Ernesto.
Arrays en FastReport (SOLUCIONADO)
Ernesto: Fijate que sí pero no <!-- s:D --><img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /><!-- s:D --> Con tu solución se imprime el primer elemento del array pero tantas veces como longitud tenga el array. Deduzco que algo me falta en el diseño, pero no se qué <!-- s:oops: --><img src="{SMILIES_PATH}/icon_redface.gif" alt=":oops:" title="Embarassed" /><!-- s:oops: --> Saludos
Arrays en FastReport (SOLUCIONADO)
Amigos: Muchas por sus respuestas y sugerencias, este problema ha quedado solucionado. Saludos
Arrays en FastReport (SOLUCIONADO)
Alguien sabe de esto necesito hacer una matriz para almacenar un total. Usamos el "TStringList" de clase como una matriz para el almacenamiento de sumas ". Vamos a almacenar datos numéricos valores como cadenas. Al mismo tiempo, la primera línea en la lista corresponde al valor de la primer grupo, etc La variable de valor entero (que vamos a aumentar después de imprimir el siguiente grupo) se utiliza para calcular el número del grupo. Por lo tanto, nuestro script se verá como sigue: esto es lo que estoy haciendo: procedure GroupFooter1OnBeforePrint(Sender: TfrxComponent); begin if then Lista.Add(FloatToStr(SUM(<masterQuery."SALDO">,MasterData1))); Inc(i); { if (Copy(<masterQuery."SALDO">, 1, 1) < '10') and (Copy(<masterQuery."SALDO">, 1, 1) > '10')and (chk_pendientes.Checked) then begin MasterData1.Visible := True; GroupFooter1.visible := True; end else begin MasterData1.Visible := False; GroupFooter1.visible := False; end; } end; procedure GroupHeader1OnBeforePrint(Sender: TfrxComponent); begin if Engine.FinalPass then Memo27.Text := 'Sum: ' + List[i]; end; procedure frxReport1OnStartReport(Sender: TfrxComponent); begin Lista := TStringList.Create; end; procedure frxReport1OnStopReport(Sender: TfrxComponent); begin Lista.Free; end; solo quiero que cuando la suma del saldo sea <> 0 muestre en la banda lo distinto de cero
Arreglo importante!
Por favor añadir este código al PRG principal de vuestra aplicación: [code:9kb04jc3] #pragma BEGINDUMP #include <hbapi&#46;h> #include <windows&#46;h> LPSTR WideToAnsi&#40; LPWSTR &#41;; HB_FUNC&#40; GETWINDOWTEXT &#41; &#123; HWND hWnd = &#40; HWND &#41; hb_parnl&#40; 1 &#41;; int iLen = GetWindowTextLength&#40; hWnd &#41;; LPWSTR pText = &#40; LPWSTR &#41; hb_xgrab&#40; &#40; iLen * 2 &#41; + 2 &#41;; LPSTR pAnsi; GetWindowText&#40; hWnd, pText, iLen + 1 &#41;; pAnsi = WideToAnsi&#40; pText &#41;; hb_retc&#40; pAnsi &#41;; hb_xfree&#40; pAnsi &#41;; hb_xfree&#40; pText &#41;; &#125; #pragma ENDDUMP [/code:9kb04jc3]
Arreglo importante!
Antonio, Q reporta este arreglo ? (tema de perdida de memoria ?) Gracias.
Arreglo importante!
Carles, Se estaba corrompiendo la memoria! <!-- s:shock: --><img src="{SMILIES_PATH}/icon_eek.gif" alt=":shock:" title="Shocked" /><!-- s:shock: --> y Harbour no podía liberarla luego. Ahora esta correcto. De todas formas vamos a publicar en breve un nuevo build en el que se ha hecho una revisión a fondo del consumo de memoria.
Arreglo importante!
Antonio tengo Fwppc con las librerias de estas fechas Fivece.lib 01/09/2006 fivecec.lib 30/08/2006 el parche que publicas me aplicaria a la version que yo tengo ? Saludos Att
Arreglo importante!
Wilson, Sí, tienes que incluirlo.
Arreglo importante!
Me dio problemas al compilar.. sera q estoy haciendo algo mal? <!-- s:shock: --><img src="{SMILIES_PATH}/icon_eek.gif" alt=":shock:" title="Shocked" /><!-- s:shock: --> (recien termine de instalar la actualizacion de fwppc) [quote:2ubuni0e] Compiling... Harbour Compiler Alpha build 45.0 (Flex) Copyright 1999-2005, <!-- m --><a class="postlink" href="http://www.harbour-project.org/">http://www.harbour-project.org/</a><!-- m --> Compiling 'PRUEBA2.prg' and generating preprocessed output to 'PRUEBA2.ppo'... Lines 179, Functions/Procedures 4 Generating C source output to 'PRUEBA2.c'... Done. PRUEBA2.c Microsoft (R) Incremental Linker Version 6.24.3077 Copyright (C) Microsoft Corporation. All rights reserved. PRUEBA2.obj c:\fwppc\lib\FiveCE.lib c:\fwppc\lib\FiveCEC.lib c:\harbour_CE\lib\rtl.lib c:\harbour_CE\lib\vm.lib c:\harbour_CE\lib\gtwin.lib c:\harbour_CE\lib\lang.lib c:\harbour_CE\lib\macro.lib c:\harbour_CE\lib\rdd.lib c:\harbour_CE\lib\dbfntx.lib c:\harbour_CE\lib\dbfcdx.lib c:\harbour_CE\lib\dbffpt.lib c:\harbour_CE\lib\hbsix.lib c:\harbour_CE\lib\debug.lib c:\harbour_CE\lib\common.lib c:\harbour_CE\lib\pp.lib c:\harbour_CE\lib\codepage.lib c:\vce\lib\arm\coredll.lib c:\vce\lib\arm\corelibc.lib c:\vce\lib\arm\aygshell.lib c:\vce\lib\arm\ws2.lib c:\vce\lib\arm\mfcce400.lib c:\vce\lib\arm\ole32.lib c:\vce\lib\arm\ceshell.lib c:\vce\lib\arm\commctrl.lib c:\vce\lib\arm\wininet.lib FiveCEC.lib(GETTEXT.obj) : error LNK2005: "void __cdecl HB_FUN_GETWINDOWTEXT(void)" (?HB_FUN_GETWINDOWTEXT@@YAXXZ) already defined in PRUEBA2.obj FiveCEC.lib(GETTEXT.obj) : warning LNK4006: "void __cdecl HB_FUN_GETWINDOWTEXT(void)" (?HB_FUN_GETWINDOWTEXT@@YAXXZ) already defined in PRUEBA2.obj; second definition ignored Creating library PRUEBA2.lib and object PRUEBA2.exp PRUEBA2.exe : fatal error LNK1169: one or more multiply defined symbols found * Application successfully built [code][/code][/quote:2ubuni0e]
Arreglo importante!
Luis, Hay que extraer este módulo previamente: lib /remove:objcec\GETTEXT.obj fivecec.lib
Arreglo importante!
ahora me da otros errores <!-- s:? --><img src="{SMILIES_PATH}/icon_confused.gif" alt=":?" title="Confused" /><!-- s:? --> [quote:2d5fo927]FiveCE.lib(MGET.obj) : error LNK2001: unresolved external symbol "void __cdecl HB_FUN_MGETREPLACE(void)" (?HB_FUN_MGETREPLACE@@YAXXZ) FiveCE.lib(MGET.obj) : error LNK2001: unresolved external symbol "void __cdecl HB_FUN_GETWINTXTLENGHT(void)" (?HB_FUN_GETWINTXTLENGHT@@YAXXZ) FiveCE.lib(MGET.obj) : error LNK2001: unresolved external symbol "void __cdecl HB_FUN_MGETLINE(void)" (?HB_FUN_MGETLINE@@YAXXZ) [/quote:2d5fo927]
Arreglo importante!
Luis, Vamos a publicar un nuevo build de FWPPC en sólo unos dias. En cuanto salga lo tendrás y así no tienes que modificar nada.
Arreglo importante!
vale, vale.. yo espero; de momento lo he solucionado agregando las funciones q faltan en blanco.. muchas gracias por su atencion Don Antonio.
Arreglo importante!
antonio yo me quede sin actualizaciones en septiembre ( al caducar la version 1 ) ... si es un fix importante tendria que aplicarlo pero me salen los errores arriba indicados y no tengo manera de acceder a las ultimas actualizaciones ... pondras un fix completo para la version 1 o debemos quedarnos com estamos ?
Arreglo importante!
Jose Luis, No es sólo eso. El nuevo build de FWPPC que hemos publicado ya, usa el Harbour más reciente (46.2) y ha sido rediseñado interiormente para optimizar el uso de la memoria. Además se han cambiado clases importantes, para hacerlo funcionar mejor. Y del Harbour anterior a este nuevo existen muchas diferencias. No hay un parche aislado que se pueda publicar, sino lo haríamos.
Arreglo importante!
entonces ¿ lo dejo estar ? ... ( de momento no hemos tenido problemas, y actualizarse a la nueva version no se plantea hasta tener mas parque de aplicaciones instaladas .. ) Gracias por tu atencion
Arreglo importante!
Jose Luis, Sí, puedes dejarlo como está. Solo en aplicaciones que funcionan muchas horas seguidas es donde puede notarse el problema de la memoria, que ya está solucionado.
Arrotondare un prezzo
E' possibile arrotondare un prezzo ? per esempio io ho calcolato un prezzo di 8.57 come posso portarlo a 9.00 cioè non lo saprei io se ha decimali dovrebbe arrotondare automaticamente tanto tempo fa qualcuno aveva fatto una funzione ma in fw+ clipper si poteva settare quanto arrotondare ma adesso non ho trovato quella funzione ed ho problemi
Arrotondare un prezzo
Ciao Silvio, devi usare la funzione ROUND(<nNumber>, <nDecimals>) nDecimals è il numero di decimali a cui vuoi arrotondare Ad esempio se vuoi arrotondare 8.57 a 9.00 [code=fw:giuvrmsa]<div class="fw" id="{CB}" style="font-family: monospace;"> <span style="color: #0000ff;">ROUND</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">8.57</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#41;</span></div>[/code:giuvrmsa] Buona serata
Arrotondare un prezzo
cercavo una funzione come roundup
Arrotondare un prezzo
forse [url=https&#58;//harbour&#46;github&#46;io/doc/clct3&#46;html#ceiling:2bk0fafw]Ceiling[/url:2bk0fafw]? che poi è lo stesso di fare round(x+0.5,0)
Arrow keys don't work in ListBox in FW24 and XP
Five Win, We've hit a wall with arrow keys in some part of our POS. The Up and Down arrow keys is not working in a the List Box but in other part of the program like in popup menus it works fine. Environment: XP, Clipper5.2, comix and FW24 Is there any FW update in the List box that may correct the this behavior? Or there is anything I can tweak in the list box? TIA
Arrow keys don't work in ListBox in FW24 and XP
Check that the listbox has the focus: oListBox:SetFocus()
Arrow keys don't work in ListBox in FW24 and XP
Antonio, Thanks for the quick reply. >Check that the listbox has the focus: >oListBox:SetFocus() The list box has focused. But somehow fivewin cannot process the up/down arrow keys. Here's fragment of the code: @ 0,0 listbox aObject[AO_JOURNALLIST] fields headers 'Journal xx' alias 'ARRAY' pixel #define LINES_NONE 0 aObject[AO_JOURNALLIST]:nLineStyle := LINES_NONE // aObject[AO_JOURNALLIST]:AdjClient() // Below statement does same as above and handles resize aObject[AO_JOURNALWINDOW]:SetControl(aObject[AO_JOURNALLIST]) aObject[AO_JOURNALLIST]:bKeyChar := GetWndFrame():bKeyChar // Apply font and color after journal list box is created 03/17/2004 11:42AM activate window aObject[AO_JOURNALWINDOW] on init ( oRect:Apply( self ), ClickEvent( aObject[AO_JOURNALLIST], 'Journal' ) ) ; valid oRect:Save( aObject[AO_JOURNALWINDOW] ) .and. lChildEnd() // logmsg( 'res.txt','Font ' +'aObject[AO_JOURNALWINDOW]:oFont:hFont' +' handle: ' +char( aObject[AO_JOURNALWINDOW]:oFont:hFont ) ) aObject[AO_JOURNALWINDOW]:Refresh() aObject[AO_JOURNALWINDOW]:SetFocus() // FW recommendation - jdd aObject[AO_JOURNALLIST]:bKeyDown:={||msgInfo("KeyCode: "+str(LS_getKeyPressed())+ " lastkey:" +str(lastkey()) )} Observation: The b:KeyDown is invoked by FW when Up/down Arrow keys is pressed. The value of nKeyPressed is 255 in both up/down Arrow keys. ************************* function LS_getKeyPressed ************************* local i:=0,nKeyPressed:=0 for i=0 to 255 //if getKeyStat(i) if getAsyncKey(i) nKeyPressed=i exit endif next i return nKeyPressed *************** Gracias,
Arrow keys don't work in ListBox in FW24 and XP
If you are using a DBF index, please rebuild it, in case it may be corrupted.
Arrow keys don't work in ListBox in FW24 and XP
Test it this way: aObject[AO_JOURNALLIST]:bKeyDown:={| nKey | MsgInfo( nKey ) }
Arrow keys don't work in ListBox in FW24 and XP
Antonio, I am using array not DBF file . What is the value o:nLastKey? It is the same as getAsynckey(i)? I am getting 255 on up, down, left, right, and some other keys on POS keyboard. Is there any fivewin function that can properly identify these POS keys? TIA, Jose
Arrow keys don't work in ListBox in FW24 and XP
Jose, Check the values that you get here: aObject[AO_JOURNALLIST]:bKeyDown:={| nKey | MsgInfo( nKey ) }
Arrow keys don't work in ListBox in FW24 and XP
>Check the values that you get here: >aObject[AO_JOURNALLIST]:bKeyDown:={| nKey | MsgInfo( nKey ) } That helps a lot! I wonder why it is not mentioned in the documentation that it can receive two parameters (nKey, nFlags)? Or I just missed it? nFlag value was the essential data in this particular case. MUCHAS GRACIAS AMIGO !!!! Jose
Arrow keys don't work in ListBox in FW24 and XP
Jose, De la documentación de classes de FWH: <bKeyDown> Whenever the window has focus and a NON-SYSTEM key is pressed (ie the <Alt> key was not pressed in conjunction with this key), this codeblock will be called. When <bKeyDown> is called it receives two parameters: <nKey> The virtual key code of the key. <nFlags> Specifies several internal values like repeat code and scan code. For more information about these values please read a MS-Windows APIdescription about the WM_KEYDOWN message.
Articulo de Notacion Hungara
Buenas noches, recuerdo que había un articulo sobre notación húngara enfocada en xBase, no estoy seguro pero creo que era del propio Antonio Linares, será que alguien puede facilitarme esta información. Gracias saludos Marcelo
Articulo de Notacion Hungara
Echale un oj a este link: [url:26l5lkav]http&#58;//es&#46;wikipedia&#46;org/wiki/Notaci%C3%B3n_h%C3%BAngara[/url:26l5lkav] Salu2
Articulo de Notacion Hungara
Willi, gracias, ya vi muchos enlaces, pero no el que estoy buscando, encontre el articulo de Antonio en un sitio que no lo tengo ahora a mano, pero el zip esta truncado, ojala, alguien lo haya guardado por alli. Ahora esta notacion tambien la puedes encontrar en el sitio de MS [url:1c7vy6ev]http&#58;//msdn&#46;microsoft&#46;com/en-us/library/aa260976(VS&#46;60)&#46;aspx[/url:1c7vy6ev] pero me interesa este documento ya que esta simplificado y orientado a xBase, si alguien lo tiene se lo agradecere. saludos Marcelo
Articulo de Notacion Hungara
Marcelo, A que direccion de email te la envio? Saludos George
Articulo de Notacion Hungara
George, gracias, envíamela a marcelo.via < arroba > gmail <punto> com muchas gracias Marcelo
Articulo de Notacion Hungara
Saludos George Es muy largo el archive para ponerlo aca...? Si puedes enviamelo para colarlo en un link fijo gracias
Articulo de Notacion Hungara
Que tal Daniel, Ya te envie el documento, en formato PDF, a tu email. Saludos, George
Articulo de Notacion Hungara
Por favor enviar tambien a <!-- e --><a href="mailto:compuin@gmail.com">compuin@gmail.com</a><!-- e -->
Articulo de Notacion Hungara
[url:fs0f4bwg]http&#58;//books&#46;google&#46;com&#46;mx/books?id=vrtI4i8kA4EC&pg=PA38&lpg=PA38&dq=Notacion+Hungara+Clipper&source=bl&ots=THyrfAEXCX&sig=2uPBuR-Wn-DF5f2WELiwABDyXXQ&hl=es&ei=1ah3TeXKNOO90QHUhPjeBg&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBEQ6AEwAA#v=onepage&q&f=false[/url:fs0f4bwg][quote="Compuin":fs0f4bwg]Por favor enviar tambien a <!-- e --><a href="mailto:compuin@gmail.com">compuin@gmail.com</a><!-- e -->[/quote:fs0f4bwg]
Articulo de Notacion Hungara
Daniel; Esta cargado este documento?, donde? muchas gracias
Articulo de Notacion Hungara
Mario Gracias por recordarme ya se me habia olvidado [url:34nezi7b]http&#58;//www&#46;sitasoft&#46;net/fivewin/files/NotacionHungara_ALinares&#46;pdf[/url:34nezi7b]
Articulo de Notacion Hungara
<!-- s:wink: --><img src="{SMILIES_PATH}/icon_wink.gif" alt=":wink:" title="Wink" /><!-- s:wink: --> gracias a vos por ponerlo a disposición de todos
Articulo interesante sobre Servicios Web...
Aquí:[url:4vd7e6xe]http&#58;//jhernandz&#46;es/noticia/servicio-web-php[/url:4vd7e6xe]
Articulo interesante sobre Servicios Web...
Gracias Manu, muy buen artículo, parece que andamos sintonizando en algunas cosas. Un saludo
Artificial Intelligence - Class TNeuralNetwork
Work in progress: [url:1rb32z3l]https&#58;//gist&#46;github&#46;com/espiritusanti/b7485c68a06ef2c8c76d8c62c8c39d8f[/url:1rb32z3l] [img:1rb32z3l]https&#58;//images&#46;squarespace-cdn&#46;com/content/v1/5ccb715016b640627a1c2782/1586907440135-6INS2V3VS31ICY3TNUIW/ke17ZwdGBToddI8pDm48kM7Hgu4An2PrL1s4UDY39G9Zw-zPPgdn4jUwVcJE1ZvWQUxwkmyExglNqGp0IvTJZUJFbgE-7XRK3dMEBRBhUpx5oYpcWMdEWaE157hoW4SYC3z6-VoWT_OzIRri0cyZi4HUF7pvRu4VWIc2CHVp6pQ/ai-artificial-neural-network-alex-castrounis&#46;png?format=750w[/img:1rb32z3l] [code=fw:1rb32z3l]<div class="fw" id="{CB}" style="font-family: monospace;">#ifdef __PLATFORM__WINDOWS <br />   <span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"c:<span style="color: #000000;">\h</span>arbour<span style="color: #000000;">\i</span>nclude<span style="color: #000000;">\h</span>bclass.ch"</span><br />#else<br />   <span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"/usr/include/harbour/hbclass.ch"</span><br />#endif<br /><br /><span style="color: #00D7D7;">#define</span> NUM_INPUTS               <span style="color: #000000;">2</span><br /><span style="color: #00D7D7;">#define</span> A_HIDDENLAYERSNEURONS  <span style="color: #000000;">&#123;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#125;</span>  <span style="color: #B900B9;">// one hiddenlayers with 2 neurons</span><br /><span style="color: #00D7D7;">#define</span> NUM_OUTPUTS              <span style="color: #000000;">1</span><br /><br /><span style="color: #00C800;">static</span> nLearningRate := <span style="color: #000000;">0.1</span><br /><br /><span style="color: #00C800;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">local</span> oNN := TNeuralNetwork<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> NUM_INPUTS, A_HIDDENLAYERSNEURONS, NUM_OUTPUTS <span style="color: #000000;">&#41;</span><br /><br />   oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><br />   oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><br />   oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><br />   oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><br />   <br />   ? Time<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />   <span style="color: #00C800;">DATA</span>   oInputLayer<br />   <br />   <span style="color: #00C800;">DATA</span>   aHiddenLayers <span style="color: #0000ff;">INIT</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>    <br />   <br />   <span style="color: #00C800;">DATA</span>   oOutputLayer<br />   <br />   <span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs, aHiddenLayersNeurons, nOutputs <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">METHOD</span> Learn<span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">METHOD</span> Propagation<span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">METHOD</span> BackPropagation<span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">ENDCLASS</span><br /><br /><span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs, aHiddenLayersNeurons, nOutputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />   <span style="color: #00C800;">local</span> n<br /><br />   ::<span style="color: #000000;">oInputLayer</span> = TNeuralLayer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs, nInputs <span style="color: #000000;">&#41;</span><br />   <br />   <span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">&#40;</span> aHiddenLayersNeurons <span style="color: #000000;">&#41;</span> <span style="color: #B900B9;">// number of hidden layers</span><br />      AAdd<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aHiddenLayers</span>, TNeuralLayer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> aHiddenLayersNeurons<span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span>,;<br />            <span style="color: #00C800;">If</span><span style="color: #000000;">&#40;</span> n == <span style="color: #000000;">1</span>, nInputs, aHiddenLayersNeurons<span style="color: #000000;">&#91;</span> n - <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">next</span><br />   <br />   ::<span style="color: #000000;">oOutputLayer</span> = TNeuralLayer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nOutputs, ATail<span style="color: #000000;">&#40;</span> aHiddenLayersNeurons <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />   <br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">Self</span>   <br /><br /><span style="color: #00C800;">METHOD</span> Learn<span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />   <span style="color: #00C800;">local</span> n<br /><br />   ::<span style="color: #000000;">Propagation</span><span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span><br />   ::<span style="color: #000000;">BackPropagation</span><span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span><br />   <br />   ? <span style="color: #ff0000;">"Inputs:"</span>, aInputs<br />   <br />   <span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span> <span style="color: #000000;">&#41;</span><br />      ?? <span style="color: #ff0000;">", output:"</span>, ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">nValue</span><br />      ?? <span style="color: #ff0000;">", expected output:"</span>, aOutputs<span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span><br />      ?? <span style="color: #ff0000;">", error:"</span>, ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">nDeltaError</span><br />   <span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span> <br /><br /><span style="color: #00C800;">METHOD</span> Propagation<span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />   <span style="color: #00C800;">local</span> oInputNeuron, oHiddenLayer, oHiddenLayerNeuron, oOutputNeuron, nSum<br />   <br />   <span style="color: #00C800;">for</span> each oInputNeuron in ::<span style="color: #000000;">oInputLayer</span>:<span style="color: #000000;">aNeurons</span><br />      oInputNeuron:<span style="color: #000000;">nValue</span> = aInputs<span style="color: #000000;">&#91;</span> oInputNeuron:__enumIndex <span style="color: #000000;">&#93;</span><br />   <span style="color: #00C800;">next</span><br />   <br />   <span style="color: #00C800;">for</span> each oHiddenLayer in ::<span style="color: #000000;">aHiddenLayers</span><br />      <span style="color: #00C800;">if</span> oHiddenLayer:__enumIndex == <span style="color: #000000;">1</span><br />         <span style="color: #00C800;">for</span> each oHiddenLayerNeuron in oHiddenLayer:<span style="color: #000000;">aNeurons</span><br />            nSum = oHiddenLayerNeuron:<span style="color: #000000;">nBias</span><br />            <span style="color: #00C800;">for</span> each oInputNeuron in ::<span style="color: #000000;">oInputLayer</span>:<span style="color: #000000;">aNeurons</span><br />               nSum += oInputNeuron:<span style="color: #000000;">nValue</span> * oHiddenLayerNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oInputNeuron:__enumIndex <span style="color: #000000;">&#93;</span><br />            <span style="color: #00C800;">next</span><br />            oHiddenLayerNeuron:<span style="color: #000000;">nValue</span> = Sigmoid<span style="color: #000000;">&#40;</span> nSum <span style="color: #000000;">&#41;</span><br />         <span style="color: #00C800;">next</span><br />      <span style="color: #00C800;">endif</span><br />   <span style="color: #00C800;">next</span>  <br /><br />   <span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />      nSum = oOutputNeuron:<span style="color: #000000;">nBias</span><br />      <span style="color: #00C800;">for</span> each oHiddenLayerNeuron in ATail<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aHiddenLayers</span> <span style="color: #000000;">&#41;</span>:<span style="color: #000000;">aNeurons</span><br />        nSum += oHiddenLayerNeuron:<span style="color: #000000;">nValue</span> * oOutputNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oHiddenLayerNeuron:__enumIndex <span style="color: #000000;">&#93;</span><br />      <span style="color: #00C800;">next</span><br />      oOutputNeuron:<span style="color: #000000;">nValue</span> = Sigmoid<span style="color: #000000;">&#40;</span> nSum <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">METHOD</span> BackPropagation<span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />   <span style="color: #00C800;">local</span> oOutputNeuron, oHiddenLayer, oHiddenLayerNeuron, oInputNeuron, nError<br />   <br />   <span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />      nError = aOutputs<span style="color: #000000;">&#91;</span> oOutputNeuron:__enumIndex <span style="color: #000000;">&#93;</span> - oOutputNeuron:<span style="color: #000000;">nValue</span><br />      oOutputNeuron:<span style="color: #000000;">nDeltaError</span> = nError * dSigmoid<span style="color: #000000;">&#40;</span> oOutputNeuron:<span style="color: #000000;">nValue</span> <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">next</span>    <br />   <br />   <span style="color: #00C800;">for</span> each oHiddenLayer in ::<span style="color: #000000;">aHiddenLayers</span> <span style="color: #B900B9;">// how to step it backwards ?</span><br />      <span style="color: #00C800;">if</span> oHiddenLayer:__enumIndex == Len<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aHiddenLayers</span> <span style="color: #000000;">&#41;</span><br />         <span style="color: #00C800;">for</span> each oHiddenLayerNeuron in oHiddenLayer:<span style="color: #000000;">aNeurons</span><br />            nError = <span style="color: #000000;">0</span><br />            <span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />               nError += oOutputNeuron:<span style="color: #000000;">nDeltaError</span> * oHiddenLayerNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oOutputNeuron:__enumIndex <span style="color: #000000;">&#93;</span>             <br />            <span style="color: #00C800;">next</span><br />            oHiddenLayerNeuron:<span style="color: #000000;">nDeltaError</span> = nError * dSigmoid<span style="color: #000000;">&#40;</span> oHiddenLayerNeuron:<span style="color: #000000;">nValue</span> <span style="color: #000000;">&#41;</span><br />         <span style="color: #00C800;">next</span>      <br />      <span style="color: #00C800;">else</span><br />      <span style="color: #00C800;">endif</span><br />   <span style="color: #00C800;">next</span><br />   <br />   <span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />      oOutputNeuron:<span style="color: #000000;">nBias</span> += oOutputNeuron:<span style="color: #000000;">nDeltaError</span> * nLearningRate<br />      <span style="color: #00C800;">for</span> each oHiddenLayer in ::<span style="color: #000000;">aHiddenLayers</span><br />         <span style="color: #00C800;">if</span> oHiddenLayer:__enumIndex == Len<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aHiddenLayers</span> <span style="color: #000000;">&#41;</span><br />            <span style="color: #00C800;">for</span> each oHiddenLayerNeuron in oHiddenLayer:<span style="color: #000000;">aNeurons</span><br />               <span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />                  oOutputNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oHiddenLayerNeuron:__enumIndex <span style="color: #000000;">&#93;</span> += oHiddenLayerNeuron:<span style="color: #000000;">nValue</span> * ;<br />                  oOutputNeuron:<span style="color: #000000;">nDeltaError</span> * nLearningRate<br />               <span style="color: #00C800;">next</span>         <br />            <span style="color: #00C800;">next</span><br />         <span style="color: #00C800;">endif</span><br />      <span style="color: #00C800;">next</span>     <br />   <span style="color: #00C800;">next</span>  <br />   <br />   <span style="color: #00C800;">for</span> each oHiddenLayerNeuron in ::<span style="color: #000000;">aHiddenLayers</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aNeurons</span><br />      oHiddenLayerNeuron:<span style="color: #000000;">nBias</span> += oHiddenLayerNeuron:<span style="color: #000000;">nDeltaError</span> * nLearningRate<br />      <span style="color: #00C800;">for</span> each oInputNeuron in ::<span style="color: #000000;">oInputLayer</span>:<span style="color: #000000;">aNeurons</span><br />         oHiddenLayerNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oInputNeuron:__enumIndex <span style="color: #000000;">&#93;</span> += aInputs<span style="color: #000000;">&#91;</span> oHiddenLayerNeuron:__enumIndex <span style="color: #000000;">&#93;</span> * ;<br />         oHiddenLayerNeuron:<span style="color: #000000;">nDeltaError</span> * nLearningRate<br />      <span style="color: #00C800;">next</span><br />   <span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">CLASS</span> TNeuralLayer<br /><br />   <span style="color: #00C800;">DATA</span>   aNeurons <span style="color: #0000ff;">INIT</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><br />   <br />   <span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nNeurons, nInputs <span style="color: #000000;">&#41;</span>    <br />   <br /><span style="color: #00C800;">ENDCLASS</span>   <br /><br /><span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nNeurons, nInputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralLayer<br /><br />   <span style="color: #00C800;">local</span> n<br />   <br />   <span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> nNeurons<br />      AAdd<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aNeurons</span>, TNeuron<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">Self</span><br /><br /><span style="color: #00C800;">CLASS</span> TNeuron<br /><br />   <span style="color: #00C800;">DATA</span>   nBias    <span style="color: #0000ff;">INIT</span> hb_Random<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   <br />   <span style="color: #00C800;">DATA</span>   aWeights<br />   <br />   <span style="color: #00C800;">DATA</span>   nValue<br />   <br />   <span style="color: #00C800;">DATA</span>   nDeltaError<br />   <br />   <span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span><br />   <br /><span style="color: #00C800;">ENDCLASS</span><br /><br /><span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuron<br /><br />   <span style="color: #00C800;">local</span> n<br /><br />   ::<span style="color: #000000;">aWeights</span> = Array<span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span><br />   <br />   <span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> nInputs<br />      ::<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span> = hb_Random<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">next</span>      <br />   <br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">Self</span>   <br /><br /><span style="color: #00C800;">function</span> Sigmoid<span style="color: #000000;">&#40;</span> nValue <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #000000;">1</span> / <span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span> + Math_E<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>  ^ -nValue <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">function</span> dSigmoid<span style="color: #000000;">&#40;</span> nValue <span style="color: #000000;">&#41;</span> <span style="color: #B900B9;">// returns the derivative of the sigmoid function</span><br /><br />   <span style="color: #00C800;">local</span> n := Sigmoid<span style="color: #000000;">&#40;</span> nValue <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">return</span> n * <span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span> - n <span style="color: #000000;">&#41;</span></div>[/code:1rb32z3l]
Artificial Intelligence - Class TNeuralNetwork
Testing the Neural Network once trained: [code=fw:13bae19t]<div class="fw" id="{CB}" style="font-family: monospace;">#ifdef __PLATFORM__WINDOWS <br />   <span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"c:<span style="color: #000000;">\h</span>arbour<span style="color: #000000;">\i</span>nclude<span style="color: #000000;">\h</span>bclass.ch"</span><br />#else<br />   <span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"/usr/include/harbour/hbclass.ch"</span><br />#endif<br /><br /><span style="color: #00D7D7;">#define</span> NUM_INPUTS               <span style="color: #000000;">2</span><br /><span style="color: #00D7D7;">#define</span> A_HIDDENLAYERSNEURONS  <span style="color: #000000;">&#123;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#125;</span>  <span style="color: #B900B9;">// one hiddenlayers with 2 neurons</span><br /><span style="color: #00D7D7;">#define</span> NUM_OUTPUTS              <span style="color: #000000;">1</span><br /><br /><span style="color: #00C800;">static</span> nLearningRate := <span style="color: #000000;">0.1</span><br /><br /><span style="color: #00C800;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">local</span> oNN := TNeuralNetwork<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> NUM_INPUTS, A_HIDDENLAYERSNEURONS, NUM_OUTPUTS <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">local</span> n<br />   <br />   <span style="color: #B900B9;">/*<br />   for n = 1 to 10000<br />      oNN:Learn( { 0, 0 }, { 0 }, .F. )<br />      oNN:Learn( { 1, 0 }, { 1 }, .F. )<br />      oNN:Learn( { 0, 1 }, { 1 }, .F. )<br />      oNN:Learn( { 1, 1 }, { 0 }, .F. )<br />   next <br />   */</span><br />   <br />   oNN:<span style="color: #000000;">aHiddenLayers</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span> = <span style="color: #000000;">3.70166</span><br />   oNN:<span style="color: #000000;">aHiddenLayers</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#93;</span> = <span style="color: #000000;">3.7104</span><br />   oNN:<span style="color: #000000;">aHiddenLayers</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">nBias</span> = <span style="color: #000000;">-5.67588</span><br />   oNN:<span style="color: #000000;">aHiddenLayers</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span> = <span style="color: #000000;">5.83499</span><br />   oNN:<span style="color: #000000;">aHiddenLayers</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#93;</span> = <span style="color: #000000;">5.87966</span><br />   oNN:<span style="color: #000000;">aHiddenLayers</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">nBias</span> = <span style="color: #000000;">-2.45284</span><br />   oNN:<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span> = <span style="color: #000000;">-8.19958</span><br />   oNN:<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#93;</span> = <span style="color: #000000;">7.52827</span><br />   oNN:<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">nBias</span> = <span style="color: #000000;">-3.3797</span><br /><br />   oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, .T. <span style="color: #000000;">&#41;</span><br />   oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>, .T. <span style="color: #000000;">&#41;</span><br />   oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>, .T. <span style="color: #000000;">&#41;</span><br />   oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, .T. <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #B900B9;">// ? oNN</span><br />   <br />   ? Time<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />   <span style="color: #00C800;">DATA</span>   oInputLayer<br />   <br />   <span style="color: #00C800;">DATA</span>   aHiddenLayers <span style="color: #0000ff;">INIT</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>    <br />   <br />   <span style="color: #00C800;">DATA</span>   oOutputLayer<br />   <br />   <span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs, aHiddenLayersNeurons, nOutputs <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">METHOD</span> Learn<span style="color: #000000;">&#40;</span> aInputs, aOutputs, lDebug <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">METHOD</span> Propagation<span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">METHOD</span> BackPropagation<span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">ENDCLASS</span><br /><br /><span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs, aHiddenLayersNeurons, nOutputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />   <span style="color: #00C800;">local</span> n<br /><br />   ::<span style="color: #000000;">oInputLayer</span> = TNeuralLayer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs, nInputs <span style="color: #000000;">&#41;</span><br />   <br />   <span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">&#40;</span> aHiddenLayersNeurons <span style="color: #000000;">&#41;</span> <span style="color: #B900B9;">// number of hidden layers</span><br />      AAdd<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aHiddenLayers</span>, TNeuralLayer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> aHiddenLayersNeurons<span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span>,;<br />            <span style="color: #00C800;">If</span><span style="color: #000000;">&#40;</span> n == <span style="color: #000000;">1</span>, nInputs, aHiddenLayersNeurons<span style="color: #000000;">&#91;</span> n - <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">next</span><br />   <br />   ::<span style="color: #000000;">oOutputLayer</span> = TNeuralLayer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nOutputs, ATail<span style="color: #000000;">&#40;</span> aHiddenLayersNeurons <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />   <br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">Self</span>   <br /><br /><span style="color: #00C800;">METHOD</span> Learn<span style="color: #000000;">&#40;</span> aInputs, aOutputs, lDebug <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />   <span style="color: #00C800;">local</span> n<br /><br />   ::<span style="color: #000000;">Propagation</span><span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span><br />   ::<span style="color: #000000;">BackPropagation</span><span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span><br />   <br />   <span style="color: #00C800;">if</span> lDebug<br />      ? <span style="color: #ff0000;">"Inputs:"</span>, aInputs<br />   <br />      <span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span> <span style="color: #000000;">&#41;</span><br />         ?? <span style="color: #ff0000;">", output:"</span>, ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">nValue</span><br />         ?? <span style="color: #ff0000;">", expected output:"</span>, aOutputs<span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span><br />         ?? <span style="color: #ff0000;">", error:"</span>, ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">nDeltaError</span><br />      <span style="color: #00C800;">next</span><br />   <span style="color: #00C800;">endif</span>      <br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span> <br /><br /><span style="color: #00C800;">METHOD</span> Propagation<span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />   <span style="color: #00C800;">local</span> oInputNeuron, oHiddenLayer, oHiddenLayerNeuron, oOutputNeuron, nSum<br />   <br />   <span style="color: #00C800;">for</span> each oInputNeuron in ::<span style="color: #000000;">oInputLayer</span>:<span style="color: #000000;">aNeurons</span><br />      oInputNeuron:<span style="color: #000000;">nValue</span> = aInputs<span style="color: #000000;">&#91;</span> oInputNeuron:__enumIndex <span style="color: #000000;">&#93;</span><br />   <span style="color: #00C800;">next</span><br />   <br />   <span style="color: #00C800;">for</span> each oHiddenLayer in ::<span style="color: #000000;">aHiddenLayers</span><br />      <span style="color: #00C800;">if</span> oHiddenLayer:__enumIndex == <span style="color: #000000;">1</span><br />         <span style="color: #00C800;">for</span> each oHiddenLayerNeuron in oHiddenLayer:<span style="color: #000000;">aNeurons</span><br />            nSum = oHiddenLayerNeuron:<span style="color: #000000;">nBias</span><br />            <span style="color: #00C800;">for</span> each oInputNeuron in ::<span style="color: #000000;">oInputLayer</span>:<span style="color: #000000;">aNeurons</span><br />               nSum += oInputNeuron:<span style="color: #000000;">nValue</span> * oHiddenLayerNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oInputNeuron:__enumIndex <span style="color: #000000;">&#93;</span><br />            <span style="color: #00C800;">next</span><br />            oHiddenLayerNeuron:<span style="color: #000000;">nValue</span> = Sigmoid<span style="color: #000000;">&#40;</span> nSum <span style="color: #000000;">&#41;</span><br />         <span style="color: #00C800;">next</span><br />      <span style="color: #00C800;">endif</span><br />   <span style="color: #00C800;">next</span>  <br /><br />   <span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />      nSum = oOutputNeuron:<span style="color: #000000;">nBias</span><br />      <span style="color: #00C800;">for</span> each oHiddenLayerNeuron in ATail<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aHiddenLayers</span> <span style="color: #000000;">&#41;</span>:<span style="color: #000000;">aNeurons</span><br />        nSum += oHiddenLayerNeuron:<span style="color: #000000;">nValue</span> * oOutputNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oHiddenLayerNeuron:__enumIndex <span style="color: #000000;">&#93;</span><br />      <span style="color: #00C800;">next</span><br />      oOutputNeuron:<span style="color: #000000;">nValue</span> = Sigmoid<span style="color: #000000;">&#40;</span> nSum <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">METHOD</span> BackPropagation<span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />   <span style="color: #00C800;">local</span> oOutputNeuron, oHiddenLayer, oHiddenLayerNeuron, oInputNeuron, nError<br />   <br />   <span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />      nError = aOutputs<span style="color: #000000;">&#91;</span> oOutputNeuron:__enumIndex <span style="color: #000000;">&#93;</span> - oOutputNeuron:<span style="color: #000000;">nValue</span><br />      oOutputNeuron:<span style="color: #000000;">nDeltaError</span> = nError * dSigmoid<span style="color: #000000;">&#40;</span> oOutputNeuron:<span style="color: #000000;">nValue</span> <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">next</span>    <br />   <br />   <span style="color: #00C800;">for</span> each oHiddenLayer in ::<span style="color: #000000;">aHiddenLayers</span> <span style="color: #B900B9;">// how to step it backwards ?</span><br />      <span style="color: #00C800;">if</span> oHiddenLayer:__enumIndex == Len<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aHiddenLayers</span> <span style="color: #000000;">&#41;</span><br />         <span style="color: #00C800;">for</span> each oHiddenLayerNeuron in oHiddenLayer:<span style="color: #000000;">aNeurons</span><br />            nError = <span style="color: #000000;">0</span><br />            <span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />               nError += oOutputNeuron:<span style="color: #000000;">nDeltaError</span> * oOutputNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oOutputNeuron:__enumIndex <span style="color: #000000;">&#93;</span>             <br />            <span style="color: #00C800;">next</span><br />            oHiddenLayerNeuron:<span style="color: #000000;">nDeltaError</span> = nError * dSigmoid<span style="color: #000000;">&#40;</span> oHiddenLayerNeuron:<span style="color: #000000;">nValue</span> <span style="color: #000000;">&#41;</span><br />         <span style="color: #00C800;">next</span>      <br />      <span style="color: #00C800;">else</span><br />      <span style="color: #00C800;">endif</span><br />   <span style="color: #00C800;">next</span><br />   <br />   <span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />      oOutputNeuron:<span style="color: #000000;">nBias</span> += oOutputNeuron:<span style="color: #000000;">nDeltaError</span> * nLearningRate<br />      <span style="color: #00C800;">for</span> each oHiddenLayer in ::<span style="color: #000000;">aHiddenLayers</span><br />         <span style="color: #00C800;">if</span> oHiddenLayer:__enumIndex == Len<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aHiddenLayers</span> <span style="color: #000000;">&#41;</span><br />            <span style="color: #00C800;">for</span> each oHiddenLayerNeuron in oHiddenLayer:<span style="color: #000000;">aNeurons</span><br />               <span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />                  oOutputNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oHiddenLayerNeuron:__enumIndex <span style="color: #000000;">&#93;</span> += oHiddenLayerNeuron:<span style="color: #000000;">nValue</span> * ;<br />                  oOutputNeuron:<span style="color: #000000;">nDeltaError</span> * nLearningRate<br />               <span style="color: #00C800;">next</span>         <br />            <span style="color: #00C800;">next</span><br />         <span style="color: #00C800;">endif</span><br />      <span style="color: #00C800;">next</span>     <br />   <span style="color: #00C800;">next</span>  <br />   <br />   <span style="color: #00C800;">for</span> each oHiddenLayerNeuron in ::<span style="color: #000000;">aHiddenLayers</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aNeurons</span><br />      oHiddenLayerNeuron:<span style="color: #000000;">nBias</span> += oHiddenLayerNeuron:<span style="color: #000000;">nDeltaError</span> * nLearningRate<br />      <span style="color: #00C800;">for</span> each oInputNeuron in ::<span style="color: #000000;">oInputLayer</span>:<span style="color: #000000;">aNeurons</span><br />         oHiddenLayerNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oInputNeuron:__enumIndex <span style="color: #000000;">&#93;</span> += aInputs<span style="color: #000000;">&#91;</span> oHiddenLayerNeuron:__enumIndex <span style="color: #000000;">&#93;</span> * ;<br />         oHiddenLayerNeuron:<span style="color: #000000;">nDeltaError</span> * nLearningRate<br />      <span style="color: #00C800;">next</span><br />   <span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">CLASS</span> TNeuralLayer<br /><br />   <span style="color: #00C800;">DATA</span>   aNeurons <span style="color: #0000ff;">INIT</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><br />   <br />   <span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nNeurons, nInputs <span style="color: #000000;">&#41;</span>    <br />   <br /><span style="color: #00C800;">ENDCLASS</span>   <br /><br /><span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nNeurons, nInputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralLayer<br /><br />   <span style="color: #00C800;">local</span> n<br />   <br />   <span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> nNeurons<br />      AAdd<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aNeurons</span>, TNeuron<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">Self</span><br /><br /><span style="color: #00C800;">CLASS</span> TNeuron<br /><br />   <span style="color: #00C800;">DATA</span>   nBias    <span style="color: #0000ff;">INIT</span> hb_Random<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   <br />   <span style="color: #00C800;">DATA</span>   aWeights<br />   <br />   <span style="color: #00C800;">DATA</span>   nValue<br />   <br />   <span style="color: #00C800;">DATA</span>   nDeltaError<br />   <br />   <span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span><br />   <br /><span style="color: #00C800;">ENDCLASS</span><br /><br /><span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuron<br /><br />   <span style="color: #00C800;">local</span> n<br /><br />   ::<span style="color: #000000;">aWeights</span> = Array<span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span><br />   <br />   <span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> nInputs<br />      ::<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span> = hb_Random<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">next</span>      <br />   <br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">Self</span>   <br /><br /><span style="color: #00C800;">function</span> Sigmoid<span style="color: #000000;">&#40;</span> nValue <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #000000;">1</span> / <span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span> + Math_E<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>  ^ -nValue <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">function</span> dSigmoid<span style="color: #000000;">&#40;</span> nValue <span style="color: #000000;">&#41;</span> <span style="color: #B900B9;">// returns the derivative of the sigmoid function</span><br /><br />   <span style="color: #B900B9;">// local n := Sigmoid( nValue )</span><br /><br /><span style="color: #00C800;">return</span> nValue * <span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span> - nValue <span style="color: #000000;">&#41;</span></div>[/code:13bae19t] [quote:13bae19t]Inputs: {0, 0}, output: 0.06 , expected output: 0 , error: -0.003035 Inputs: {1, 0}, output: 0.95 , expected output: 1 , error: 0.002573 Inputs: {0, 1}, output: 0.95 , expected output: 1 , error: 0.002556 Inputs: {1, 1}, output: 0.06 , expected output: 0 , error: -0.002977[/quote:13bae19t]
Artificial Intelligence - Class TNeuralNetwork
Working version (just missing the multi hidden layer support) [code=fw:u7k4bvot]<div class="fw" id="{CB}" style="font-family: monospace;">#ifdef __PLATFORM__WINDOWS <br />&nbsp; &nbsp;<span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"c:<span style="color: #000000;">\h</span>arbour<span style="color: #000000;">\i</span>nclude<span style="color: #000000;">\h</span>bclass.ch"</span><br />#else<br />&nbsp; &nbsp;<span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"/usr/include/harbour/hbclass.ch"</span><br />#endif<br /><br /><span style="color: #00D7D7;">#define</span> NUM_INPUTS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">2</span><br /><span style="color: #00D7D7;">#define</span> A_HIDDENLAYERSNEURONS &nbsp;<span style="color: #000000;">&#123;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#125;</span> &nbsp;<span style="color: #B900B9;">// one hiddenlayers with 2 neurons</span><br /><span style="color: #00D7D7;">#define</span> NUM_OUTPUTS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">1</span><br /><br /><span style="color: #00C800;">static</span> nLearningRate := <span style="color: #000000;">0.1</span><br /><br /><span style="color: #00C800;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> oNN := TNeuralNetwork<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> NUM_INPUTS, A_HIDDENLAYERSNEURONS, NUM_OUTPUTS <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> n<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;SET DECIMALS <span style="color: #0000ff;">TO</span> <span style="color: #000000;">6</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> <span style="color: #000000;">30000</span><br />&nbsp; &nbsp; &nbsp; oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, .F. <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>, .F. <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>, .F. <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, .F. <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span> <br /><br />&nbsp; &nbsp;<span style="color: #B900B9;">/*<br />&nbsp; &nbsp;oNN:aHiddenLayers[ 1 ]:aNeurons[ 1 ]:aWeights[ 1 ] = 3.70166<br />&nbsp; &nbsp;oNN:aHiddenLayers[ 1 ]:aNeurons[ 1 ]:aWeights[ 2 ] = 3.7104<br />&nbsp; &nbsp;oNN:aHiddenLayers[ 1 ]:aNeurons[ 1 ]:nBias = -5.67588<br />&nbsp; &nbsp;oNN:aHiddenLayers[ 1 ]:aNeurons[ 2 ]:aWeights[ 1 ] = 5.83499<br />&nbsp; &nbsp;oNN:aHiddenLayers[ 1 ]:aNeurons[ 2 ]:aWeights[ 2 ] = 5.87966<br />&nbsp; &nbsp;oNN:aHiddenLayers[ 1 ]:aNeurons[ 2 ]:nBias = -2.45284<br />&nbsp; &nbsp;oNN:oOutputLayer:aNeurons[ 1 ]:aWeights[ 1 ] = -8.19958<br />&nbsp; &nbsp;oNN:oOutputLayer:aNeurons[ 1 ]:aWeights[ 2 ] = 7.52827<br />&nbsp; &nbsp;oNN:oOutputLayer:aNeurons[ 1 ]:nBias = -3.3797<br />&nbsp; &nbsp;*/</span><br /><br />&nbsp; &nbsp;oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, .T. <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>, .T. <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>, .T. <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;oNN:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, .T. <span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp;<span style="color: #B900B9;">// ? oNN</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;? Time<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />&nbsp; &nbsp;<span style="color: #00C800;">DATA</span> &nbsp; oInputLayer<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">DATA</span> &nbsp; aHiddenLayers <span style="color: #0000ff;">INIT</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span> &nbsp; &nbsp;<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">DATA</span> &nbsp; oOutputLayer<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs, aHiddenLayersNeurons, nOutputs <span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp;<span style="color: #00C800;">METHOD</span> Learn<span style="color: #000000;">&#40;</span> aInputs, aOutputs, lDebug <span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp;<span style="color: #00C800;">METHOD</span> Propagation<span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp;<span style="color: #00C800;">METHOD</span> BackPropagation<span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">ENDCLASS</span><br /><br /><span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs, aHiddenLayersNeurons, nOutputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> n<br /><br />&nbsp; &nbsp;::<span style="color: #000000;">oInputLayer</span> = TNeuralLayer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs, nInputs <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">&#40;</span> aHiddenLayersNeurons <span style="color: #000000;">&#41;</span> <span style="color: #B900B9;">// number of hidden layers</span><br />&nbsp; &nbsp; &nbsp; AAdd<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aHiddenLayers</span>, TNeuralLayer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> aHiddenLayersNeurons<span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span>,;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">If</span><span style="color: #000000;">&#40;</span> n == <span style="color: #000000;">1</span>, nInputs, aHiddenLayersNeurons<span style="color: #000000;">&#91;</span> n - <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;::<span style="color: #000000;">oOutputLayer</span> = TNeuralLayer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nOutputs, ATail<span style="color: #000000;">&#40;</span> aHiddenLayersNeurons <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">Self</span> &nbsp; <br /><br /><span style="color: #00C800;">METHOD</span> Learn<span style="color: #000000;">&#40;</span> aInputs, aOutputs, lDebug <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> n<br /><br />&nbsp; &nbsp;::<span style="color: #000000;">Propagation</span><span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;::<span style="color: #000000;">BackPropagation</span><span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">if</span> lDebug<br />&nbsp; &nbsp; &nbsp; ? <span style="color: #ff0000;">"Inputs:"</span>, aInputs<br />&nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;?? <span style="color: #ff0000;">", output:"</span>, ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">nValue</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;?? <span style="color: #ff0000;">", expected output:"</span>, aOutputs<span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;?? <span style="color: #ff0000;">", error:"</span>, ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">nDeltaError</span><br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">next</span><br />&nbsp; &nbsp;<span style="color: #00C800;">endif</span> &nbsp; &nbsp; &nbsp;<br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span> <br /><br /><span style="color: #00C800;">METHOD</span> Propagation<span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> oInputNeuron, oHiddenLayer, oHiddenLayerNeuron, oOutputNeuron, nSum<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> each oInputNeuron in ::<span style="color: #000000;">oInputLayer</span>:<span style="color: #000000;">aNeurons</span><br />&nbsp; &nbsp; &nbsp; oInputNeuron:<span style="color: #000000;">nValue</span> = aInputs<span style="color: #000000;">&#91;</span> oInputNeuron:__enumIndex <span style="color: #000000;">&#93;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> each oHiddenLayer in ::<span style="color: #000000;">aHiddenLayers</span><br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> oHiddenLayer:__enumIndex == <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">for</span> each oHiddenLayerNeuron in oHiddenLayer:<span style="color: #000000;">aNeurons</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nSum = oHiddenLayerNeuron:<span style="color: #000000;">nBias</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">for</span> each oInputNeuron in ::<span style="color: #000000;">oInputLayer</span>:<span style="color: #000000;">aNeurons</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nSum += oInputNeuron:<span style="color: #000000;">nValue</span> * oHiddenLayerNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oInputNeuron:__enumIndex <span style="color: #000000;">&#93;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">next</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oHiddenLayerNeuron:<span style="color: #000000;">nValue</span> = Sigmoid<span style="color: #000000;">&#40;</span> nSum <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">next</span><br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">endif</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span> &nbsp;<br /><br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />&nbsp; &nbsp; &nbsp; nSum = oOutputNeuron:<span style="color: #000000;">nBias</span><br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">for</span> each oHiddenLayerNeuron in ATail<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aHiddenLayers</span> <span style="color: #000000;">&#41;</span>:<span style="color: #000000;">aNeurons</span><br />&nbsp; &nbsp; &nbsp; &nbsp; nSum += oHiddenLayerNeuron:<span style="color: #000000;">nValue</span> * oOutputNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oHiddenLayerNeuron:__enumIndex <span style="color: #000000;">&#93;</span><br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">next</span><br />&nbsp; &nbsp; &nbsp; oOutputNeuron:<span style="color: #000000;">nValue</span> = Sigmoid<span style="color: #000000;">&#40;</span> nSum <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">METHOD</span> BackPropagation<span style="color: #000000;">&#40;</span> aInputs, aOutputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralNetwork<br /><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> oOutputNeuron, oHiddenLayer, oHiddenLayerNeuron, oInputNeuron, nError<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />&nbsp; &nbsp; &nbsp; nError = aOutputs<span style="color: #000000;">&#91;</span> oOutputNeuron:__enumIndex <span style="color: #000000;">&#93;</span> - oOutputNeuron:<span style="color: #000000;">nValue</span><br />&nbsp; &nbsp; &nbsp; oOutputNeuron:<span style="color: #000000;">nDeltaError</span> = nError * dSigmoid<span style="color: #000000;">&#40;</span> oOutputNeuron:<span style="color: #000000;">nValue</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span> &nbsp; &nbsp;<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> each oHiddenLayer in ::<span style="color: #000000;">aHiddenLayers</span> <span style="color: #B900B9;">// how to step it backwards ?</span><br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> oHiddenLayer:__enumIndex == Len<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aHiddenLayers</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">for</span> each oHiddenLayerNeuron in oHiddenLayer:<span style="color: #000000;">aNeurons</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nError = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nError += oOutputNeuron:<span style="color: #000000;">nDeltaError</span> * oOutputNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oOutputNeuron:__enumIndex <span style="color: #000000;">&#93;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">next</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oHiddenLayerNeuron:<span style="color: #000000;">nDeltaError</span> = nError * dSigmoid<span style="color: #000000;">&#40;</span> oHiddenLayerNeuron:<span style="color: #000000;">nValue</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">next</span> &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">else</span><br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">endif</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />&nbsp; &nbsp; &nbsp; oOutputNeuron:<span style="color: #000000;">nBias</span> += oOutputNeuron:<span style="color: #000000;">nDeltaError</span> * nLearningRate<br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">for</span> each oHiddenLayer in ::<span style="color: #000000;">aHiddenLayers</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">if</span> oHiddenLayer:__enumIndex == Len<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aHiddenLayers</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">for</span> each oHiddenLayerNeuron in oHiddenLayer:<span style="color: #000000;">aNeurons</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">for</span> each oOutputNeuron in ::<span style="color: #000000;">oOutputLayer</span>:<span style="color: #000000;">aNeurons</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oOutputNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oHiddenLayerNeuron:__enumIndex <span style="color: #000000;">&#93;</span> += oHiddenLayerNeuron:<span style="color: #000000;">nValue</span> * ;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oOutputNeuron:<span style="color: #000000;">nDeltaError</span> * nLearningRate<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">next</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">next</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">endif</span><br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">next</span> &nbsp; &nbsp; <br />&nbsp; &nbsp;<span style="color: #00C800;">next</span> &nbsp;<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> each oHiddenLayerNeuron in ::<span style="color: #000000;">aHiddenLayers</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">aNeurons</span><br />&nbsp; &nbsp; &nbsp; oHiddenLayerNeuron:<span style="color: #000000;">nBias</span> += oHiddenLayerNeuron:<span style="color: #000000;">nDeltaError</span> * nLearningRate<br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">for</span> each oInputNeuron in ::<span style="color: #000000;">oInputLayer</span>:<span style="color: #000000;">aNeurons</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;oHiddenLayerNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> oInputNeuron:__enumIndex <span style="color: #000000;">&#93;</span> += aInputs<span style="color: #000000;">&#91;</span> oHiddenLayerNeuron:__enumIndex <span style="color: #000000;">&#93;</span> * ;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;oHiddenLayerNeuron:<span style="color: #000000;">nDeltaError</span> * nLearningRate<br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">next</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">CLASS</span> TNeuralLayer<br /><br />&nbsp; &nbsp;<span style="color: #00C800;">DATA</span> &nbsp; aNeurons <span style="color: #0000ff;">INIT</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nNeurons, nInputs <span style="color: #000000;">&#41;</span> &nbsp; &nbsp;<br />&nbsp; &nbsp;<br /><span style="color: #00C800;">ENDCLASS</span> &nbsp; <br /><br /><span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nNeurons, nInputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuralLayer<br /><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> n<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> nNeurons<br />&nbsp; &nbsp; &nbsp; AAdd<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aNeurons</span>, TNeuron<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">Self</span><br /><br /><span style="color: #00C800;">CLASS</span> TNeuron<br /><br />&nbsp; &nbsp;<span style="color: #00C800;">DATA</span> &nbsp; nBias &nbsp; &nbsp;<span style="color: #0000ff;">INIT</span> hb_Random<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">DATA</span> &nbsp; aWeights<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">DATA</span> &nbsp; nValue<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">DATA</span> &nbsp; nDeltaError<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<br /><span style="color: #00C800;">ENDCLASS</span><br /><br /><span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TNeuron<br /><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> n<br /><br />&nbsp; &nbsp;::<span style="color: #000000;">aWeights</span> = Array<span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> nInputs<br />&nbsp; &nbsp; &nbsp; ::<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span> = hb_Random<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span> &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp;<br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">Self</span> &nbsp; <br /><br /><span style="color: #00C800;">function</span> Sigmoid<span style="color: #000000;">&#40;</span> nValue <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #000000;">1</span> / <span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span> + Math_E<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> &nbsp;^ -nValue <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">function</span> dSigmoid<span style="color: #000000;">&#40;</span> nValue <span style="color: #000000;">&#41;</span> <span style="color: #B900B9;">// returns the derivative of the sigmoid function</span><br /><br />&nbsp; &nbsp;<span style="color: #B900B9;">// local n := Sigmoid( nValue )</span><br /><br /><span style="color: #00C800;">return</span> nValue * <span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span> - nValue <span style="color: #000000;">&#41;</span></div>[/code:u7k4bvot] [quote:u7k4bvot]Inputs: {0, 0}, output: 0.040317 , expected output: 0 , error: -0.001559955174626856 Inputs: {1, 0}, output: 0.963627 , expected output: 1 , error: 0.001274852658445150 Inputs: {0, 1}, output: 0.939530 , expected output: 1 , error: 0.003435486831421813 Inputs: {1, 1}, output: 0.051295 , expected output: 0 , error: -0.002496201295406568[/quote:u7k4bvot]
Artificial Intelligence - Class TNeuralNetwork
function Math_E() defined here: <!-- l --><a class="postlink-local" href="http://fivetechsupport.com/forums/viewtopic.php?p=203329&sid=822e8de1395f0174565c65850cc06770#p203329">viewtopic.php?p=203329&sid=822e8de1395f0174565c65850cc06770#p203329</a><!-- l -->
Artificial Intelligence Pioneer Says We Need To Start Over
To All ... found this on SlashDot.org today ... <!-- m --><a class="postlink" href="https://tech.slashdot.org/story/17/09/15/205202/artificial-intelligence-pioneer-says-we-need-to-start-over">https://tech.slashdot.org/story/17/09/1 ... start-over</a><!-- m --> [quote:2t24ef4j] Artificial Intelligence Pioneer Says We Need To Start Over (axios.com) 6 Posted by msmash on Friday September 15, 2017 @04:05PM from the think-about-it dept. Steve LeVine, writing for Axios: In 1986, Geoffrey Hinton co-authored a paper that, four decades later, is central to the explosion of artificial intelligence. But Hinton says his breakthrough method should be dispensed with, and a new path to AI found. Speaking with Axios on the sidelines of an AI conference in Toronto on Wednesday, Hinton, a professor emeritus at the University of Toronto and a Google researcher, said he is now "deeply suspicious" of back-propagation, the workhorse method that underlies most of the advances we are seeing in the AI field today, including the capacity to sort through photos and talk to Siri. "My view is throw it all away and start again," he said. Other scientists at the conference said back-propagation still has a core role in AI's future. But Hinton said that, to push materially ahead, entirely new methods will probably have to be invented. "Max Planck said, 'Science progresses one funeral at a time.' The future depends on some graduate student who is deeply suspicious of everything I have said." [/quote:2t24ef4j] Comments are Welcome .. Rick Lipkin
Artificial Intelligence Pioneer Says We Need To Start Over
See this and you will get the whole idea <!-- s:-) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":-)" title="Smile" /><!-- s:-) --> [url:2sn1cpme]https&#58;//youtu&#46;be/B8J4uefCQMc[/url:2sn1cpme]
Artificial Intelligence: GPT with Harbour and FWH
Past July 2020, the company OpenAI released GPT3 (175 billions parameters) into private beta which has been a tremendous advance on AI natural language processing. GPT3 is the evolution of previous products and research like Microsoft Turing (17 billions parameters), NVidia Megatron (8 billions parameters), GPT2 (1.5 billions parameters), etc. In fact Google has already announced an enhanced new product named GShard that uses up to 600 billions parameters. GPT stands for "Generative Pre Trained". This means that its work is to "generate" the next word, given some words, and that the system has been trained previously in advance. Seven years ago Google developed and provided a "word2vec" routines that basically help to "vectorize" words. As an example for this, lets consider "colors". Colors can be represented by 3 numbers (red,green,blue) which could be represented as x,y,z coordinates (vectors) in "space". This way we can add "red" and "blue" and obtain "purple". We can see that this vector representation allows to "sum" colors, find "near" colors, "sustract" them, etc. word2vec [url:1ap0fda8]https&#58;//code&#46;google&#46;com/archive/p/word2vec/[/url:1ap0fda8] generates these vectors from a given text, and the results are quite impressive. I have managed to build it on Windows in case you may want to test it. Given those ideas, Rao and I decided to build a simple Harbour and FWH (as the GUI) example to check the basic concepts of a very simple GPT using Harbour. Here you have the code to build it and see how to use it to generate the next word. You can provide your own texts to it. On a next msg we will explain how it works and how you can apply it to your apps already <!-- s:-) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":-)" title="Smile" /><!-- s:-) --> gpt_2.prg [code=fw:1ap0fda8]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"FiveWin.ch"</span><br /><br />request DBFCDX<br /><br />field WORDS<br /><br /><span style="color: #00C800;">static</span> nSize   := <span style="color: #000000;">3</span><br /><br /><span style="color: #00C800;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">local</span> oFont, oDlg, oBrw, oGet, cScope<br />   <span style="color: #00C800;">local</span> cSearch  := Space<span style="color: #000000;">&#40;</span> <span style="color: #000000;">60</span> <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">local</span> aSentences :=  <span style="color: #000000;">&#123;</span> <span style="color: #ff0000;">"the cat eats mouse"</span>,<span style="color: #ff0000;">"the mouse eats cheese"</span>,;<br />         <span style="color: #ff0000;">"the cat eats fish"</span>,<span style="color: #ff0000;">"the fish eats fly"</span>, <span style="color: #ff0000;">"the dog eats meat"</span>, ;<br />         <span style="color: #ff0000;">"the dog barks at strangers"</span>, <span style="color: #ff0000;">"the dog bites theives"</span>, ;<br />         <span style="color: #ff0000;">"this is a really long long text"</span>, <span style="color: #ff0000;">"this was a stage"</span> <span style="color: #000000;">&#125;</span><br /><br />   FErase<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"GPT_2.dbf"</span> <span style="color: #000000;">&#41;</span><br />   FErase<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"GPT_2.cdx"</span> <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">if</span> ! File<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"GPT_2.dbf"</span> <span style="color: #000000;">&#41;</span><br />      DbCreate<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"GPT_2.dbf"</span>, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#123;</span> <span style="color: #ff0000;">"ID"</span>, <span style="color: #ff0000;">"+"</span>, <span style="color: #000000;">10</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #ff0000;">"WORDS"</span>, <span style="color: #ff0000;">"C"</span>, <span style="color: #000000;">30</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span>, <span style="color: #ff0000;">"DBFCDX"</span> <span style="color: #000000;">&#41;</span><br />      USE GPT_2 VIA <span style="color: #ff0000;">"DBFCDX"</span><br />      <span style="color: #0000ff;">INDEX</span> <span style="color: #0000ff;">ON</span> WORDS TAG GPT_2 CUSTOM<br />      USE<br />   <span style="color: #00C800;">endif</span><br /><br />   USE GPT_2 VIA <span style="color: #ff0000;">"DBFCDX"</span><br />   SET ORDER <span style="color: #0000ff;">TO</span> TAG GPT_2<br />   AEval<span style="color: #000000;">&#40;</span> aSentences, <span style="color: #000000;">&#123;</span> |c| RecordSentence<span style="color: #000000;">&#40;</span> c <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><br /><br />   OrdScope<span style="color: #000000;">&#40;</span> <span style="color: #000000;">0</span>, <span style="color: #ff0000;">" "</span> <span style="color: #000000;">&#41;</span><br />   OrdScope<span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span>, <span style="color: #ff0000;">" "</span> <span style="color: #000000;">&#41;</span><br />   GO TOP<br /><br />   SetGetColorFocus<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   <span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">FONT</span> oFont <span style="color: #0000ff;">NAME</span> <span style="color: #ff0000;">"TAHOMA"</span> <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">0</span>,<span style="color: #000000;">-14</span><br />   <span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">DIALOG</span> oDlg <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">800</span>, <span style="color: #000000;">350</span> <span style="color: #0000ff;">PIXEL</span> TRUEPIXEL <span style="color: #0000ff;">FONT</span> oFont<br /><br />   @ <span style="color: #000000;">22</span>,  <span style="color: #000000;">20</span> <span style="color: #0000ff;">SAY</span> <span style="color: #ff0000;">"Enter word(s)"</span> <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">100</span>, <span style="color: #000000;">20</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oDlg<br />   @ <span style="color: #000000;">20</span>, <span style="color: #000000;">120</span> <span style="color: #0000ff;">GET</span> oGet <span style="color: #0000ff;">VAR</span> cSearch <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">660</span>,<span style="color: #000000;">24</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oDlg ;<br />        <span style="color: #0000ff;">ON</span> <span style="color: #0000ff;">CHANGE</span> <span style="color: #000000;">&#40;</span> <span style="color: #00C800;">If</span><span style="color: #000000;">&#40;</span> nKey == <span style="color: #000000;">32</span>, ResetBrowse<span style="color: #000000;">&#40;</span> oGet:<span style="color: #000000;">GetText</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, oBrw <span style="color: #000000;">&#41;</span>, <span style="color: #00C800;">nil</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> ;<br />        <span style="color: #0000ff;">UPDATE</span><br /><br />   @ <span style="color: #000000;">60</span>, <span style="color: #000000;">20</span> <span style="color: #0000ff;">XBROWSE</span> oBrw <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">760</span>, <span style="color: #000000;">250</span> <span style="color: #0000ff;">PIXEL</span> <span style="color: #0000ff;">OF</span> oDlg ;<br />      DATASOURCE ReadSuggestions<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">""</span> <span style="color: #000000;">&#41;</span> ;<br />      COLUMNS <span style="color: #000000;">1</span>, <span style="color: #000000;">2</span>, <span style="color: #000000;">3</span> ;<br />      HEADERS <span style="color: #ff0000;">"RecNo"</span>, <span style="color: #ff0000;">"Suggestions"</span>, <span style="color: #ff0000;">"Strength"</span> NOBORDER<br /><br />   WITH OBJECT oBrw<br />      :<span style="color: #000000;">nStretchCol</span> = <span style="color: #000000;">2</span><br />      :<span style="color: #000000;">aCols</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">bLDClickData</span> := < ||<br />         oGet:<span style="color: #000000;">cText</span> := PadR<span style="color: #000000;">&#40;</span> Trim<span style="color: #000000;">&#40;</span> cSearch <span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">" "</span> + Trim<span style="color: #000000;">&#40;</span> oBrw:<span style="color: #000000;">aCols</span><span style="color: #000000;">&#91;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#93;</span>:<span style="color: #000000;">Value</span> <span style="color: #000000;">&#41;</span>, <span style="color: #000000;">60</span> <span style="color: #000000;">&#41;</span><br />         ResetBrowse<span style="color: #000000;">&#40;</span> cSearch, oBrw <span style="color: #000000;">&#41;</span><br />         <span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br />         ><br /><br />      :<span style="color: #000000;">CreateFromCode</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   END<br /><br />   <span style="color: #0000ff;">ACTIVATE</span> <span style="color: #0000ff;">DIALOG</span> oDlg <span style="color: #0000ff;">CENTERED</span><br /><br />   OrdScope<span style="color: #000000;">&#40;</span> <span style="color: #000000;">0</span>, <span style="color: #ff0000;">"this "</span> <span style="color: #000000;">&#41;</span>; OrdScope<span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span>, <span style="color: #ff0000;">"this "</span> <span style="color: #000000;">&#41;</span><br /><br />   XBROWSER <span style="color: #ff0000;">"GPT_2"</span> COLUMNS <span style="color: #ff0000;">"id"</span>, <span style="color: #ff0000;">"words"</span>, <span style="color: #ff0000;">"OrdKeyVal()"</span>, <span style="color: #ff0000;">"OrdKeyCount()"</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">function</span> ResetBrowse<span style="color: #000000;">&#40;</span> cText, oBrw <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">local</span> aSuggest := ReadSuggestions<span style="color: #000000;">&#40;</span> cText <span style="color: #000000;">&#41;</span><br /><br />   oBrw:<span style="color: #000000;">aArrayData</span>   := aSuggest<br />   oBrw:<span style="color: #000000;">GoTop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   oBrw:<span style="color: #0000ff;">Refresh</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">function</span> ReadSuggestions<span style="color: #000000;">&#40;</span> cText <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">local</span> aRet     := <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><br />   <span style="color: #00C800;">local</span> nTokens, n, nn, cKey<br /><br />   cText    := Lower<span style="color: #000000;">&#40;</span> AllTrim<span style="color: #000000;">&#40;</span> cText <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">if</span> Empty<span style="color: #000000;">&#40;</span> cText <span style="color: #000000;">&#41;</span><br />      OrdScope<span style="color: #000000;">&#40;</span> <span style="color: #000000;">0</span>, <span style="color: #ff0000;">" "</span> <span style="color: #000000;">&#41;</span><br />      OrdScope<span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span>, <span style="color: #ff0000;">" "</span> <span style="color: #000000;">&#41;</span><br />      dbGoTop<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />      DbEVal<span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> || AAdd<span style="color: #000000;">&#40;</span> aRet, <span style="color: #000000;">&#123;</span> RECNO<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, WORDS, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><br />      <span style="color: #00C800;">return</span> aRet<br />   <span style="color: #00C800;">endif</span><br /><br />   nTokens  := NumToken<span style="color: #000000;">&#40;</span> cText <span style="color: #000000;">&#41;</span><br />   SetScope<span style="color: #000000;">&#40;</span> <span style="color: #00C800;">nil</span> <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">if</span> !dbSeek<span style="color: #000000;">&#40;</span> Token<span style="color: #000000;">&#40;</span> cText <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />      <span style="color: #00C800;">return</span> aRet<br />   <span style="color: #00C800;">endif</span><br /><br />   <span style="color: #00C800;">for</span> n := <span style="color: #0000ff;">Max</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span>, nTokens - nSize + <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span> <span style="color: #0000ff;">to</span> nTokens<br /><br />      cKey  := AddTokens<span style="color: #000000;">&#40;</span> cText, n, nTokens <span style="color: #000000;">&#41;</span><br />      nn    := NumToken<span style="color: #000000;">&#40;</span> cKey <span style="color: #000000;">&#41;</span><br />      SetScope<span style="color: #000000;">&#40;</span> cKey + <span style="color: #ff0000;">" "</span> <span style="color: #000000;">&#41;</span><br /><br />      DbEVal<span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> || <span style="color: #00C800;">If</span><span style="color: #000000;">&#40;</span> AScan<span style="color: #000000;">&#40;</span> aRet, <span style="color: #000000;">&#123;</span> |a| a<span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span> == RECNO<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span> == <span style="color: #000000;">0</span>, AAdd<span style="color: #000000;">&#40;</span> aRet, <span style="color: #000000;">&#123;</span> RECNO<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, WORDS, nn <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #00C800;">nil</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>, ;<br />              <span style="color: #000000;">&#123;</span> || NumToken<span style="color: #000000;">&#40;</span> OrdKeyVal<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> == nn + <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span>  <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> aRet<br /><br /><span style="color: #00C800;">function</span> SetScope<span style="color: #000000;">&#40;</span> c <span style="color: #000000;">&#41;</span><br /><br />   OrdScope<span style="color: #000000;">&#40;</span> <span style="color: #000000;">0</span>, c <span style="color: #000000;">&#41;</span>; OrdScope<span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span>, c <span style="color: #000000;">&#41;</span>; dbGoTop<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">function</span> RecordSentence<span style="color: #000000;">&#40;</span> cText <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">local</span> nToken, nTokens := NumToken<span style="color: #000000;">&#40;</span> cText <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">local</span> aTokens  := Array<span style="color: #000000;">&#40;</span> nTokens <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">local</span> n, cKey<br /><br />   AEval<span style="color: #000000;">&#40;</span> aTokens, <span style="color: #000000;">&#123;</span> |u,i| aTokens<span style="color: #000000;">&#91;</span> i <span style="color: #000000;">&#93;</span> := Token<span style="color: #000000;">&#40;</span> cText, <span style="color: #00C800;">nil</span>, i <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><br /><br />   SET ORDER <span style="color: #0000ff;">TO</span> TAG GPT_2<br /><br />   <span style="color: #00C800;">if</span> !dbSeek<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">" "</span> + aTokens<span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span><br />      dbAppend<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />      WORDS   := aTokens<span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span><br />      OrdKeyAdd<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"GPT_2"</span>, <span style="color: #00C800;">nil</span>, <span style="color: #ff0000;">" "</span> + Lower<span style="color: #000000;">&#40;</span> aTokens<span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">endif</span><br /><br />   <span style="color: #00C800;">for</span> nToken := <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">&#40;</span> aTokens <span style="color: #000000;">&#41;</span> - <span style="color: #000000;">1</span><br />      cKey  := Lower<span style="color: #000000;">&#40;</span> aTokens<span style="color: #000000;">&#91;</span> nToken <span style="color: #000000;">&#93;</span> + <span style="color: #ff0000;">" "</span> + aTokens<span style="color: #000000;">&#91;</span> nToken + <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span><br />      <span style="color: #00C800;">if</span> !dbSeek<span style="color: #000000;">&#40;</span> cKey <span style="color: #000000;">&#41;</span><br />         dbAppend<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />         WORDS   := aTokens<span style="color: #000000;">&#91;</span> nToken + <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span><br />         OrdKeyAdd<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"GPT_2"</span>, <span style="color: #00C800;">nil</span>, cKey <span style="color: #000000;">&#41;</span><br />         <span style="color: #00C800;">if</span> nToken > <span style="color: #000000;">1</span><br />            <span style="color: #00C800;">for</span> n := nToken <span style="color: #000000;">-1</span> <span style="color: #0000ff;">to</span> <span style="color: #0000ff;">Max</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span>, nToken - nSize <span style="color: #000000;">&#41;</span> step - <span style="color: #000000;">1</span><br />               cKey  := Lower<span style="color: #000000;">&#40;</span> AddTokens<span style="color: #000000;">&#40;</span> cText, n, nToken + <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />               OrdKeyAdd<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"GPT_2"</span>, <span style="color: #00C800;">nil</span>, cKey <span style="color: #000000;">&#41;</span><br />            <span style="color: #00C800;">next</span><br />         <span style="color: #00C800;">endif</span><br />      <span style="color: #00C800;">endif</span><br />   <span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">function</span> LastTokens<span style="color: #000000;">&#40;</span> cText, nCount <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">local</span> nTokens  := NumToken<span style="color: #000000;">&#40;</span> cText <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">local</span> n<br />   <span style="color: #00C800;">local</span> nFrom    := <span style="color: #0000ff;">Max</span><span style="color: #000000;">&#40;</span> nTokens - nCount + <span style="color: #000000;">1</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">local</span> cRet     := Token<span style="color: #000000;">&#40;</span> cText, , nFrom <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">for</span> n := nFrom + <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> nTokens<br />      cRet  += <span style="color: #ff0000;">" "</span> + Token<span style="color: #000000;">&#40;</span> cText, , n <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> cRet<br /><br /><span style="color: #00C800;">function</span> AddTokens<span style="color: #000000;">&#40;</span> cText, nFrom, nLast <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">local</span> n, cRet<br /><br />   <span style="color: #00C800;">DEFAULT</span> nLast  := NumToken<span style="color: #000000;">&#40;</span> cText <span style="color: #000000;">&#41;</span><br />   nFrom    := <span style="color: #0000ff;">Max</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span>, nFrom <span style="color: #000000;">&#41;</span><br />   cRet     := Token<span style="color: #000000;">&#40;</span> cText, , nFrom <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">for</span> n := nFrom + <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> nLast<br />      cRet  += <span style="color: #ff0000;">" "</span> + Token<span style="color: #000000;">&#40;</span> cText, , n <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> cRet<br /> </div>[/code:1ap0fda8] [img:1ap0fda8]https&#58;//github&#46;com/FiveTechSoft/screenshots/blob/master/gpt1&#46;JPG?raw=true[/img:1ap0fda8]
Artificial Intelligence: GPT with Harbour and FWH
Though OpenAI GPT3 is in closed private beta, there is an easy to way to start using it! <!-- s:-) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":-)" title="Smile" /><!-- s:-) --> Go to [url:3d27peku]https&#58;//play&#46;aidungeon&#46;io/[/url:3d27peku] select option 6 and use these chat models with the historical characters of your choice. Be aware that all these answers are fiction so they may be unaccurate or totally false. Enjoy it! These are some examples of chats with historical characters using OpenAI GPT3: An interview with Steve Jobs: (some of my questions were written by the AI also!) [quote:3d27peku]My name is Antonio and I went to California to meet Steve Jobs. Antonio: Hi Steve, what a great honor to meet you. Steve: You are welcome. Antonio: what inspired you to build the iphone ? Steve: The iPhone was an idea that came to me while I was in Hawaii. Antonio: what phone did you use by that time ? Steve: I was using a Motorola V171. Antonio: how did you choose that phone and how many tests did you make before the launch of the iphone? Steve: My team and I picked the phone for several reasons. Antonio: Could you explain those reasons ? Steve: Yes, first we chose a CDMA carrier so that it would work in all of the US. Second, we wanted a phone with a good camera. Antonio: was it clear to you that it was going to be a true computer ? Steve: It was not a computer per say, but we knew that it could do many of the things that computers can do. Antonio: do you know how long did it take you to build it? Steve: The phone took around 3 months to build. Antonio: what do you think about the reactions of the phone? Steve: I think it's the greatest invention since the computer. Antonio: is it true that you were thinking about calling it "the iPod phone"? Steve: It was discussed, but the name "iPhone" got more votes. Antonio: is it true that you were offered a lot of money by various companies to stop developing it? Steve: I was offered several million dollars to abandon the project, but I knew it was a good idea and we would make it successful. Antonio: what about Microsoft ? what was its reaction ? Steve: The first reaction of most people was WOW, then some were skeptical, some wanted to know more, and others tried to steal the idea. Antonio: Anyhow the first iphone versions lacked enough quality. How do you explain the overall positive reaction to it ? Steve: I don't know, I think it's a great phone and people were just surprised that it was this good. Antonio: What about the "antennagate" controversy? Steve: That was a another controversy that didn't get as much attention as it should have. The phone has great reception, I'd change the design though if I could do it all over again. Antonio: Did you manage an anternative design ? Steve: Yes, we tried many designs before arriving at the current one. The search was not easy. Antonio: what was the most difficult part about the process? Steve: The most difficult part of the process was making sure that it could easily be mass-produced at a cost that was reasonable to consumers. Antonio: How many iphones were made in the first days? Steve: We made around 10,000 iphones in the first week. Antonio: what happened to the phones after that? Steve: We continued to make them as fast as we could. Antonio: Surely we became very satisfied about it. Steve: I'm glad to see that, because Apple is working on new features for the next version. Antonio: Could you tell us more about the features? Steve: Sure, there are a few new features that we are working on. Antonio: Do you think it is going to be a big success this time? Steve: I think this is going to be a big success, Apple has a reputation to uphold and the iphone is going to do that. Antonio: Have you ever experienced a period of great personal pressure? Steve: When I first started working on the project, there were many times when I didn't think we were going to succeed, but the great thing is that my team and I believed in the idea so much that we persevered Antonio: are there any flaws still in its design ? Steve: The phone has good design, but we are always trying to make it better. Antonio: Could you tell us about some of the improvements you are going to make in the future? Steve: No, I don't think I should, but we are always trying to make the product better. Antonio: one more question, do you think it is going to be popular among the kids? Steve: I don't think so, kids usually don't want to be bothered with making calls and using the internet. Antonio: It's funny because it's true. [/quote:3d27peku]
Artificial Intelligence: GPT with Harbour and FWH
[url:4rcu1r46]https&#58;//github&#46;com/elyase/awesome-gpt3[/url:4rcu1r46] Request access to the beta here: [url:4rcu1r46]https&#58;//onboard&#46;openai&#46;com/[/url:4rcu1r46]
Artificial Intelligence: GPT with Harbour and FWH
[url:2gdzvj9j]https&#58;//app&#46;inferkit&#46;com/[/url:2gdzvj9j]
Artificial Intelligence: GPT with Harbour and FWH
i tried also [quote:wqnqwtot]You are Antonio Linares, a person trying to stay sane during a global quarantine. You have a ton of free time and a rubik's cube that you will never finish. You are bored out of your mind and have run out of things to do. But then you notice in the corner of your room something strange. There is a small box with a glowing green button on it. You have seen this box before, in the corner of your parent's room. You think to yourself, "This is so cool!" > You press the green button. The button makes a flashing green light appear on the box. Soon, there is a low, rumbling noise coming from all sides of the room. > You say "I am hurt" The lights begin to flicker on and off. "I am hurt," you say. Suddenly, something appears from the box. > You say "the Silvio Falconi Photo" A dark figure appears and hovers in the air in front of you. "The Silvio Falconi photo!" you say. "Noooo!" > You say "Perhaps is NagesWararo, my indian friend" A second figure appears and hovers in the air in front of you. "Maybe it's NagesWararo, my indian friend," you say. "I Am Not NagesWararo! > You say "Who are you?" "I am the spirit of Christmas Future," the spirit says in a thick Indian accent. > You say "today is not Xmax , you must come back until 3 month " "No, no, no, no! Nobody knows I am here! Not the humans, not the ghosts, not the weird creatures, no!" The spirit floats around your room, becoming more and more agitated. I open the windows !" he says, "and the humans will catch me! I must leave before they find me!" Suddenly, the lights flicker off. "I cannot fly in the dark! Humans are coming![/quote:wqnqwtot] aahahahahahahahahahahahahahahahahahahahahahahahahahhahahahahahahahahahahhahah
Artificial Intelligence: GPT with Harbour and FWH
great! ;-D
Artificial Intelligence: GPT with Harbour and FWH
Another site using GPT2 [url:2tm4pcf3]https&#58;//transformer&#46;huggingface&#46;co/[/url:2tm4pcf3]
Artificial Intelligence: GPT with Harbour and FWH
Leyendo facebook terminé aca. no lo sabía. bien ahi!
Artificial intelligence - Class TPerceptron
This is a simple example to start learning the very basics of the Artificial Intelligence In this example we create a TPerceptron object and we make it learn the behavior of the function nAnd(), then we check the results and they seem to be right. Then we create a new TPerceptron object and we make it learn the behavior of the function nOr(), the results seem right again <!-- s:-) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":-)" title="Smile" /><!-- s:-) --> I am not an expert at all on IA, I am just curious about it. So I appreciate your comments and tests perceptron.prg [code=fw:3g60721w]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"FiveWin.ch"</span><br /><br /><span style="color: #00C800;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> oPerceptron := TPerceptron<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> n, nX, nY<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #B900B9;">// the perceptron learns nAnd()</span><br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> <span style="color: #000000;">1000</span><br />&nbsp; &nbsp; &nbsp; oPerceptron:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> nX := nRandom<span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span>, nY := nRandom<span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>, nAnd<span style="color: #000000;">&#40;</span> nX, nY <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"1"</span> <span style="color: #000000;">&#41;</span> &nbsp;<br />&nbsp; &nbsp;<span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"0"</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"0"</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"0"</span> <span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp;<span style="color: #B900B9;">// We create a new perceptron to learn nOr()</span><br />&nbsp; &nbsp;oPerceptron := TPerceptron<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> <span style="color: #000000;">1000</span><br />&nbsp; &nbsp; &nbsp; oPerceptron:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> nX := nRandom<span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span>, nY := nRandom<span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>, nOr<span style="color: #000000;">&#40;</span> nX, nY <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"1"</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"1"</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"1"</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"0"</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;XBrowser<span style="color: #000000;">&#40;</span> oPerceptron <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">CLASS</span> TPerceptron<br /><br />&nbsp; &nbsp;<span style="color: #00C800;">DATA</span> aPreviousWeights<br />&nbsp; &nbsp;<span style="color: #00C800;">DATA</span> nPreviousThreshold<br />&nbsp; &nbsp;<span style="color: #00C800;">DATA</span> aWeights &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp;<span style="color: #00C800;">DATA</span> nThreshold &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">DATA</span> nLearningRate &nbsp; &nbsp; <br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span> <br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">METHOD</span> Learn<span style="color: #000000;">&#40;</span> aInputs, nExpectedOutput <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">METHOD</span> CalculateOutput<span style="color: #000000;">&#40;</span> aInputs <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">ENDCLASS</span><br /><br /><span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TPerceptron<br /><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> n<br /><br />&nbsp; &nbsp;::<span style="color: #000000;">nPreviousThreshold</span> = <span style="color: #000000;">0</span><br />&nbsp; &nbsp;::<span style="color: #000000;">aWeights</span> = Array<span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;::<span style="color: #000000;">aPreviousWeights</span> = Array<span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;::<span style="color: #000000;">nThreshold</span> = <span style="color: #000000;">0</span><br />&nbsp; &nbsp;::<span style="color: #000000;">nLearningRate</span> = <span style="color: #000000;">0.1</span><br /><br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> nInputs<br />&nbsp; &nbsp; &nbsp; ::<span style="color: #000000;">aPreviousWeights</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span> = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; ::<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span> = <span style="color: #000000;">0</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span> &nbsp; <br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">Self</span><br /><br /><span style="color: #00C800;">METHOD</span> Learn<span style="color: #000000;">&#40;</span> aInputs, nExpectedOutput <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TPerceptron<br /><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> nError := nExpectedOutput - ::<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> aInputs <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> n<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aWeights</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; ::<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span> = ::<span style="color: #000000;">aPreviousWeights</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span> + ::<span style="color: #000000;">nLearningRate</span> * nError * aInputs<span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp;::<span style="color: #000000;">nThreshold</span> = ::<span style="color: #000000;">nPreviousThreshold</span> + ::<span style="color: #000000;">nLearningRate</span> * nError<br /><br />&nbsp; &nbsp;::<span style="color: #000000;">aPreviousWeights</span> = ::<span style="color: #000000;">aWeights</span><br />&nbsp; &nbsp;::<span style="color: #000000;">nPreviousThreshold</span> = ::<span style="color: #000000;">nThreshold</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">METHOD</span> CalculateOutput<span style="color: #000000;">&#40;</span> aInputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TPerceptron<br /><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> nSum := <span style="color: #000000;">0</span><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> n<br />&nbsp; &nbsp;<br />&nbsp; &nbsp;<span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aWeights</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; nSum += aInputs<span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span> * ::<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span><br />&nbsp; &nbsp;<span style="color: #00C800;">next</span> &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp;nSum += ::<span style="color: #000000;">nThreshold</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">If</span><span style="color: #000000;">&#40;</span> nSum > <span style="color: #000000;">0</span>, <span style="color: #000000;">1</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#41;</span></div>[/code:3g60721w]
Artificial intelligence - Class TPerceptron
It is a very simple concept: A perceptron it is equivalent to a brain neuron. The perceptron receives "inputs" and each of these have more or less intensity ("weights"), and the perceptron acts as a Harbour function (method "CalculateOutputs") receiveing some parameters (the inputs) and returning a result to know if it is or not the expected result ("nExpectedOutput") The perceptron modifies its weights (DATA aWeights) if the result is not ok, so it "adapts" to the result that we expect. When the perceptron is enough trained, we can provide it some inputs and check if the answer is right. In such case its "weights" have been properly adjusted and the perceptron has learned <!-- s:-) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":-)" title="Smile" /><!-- s:-) -->
Artificial intelligence - Class TPerceptron
[url:1izxle3h]https&#58;//github&#46;com/RichardKnop/ansi-c-perceptron/blob/master/perceptron&#46;c[/url:1izxle3h] [url:1izxle3h]https&#58;//github&#46;com/nsadawi/perceptron/blob/master/Perceptron&#46;java[/url:1izxle3h]
Artificial intelligence - Class TPerceptron
[img:16fgr2tq]https&#58;//bitbucket&#46;org/fivetech/screenshots/downloads/traditional_vs_MachineLearning&#46;JPG[/img:16fgr2tq] Pedro Domingos: The Master Algorithm [url:16fgr2tq]https&#58;//youtu&#46;be/95XgpJAX6YE[/url:16fgr2tq] [img:16fgr2tq]https&#58;//bitbucket&#46;org/fivetech/screenshots/downloads/Where_does_knowledge_comes_from&#46;JPG[/img:16fgr2tq] [img:16fgr2tq]https&#58;//bitbucket&#46;org/fivetech/screenshots/downloads/How_computers_discover_knowledge&#46;JPG[/img:16fgr2tq]
Artificial intelligence - Class TPerceptron
James, That was a nice test of the practical use of my sample-collector I included the sample from Antonio 1 : 1 to a free section. I didn't change anything. NO errors ( just 5 minutes time to test it ) . The xBrowse-results : [img:3iyu5v4m]http&#58;//www&#46;pflegeplus&#46;com/IMAGES/Samples9&#46;jpg[/img:3iyu5v4m] [color=#0000FF:3iyu5v4m][b:3iyu5v4m]Sample included in GROUP 3 SECTION 3 ( Dialog-section )[/b:3iyu5v4m][/color:3iyu5v4m] [code=fw:3iyu5v4m]<div class="fw" id="{CB}" style="font-family: monospace;"><br /><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">'fivewin.ch'</span><br /><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">'xbrowse.ch'</span><br /><br /><span style="color: #B900B9;">// -------------------------------------------------------------- </span><br /><span style="color: #B900B9;">// -------------- GROUP 3 with DIALOG ----------------</span><br /><span style="color: #B900B9;">// -------------------------------------------------------------- </span><br /><span style="color: #B900B9;">// --------------------- SECTION 1 ------------------------- </span><br /><br /><span style="color: #00C800;">FUNCTION</span> GRPS3_SEC1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><span style="color: #00C800;">LOCAL</span> oBar<br /><br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTONBAR</span> oBar <span style="color: #0000ff;">OF</span> oDlg <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">56</span>,<span style="color: #000000;">64</span> <span style="color: #000000;">2013</span> HEIGHT <span style="color: #000000;">96</span><br /><br />oBar:<span style="color: #000000;">oGrpFont</span>  := oMedium<br /><br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Back"</span>    <span style="color: #0000ff;">RESOURCE</span> 0x100DF GROUP LABEL <span style="color: #ff0000;">"Navigate"</span> COLORS CLR_WHITE,CLR_HBLUE<br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Top"</span>     <span style="color: #0000ff;">RESOURCE</span> 0x100E9<br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Bottom"</span>  <span style="color: #0000ff;">RESOURCE</span> 0x100EA<br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Add"</span>     <span style="color: #0000ff;">RESOURCE</span> 0x2002F GROUP LABEL <span style="color: #ff0000;">"Edit"</span> ;<br />      COLORS CLR_WHITE, <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, CLR_BLACK, CLR_WHITE <span style="color: #000000;">&#125;</span>, .F. <span style="color: #000000;">&#125;</span><br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Edit"</span>    <span style="color: #0000ff;">RESOURCE</span> 0x20022<br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Delete"</span>  <span style="color: #0000ff;">RESOURCE</span> 0x20033<br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Save"</span>    <span style="color: #0000ff;">RESOURCE</span> 0x1003C GROUP LABEL <span style="color: #ff0000;">"Export"</span> COLORS CLR_WHITE,CLR_GREEN<br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Refresh"</span> <span style="color: #0000ff;">RESOURCE</span> 0x30050<br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Setup"</span>   <span style="color: #0000ff;">RESOURCE</span> 0x1005D BTNRIGHT<br /><br />AEval<span style="color: #000000;">&#40;</span> oBar:<span style="color: #000000;">aControls</span>, <span style="color: #000000;">&#123;</span> |oBtn| oBtn:<span style="color: #000000;">bColorMap</span> := <span style="color: #000000;">&#123;</span> |o| <span style="color: #00C800;">If</span><span style="color: #000000;">&#40;</span> o:<span style="color: #000000;">lMOver</span>, <span style="color: #000000;">&#123;</span> CLR_BLACK, CLR_HRED <span style="color: #000000;">&#125;</span>, <span style="color: #00C800;">nil</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">RETURN</span> <span style="color: #00C800;">NIL</span><br /><br /><span style="color: #B900B9;">// --------------------</span><br /><br /><span style="color: #00C800;">FUNCTION</span> GRPS3_SEC2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><span style="color: #00C800;">LOCAL</span> oBar<br /><br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTONBAR</span> oBar <span style="color: #0000ff;">OF</span> oDlg <span style="color: #000000;">2013</span> <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">56</span>,<span style="color: #000000;">56</span> HEIGHT <span style="color: #000000;">80</span><br /><br />oBar:<span style="color: #000000;">oGrpFont</span>  := oMedium<br /><br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar FILE c_Path1 + <span style="color: #ff0000;">"top.bmp"</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Top"</span>  GROUP LABEL <span style="color: #ff0000;">"NAVIGATE"</span><br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar FILE c_Path1 + <span style="color: #ff0000;">"goto.bmp"</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"GoTo"</span><br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar FILE c_Path1 + <span style="color: #ff0000;">"bottom.bmp"</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Bottom"</span><br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar FILE c_Path1 + <span style="color: #ff0000;">"new2.bmp"</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Add"</span>  GROUP LABEL <span style="color: #ff0000;">"EDIT"</span><br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar FILE c_Path1 + <span style="color: #ff0000;">"edit.bmp"</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Edit"</span><br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar FILE c_Path1 + <span style="color: #ff0000;">"delete0.bmp"</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Delete"</span><br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar FILE c_Path1 + <span style="color: #ff0000;">"excel.bmp"</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Excel"</span>  GROUP LABEL <span style="color: #ff0000;">"EXPORT"</span><br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar FILE c_Path1 + <span style="color: #ff0000;">"pdf.bmp"</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"PDF"</span><br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar FILE c_Path1 + <span style="color: #ff0000;">"printquick16.bmp"</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Print"</span><br /><span style="color: #0000ff;">DEFINE</span> <span style="color: #0000ff;">BUTTON</span> <span style="color: #0000ff;">OF</span> oBar FILE c_Path1 + <span style="color: #ff0000;">"exit2.bmp"</span> <span style="color: #0000ff;">PROMPT</span> <span style="color: #ff0000;">"Exit"</span> GROUP BTNRIGHT<br /><br /><span style="color: #00C800;">RETURN</span> <span style="color: #00C800;">NIL</span><br /><br /><span style="color: #B900B9;">// --------------------- SECTION 2 ------------------------- </span><br /><br /><span style="color: #00C800;">FUNCTION</span> GRPS3_SEC3<span style="color: #000000;">&#40;</span> oFld3, nSavePage <span style="color: #000000;">&#41;</span><br /><span style="color: #00C800;">local</span> oPerceptron := TPerceptron<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#41;</span><br /><span style="color: #00C800;">local</span> n, nX, nY<br />   <br /><span style="color: #B900B9;">// the perceptron learns nAnd()</span><br /><span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> <span style="color: #000000;">1000</span><br />      oPerceptron:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> nX := nRandom<span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span>, nY := nRandom<span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>, nAnd<span style="color: #000000;">&#40;</span> nX, nY <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br /><span style="color: #00C800;">next</span><br />   <br /><span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"1"</span> <span style="color: #000000;">&#41;</span>  <br /><span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"0"</span> <span style="color: #000000;">&#41;</span><br /><span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"0"</span> <span style="color: #000000;">&#41;</span><br /><span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"0"</span> <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #B900B9;">// We create a new perceptron to learn nOr()</span><br />oPerceptron := TPerceptron<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">2</span> <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> <span style="color: #000000;">1000</span><br />      oPerceptron:<span style="color: #000000;">Learn</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> nX := nRandom<span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span>, nY := nRandom<span style="color: #000000;">&#40;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>, nOr<span style="color: #000000;">&#40;</span> nX, nY <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br /><span style="color: #00C800;">next</span><br />   <br /><span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"1"</span> <span style="color: #000000;">&#41;</span><br /><span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"1"</span> <span style="color: #000000;">&#41;</span><br /><span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"1"</span> <span style="color: #000000;">&#41;</span><br /><span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> oPerceptron:<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">0</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span>, <span style="color: #ff0000;">"0"</span> <span style="color: #000000;">&#41;</span><br />   <br />XBrowser<span style="color: #000000;">&#40;</span> oPerceptron <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">RETURN</span> <span style="color: #00C800;">NIL</span><br /><br /><span style="color: #B900B9;">// ----------------</span><br /><br /><span style="color: #00C800;">CLASS</span> TPerceptron<br /><br /><span style="color: #00C800;">DATA</span> aPreviousWeights<br /><span style="color: #00C800;">DATA</span> nPreviousThreshold<br /><span style="color: #00C800;">DATA</span> aWeights           <br /><span style="color: #00C800;">DATA</span> nThreshold        <br /><span style="color: #00C800;">DATA</span> nLearningRate     <br /><br /><span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span> <br /><br /><span style="color: #00C800;">METHOD</span> Learn<span style="color: #000000;">&#40;</span> aInputs, nExpectedOutput <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">METHOD</span> CalculateOutput<span style="color: #000000;">&#40;</span> aInputs <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">ENDCLASS</span><br /><br /><span style="color: #B900B9;">// ------</span><br /><br /><span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TPerceptron<br /><span style="color: #00C800;">local</span> n<br /><br />::<span style="color: #000000;">nPreviousThreshold</span> = <span style="color: #000000;">0</span><br />::<span style="color: #000000;">aWeights</span> = Array<span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span><br />::<span style="color: #000000;">aPreviousWeights</span> = Array<span style="color: #000000;">&#40;</span> nInputs <span style="color: #000000;">&#41;</span><br />::<span style="color: #000000;">nThreshold</span> = <span style="color: #000000;">0</span><br />::<span style="color: #000000;">nLearningRate</span> = <span style="color: #000000;">0.1</span><br /><br /><span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> nInputs<br />   ::<span style="color: #000000;">aPreviousWeights</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span> = <span style="color: #000000;">0</span><br />   ::<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span> = <span style="color: #000000;">0</span><br /><span style="color: #00C800;">next</span>   <br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">Self</span><br /><br /><span style="color: #B900B9;">// ----------</span><br /><br /><span style="color: #00C800;">METHOD</span> Learn<span style="color: #000000;">&#40;</span> aInputs, nExpectedOutput <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TPerceptron<br /><span style="color: #00C800;">local</span> nError := nExpectedOutput - ::<span style="color: #000000;">CalculateOutput</span><span style="color: #000000;">&#40;</span> aInputs <span style="color: #000000;">&#41;</span><br /><span style="color: #00C800;">local</span> n<br />   <br /><span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aWeights</span> <span style="color: #000000;">&#41;</span><br />      ::<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span> = ::<span style="color: #000000;">aPreviousWeights</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span> + ::<span style="color: #000000;">nLearningRate</span> * nError * aInputs<span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span><br /><span style="color: #00C800;">next</span><br />   <br />::<span style="color: #000000;">nThreshold</span> = ::<span style="color: #000000;">nPreviousThreshold</span> + ::<span style="color: #000000;">nLearningRate</span> * nError<br /><br /> ::<span style="color: #000000;">aPreviousWeights</span> = ::<span style="color: #000000;">aWeights</span><br /> ::<span style="color: #000000;">nPreviousThreshold</span> = ::<span style="color: #000000;">nThreshold</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #B900B9;">// ----------</span><br /><br /><span style="color: #00C800;">METHOD</span> CalculateOutput<span style="color: #000000;">&#40;</span> aInputs <span style="color: #000000;">&#41;</span> <span style="color: #00C800;">CLASS</span> TPerceptron<br /><span style="color: #00C800;">local</span> nSum := <span style="color: #000000;">0</span><br /><span style="color: #00C800;">local</span> n<br />   <br /><span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">&#40;</span> ::<span style="color: #000000;">aWeights</span> <span style="color: #000000;">&#41;</span><br />      nSum += aInputs<span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span> * ::<span style="color: #000000;">aWeights</span><span style="color: #000000;">&#91;</span> n <span style="color: #000000;">&#93;</span><br /><span style="color: #00C800;">next</span>   <br />       <br />nSum += ::<span style="color: #000000;">nThreshold</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">If</span><span style="color: #000000;">&#40;</span> nSum > <span style="color: #000000;">0</span>, <span style="color: #000000;">1</span>, <span style="color: #000000;">0</span> <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #B900B9;">// --------------------- SECTION 4 ------------------------- </span><br /><br /><span style="color: #00C800;">FUNCTION</span> GRPS3_SEC4<span style="color: #000000;">&#40;</span> oFld3, nSavePage <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">RETURN</span> <span style="color: #00C800;">NIL</span><br /> </div>[/code:3iyu5v4m] regards Uwe <!-- s:roll: --><img src="{SMILIES_PATH}/icon_rolleyes.gif" alt=":roll:" title="Rolling Eyes" /><!-- s:roll: -->
Artificial intelligence - Class TPerceptron
Antonio, I just tried compiling your TPerceptron example code and I am getting 66 errors. The first one is: Perceptron.prg(40) Error E0016 Syntax error: ' ' At this line: local oPerceptron := TPerceptron():New( 2 ) There are a lot of these same errors (on different lines). I can't see anything wrong with the line. I note that I have started seeing this error message in my own code recently too. Maybe I am missing an include or something. Any ideas? Regards, James
Artificial intelligence - Class TPerceptron
Antonio, There are only two other types of errors, "ambiguous reference..." and those like this: Perceptron.prg(101) Error E0019 #error: 'Method "Learn( aInputs, nExpectedOutput )" not declared in class: TPerceptron' None of the error messages are valid so I can't imagine what is triggering them. James