1 / 58

Data Driven Function Approximation

Data Driven Function Approximation. One link. Given X t what is the joint angle P. Y. x t. P. x. Plot1d. Plot a function that maps joint angle P to tool position X t. clear all fstr=input('input a function: x.^2+cos(x) :','s'); fx=inline(fstr); range=2*pi; x=linspace(-range,range);

lobo
Download Presentation

Data Driven Function Approximation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Driven Function Approximation

  2. One link Given Xt what is the joint angle P Y xt P x

  3. Plot1d Plot a function that maps joint angle P to tool position Xt clear all fstr=input('input a function: x.^2+cos(x) :','s'); fx=inline(fstr); range=2*pi; x=linspace(-range,range); y=fx(x); max_y=max(abs(y)); plot(x,y/max_y); hold on;

  4. Black box Black box Xt P range=2*pi; linspace(-range,range); observation N=input('keyin sample size:'); x=rand(1,N)*2*range-range; n=rand(1,N)*0.1-0.05; y=fx(x)/max_y+n; figure plot(x,y,'.');

  5. Paired data

  6. Adaptive function Desired output Network output Input error

  7. Network function Weight sum of hyper-tangent functions

  8. Network b1 tanh r1 b2 1 a1 tanh r2 a2 x ……. bM rM aM tanh rM+1 1

  9. Procedure 1: MLP evaluation • Input r,a,b and x,M • y=r(M+1) • Set M to the length of a • For m=1:M • Add r(i)*tanh(x*a(i)+b(i)) to y • Return y

  10. Matlab code eval_MLP.m function y=eval_MLP(x,r,a,b,M) y=r(M+1); for m=1:M y=y+r(m)*tanh(x.*a(m)+b(m)); end return

  11. Mean square error Given Find to minimize

  12. Procedure 2: Mean square error • Input x,y,a,b,r • Set E to zero • Set n to the length of x • For i=1:n • Calculate the square error of approximating y(i) by f(x;r,a,b) • Add the error to E • Return E

  13. Matlab code mean_square_error2.m function E=mean_square_error2(x,y,a,b,r) E=0; M=length(a); n=length(x); for i=1:n s_err=(y(i)-eval_MLP(x(i),r,a,b,M)).^2; E=E+s_err; end E=E/n; return

  14. Matlab code

  15. Desired output Network output Input error Application Black box plot1d.m Xt P observation Create paired data sampling.m Leaning learning.m

  16. Matlab code Function approximation for an arbitrary target function fa1d.m

  17. Y xt P x Inverse kinematics

  18. Construction of inverse kinematics • Procedure • Input a 1d forward kinematics • Sampling to form paired data • Input-output swapping • Rescaling • Learning

  19. Data preparation Black box plot1d.m Xt P observation Create paired data sampling.m Rescaling temp=x; x=y; y=temp; swapping max_y=max(y); y=y/max_y; plot(x,y,'.')

  20. Learning inverse kinematics Desired output Network output Input error Leaning learning.m

  21. Matlab code fa1d_inv.m MSE for training data 0.336461 ME for training data 0.490247 Unacceptable training errors

  22. Multiple outputs • Inverse kinematics • Conflicts of I/O relation • Two distinct outcomes for the same input

  23. First order derivative • Forward kinematics should be characterized by two outputs for construction of inverse kinematics Two observations Xt Black box plot1d.m P Derivative

  24. Symbolic differentiation demo_diff.m function demo_diff() % input a string to specify a function % plot its derivative ss=input('function of x:','s'); fx=inline(ss); x=sym('x'); ss=['diff(' ss ')']; ss1=eval([sprintf(ss)]); fx1=inline(ss1) x=linspace(-pi,pi); plot(x,fx(x),'b');hold on; plot(x,fx1(x),'r'); return

  25. Data preparation Two observations Xt Black box plot1dd.m P Dt Derivative

  26. Reverse kinematics Xt Reverse Kinematics P Dt Derivative plot3(y1,y2,ix)

  27. Reverse kinematics

  28. Matlab code

  29. Segmentation • Procedure • Input paired data,(x,y) • Sort data by y

  30. Write a matlab function to divide paired data to four segments

  31. Matlab code

  32. multiple solutions

  33. Two links (xt yt) Y P2 P1 x

  34. Forward kinematics of two-link robot

  35. Inverse kinematics of two-link robot

  36. Reconstruction of forward Kinematics

  37. Learning forward kinematics learn_MLP.m eval_MLP2.m fa2d.m

  38. Forward Kinematics for planar robot

  39. Inverse kinematics At the position level, the problem is stated as, "Given the desired position of the robot's hand, what must be the angles at all of the robots joints? "

  40. Plot

  41. Exercise • Write matlab functions to implement forward and inverse kinematics of a two-link robot

  42. Example l1=1;l2=1; p1=pi/3;p2=pi/5; [x,y]=fkin(p1,p2,l1,l2) [p1,p2]=inverse_kin(x,y,l1,l2); p1/pi p2/pi

  43. Nonlinear system

  44. A set of nonlinear functions

  45. x=linspace(-2,2); plot(x,x); hold on; plot(x,sqrt(4-x.^2)) plot(x,-sqrt(4-x.^2))

  46. function F = myfun(x) F(1) = x(1).^2 + x(2)^2-4; F(2) = x(1) - x(2); return

More Related