bugGNU Octave - Bugs: bug #45754, neural net package :hardlims...

 
 

bug #45754: neural net package :hardlims function returns always an scalar

Submitter:  Roberto Ratti <robertus85>
Submitted:  Fri 14 Aug 2015 07:28:36 AM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Roberto Ratti Open/Closed:  * Closed
Release:  * other Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 08 Oct 2015 05:59:20 PM UTC, comment #4: 

Hi Roberto. It took while but I got around to do it now.

I fixed the original issue (hardlims) with:

http://hg.code.sf.net/p/octave/nnet/rev/bd0b831fcbd6

I then also fixed it for satlin and satlins with:

http://hg.code.sf.net/p/octave/nnet/rev/b98d743b7089

I ended up doing some other fixes on those functions, so take a look at http://hg.code.sf.net/p/octave/nnet

Carnë Draug <carandraug>
Group Member
Wed 26 Aug 2015 07:59:49 PM UTC, comment #3: 

Hi,
i post code and attach examples use of functions.


function a = hardlims(n)

  for i=1:size(n,1)
    for j=1:size(n,2)
     if n(i,j)>=0
      a(i,j)=1;
     else
      a(i,j)=-1;
     endif
    end
  end

endfunction

function a = satlin(n)

  for i=1:size(n, 1)
   for j=1:size(n, 2)
    if (n(i,j)<0)
     a(i,j) = 0;
    elseif (n(i,j)>=0 && n(i,j)<=1)
     a(i,j) = n(i,j);
    else
     a(i,j) = 1; # if n>1
    endif
   end
  end

endfunction

function a = satlins(n)

  for i=1:size(n,1)
   for j=1:size(n,2)
    if (n(i,j)<-1)
      a(i,j) = -1;
    elseif (n(i,j)>=-1 && n(i,j)<=1)
      a(i,j) = n(i,j);
    else
      a(i,j) = 1; # if n>1
    endif
   end
  end

endfunction




file attached are:
variables.png
hardlims.png
satlin.png
satlins.pg


Roberto Ratti <robertus85>
Mon 24 Aug 2015 05:52:14 PM UTC, comment #2: 

The neural net package is currently unmaintained. If you can supply a patch that fixes this with tests, I will apply it.

Carnë Draug <carandraug>
Group Member
Fri 14 Aug 2015 11:58:09 AM UTC, comment #1: 

Same problem (and same solution) for functions satlin and satlins



function a = satlin(n)

  ####### here commented, the original code #########
  ##if (n<0)
  ##  a = 0;
  ##elseif (n>=0 && n<=1)
  ##  a = n;
  ##else
  ## a = 1; # if n>1
  ##endif
  ###################################################

  for i=1:size(n, 1)
   for j=1:size(n, 2)
    if (n(i,j)<0)
     a(i,j) = 0;
    elseif (n(i,j)>=0 && n(i,j)<=1)
     a(i,j) = n(i,j);
    else
     a(i,j) = 1; # if n>1
    endif
   end
  end

endfunction

function a = satlins(n)

  ####### here commented, the original code #########
  ##if (n<-1)
  ##  a = -1;
  ##elseif (n>=-1 && n<=1)
  ##  a = n;
  ##else
  ##  a = 1; # if n>1
  ##endif
  ###################################################

  for i=1:size(n,1)
   for j=1:size(n,2)
    if (n(i,j)<-1)
      a(i,j) = -1;
    elseif (n(i,j)>=-1 && n(i,j)<=1)
      a(i,j) = n(i,j);
    else
      a(i,j) = 1; # if n>1
    endif
   end
  end

endfunction


Roberto Ratti <robertus85>
Fri 14 Aug 2015 07:28:36 AM UTC, original submission:  

Good morning,
during some exercises about neurual nets functions, i found a difference of results between hardlim function and hardlims (..../packages/nnet-0.1.13).
The first one returned correctly a vector, the second one returned always a scalar.
(Actually the only difference should be that hardlims returns -1 when hardlim returns 0)

You can see, in the image attatched (octave_hardlims_orig.png).

The code of hardlims function was:


function a = hardlims(n)
  if n>=0
    a=1;
  else
    a=-1;
  endif
endfunction


I modified that code in this:


function a = hardlims(n)
  righe=size(n,1);
  colonne=size(n,2);
  for i=1:righe
    for j=1:colonne
     if n(i,j)>=0
      a(i,j)=1;
     else
      a(i,j)=-1;
     endif
    end
  end
endfunction


Now it returns correctly a vector when input is a vector (attatched image octave_hardlims_modif.png).
I'm not sure that my code is the best way for the function, but i hope that it could be useful.

Thank you.
Roberto Ratti
-email is unavailable-

Roberto Ratti <robertus85>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #34744:  variables.png added by robertus85 (19KiB - image/png)
file #34745:  satlin.png added by robertus85 (15KiB - image/png)
file #34746:  hardlims.png added by robertus85 (12KiB - image/png)
file #34747:  satlins.png added by robertus85 (17KiB - image/png)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by robertus85 (Submitted the item)
  • -email is unavailable- added by robertus85
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-10-08 carandraug StatusNone Fixed
        Open/ClosedOpen Closed
        Release3.8.1 other
    2015-08-26 robertus85 Attached File- Added variables.png, #34744
        Attached File- Added satlin.png, #34745
        Attached File- Added hardlims.png, #34746
        Attached File- Added satlins.png, #34747
    2015-08-24 carandraug Summaryhardlims nerual nets function returns always an scalar neural net package :hardlims function returns always an scalar
    2015-08-14 robertus85 Attached File- Added octave_hardlims_orig.png, #34642
        Attached File- Added octave_hardlims_modif.png, #34643
        Carbon-Copy- Added robertus85

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code