• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Jun 12th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function d = ann_dist(w,x)
2. // Distance weight function
3. //
4. //    Copyright 2011 Trity Technologies.
5. //
6. //    This program is free software: you can redistribute it and/or modify
7. //    it under the terms of the GNU General Public License as published by
8. //    the Free Software Foundation, either version 2 of the License, or
9. //    (at your option) any later version.
10. //
11. //    This program is distributed in the hope that it will be useful,
12. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14. //    GNU General Public License for more details.
15. //
16. //    You should have received a copy of the GNU General Public License
17. //    along with this program.  If not, see <http://www.gnu.org/licenses/
18. //
19. // Calling Sequence
20. //     d=ann_dist(w,x)
21. //
22. // Parameters
23. //      w : weight
24. //      x : input
25. //      d : distance
26. //
27. // Description
28. //     Calculate distance weight function
29. //
30. // Examples
31. //    w = [1 2 3;4 5 6];
32. //    x = [1 2; 3 4; 5 6];
33. //    d = ann_dist(w,x)
34. //
36. //     ann_negdist
37. //
38. // Authors
39. //     Chenwei, modified and used in Scilab NN Toolbox by Tan C.L.
40.
41. [lsh,rsh]=argn(0);
42. if(rsh<1),error('wrong input');end;
43. if(rsh<2),x=w';end;
44. [S,R]=size(w);
45. [R1,P]=size(x);
46. if(R~=R1),error('Inner matrix dimension do not match');end
47. d=zeros(S,P);
48. if(P<S)
49.    x=x';
50.    temp=zeros(1,S);
51.    for p=1:P
52.    d(:,p)=sum((w-x(p+temp,:)).^2,2);
53.    end
54. else
55.    w=w';
56.    temp=zeros(1,P);
57.    for i=1:S
58.    d(i,:)=sum((w(:,i+temp)-x).^2,1);
59.    end
60. end
61. d=sqrt(d);
62. endfunction
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top