From 0706d857d5b0f6f2654e0adabd4c56d0e599fcf4 Mon Sep 17 00:00:00 2001 From: Natasha Rouse Date: Mon, 22 Jun 2020 16:15:41 -0400 Subject: [PATCH 1/7] Adding run8 & Eval run8 calls Eval with choice of DMP or RMP system, and choice between three different trajectories. --- Eval.m | 257 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ run8.m | 236 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 493 insertions(+) create mode 100644 Eval.m create mode 100644 run8.m diff --git a/Eval.m b/Eval.m new file mode 100644 index 0000000..c464728 --- /dev/null +++ b/Eval.m @@ -0,0 +1,257 @@ +function d = Eval(w, Nt, y0dot, y0, x0, alphax, tau, dt, sigma_or_rho, c_or_alpha, alphay, betay,g, desiredtraj, ShowPlot, OneforDMPtwoforRMP, w1,w2,Nsaddles) +% %-------------------- +goaltol = .005; +%ShowPlot = 1; +% % initialize or variable descriptions (basics that are the same for RMP/DMP) +% Nt = 1000; % number of timesteps +% y0 = .001 * [1,1]; %system initial position +% y0dot= 0 * [1,1]; %system initial velocity +% dt = .01; %timestep +% tau = 1; %time constant base system, also reused in canonical system +% alphay = 4; %damping base system +% betay = alphay/4; %stiffness base system +% alphax = .5; %how fast cannonical system decays +% g = [1,0]; %goal position of base system +% desiredtraj = [0:.05:.5, fliplr(.5*cos((-pi/2):-.1:-(pi))+1); +% 0:.05:.5, fliplr(.5*sin((-pi/2):-.1:-(pi))+.5)]'; + +% %shared naming +% x0 = 1; %cannonical system initial state (scalar for DMP, vector for RMP) +% w = weights that are learned + %for DMP w will be size 2 by Npsi (assuming planar trajectory) +% w = [0.8726 -4.8226 -5.2870 -5.6955 11.9854 -1.6538 0.2696 -0.6114 2.2657 -0.8382; +% 4.3342 1.8618 0.2612 -1.5936 -5.3375 5.2797 -3.1289 0.0051 0.4761 -1.3480]; +% for RMP w will be size +% +% + +% Nsaddles = 20; +if OneforDMPtwoforRMP == 1 +% %for DMP +% Npsi = 10; %number of basis functions (use this generate c and sigma) + % c = logspace(log10(1), log10(.01), Npsi); % these are the positions of DMP in X, and they do not change. + % sigma = 2*logspace(log10(.3),log10(.002), Npsi); + sigma = sigma_or_rho; + c = c_or_alpha; + + x = x0; + if ShowPlot +xall = nan*ones(Nt,1); +psiall = nan*ones(Nt,length(sigma)); + end + + else +% %for RMP +% Nsaddles = 10; +alpha = 10; +beta = 1; +nu = 1.2; +rho = calculaterho_notacycle(alpha*ones(Nsaddles,1), beta*ones(Nsaddles,1), nu*ones(Nsaddles,1)); + + +ep = 10^-9*ones(1,Nsaddles); +a0 = ep; +a0(1) = 1; +a0(2) = .01; +a = a0; +if ShowPlot +aall = nan*ones(Nt, Nsaddles); +end +% %%rho = []; %coupling matrix +% %%alpha = []; %growth factors +% % for now P and zd are zero since not measuring contact +% % and C is zero because there is no coupling and no measured z +% rho = sigma_or_rho; +% alpha = c_or_alpha; +% +end + +distance = 0; + +ydot = y0dot; +y = y0; +fnum = 0; + +maxtime = (Nt+1)*dt; +timetogoal = nan; + +if ShowPlot +yall = nan*ones(Nt,2); +ydotall = nan*ones(Nt,2); +whichcolor = nan*ones(Nt,1); +alldistanceerror = nan*ones(Nt,1); +whichtraj = nan*ones(Nt,1); +allverror = nan*ones(Nt,1); +end + +desiredtrajdir = diff(desiredtraj); +desiredtrajdir = .5*( [desiredtrajdir;desiredtrajdir(end,:)] + [desiredtrajdir(1,:);desiredtrajdir]);%centerdiffs +desiredtrajdir = desiredtrajdir ./sqrt(sum(desiredtrajdir.^2,2)); %normalize + +trajpointdistancessq = Inf*ones(size(desiredtraj, 1), 1); + +for i = 1:Nt + % advance diff equation + %DMP + if OneforDMPtwoforRMP == 1 +% w = [w(1,:); zeros(1,length(w))]; +% w = [zeros(1,length(w));w(2,:)]; + x = x + ((-alphax)*x)/tau*dt; + psi = exp(-1./(2*sigma.^2).*(x-c).^2); +% fnum = fnum + ((psi*w')*x); + f = (psi*w') *x /sum(psi); +% f = [0,f(2)]; +% f = [f(1),0]; +% %new weights +% beta2 = ((alphay*(betay*(g-y)-ydot))*(dt^2)/tau) + ydot*dt + y; +% beta1 = (psi*w'*(dt^2))*x/tau; +% f = beta2; + end + %RMP + if OneforDMPtwoforRMP == 2 + dW = sqrt(dt)*randn(1,Nsaddles); + da = a .* (alpha - a*rho) *dt + ep.*dW; %%%DID I forget tau?? + a = max(min(a + da, 1), .0005); + f = a*w'/sum(a); + end + ydotdot = (alphay*(betay*(g-y)-ydot)+f)/tau; + ydot = ydotdot*dt + ydot; + y = ydot*dt+y; + + + if ShowPlot + % find out which part of solution has max contribution + if OneforDMPtwoforRMP == 1 + [~, whichcolor(i)] = max( [sum( abs(alphay*(betay*(g-y)-ydot)).^2)*.1; + sum((abs((psi.*w) *x /sum(psi))').^2,2)]); + else + [~, whichcolor(i)] = max( [sum( abs(alphay*(betay*(g-y)-ydot)).^2)*.1; + sum((abs((a.*w)/sum(a))').^2,2)]); + + end + + end + trajpointdistancessq = min ((y(1) - desiredtraj(:,1)).^2 + (y(2) - desiredtraj(:,2)).^2, ... + trajpointdistancessq); + + [dsquared, whichtrajpoint] = min( (y(1) - desiredtraj(:,1)).^2 + ... + (y(2) - desiredtraj(:,2)).^2); + distance = distance + ... + sqrt( dsquared); + desv = desiredtrajdir(whichtrajpoint, :); + vnormalerror = (desv(1)*ydot(2) - desv(2)*ydot(1))/sqrt(ydot*ydot'); + + % here if its at the goal, I record time + if isnan(timetogoal) && sum((y-g).^2)=desiredt(index) + index = index+1; + else + expected_SHCas(index, :) = a; + end +end + + + size(expected_SHCas) + betaw = ( expected_SHCas) \ (sum(expected_SHCas')'.* fdesired); +end + + +% meanerror = sum(sum(errors.^2)) +w = betaw'; +%%%%%%% $$$ end insertion +end + + +%TWO main functions here, one to evaluate weights +d = Eval(w, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj, 1, OneforDMPtwoforRMP, w1,w2,Nsaddles); + +delta = 1; +allds = []; +for passes = 1:10 +bestw = w; +bestd = d; +for i = 1:Ktrials + if rand(1)>.5 + % try random stuff + w = 1-.5*rand(2, Npsi); + d = Eval(w, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj, 0,OneforDMPtwoforRMP, w1,w2,Nsaddles); + if d=2 +chosenew = 0; +chosedel = 0; + for i = 1:size(w,1) + for j = 1:size(w,2) + wtrial = bestw; + wnew = bestw; + delt = delta*(1-2*rand(1)); + wtrial(i,j) = bestw(i,j) + delt; + dtrial = Eval(wtrial, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj, 0,OneforDMPtwoforRMP,w1,w2,Nsaddles); + wnew(i,j) = bestw(i,j) + max(min(bestd*delt/(bestd - dtrial), delta*5), -delta*5); + dnew = Eval(wnew, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj, 0,OneforDMPtwoforRMP,w1,w2,Nsaddles); + if dnew < bestd + bestw = wnew; + bestd = dnew; + chosenew = chosenew +1; + end + if dtrial < bestd + bestw = wtrial; + bestd = dtrial; + chosedel = chosedel +1; + end + + end + end +% chosenew +% chosedel +end + +%at the end of one pass, save progress +allds = [allds,bestd]; +w = bestw; +d = bestd; +%ShowTraj(w, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj); +% if passes==1 || passes==5 || passes==10 +% pause +% end +end +Eval(w, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj, 1,OneforDMPtwoforRMP,w1,w2,Nsaddles); + +% figure(4) +% plot(allds) + +% +% pause +% ShowTraj(w, Nt, y0dot, y0, x0, alphax, 2*tau, dt, sigma, c, alphay, betay,g, desiredtraj); +% w = weights +% example +% 0.8726 -4.8226 -5.2870 -5.6955 11.9854 -1.6538 0.2696 -0.6114 2.2657 -0.8382 +% 4.3342 1.8618 0.2612 -1.5936 -5.3375 5.2797 -3.1289 0.0051 0.4761 -1.3480 +% Nt = number of timesteps +% y0 initial conditions +% x0 initial conditions +% alphax % keep same as training +% tau % changing this makes shape pretty different, sloppier if highter +%dt %seems like I can change this without changing shape + +finalds = [finalds,allds(end)] +figure(6) +plot(finalds) +end + +toc \ No newline at end of file From c1834b3f33d65b4f06a65a9098295b644b8671e7 Mon Sep 17 00:00:00 2001 From: Natasha Rouse Date: Fri, 3 Jul 2020 12:35:13 -0400 Subject: [PATCH 2/7] Add files via upload --- DMPandRMP1.m | 416 +++++++++++++++++++++++++++++++++++ Eval.m | 38 ++-- RunbothRMP_and_DMP.m | 28 +++ run8.m | 332 +++++++++++++++++++++++++--- run9.m | 506 +++++++++++++++++++++++++++++++++++++++++++ wbestDMP1.mat | Bin 0 -> 16023 bytes wbestRMP1.mat | Bin 0 -> 18572 bytes 7 files changed, 1273 insertions(+), 47 deletions(-) create mode 100644 DMPandRMP1.m create mode 100644 RunbothRMP_and_DMP.m create mode 100644 run9.m create mode 100644 wbestDMP1.mat create mode 100644 wbestRMP1.mat diff --git a/DMPandRMP1.m b/DMPandRMP1.m new file mode 100644 index 0000000..af2b47f --- /dev/null +++ b/DMPandRMP1.m @@ -0,0 +1,416 @@ +%June 2020 +%DMP and RMP structures using simple trajectory following (no point mass) + +close all +clear all +clc +tic + +rng(2) %seeding different random numbers to check validity of cost evaluation + +%TRAJECTORY CHOICES +% %ramp up bubble out ----- +% desiredtraj = [0:.05:.5, .5*cos((pi/2):-.1:0)+.5; +% 0:.05:.5, .5*sin((pi/2):-.1:0)]'; +% g = [1,0]; %goal +% %ramp up bubble in ------ +% desiredtraj = [0:.05:.5, fliplr(.5*cos((-pi/2):-.1:-(pi))+1); +% 0:.05:.5, fliplr(.5*sin((-pi/2):-.1:-(pi))+.5)]'; +% g = [1,0]; +%ramp up wrap around ----- +desiredtraj = [(0:.05:.5)*0, .5*cos(pi/2:.1:pi*2.6); + 0:.05:.5, .5*sin(pi/2:.1:pi*2.6)]'; +g = [0,0]; +y0 = .001 * [1,1]; +y0dot= 0 * [1,1]; +x0 = 1; +bfs = 10; + +%system init +S = struct('desiredtraj',desiredtraj,'dt',0.01,'Nt',1000,'g',g); +%trajectory start, velocity at trajectory start, canonical state vector, +%size of timestep, number of timesteps, goal + +%dmp init +D = struct('tau',1,'alphay',4,'betay',1,'alphax',.5,... %how fast cannonical system decays + 'bfs',bfs,... %number of basis functions (psi activations) + 'c',logspace(log10(1), log10(.01), bfs),... %basis function centers + 'sigma',logspace(log10(.3),log10(.002), bfs),... %basis function widths + 'w',zeros(1,length(desiredtraj)),... + 'psi',nan(S.Nt,bfs),'y',y0,'ydot',y0dot,'x',x0); + +%rmp init +R = struct('tau',1,'alphay',4,'betay',1,'alpha',10,'beta',1,'nu',1.2,'bfs',bfs,... + 'rho',logspace(log10(.3),log10(.002), bfs),... + 'a',[1,0.1,10^-9*ones(1,bfs-2)],... + 'ep',[10^-9*ones(1,bfs)],... + 'w',zeros(1,length(desiredtraj)),'y',y0,'ydot',y0dot,'x',x0); + +%Init +D.w = S.desiredtraj(round(linspace(1,length(S.desiredtraj),D.bfs)) ,:)'*(D.alphay+D.betay); +R.w = S.desiredtraj(round(linspace(1,length(S.desiredtraj),R.bfs)) ,:)'*(R.alphay+R.betay); + +Ntrials = 500; +desiredt = linspace(0,10,length(S.desiredtraj))';% assumes constant velocity +desiredydot = [0,0;diff(S.desiredtraj)./(diff(desiredt)*[1,1])]; % desired speed +desiredydotdot = [0,0;diff(desiredydot)./(diff(desiredt)*[1,1])]; +fdesired = D.tau * desiredydotdot - (D.alphay * (D.betay*(S.g-S.desiredtraj) - desiredydot)); + +expected_x = x0*exp(-D.alphax/D.tau*(desiredt-desiredt(1))); +expectedPsi = exp(ones(length(desiredt),1)*(-1./(2*D.sigma.^2)) .*(expected_x - D.c).^2); %n traj points by n basis +% proveXexpworking % run this code to make a plot +betaw = (expected_x .* expectedPsi) \ (sum(expectedPsi')'.* fdesired); +errors = (expected_x .* expectedPsi)*betaw - (sum(expectedPsi')'.* fdesired); + +D.w = betaw'; + +index = 1; +expected_SHCas = R.a; +for t = desiredt(1): S.dt: desiredt(end) + dW = sqrt(S.dt)*randn(1,R.bfs); + da = R.a .* (R.alpha - R.a*R.rho') *S.dt + R.ep.*dW; %wondering if I forgot tau + R.a = max(min(R.a + da, 1), .0005); + + if t>=desiredt(index) + index = index+1; + else + expected_SHCas(index, :) = R.a; + end +end +size(expected_SHCas) +betaw = (expected_SHCas) \ (sum(expected_SHCas')'.* fdesired); +% meanerror = sum(sum(errors.^2)) +R.w = betaw'; + +[dcost,rcost] = Eval(D,R,S); +%DMP weight evaluation +delta = 1; +alldcosts = []; +for passes = 1:10 + bestw = D.w; + bestcost = dcost; +% for i = 1:Ntrials +% if rand(1)>.5 +% % try random stuff +% D.dmp.w = 1-.5*rand(2, D.dmp.bfs); +% [dcost,~] = Eval(D,R,S); +% if dcost=3 + chosenew = 0; + chosedel = 0; + for i = 1:size(D.w,1) + for j = 1:size(D.w,2) + wtrial = bestw; + wnew = bestw; + delt = delta*(1-2*rand(1)); + wtrial(i,j) = bestw(i,j) + delt; + [dcosttrial,~] = Eval(D,R,S,wtrial); + wnew(i,j) = bestw(i,j) + max(min(bestcost*delt/(bestcost - dcosttrial), delta*5), -delta*5); + [dcostnew,~] = Eval(D,R,S,wnew); + if dcostnew < bestcost + bestw = wnew; + bestcost = dcostnew; + chosenew = chosenew +1; + end + if dcosttrial < bestcost + bestw = wtrial; + bestcost = dcosttrial; + chosedel = chosedel +1; + end + end + end + end + + %at the end of one pass, save progress + alldcosts = [alldcosts, bestcost]; + D.w = bestw; + dcost = bestcost; + ShowPlot(D,R,S) +end + +%RMP weight evaluation +delta = 1; +allrcosts = []; +for passes = 1:10 + bestw = R.w; + bestcost = rcost; +% for i = 1:Ntrials +% if rand(1)>.5 +% % try random stuff +% R.w = 1-.5*rand(2, R.bfs); +% [~,rcost] = Eval(D,R,S); +% if rcost=3 + chosenew = 0; + chosedel = 0; + for i = 1:size(R.w,1) + for j = 1:size(R.w,2) + wtrial = bestw; + wnew = bestw; + delt = delta*(1-2*rand(1)); + wtrial(i,j) = bestw(i,j) + delt; + [~,rcosttrial] = Eval(D,R,S,wtrial); + wnew(i,j) = bestw(i,j) + max(min(bestcost*delt/(bestcost - rcosttrial), delta*5), -delta*5); + [~,rcostnew] = Eval(D,R,S,wnew); + if rcostnew < bestcost + bestw = wnew; + bestcost = rcostnew; + chosenew = chosenew +1; + end + if rcosttrial < bestcost + bestw = wtrial; + bestcost = rcosttrial; + chosedel = chosedel +1; + end + end + end + end + + %at the end of one pass, save progress + allrcosts = [allrcosts, bestcost]; + R.w = bestw; + rcost = bestcost; +end +ShowPlot(D,R,S) +Eval(D,R,S); +toc + +%% Evaluate Cost +function [dcost,rcost] = Eval(D,R,S,wnew) +if nargin == 4 + wdmp = wnew; + wrmp = wnew; +end +if nargin == 3 + wdmp = D.w; + wrmp = R.w; +end + +goaltol = 0.005; +distance = 0; +maxtime = (S.Nt+1)*S.dt; + +%DMP +timetogoal = nan; +trajpointdistancessq = Inf*ones(size(S.desiredtraj, 1), 1); +for i = 1:S.Nt + D.x = D.x + ((-D.alphax)*D.x)/D.tau*S.dt; + D.psi(i,:) = exp(-1./(2*D.sigma.^2).*((D.x-D.c).^2)); + D.psi(i,:) + forcing = (D.psi*wdmp') *D.x /sum(D.psi(i,:)); + f = forcing(i,:); + + ydotdot = (D.alphay*(D.betay*(S.g-D.y)-D.ydot)+f)/D.tau; + D.ydot = ydotdot*S.dt + D.ydot; + D.y = D.ydot*S.dt+D.y; + + trajpointdistancessq = min ((D.y(1) - S.desiredtraj(:,1)).^2 + (D.y(2) - S.desiredtraj(:,2)).^2, ... + trajpointdistancessq); + + [dsquared, whichtrajpoint] = min( (D.y(1) - S.desiredtraj(:,1)).^2 + ... + (D.y(2) - S.desiredtraj(:,2)).^2); + distance = distance + sqrt(dsquared); + + %record the time if it's at the goal + if isnan(timetogoal) && sum((D.y-S.g).^2)=desiredt(index) index = index+1; else expected_SHCas(index, :) = a; end + pause end @@ -130,10 +132,11 @@ %TWO main functions here, one to evaluate weights -d = Eval(w, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj, 1, OneforDMPtwoforRMP, w1,w2,Nsaddles); +[d,dcomponents] = Eval(w, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj, 1, OneforDMPtwoforRMP); delta = 1; allds = []; +dcomponentsplot = []; for passes = 1:10 bestw = w; bestd = d; @@ -141,7 +144,7 @@ if rand(1)>.5 % try random stuff w = 1-.5*rand(2, Npsi); - d = Eval(w, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj, 0,OneforDMPtwoforRMP, w1,w2,Nsaddles); + [d,dcomponents] = Eval(w, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj, 0,OneforDMPtwoforRMP); if d=desiredt(index) + index = index+1; + else + expected_SHCas(index, :) = a; + end +end + + + size(expected_SHCas) + betaw = ( expected_SHCas) \ (sum(expected_SHCas')'.* fdesired); +end + + +% meanerror = sum(sum(errors.^2)) +w = betaw'; +%%%%%%% $$$ end insertion +end + + +%TWO main functions here, one to evaluate weights +[d,dcomponents] = Eval(w, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj, 1, OneforDMPtwoforRMP); + +delta = 1; +allds = []; +dcomponentsplot = []; +for passes = 1:10 +bestw = w; +bestd = d; +for i = 1:Ktrials + if rand(1)>.5 + % try random stuff + w = 1-.5*rand(2, Npsi); + [d,dcomponents] = Eval(w, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj, 0,OneforDMPtwoforRMP); + if d=2 +chosenew = 0; +chosedel = 0; + for i = 1:size(w,1) + for j = 1:size(w,2) + wtrial = bestw; + wnew = bestw; + delt = delta*(1-2*rand(1)); + wtrial(i,j) = bestw(i,j) + delt; + [dtrial,dtrialcomponents] = Eval(wtrial, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj, 0,OneforDMPtwoforRMP); + wnew(i,j) = bestw(i,j) + max(min(bestd*delt/(bestd - dtrial), delta*5), -delta*5); + [dnew,dnewcomponents] = Eval(wnew, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj, 0,OneforDMPtwoforRMP); + if dnew < bestd + bestw = wnew; + bestd = dnew; + dcomponents = dnewcomponents; + chosenew = chosenew +1; + end + if dtrial < bestd + bestw = wtrial; + bestd = dtrial; + dcomponents = dtrialcomponents; + chosedel = chosedel +1; + end + + end + end + chosenew + chosedel +end + +allds = [allds,bestd]; +dcomponentsplot = [dcomponentsplot;dcomponents]; +w = bestw; +d = bestd; +%ShowTraj(w, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj); +% if passes==1 || passes==5 || passes==10 +% pause +% end +end +Eval(w, Nt, y0dot, y0, x0, alphax, tau, dt, sigma, c, alphay, betay,g, desiredtraj, 1,OneforDMPtwoforRMP); + +figure(4) +hold on +plot(allds,'k','Linewidth',2) +plot(dcomponentsplot(:,1),'b') +plot(dcomponentsplot(:,2),'m') +plot(dcomponentsplot(:,3),'r') +% +% pause +% ShowTraj(w, Nt, y0dot, y0, x0, alphax, 2*tau, dt, sigma, c, alphay, betay,g, desiredtraj); +% w = weights +% example +% 0.8726 -4.8226 -5.2870 -5.6955 11.9854 -1.6538 0.2696 -0.6114 2.2657 -0.8382 +% 4.3342 1.8618 0.2612 -1.5936 -5.3375 5.2797 -3.1289 0.0051 0.4761 -1.3480 +% Nt = number of timesteps +% y0 initial conditions +% x0 initial conditions +% alphax % keep same as training +% tau % changing this makes shape pretty different, sloppier if highter +%dt %seems like I can change this without changing shape + +% finalds = [finalds,allds(end)] +% figure(6) +% plot(finalds) +% end +% figure(7) +% hold on +% plot((1:Nt)*dt,ftrace(:,1),'Linewidth',2,'Color','r') +% plot((1:Nt)*dt,ftrace(:,2),'Linewidth',2,'Color','b') + +toc + +function [d,dcomponents,ftrace] = Eval(w, Nt, y0dot, y0, x0, alphax, tau, dt, sigma_or_rho, c_or_alpha, alphay, betay,g, desiredtraj, ShowPlot, OneforDMPtwoforRMP) +% %-------------------- +goaltol = .005; +%ShowPlot = 1; +% % initialize or variable descriptions (basics that are the same for RMP/DMP) +% Nt = 1000; % number of timesteps +% y0 = .001 * [1,1]; %system initial position +% y0dot= 0 * [1,1]; %system initial velocity +% dt = .01; %timestep +% tau = 1; %time constant base system, also reused in canonical system +% alphay = 4; %damping base system +% betay = alphay/4; %stiffness base system +% alphax = .5; %how fast cannonical system decays +% g = [1,0]; %goal position of base system +% desiredtraj = [0:.05:.5, fliplr(.5*cos((-pi/2):-.1:-(pi))+1); +% 0:.05:.5, fliplr(.5*sin((-pi/2):-.1:-(pi))+.5)]'; + +% %shared naming +% x0 = 1; %cannonical system initial state (scalar for DMP, vector for RMP) +% w = weights that are learned + %for DMP w will be size 2 by Npsi (assuming planar trajectory) +% w = [0.8726 -4.8226 -5.2870 -5.6955 11.9854 -1.6538 0.2696 -0.6114 2.2657 -0.8382; +% 4.3342 1.8618 0.2612 -1.5936 -5.3375 5.2797 -3.1289 0.0051 0.4761 -1.3480]; +% for RMP w will be size +% +% + +% Nsaddles = 20; +if OneforDMPtwoforRMP == 1 +% %for DMP +% Npsi = 10; %number of basis functions (use this generate c and sigma) + % c = logspace(log10(1), log10(.01), Npsi); % these are the positions of DMP in X, and they do not change. + % sigma = 2*logspace(log10(.3),log10(.002), Npsi); + sigma = sigma_or_rho; + c = c_or_alpha; + + x = x0; + if ShowPlot +xall = nan*ones(Nt,1); +psiall = nan*ones(Nt,length(sigma)); + end + + else +% %for RMP +Nsaddles = 10; +alpha = 10; +beta = 1; +nu = 1.2; +rho = calculaterho_notacycle(alpha*ones(Nsaddles,1), beta*ones(Nsaddles,1), nu*ones(Nsaddles,1)); + + +ep = 10^-9*ones(1,Nsaddles); +a0 = ep; +a0(1) = 1; +a0(2) = .01; +a = a0; +if ShowPlot +aall = nan*ones(Nt, Nsaddles); +end +% %%rho = []; %coupling matrix +% %%alpha = []; %growth factors +% % for now P and zd are zero since not measuring contact +% % and C is zero because there is no coupling and no measured z +% rho = sigma_or_rho; +% alpha = c_or_alpha; +% +end + +distance = 0; +ydot = y0dot; +y = y0; +% fnum = 0; +sumf = 0; +ftrace = []; + +maxtime = (Nt+1)*dt; +timetogoal = nan; + +if ShowPlot +yall = nan*ones(Nt,2); +ydotall = nan*ones(Nt,2); +whichcolor = nan*ones(Nt,1); +alldistanceerror = nan*ones(Nt,1); +whichtraj = nan*ones(Nt,1); +allverror = nan*ones(Nt,1); +end + +desiredtrajdir = diff(desiredtraj); +desiredtrajdir = .5*( [desiredtrajdir;desiredtrajdir(end,:)] + [desiredtrajdir(1,:);desiredtrajdir]);%centerdiffs +desiredtrajdir = desiredtrajdir ./sqrt(sum(desiredtrajdir.^2,2)); %normalize + +trajpointdistancessq = Inf*ones(size(desiredtraj, 1), 1); + +xall = []; +for i = 1:Nt + % advance diff equation + %DMP + if OneforDMPtwoforRMP == 1 +% w = [w(1,:); zeros(1,length(w))]; +% w = [zeros(1,length(w));w(2,:)]; + x = x + ((-alphax)*x)/tau*dt; + psi = exp(-1./(2*sigma.^2).*(x-c).^2); +% fnum = fnum + ((psi*w')*x); + f = (psi*w') *x /sum(psi); +% f = [0,f(2)]; +% f = [f(1),0]; +% %new weights +% beta2 = ((alphay*(betay*(g-y)-ydot))*(dt^2)/tau) + ydot*dt + y; +% beta1 = (psi*w'*(dt^2))*x/tau; +% f = beta2; + end + %RMP + if OneforDMPtwoforRMP == 2 + dW = sqrt(dt)*randn(1,Nsaddles); + da = a .* (alpha - a*rho) *dt + ep.*dW; %tau for scaling? + a = max(min(a + da, 1), .0005); %enforcing boundaries on a + f = a*w'/sum(a); + end + ydotdot = (alphay*(betay*(g-y)-ydot)+f)/tau; + ydot = ydotdot*dt + ydot; + y = ydot*dt+y; + + + if ShowPlot + % find out which part of solution has max contribution + if OneforDMPtwoforRMP == 1 + [~, whichcolor(i)] = max( [sum( abs(alphay*(betay*(g-y)-ydot)).^2)*.1; + sum((abs((psi.*w) *x /sum(psi))').^2,2)]); + else + [~, whichcolor(i)] = max( [sum( abs(alphay*(betay*(g-y)-ydot)).^2)*.1; + sum((abs((a.*w)/sum(a))').^2,2)]); + + end + + end + trajpointdistancessq = min ((y(1) - desiredtraj(:,1)).^2 + (y(2) - desiredtraj(:,2)).^2, ... + trajpointdistancessq); + [dsquared, whichtrajpoint] = min( (y(1) - desiredtraj(:,1)).^2 + ... + (y(2) - desiredtraj(:,2)).^2); +% distance = distance + sqrt(dsquared); +distance = sqrt(dsquared); + desv = desiredtrajdir(whichtrajpoint, :); + vnormalerror = (desv(1)*ydot(2) - desv(2)*ydot(1))/sqrt(ydot*ydot'); + + % here if its at the goal, I record time + if isnan(timetogoal) && sum((y-g).^2)izretFEg3 zV~(}PTzjsuYtLFkl2<{3mk*bbiUwDbSAo*d#N2=aSH@h&-q6a{f(=)OUrAJoiGc!_ z-_}6K-asGM%90IN(#jH7%)t_ujun@dk&T|7je!N1j)sl~_y6$%_&*n*s3h#4dx}4Q z=d@itZS5)mT_)Uv-!r&fko)vMbsTXYs7Oa7#z+mdb+mP#fDl0dcx*w0zc569V`%;r z(?bj8tHovax(5t^FAD_o6;1q~q7i(xAb^3PqCC6Dx&Q#Mhk;PP!WsS!zxvm~ zf9l}jK1_;Bj#ArRLz9qBg46l91LK|~|0d%x1sGTaH~Yd;{f)K$cdR8Y45bt$i5R8S zI5{a;sUFbC?>ztqK~VfJl;z*3qklyK(W1nG1rr|Z;!67dOp`5v0$b( z&{b)O4sOqv)qu`E*<)5?UDRz;x4f1l*v5IwZ?{JNU7e@VVm`|{))kDfdr!<1<(Avu4}t>T(4!+!)(m5#u`uB z<<-B<aBnMUVGu;=!@M>j^u-Xa$?w)cPRr>w!dJ z6@m^7y_FT~Vi)#SlrzH+D?QCY7oy!ZClc4@xr1L?>76byKRr&>>$>d(^_)g_EF1Pb}x2f$DO^jFb3{{5JZ|Fr`DY?UNKe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3;>|#yRi2c_u2o#U0+*=WKx{+5TphL z;JUy$-n2Ph_)(e`WkY`Zc75Yy(QH5VvSJx0C}iqLh43KCS!ym=FLcM-zEDe;dGNEE zc}Dr|-m>w<+bv}ssu495lf?7!V?a{PA2>d?Ptvn73Dep2d@=b78Xd+-$^i08%ZBBL zrn40SduC*>T4p_V>i8IJklRALPC0~~^ONiKj2o{M%)GkeBKPOL1C571N3I&jvbShg z?wz&eoj3J+BiCBoS6Ow6%ENx8w(!r?{%>#TNPHrq0nq^sjWy8n{|`1zLZ|C}=i@#b z0DumqeBW1g|4|ze_(5gx{zo{_(E;JUV(I=~iGMpJ_m@8F7BOgRZ-LZ+{(hPqiA;2l q1v=AV00<6(^!q}R{Ee*oca22&qmhc}d3%Y!`;)p(0O)Fg4E{fVxQhG$ literal 0 HcmV?d00001 diff --git a/wbestRMP1.mat b/wbestRMP1.mat new file mode 100644 index 0000000000000000000000000000000000000000..0a2f17f96ca030219b1ed1237934217430e618d4 GIT binary patch literal 18572 zcma&Ob9`jo(l#7t;)y1R{Vn>Gx)!u_n8RwUGN`hDMqBnC`|P9^$easP{4rr9l*psF{FQE=>Hkh z!vGVYD_~EG9MccJ2MR=_00RFhP5HO4p+G@lVtl&CeggsF4uhb7inIJJe)Z3E2=xi@A10+_M(G@`;m9c_AsPL>K=Dsf ze^93UU^Kz#M42JT$d5fBXAy9sPn6)_D6@Y? zfiR$@m>7wJ&1CRn1NHfS_i5it-_w($Jzvw+9d#q_^O=Zx^)D^kSOo>TU89Nm)WrK= zG#Q99>*;NQ)qk`wiVg#qYH+oU)dY|m07C^i*w<8Wt++}J(auA=PyI}MZlHUREL{k z`nSO3%~&hHE@;Tje7Y$I?SkvqAv9;?%<@YhpeI^nQ4+E2sfeyo;0lcnB!1bqxU*LgwXTW}ZLjI!<#HcA+*h@gi90ZQQ z?1i_6$}YG90V$P$MSP;>|DH`VaGw?b7;u5W57ZG;5Cd9#lfW>Nf^W$QpGMaK>Ql-K3gC{kO~hJXx0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rXSndwcU2}5TGR|`ldj=~?P6Ii5%N-cRZz2WGL1Fsm2HZ!FH0DP)mRR910 literal 0 HcmV?d00001 From 39065874982b5a8ff949d574aeb65014fd44b2ef Mon Sep 17 00:00:00 2001 From: Natasha Rouse Date: Fri, 10 Jul 2020 11:40:30 -0400 Subject: [PATCH 3/7] Still not plotting correctly --- DMPandRMP1.m | 404 +++++++++++++++++++++++++++------------------------ 1 file changed, 211 insertions(+), 193 deletions(-) diff --git a/DMPandRMP1.m b/DMPandRMP1.m index af2b47f..69ac490 100644 --- a/DMPandRMP1.m +++ b/DMPandRMP1.m @@ -6,7 +6,7 @@ clc tic -rng(2) %seeding different random numbers to check validity of cost evaluation +rng(1) %seeding different random numbers to check validity of cost evaluation %TRAJECTORY CHOICES % %ramp up bubble out ----- @@ -21,15 +21,17 @@ desiredtraj = [(0:.05:.5)*0, .5*cos(pi/2:.1:pi*2.6); 0:.05:.5, .5*sin(pi/2:.1:pi*2.6)]'; g = [0,0]; -y0 = .001 * [1,1]; -y0dot= 0 * [1,1]; -x0 = 1; -bfs = 10; %system init S = struct('desiredtraj',desiredtraj,'dt',0.01,'Nt',1000,'g',g); %trajectory start, velocity at trajectory start, canonical state vector, %size of timestep, number of timesteps, goal +y0 = []; +y0(1,:) = .001 * [1,1]; +y0dot = []; +y0dot(1,:) = 0 * [1,1]; +x0 = 1; +bfs = 10; %dmp init D = struct('tau',1,'alphay',4,'betay',1,'alphax',.5,... %how fast cannonical system decays @@ -41,35 +43,54 @@ %rmp init R = struct('tau',1,'alphay',4,'betay',1,'alpha',10,'beta',1,'nu',1.2,'bfs',bfs,... - 'rho',logspace(log10(.3),log10(.002), bfs),... - 'a',[1,0.1,10^-9*ones(1,bfs-2)],... + 'rho',zeros(bfs),... + 'a',[],... 'ep',[10^-9*ones(1,bfs)],... - 'w',zeros(1,length(desiredtraj)),'y',y0,'ydot',y0dot,'x',x0); - + 'w',zeros(1,length(desiredtraj)),'y',y0,'ydot',y0dot); + %Init -D.w = S.desiredtraj(round(linspace(1,length(S.desiredtraj),D.bfs)) ,:)'*(D.alphay+D.betay); -R.w = S.desiredtraj(round(linspace(1,length(S.desiredtraj),R.bfs)) ,:)'*(R.alphay+R.betay); +% D.w = S.desiredtraj(round(linspace(1,length(S.desiredtraj),D.bfs)) ,:)'*(D.alphay+D.betay); +% R.w = S.desiredtraj(round(linspace(1,length(S.desiredtraj),R.bfs)) ,:)'*(R.alphay+R.betay); -Ntrials = 500; +Ntrials = 100; desiredt = linspace(0,10,length(S.desiredtraj))';% assumes constant velocity desiredydot = [0,0;diff(S.desiredtraj)./(diff(desiredt)*[1,1])]; % desired speed desiredydotdot = [0,0;diff(desiredydot)./(diff(desiredt)*[1,1])]; -fdesired = D.tau * desiredydotdot - (D.alphay * (D.betay*(S.g-S.desiredtraj) - desiredydot)); +fdesiredd = D.tau * desiredydotdot - (D.alphay * (D.betay*(S.g-S.desiredtraj) - desiredydot)); expected_x = x0*exp(-D.alphax/D.tau*(desiredt-desiredt(1))); expectedPsi = exp(ones(length(desiredt),1)*(-1./(2*D.sigma.^2)) .*(expected_x - D.c).^2); %n traj points by n basis % proveXexpworking % run this code to make a plot -betaw = (expected_x .* expectedPsi) \ (sum(expectedPsi')'.* fdesired); -errors = (expected_x .* expectedPsi)*betaw - (sum(expectedPsi')'.* fdesired); - -D.w = betaw'; +betawd = (expected_x .* expectedPsi) \ (sum(expectedPsi')'.* fdesiredd); +errors = (expected_x .* expectedPsi)*betawd - (sum(expectedPsi')'.* fdesiredd); + +D.w = betawd'; + +R.a(1,:) = [1,0.1,10^-9*ones(1,R.bfs-2)]; +alpha_rho = R.alpha*ones(R.bfs,1); +beta_rho = R.beta*ones(R.bfs,1); +nu_rho = R.nu*ones(R.bfs,1); +R.rho = zeros(bfs); + +for i = 1:bfs + for j = 1:bfs + if i==j + R.rho(i,j) = alpha_rho(i)/beta_rho(i); + else if 0 == j-1-i + R.rho(i,j) = (alpha_rho(i) - alpha_rho(j)/nu_rho(j))./beta_rho(j); + else + R.rho(i,j) = (alpha_rho(i) + alpha_rho(j))/beta_rho(j); + end + end + end +end index = 1; expected_SHCas = R.a; for t = desiredt(1): S.dt: desiredt(end) dW = sqrt(S.dt)*randn(1,R.bfs); - da = R.a .* (R.alpha - R.a*R.rho') *S.dt + R.ep.*dW; %wondering if I forgot tau - R.a = max(min(R.a + da, 1), .0005); + da = R.a .* (R.alpha - R.a*R.rho) *S.dt + R.ep.*dW; %tau for scaling? + R.a = max(min(R.a + da, 1), .0005); %enforcing boundaries on 'a' if t>=desiredt(index) index = index+1; @@ -77,156 +98,153 @@ expected_SHCas(index, :) = R.a; end end +R.a +pause size(expected_SHCas) -betaw = (expected_SHCas) \ (sum(expected_SHCas')'.* fdesired); +fdesiredr = R.tau * desiredydotdot - (R.alphay * (R.betay*(S.g-S.desiredtraj) - desiredydot)); +betawr = (expected_SHCas) \ (sum(expected_SHCas')'.* fdesiredr); % meanerror = sum(sum(errors.^2)) -R.w = betaw'; +R.w = betawr'; + +'before optimization' +[dcost,rcost,D,R] = Eval(D,R,S); +ShowPlot(D,R,S) +pause -[dcost,rcost] = Eval(D,R,S); %DMP weight evaluation delta = 1; alldcosts = []; +allrcosts = []; for passes = 1:10 - bestw = D.w; - bestcost = dcost; -% for i = 1:Ntrials -% if rand(1)>.5 -% % try random stuff -% D.dmp.w = 1-.5*rand(2, D.dmp.bfs); -% [dcost,~] = Eval(D,R,S); -% if dcost.5 + % try random stuff + D.w = 1-.5*rand(2, D.bfs); + R.w = 1-.5*rand(2, R.bfs); + [dcost,rcost,D,R] = Eval(D,R,S); + ShowPlot(D,R,S) + if dcost=3 +% chosenew = 0; +% chosedel = 0; +% for i = 1:size(D.w,1) +% for j = 1:size(D.w,2) +% wtrial = bestw; +% wnew = bestw; +% delt = delta*(1-2*rand(1)); +% wtrial(i,j) = bestw(i,j) + delt; +% [dcosttrial,~,D,~] = Eval(D,R,S,wtrial); +% ShowPlot(D,R,S) +% wnew(i,j) = bestw(i,j) + max(min(bestcost*delt/(bestcost - dcosttrial), delta*5), -delta*5); +% [dcostnew,~,D,~] = Eval(D,R,S,wnew); +% if dcostnew < bestcost +% bestw = wnew; +% bestcost = dcostnew; +% chosenew = chosenew +1; +% end +% if dcosttrial < bestcost +% bestw = wtrial; +% bestcost = dcosttrial; +% chosedel = chosedel +1; +% end +% end +% end % end + +% %at the end of one pass, save progress +% alldcosts = [alldcosts, bestcost]; % D.w = bestw; % dcost = bestcost; -% delta = delta*.99; -% Eval(D,R,S); -% alldcosts = [alldcosts,bestcost]; - - %Gradient Descent on the best weights - pause(1) - chosenew = Inf; - chosedel = Inf; - while chosenew+chosedel>=3 - chosenew = 0; - chosedel = 0; - for i = 1:size(D.w,1) - for j = 1:size(D.w,2) - wtrial = bestw; - wnew = bestw; - delt = delta*(1-2*rand(1)); - wtrial(i,j) = bestw(i,j) + delt; - [dcosttrial,~] = Eval(D,R,S,wtrial); - wnew(i,j) = bestw(i,j) + max(min(bestcost*delt/(bestcost - dcosttrial), delta*5), -delta*5); - [dcostnew,~] = Eval(D,R,S,wnew); - if dcostnew < bestcost - bestw = wnew; - bestcost = dcostnew; - chosenew = chosenew +1; - end - if dcosttrial < bestcost - bestw = wtrial; - bestcost = dcosttrial; - chosedel = chosedel +1; - end - end - end - end - %at the end of one pass, save progress - alldcosts = [alldcosts, bestcost]; - D.w = bestw; - dcost = bestcost; - ShowPlot(D,R,S) -end - -%RMP weight evaluation -delta = 1; -allrcosts = []; -for passes = 1:10 - bestw = R.w; - bestcost = rcost; -% for i = 1:Ntrials -% if rand(1)>.5 -% % try random stuff -% R.w = 1-.5*rand(2, R.bfs); -% [~,rcost] = Eval(D,R,S); -% if rcost=3 +% chosenew = 0; +% chosedel = 0; +% for i = 1:size(R.w,1) +% for j = 1:size(R.w,2) +% wtrial = bestw; +% wnew = bestw; +% delt = delta*(1-2*rand(1)); +% wtrial(i,j) = bestw(i,j) + delt; +% [~,rcosttrial,~,R] = Eval(D,R,S,wtrial); +% wnew(i,j) = bestw(i,j) + max(min(bestcost*delt/(bestcost - rcosttrial), delta*5), -delta*5); +% [~,rcostnew,~,R] = Eval(D,R,S,wnew); +% if rcostnew < bestcost +% bestw = wnew; +% bestcost = rcostnew; +% chosenew = chosenew +1; +% end +% if rcosttrial < bestcost +% bestw = wtrial; +% bestcost = rcosttrial; +% chosedel = chosedel +1; +% end +% end +% end % end +% +% at the end of one pass, save progress +% allrcosts = [allrcosts, bestcost]; % R.w = bestw; % rcost = bestcost; -% delta = delta*.99; -% Eval(D,R,S); -% allrcosts = [allrcosts,bestcost]; - - %Gradient Descent on the best weights - pause(1) - chosenew = Inf; - chosedel = Inf; - while chosenew+chosedel>=3 - chosenew = 0; - chosedel = 0; - for i = 1:size(R.w,1) - for j = 1:size(R.w,2) - wtrial = bestw; - wnew = bestw; - delt = delta*(1-2*rand(1)); - wtrial(i,j) = bestw(i,j) + delt; - [~,rcosttrial] = Eval(D,R,S,wtrial); - wnew(i,j) = bestw(i,j) + max(min(bestcost*delt/(bestcost - rcosttrial), delta*5), -delta*5); - [~,rcostnew] = Eval(D,R,S,wnew); - if rcostnew < bestcost - bestw = wnew; - bestcost = rcostnew; - chosenew = chosenew +1; - end - if rcosttrial < bestcost - bestw = wtrial; - bestcost = rcosttrial; - chosedel = chosedel +1; - end - end - end - end - - %at the end of one pass, save progress - allrcosts = [allrcosts, bestcost]; - R.w = bestw; - rcost = bestcost; +ShowPlot(D,R,S) end ShowPlot(D,R,S) Eval(D,R,S); toc %% Evaluate Cost -function [dcost,rcost] = Eval(D,R,S,wnew) +function [dcost,rcost,D,R] = Eval(D,R,S,wnew) if nargin == 4 wdmp = wnew; wrmp = wnew; @@ -244,25 +262,24 @@ timetogoal = nan; trajpointdistancessq = Inf*ones(size(S.desiredtraj, 1), 1); for i = 1:S.Nt - D.x = D.x + ((-D.alphax)*D.x)/D.tau*S.dt; - D.psi(i,:) = exp(-1./(2*D.sigma.^2).*((D.x-D.c).^2)); - D.psi(i,:) - forcing = (D.psi*wdmp') *D.x /sum(D.psi(i,:)); - f = forcing(i,:); + D.x(i+1,:) = D.x(i,:) + ((-D.alphax)*D.x(i,:))/D.tau*S.dt; + D.psi(i,:) = exp(-1./(2*D.sigma.^2).*((D.x(i+1,:)-D.c).^2)); + f(i,:) = (D.psi(i,:)*wdmp') *D.x(i+1,:) /sum(D.psi(i,:)); +% f = forcing(i,:); - ydotdot = (D.alphay*(D.betay*(S.g-D.y)-D.ydot)+f)/D.tau; - D.ydot = ydotdot*S.dt + D.ydot; - D.y = D.ydot*S.dt+D.y; + ydotdot = (D.alphay*(D.betay*(S.g-D.y(i,:))-D.ydot(i,:))+f(i,:))/D.tau; + D.ydot(i+1,:) = ydotdot*S.dt + D.ydot(i,:); + D.y(i+1,:) = D.ydot(i+1,:)*S.dt+D.y(i,:); - trajpointdistancessq = min ((D.y(1) - S.desiredtraj(:,1)).^2 + (D.y(2) - S.desiredtraj(:,2)).^2, ... + trajpointdistancessq = min ((D.y(i+1,1) - S.desiredtraj(:,1)).^2 + (D.y(i+1,2) - S.desiredtraj(:,2)).^2, ... trajpointdistancessq); - [dsquared, whichtrajpoint] = min( (D.y(1) - S.desiredtraj(:,1)).^2 + ... - (D.y(2) - S.desiredtraj(:,2)).^2); + [dsquared, whichtrajpoint] = min( (D.y(i+1,1) - S.desiredtraj(:,1)).^2 + ... + (D.y(i+1,2) - S.desiredtraj(:,2)).^2); distance = distance + sqrt(dsquared); %record the time if it's at the goal - if isnan(timetogoal) && sum((D.y-S.g).^2) Date: Fri, 24 Jul 2020 13:39:32 -0400 Subject: [PATCH 4/7] Plotting works! Functional code. Includes: linear algebra formulation for weights, stochastic learning for weights, & gradient descent for learning weights. --- DMPandRMP1.m | 387 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 236 insertions(+), 151 deletions(-) diff --git a/DMPandRMP1.m b/DMPandRMP1.m index 69ac490..261708e 100644 --- a/DMPandRMP1.m +++ b/DMPandRMP1.m @@ -32,21 +32,29 @@ y0dot(1,:) = 0 * [1,1]; x0 = 1; bfs = 10; +rbfs = 10; +sigma = logspace(log10(.3),log10(.002), bfs); %original +% sigma = 0.002*ones(1,bfs); %this gives bf #10 the same size as rmps +% sigma = logspace(log10(0.205),log10(0.002),bfs); %closest overall +% sigma = logspace(log10(0.3),log10(0.0005),bfs); %dmp init D = struct('tau',1,'alphay',4,'betay',1,'alphax',.5,... %how fast cannonical system decays 'bfs',bfs,... %number of basis functions (psi activations) 'c',logspace(log10(1), log10(.01), bfs),... %basis function centers - 'sigma',logspace(log10(.3),log10(.002), bfs),... %basis function widths + 'sigma',sigma,... %basis function widths 'w',zeros(1,length(desiredtraj)),... + 'f',zeros(S.Nt,2),... 'psi',nan(S.Nt,bfs),'y',y0,'ydot',y0dot,'x',x0); %rmp init -R = struct('tau',1,'alphay',4,'betay',1,'alpha',10,'beta',1,'nu',1.2,'bfs',bfs,... - 'rho',zeros(bfs),... +R = struct('tau',1,'alphay',4,'betay',1,'alpha',10,'beta',1,'nu',1.2,'bfs',rbfs,... + 'rho',zeros(rbfs),... + 'a0',[1,0.1,10^-9*ones(1,rbfs-2)],... 'a',[],... - 'ep',[10^-9*ones(1,bfs)],... - 'w',zeros(1,length(desiredtraj)),'y',y0,'ydot',y0dot); + 'ep',10^-9*ones(1,rbfs),... + 'w',zeros(1,length(desiredtraj)),... + 'f',zeros(S.Nt,2),'y',y0,'ydot',y0dot); %Init % D.w = S.desiredtraj(round(linspace(1,length(S.desiredtraj),D.bfs)) ,:)'*(D.alphay+D.betay); @@ -66,17 +74,19 @@ D.w = betawd'; -R.a(1,:) = [1,0.1,10^-9*ones(1,R.bfs-2)]; +R.a(1,:) = R.a0; alpha_rho = R.alpha*ones(R.bfs,1); beta_rho = R.beta*ones(R.bfs,1); nu_rho = R.nu*ones(R.bfs,1); -R.rho = zeros(bfs); +% nu_rho(2) = 2.4; +R.rho = zeros(R.bfs); -for i = 1:bfs - for j = 1:bfs +for i = 1:R.bfs + for j = 1:R.bfs if i==j R.rho(i,j) = alpha_rho(i)/beta_rho(i); - else if 0 == j-1-i + else + if 0 == j-1-i R.rho(i,j) = (alpha_rho(i) - alpha_rho(j)/nu_rho(j))./beta_rho(j); else R.rho(i,j) = (alpha_rho(i) + alpha_rho(j))/beta_rho(j); @@ -87,20 +97,21 @@ index = 1; expected_SHCas = R.a; +a = R.a(1,:); +a*R.rho + for t = desiredt(1): S.dt: desiredt(end) dW = sqrt(S.dt)*randn(1,R.bfs); - da = R.a .* (R.alpha - R.a*R.rho) *S.dt + R.ep.*dW; %tau for scaling? - R.a = max(min(R.a + da, 1), .0005); %enforcing boundaries on 'a' + da = a .* (R.alpha - a*R.rho) *S.dt + R.ep.*dW; %tau for scaling? + a = max(min(a + da, 1), .0005); %enforcing boundaries on 'a' if t>=desiredt(index) index = index+1; else - expected_SHCas(index, :) = R.a; + expected_SHCas(index, :) = a; end end -R.a -pause -size(expected_SHCas) + fdesiredr = R.tau * desiredydotdot - (R.alphay * (R.betay*(S.g-S.desiredtraj) - desiredydot)); betawr = (expected_SHCas) \ (sum(expected_SHCas')'.* fdesiredr); % meanerror = sum(sum(errors.^2)) @@ -122,125 +133,130 @@ bestdcost = dcost; bestrw = R.w; bestrcost = rcost; - for i = 1:Ntrials - if rand(1)>.5 - % try random stuff - D.w = 1-.5*rand(2, D.bfs); - R.w = 1-.5*rand(2, R.bfs); - [dcost,rcost,D,R] = Eval(D,R,S); - ShowPlot(D,R,S) - if dcost.5 +% % try random stuff +% D.w = 1-.5*rand(2, D.bfs); +% R.w = 1-.5*rand(2, R.bfs); +% [dcost,rcost,D,R] = Eval(D,R,S); +% if dcost=3 -% chosenew = 0; -% chosedel = 0; -% for i = 1:size(D.w,1) -% for j = 1:size(D.w,2) -% wtrial = bestw; -% wnew = bestw; -% delt = delta*(1-2*rand(1)); -% wtrial(i,j) = bestw(i,j) + delt; -% [dcosttrial,~,D,~] = Eval(D,R,S,wtrial); -% ShowPlot(D,R,S) -% wnew(i,j) = bestw(i,j) + max(min(bestcost*delt/(bestcost - dcosttrial), delta*5), -delta*5); -% [dcostnew,~,D,~] = Eval(D,R,S,wnew); -% if dcostnew < bestcost -% bestw = wnew; -% bestcost = dcostnew; -% chosenew = chosenew +1; -% end -% if dcosttrial < bestcost -% bestw = wtrial; -% bestcost = dcosttrial; -% chosedel = chosedel +1; -% end -% end -% end -% end - -% %at the end of one pass, save progress -% alldcosts = [alldcosts, bestcost]; -% D.w = bestw; -% dcost = bestcost; +%Gradient Descent on the best weights +pause(1) +chosenew = Inf; +chosedel = Inf; +while chosenew+chosedel>=3 + chosenew = 0; + chosedel = 0; + for i = 1:size(D.w,1) + for j = 1:size(D.w,2) + wtrial = bestdw; + wnew = bestdw; + delt = delta*(1-2*rand(1)); + wtrial(i,j) = bestdw(i,j) + delt; + [dcosttrial,~,D,~] = Eval(D,R,S,wtrial); + wnew(i,j) = bestdw(i,j) + max(min(bestdcost*delt/(bestdcost - dcosttrial), delta*5), -delta*5); + [dcostnew,~,D,~] = Eval(D,R,S,wnew); + if dcostnew < bestdcost + bestdw = wnew; + bestdcost = dcostnew; + chosenew = chosenew +1; + end + if dcosttrial < bestdcost + bestdw = wtrial; + bestdcost = dcosttrial; + chosedel = chosedel +1; + end + end + end +end -% %RMP weight evaluation +%at the end of one pass, save progress +alldcosts = [alldcosts, bestdcost]; +D.w = bestdw; +dcost = bestdcost; -% Gradient Descent on the best weights -% pause(1) -% chosenew = Inf; -% chosedel = Inf; -% while chosenew+chosedel>=3 -% chosenew = 0; -% chosedel = 0; -% for i = 1:size(R.w,1) -% for j = 1:size(R.w,2) -% wtrial = bestw; -% wnew = bestw; -% delt = delta*(1-2*rand(1)); -% wtrial(i,j) = bestw(i,j) + delt; -% [~,rcosttrial,~,R] = Eval(D,R,S,wtrial); -% wnew(i,j) = bestw(i,j) + max(min(bestcost*delt/(bestcost - rcosttrial), delta*5), -delta*5); -% [~,rcostnew,~,R] = Eval(D,R,S,wnew); -% if rcostnew < bestcost -% bestw = wnew; -% bestcost = rcostnew; -% chosenew = chosenew +1; -% end -% if rcosttrial < bestcost -% bestw = wtrial; -% bestcost = rcosttrial; -% chosedel = chosedel +1; -% end -% end -% end -% end -% -% at the end of one pass, save progress -% allrcosts = [allrcosts, bestcost]; -% R.w = bestw; -% rcost = bestcost; -ShowPlot(D,R,S) +% Gradient Descent on the best weights +pause(1) +chosenew = Inf; +chosedel = Inf; +while chosenew+chosedel>=3 + chosenew = 0; + chosedel = 0; + for i = 1:size(R.w,1) + for j = 1:size(R.w,2) + wtrial = bestrw; + wnew = bestrw; + delt = delta*(1-2*rand(1)); + wtrial(i,j) = bestrw(i,j) + delt; + [~,rcosttrial,~,R] = Eval(D,R,S,wtrial); + wnew(i,j) = bestrw(i,j) + max(min(bestrcost*delt/(bestrcost - rcosttrial), delta*5), -delta*5); + [~,rcostnew,~,R] = Eval(D,R,S,wnew); + if rcostnew < bestrcost + bestrw = wnew; + bestrcost = rcostnew; + chosenew = chosenew +1; + end + if rcosttrial < bestrcost + bestrw = wtrial; + bestrcost = rcosttrial; + chosedel = chosedel +1; + end + end + end +end + +% at the end of one pass, save progress +allrcosts = [allrcosts, bestrcost]; +R.w = bestrw; +rcost = bestrcost; +% ShowPlot(D,R,S) end -ShowPlot(D,R,S) Eval(D,R,S); +ShowPlot(D,R,S) + +figure(8) +hold on +title('All Costs') +plot(alldcosts,'-k','Linewidth',1.5) +plot(allrcosts,'--k','Linewidth',1.5) +legend('DMP','RMP') +xlabel('Iterations') +ylabel('Cost') + toc %% Evaluate Cost @@ -253,7 +269,6 @@ wdmp = D.w; wrmp = R.w; end - goaltol = 0.005; distance = 0; maxtime = (S.Nt+1)*S.dt; @@ -264,17 +279,17 @@ for i = 1:S.Nt D.x(i+1,:) = D.x(i,:) + ((-D.alphax)*D.x(i,:))/D.tau*S.dt; D.psi(i,:) = exp(-1./(2*D.sigma.^2).*((D.x(i+1,:)-D.c).^2)); - f(i,:) = (D.psi(i,:)*wdmp') *D.x(i+1,:) /sum(D.psi(i,:)); + D.f(i,:) = (D.psi(i,:)*wdmp') *D.x(i+1,:) /sum(D.psi(i,:)); % f = forcing(i,:); - ydotdot = (D.alphay*(D.betay*(S.g-D.y(i,:))-D.ydot(i,:))+f(i,:))/D.tau; + ydotdot = (D.alphay*(D.betay*(S.g-D.y(i,:))-D.ydot(i,:))+D.f(i,:))/D.tau; D.ydot(i+1,:) = ydotdot*S.dt + D.ydot(i,:); D.y(i+1,:) = D.ydot(i+1,:)*S.dt+D.y(i,:); trajpointdistancessq = min ((D.y(i+1,1) - S.desiredtraj(:,1)).^2 + (D.y(i+1,2) - S.desiredtraj(:,2)).^2, ... trajpointdistancessq); - [dsquared, whichtrajpoint] = min( (D.y(i+1,1) - S.desiredtraj(:,1)).^2 + ... + [dsquared,~] = min( (D.y(i+1,1) - S.desiredtraj(:,1)).^2 + ... (D.y(i+1,2) - S.desiredtraj(:,2)).^2); distance = distance + sqrt(dsquared); @@ -287,25 +302,32 @@ if isnan(timetogoal) timetogoal = maxtime-S.dt; end +dcomponents = [1*distance, 10*timetogoal/S.Nt, 1*sum(sqrt(trajpointdistancessq))]; dcost = 1*distance + 10*timetogoal/S.Nt + 1*sum(sqrt(trajpointdistancessq)); %RMP +distance = 0; timetogoal = nan; trajpointdistancessq = Inf*ones(size(S.desiredtraj, 1), 1); for i = 1:S.Nt dW = sqrt(S.dt)*randn(1,R.bfs); - da = R.a(i,:) .* (R.alpha - R.a(i,:)*R.rho) *S.dt + R.ep.*dW; %tau for scaling? - R.a(i+1,:) = max(min(R.a(i,:) + da, 1), .0005); %enforcing boundaries on a - f(i,:) = R.a(i+1,:)*wrmp'/sum(R.a(i+1,:)); + if i == 1 + da = R.a0 .* (R.alpha - R.a0*R.rho) *S.dt + R.ep.*dW; + R.a(i,:) = max(min(R.a0 + da, 1), 0.0005); + else + da = R.a(i-1,:) .* (R.alpha - R.a(i-1,:)*R.rho) *S.dt + R.ep.*dW; %tau for scaling? + R.a(i,:) = max(min(R.a(i-1,:) + da, 1), .0005); %enforcing boundaries on a + end + R.f(i,:) = (R.a(i,:)*wrmp')/sum(R.a(i,:)); - ydotdot = (R.alphay*(R.betay*(S.g-R.y(i,:))-R.ydot(i,:))+f(i,:))/R.tau; + ydotdot = (R.alphay*(R.betay*(S.g-R.y(i,:))-R.ydot(i,:))+R.f(i,:))/R.tau; R.ydot(i+1,:) = ydotdot*S.dt + R.ydot(i,:); R.y(i+1,:) = R.ydot(i+1,:)*S.dt+R.y(i,:); trajpointdistancessq = min ((R.y(i+1,1) - S.desiredtraj(:,1)).^2 + (R.y(i+1,2) - S.desiredtraj(:,2)).^2, ... trajpointdistancessq); - [dsquared, whichtrajpoint] = min( (R.y(i+1,1) - S.desiredtraj(:,1)).^2 + ... + [dsquared,~] = min( (R.y(i+1,1) - S.desiredtraj(:,1)).^2 + ... (R.y(i+1,2) - S.desiredtraj(:,2)).^2); distance = distance + sqrt(dsquared); @@ -318,7 +340,7 @@ if isnan(timetogoal) timetogoal = maxtime-S.dt; end - +rcomponents = [1*distance, 10*timetogoal/S.Nt, 1*sum(sqrt(trajpointdistancessq))]; rcost = 1*distance + 10*timetogoal/S.Nt + 1*sum(sqrt(trajpointdistancessq)); end @@ -362,27 +384,28 @@ function ShowPlot(D,R,S) psiall(i,:) = D.psi(i,:); aall(i,:) = R.a(i,:); end + dmpcolorstouse = setdiff(unique(dmpcolor)-1, 0); rmpcolorstouse = setdiff(unique(rmpcolor)-1, 0); -psicolors = ones(1, size(D.w,2))'*[0.7, 0.7, 0.7]; +psicolors = ones(1,size(D.w,2))'*[0.7, 0.7, 0.7]; acolors = ones(1, size(R.w,2))'*[0.7, 0.7, 0.7]; psicolors(dmpcolorstouse,:) = cool(length(dmpcolorstouse)); acolors(rmpcolorstouse,:) = cool(length(rmpcolorstouse)); - figure(1) clf(1) figure(1) -hold on subplot(2,1,1) title ('Basis functions times weights (dmp)') for j = 1:size(D.psi,2) + hold on plot((1:S.Nt)*S.dt, psiall(:,j)*D.w(1,j), '-c', 'Color', psicolors(j,:)) plot((1:S.Nt)*S.dt, psiall(:,j)*D.w(2,j), '-c.', 'Color', psicolors(j,:)) end subplot(2,1,2) title('Basis functions times weights (rmp)') for j = 1:size(R.a,2) + hold on plot((1:S.Nt)*S.dt, aall(:,j)*R.w(1,j), '-c', 'Color', acolors(j,:)) plot((1:S.Nt)*S.dt, aall(:,j)*R.w(2,j), '-c.', 'Color', acolors(j,:)) end @@ -390,20 +413,19 @@ function ShowPlot(D,R,S) figure(2) clf(2) figure(2) -hold on subplot(2,1,1) -plot(yalldmp(:,1), yalldmp(:,2), 'k-') -plot(S.desiredtraj(:,1), S.desiredtraj(:,2), '-g.'); -plot(yalldmp(dmpcolor==1,1), yalldmp(dmpcolor==1,2), 'k.') +hold on +title('Weights plotted spatially (dmp)') +plot(D.w(1,:),D.w(2,:), '-ro', 'Color', [.6, .6, .6]) for i = 1:size(D.w, 2) plot(yalldmp(dmpcolor==(1+i),1), yalldmp(dmpcolor==(1+i),2), 'k.', 'Color', psicolors(i,:)) plot(D.w(1,i), D.w(2,i), 'k*', 'Color', psicolors(i,:)) end axis equal subplot(2,1,2) -plot(yallrmp(:,1), yallrmp(:,2), 'k-') -plot(S.desiredtraj(:,1), S.desiredtraj(:,2), '-g.'); -plot(yallrmp(rmpcolor==1,1), yallrmp(rmpcolor==1,2), 'k.') +hold on +title('Weights plotted spatially (rmp)') +plot(R.w(1,:),R.w(2,:), '-ro', 'Color', [.6, .6, .6]) for i = 1:size(R.w, 2) plot(yallrmp(rmpcolor==(1+i),1), yallrmp(rmpcolor==(1+i),2), 'k.', 'Color', acolors(i,:)) plot(R.w(1,i), R.w(2,i), 'k*', 'Color', acolors(i,:)) @@ -413,22 +435,85 @@ function ShowPlot(D,R,S) figure(3) clf(3) figure(3) -hold on subplot(2,1,1) +hold on +title('Desired traj (black) and produced traj (color) - dmp') for i = 1:size(D.w, 2) plot(yalldmp(dmpcolor==(1+i),1), yalldmp(dmpcolor==(1+i),2), 'k.', 'Color', psicolors(i,:)) end plot(S.desiredtraj(:,1),S.desiredtraj(:,2), '-k.'); axis equal subplot(2,1,2) +hold on +title('Desired traj (black) and produced traj (color) - rmp') for i = 1:size(R.w, 2) plot(yallrmp(rmpcolor==(1+i),1), yallrmp(rmpcolor==(1+i),2), 'k.', 'Color', acolors(i,:)) end plot(S.desiredtraj(:,1),S.desiredtraj(:,2), '-k.'); axis equal +figure(4) + clf(4) + figure(4) +subplot(2,1,1) +hold on +title('DMP forcing function') +plot((1:S.Nt)*S.dt,D.f(:,1),'-r') +plot((1:S.Nt)*S.dt,D.f(:,2),'--r') +legend('x-component','y-component') +subplot(2,1,2) +hold on +title('RMP forcing function') +plot((1:S.Nt)*S.dt,R.f(:,1),'-b') +plot((1:S.Nt)*S.dt,R.f(:,2),'--b') +legend('x-component','y-component') + +figure(5) + clf(5) + figure(5) +subplot(2,1,1) +hold on +title('Unweighted basis functions (dmp)') +for i = 1:size(psiall,2) + plot((1:S.Nt)*S.dt, psiall(:,i),'-c', 'Color', psicolors(i,:)) +end +subplot(2,1,2) +hold on +title('Unweighted basis functions (rmp)') +for i = 1:size(aall,2) + plot((1:S.Nt)*S.dt, aall(:,i),'-c','Color',acolors(i,:)) +end - +figure(6) + clf(6) + figure(6) +subplot(2,1,1) +hold on +title('DMP Basis Functions') +plot((1:S.Nt)*S.dt, psiall(:,5),'-k','Linewidth', 1.5) +set(gca,'xtick',[]) +subplot(2,1,2) +hold on +title('RMP Basis Functions') +plot((1:S.Nt)*S.dt,aall(:,5),'-k','Linewidth',1.5) +% legend('DMP','RMP') +set(gca,'xtick',[]) +% dmparea5 = trapz(psiall(:,5)) +% rmparea5 = trapz(aall(:,5)) + +figure(7) + clf(7) + figure(7) +hold on +title('Basis Functions') +plot((1:S.Nt)*S.dt, psiall(:,5),'-k','Linewidth', 1.5) +plot((1:S.Nt)*S.dt,aall(:,5),'--k','Linewidth',1.5) +legend('DMP','RMP') +set(gca,'xtick',[]) + +%Looking for area under curve +dmparea = trapz(psiall,1) +rmparea = trapz(aall,1) end From 71b00602673d85b34539516ea37a5b12524da72d Mon Sep 17 00:00:00 2001 From: Natasha Rouse Date: Fri, 24 Jul 2020 13:41:12 -0400 Subject: [PATCH 5/7] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fba87d4..fbf7e5a 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# DMPandRMP \ No newline at end of file +# DMPandRMP +Includes a LOT of files. Most relevant is DMPandRMP1.m +This file combines run8.m & Eval.m into one file and allows for plotting of multiple variables without saving Matlab Workspace (this was the issue that created RunbothRMP_and_DMP.m. From 34425616d2f55b86b03f4cb9cdc0664093be4666 Mon Sep 17 00:00:00 2001 From: Natasha Rouse Date: Wed, 29 Jul 2020 11:12:43 -0400 Subject: [PATCH 6/7] Gradient descent conditions corrected. --- DMPandRMP1.m | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/DMPandRMP1.m b/DMPandRMP1.m index 261708e..b2016bc 100644 --- a/DMPandRMP1.m +++ b/DMPandRMP1.m @@ -98,7 +98,6 @@ index = 1; expected_SHCas = R.a; a = R.a(1,:); -a*R.rho for t = desiredt(1): S.dt: desiredt(end) dW = sqrt(S.dt)*randn(1,R.bfs); @@ -178,7 +177,7 @@ pause(1) chosenew = Inf; chosedel = Inf; -while chosenew+chosedel>=3 +while chosenew+chosedel>=2 chosenew = 0; chosedel = 0; for i = 1:size(D.w,1) @@ -213,7 +212,7 @@ pause(1) chosenew = Inf; chosedel = Inf; -while chosenew+chosedel>=3 +while chosenew+chosedel>=2 chosenew = 0; chosedel = 0; for i = 1:size(R.w,1) @@ -512,8 +511,8 @@ function ShowPlot(D,R,S) set(gca,'xtick',[]) %Looking for area under curve -dmparea = trapz(psiall,1) -rmparea = trapz(aall,1) +% dmparea = trapz(psiall,1) +% rmparea = trapz(aall,1) end From b20641800d6feec26e2c29d29f13462055dbd503 Mon Sep 17 00:00:00 2001 From: Natasha Rouse Date: Fri, 22 Jan 2021 12:28:34 -0500 Subject: [PATCH 7/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fbf7e5a..c19a76f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # DMPandRMP Includes a LOT of files. Most relevant is DMPandRMP1.m -This file combines run8.m & Eval.m into one file and allows for plotting of multiple variables without saving Matlab Workspace (this was the issue that created RunbothRMP_and_DMP.m. +This file combines run8.m & Eval.m into one file and allows for plotting of multiple variables without saving Matlab Workspace (this was the issue that created RunbothRMP_and_DMP.m).