simndt2b/demo/plate1n/rbook.signal.ml.json

1 line
11 KiB
JSON

[{"Config":{"clearAuto":true,"strictScope":false,"group":"anonymous","mode":"r","file":"rbook.signal.ml","fontSize":14,"thisthat":true,"turbo":true,"user":"kapideje","docUrl":"localhost:5558","projUrl":"edu-9.de:5550","webclipTime":300,"webclipUrl":"localhost:9176","webxUrl":"localhost:9177","modules":["math.plugin","image.plugin"],"workdir":"/home/sbosse/proj/SimNDT2b/demo/plate1n","nw":"0.41.3","version":"1.15.10","wex":{"http":"http://localhost:11111","ws":"ws://localhost:11112"},"strict":true,"evalUser":"RRun","overlay":true}},{"Notes":[]},{},{"options":{"eval":"_PxEnUf_ZnVuY3Rpb24gKHRleHQpIHsKICAgICAgICAgIHZhciBjb250ZXh0ID0gUi5jb250ZXh0OwogICAgICAgICAgUi5ydW4odGV4dCxjb250ZXh0KQogICAgICAgICAgaWYgKFIud29ya2VyLmN1cnJlbnQpIHNldFRpbWVvdXQoZnVuY3Rpb24gKCkgewogICAgICAgICAgICAvLyB1cGRhdGUgd29ya2VyIGNvbnRleHQKICAgICAgICAgICAgdmFyIGluaXRzID0ge30sbW9kcz1bXTsKICAgICAgICAgICAgZm9yICh2YXIgaSBpbiBSLmxpYi5tb2R1bGVzKSB7CiAgICAgICAgICAgICAgdmFyIG1vZCA9IFIubGliLm1vZHVsZXNbaV0sCiAgICAgICAgICAgICAgICAgIE1PRCA9IG1vZC50b1VwcGVyQ2FzZSgpLAogICAgICAgICAgICAgICAgICBmb28gPSBNT0QrJyRJbml0JzsKICAgICAgICAgICAgICAvLyBDb2RlLnByaW50KCJVcGRhdGluZyB3b3JrZXIgUiAuLiAiLG1vZCk7CiAgICAgICAgICAgICAgaWYgKF9nbG9iYWxbZm9vXSkgIHsgbW9kcy5wdXNoKG1vZCk7IGluaXRzW2Zvb109X2dsb2JhbFtmb29dIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBSLndvcmtlci5jdXJyZW50Lm1vZHVsZShpbml0cykKICAgICAgICAgIH0sMTAwKQogICAgICAgIH0=","label":"Install Libraries","mode":"r","overlay":2,"heightC":100,"heightE":10,"collapsed":false},"code":"install.packages({\"math\",\"ml\",\"image\"})"},{"options":{"eval":"_PxEnUf_ZnVuY3Rpb24gKHRleHQpIHsKICAgICAgICAgIHZhciBjb250ZXh0ID0gUi5jb250ZXh0OwogICAgICAgICAgUi5ydW4odGV4dCxjb250ZXh0KQogICAgICAgIH0=","label":"Start Worker","mode":"r","overlay":2,"heightC":100,"heightE":10,"collapsed":false},"code":"worker()"},{"options":{"label":"Load Data","mode":"r","overlay":1,"evalUser":"RRun","heightC":30,"heightE":30,"collapsed":false},"code":"parameter { dir:'./data', cut:40 }\nuse math,csv,file\nfiles = list.files(parameter.dir)\ndata = data.frame(x=NA,y=NA,field=NA,data=NA)\nfor(file in files) {\n print(file)\n x = as.numeric(grep('x([0-9]+)',file,match=TRUE,value=TRUE))\n y = as.numeric(grep('y([0-9]+)',file,match=TRUE,value=TRUE))\n s = load.csv(parameter.dir+'/'+file,sep=',',auto.detect=FALSE)\n s = s[[1]] # s[,1]\n s = s[parameter.cut:length(s)]\n field = grep('signal-([A-Za-z]+).',file,value=TRUE,match=TRUE)\n data=rbind(data,{x=x,y=y,field=field,data=s})\n}\ndata.0=data\ndata=shuffle(data)\nlogg(typeof(data))\nlogg(fivenum(data[1,\"data\"]))\nlogg(summary(data))"},{"options":{"eval":"_PxEnUf_ZnVuY3Rpb24gKHRleHQsZW52KSB7CiAgICAgICAgICAgICAgICAganNTY29wZS5ydW4odGV4dCxlbnYpCiAgICAgICAgICAgICAgICB9","mode":"r","evalUser":"RRun","overlay":1,"label":"Load Compact Data","heightC":30,"heightE":30,"collapsed":false},"code":"parameter { dir:'data2', cut:40, length:99 }\nuse math,csv,file\nfile = parameter.dir+\"/data_uniform.csv\"\ndata1 = read.csv(file)\ndata = data.frame(x=NA,y=NA,data=NA)\nfor (i in 1:nrow(data1)) {\n s = as.vector(data1[[i,parameter.cut:parameter.length]])\n x = data1[i,100]*500\n y = data1[i,101]*500\n data = rbind(data,{x=x,y=y,data=s})\n}\ndata=shuffle(data)\nlogg(typeof(data))\nlogg(fivenum(data[1,\"data\"]))\nlogg(summary(data))"},{"options":{"eval":"_PxEnUf_ZnVuY3Rpb24gKHRleHQsZW52KSB7CiAgICAgICAgICAgICAgICAganNTY29wZS5ydW4odGV4dCxlbnYpCiAgICAgICAgICAgICAgICB9","mode":"r","evalUser":"RRun","overlay":1,"label":"Plot Signal(s)","heightC":30,"heightE":30,"collapsed":false},"code":"parameter { index1:1, index2:2 }\nuse plot\nsample.1 = data.0[parameter.index1,]\nsample.2 = data.0[parameter.index2,]\ndev.new(height=400)\nplot({sample.1$data, sample.2$data},type='l',\n main=sample.1$field+' x'+sample.1$x+'-y'+sample.1$y+' / '+\n sample.2$field+' x'+sample.2$x+'-y'+sample.2$y)"},{"options":{"eval":"_PxEnUf_ZnVuY3Rpb24gKHRleHQsZW52KSB7CiAgICAgICAgICAgICAgICAganNTY29wZS5ydW4odGV4dCxlbnYpCiAgICAgICAgICAgICAgICB9","mode":"r","evalUser":"RRun","overlay":1,"label":"Data Preparation","heightC":30,"heightE":30,"collapsed":false},"code":"use math\ndata.x = lapply(as.list(data$data), function (v) {\n v/0.002\n})\ndata.y = as.list(lapply(data,function (row) {\n [row$x,row$y]/500\n}))\nlogg(typeof(data.x))\nlogg(minMax(data.x))\nlogg(typeof(data.y))\nlogg(minMax(data.y))\ndata.sample = split(seq(1,length(data.x)),prob=[0.8,0.2],random=TRUE)\ndata.train.x=data.x[data.sample[[1]]]\ndata.train.y=data.y[data.sample[[1]]]\ndata.test.x=data.x[data.sample[[2]]]\ndata.test.y=data.y[data.sample[[2]]]\nlogg(typeof(data.train.x))\nlogg(typeof(data.train.y))\nlogg(typeof(data.test.x))\nlogg(typeof(data.test.y))"},{"options":{"eval":"_PxEnUf_ZnVuY3Rpb24gKHRleHQsZW52KSB7CiAgICAgICAgICAgICAgICAganNTY29wZS5ydW4odGV4dCxlbnYpCiAgICAgICAgICAgICAgICB9","mode":"r","evalUser":"RRun","overlay":1,"label":"CNN ML","heightC":30,"heightE":30,"collapsed":false},"code":"use cnn\nm = cnn(\n input.size=[length(data.x[[1]]),1,1],\n layers={\n {type=\"conv\",kernel.size=[5,1],filter=16,activation=\"relu\"},\n {type=\"pool\",kernel.size=[5,1]},\n {type=\"conv\",kernel.size=[3,1],filter=8,activation=\"relu\"},\n {type=\"pool\",kernel.size=[3,1]},\n {type=\"fc\",activation=\"relu\",num.neurons=50},\n #{type=\"fc\",activation=\"sigmoid\",num.neurons=20},\n #{type=\"fc\",activation=\"relu\",num.neurons=10},\n #{type=\"fc\",activation=\"sigmoid\",num.neurons=20},\n {type=\"regression\",num.neurons=2}\n },\n trainer = { method='sgd', batch_size=10, learning.rate=0.005 }\n)\nprint(summary(m))"},{"options":{"eval":"_PxEnUf_ZnVuY3Rpb24gKHRleHQsZW52KSB7CiAgICAgICAgICAgICAgICAganNTY29wZS5ydW4odGV4dCxlbnYpCiAgICAgICAgICAgICAgICB9","mode":"r","evalUser":"RRun","overlay":1,"label":"Ml FCANN","heightC":30,"heightE":30,"collapsed":false},"code":"use cnn\nm = cnn(\n input.size=[length(data.x[[1]]),1,1],\n layers={\n {type=\"fc\",activation=\"relu\",num.neurons=100},\n {type=\"fc\",activation=\"relu\",num.neurons=50},\n {type=\"fc\",activation=\"relu\",num.neurons=20},\n {type=\"regression\",num.neurons=2}\n },\n trainer = { method='sgd', batch_size=10, learning.rate=0.005 }\n)\nprint(summary(m))"},{"options":{"eval":"_PxEnUf_ZnVuY3Rpb24gKHRleHQsZW52KSB7CiAgICAgICAgICAgICAgICAganNTY29wZS5ydW4odGV4dCxlbnYpCiAgICAgICAgICAgICAgICB9","mode":"r","evalUser":"RRun","overlay":1,"label":"Train","heightC":30,"heightE":30,"collapsed":false},"code":"result=train(m,data.train.x,data.train.y,epochs=100, callback=function (result) {\n cprint(result)\n})"},{"options":{"eval":"_PxEnUf_ZnVuY3Rpb24gKHRleHQsZW52KSB7CiAgICAgICAgICAgICAgICAganNTY29wZS5ydW4odGV4dCxlbnYpCiAgICAgICAgICAgICAgICB9","mode":"r","evalUser":"RRun","overlay":1,"label":"Test","heightC":30,"heightE":30,"collapsed":false},"code":"use stats\nresult.1 = cbind(predict(m,data.train.x),x0=pluck(data.train.y,1),y0=pluck(data.train.y,2))\noptions(digits=1)\ncolnames(result.1)=['x','y','x0','y0']\n# print(result*500)\nprint(\"======== Training data ========\")\nlogg(rmse(result.1$x*500,result.1$x0*500))\nlogg(rmse(result.1$y*500,result.1$y0*500))\nlogg(minMax(result.1$x*500-result.1$x0*500))\nlogg(minMax(result.1$y*500-result.1$y0*500))\nresult.2 = cbind(predict(m,data.test.x),x0=pluck(data.test.y,1),y0=pluck(data.test.y,2))\noptions(digits=1)\ncolnames(result.2)=['x','y','x0','y0']\n# print(result*500)\nprint(\"======== Test data ========\")\nlogg(rmse(result.2$x*500,result.2$x0*500))\nlogg(rmse(result.2$y*500,result.2$y0*500))\nlogg(minMax(result.2$x*500-result.2$x0*500))\nlogg(minMax(result.2$y*500-result.2$y0*500))\nh.x=histogram(abs(result.2$x*500-result.2$x0*500),breaks=50,xlim=[0,200])\nh.y=histogram(abs(result.2$y*500-result.2$y0*500),breaks=50,xlim=[0,200])\nplot(h.x$breaks,h.x$density,type='l',xlab='x Test Error [mm]',ylab='density')\nplot(h.y$breaks,h.y$density,type='l',xlab='y Test Error [mm]',ylab='density')"},{"options":{"eval":"_PxEnUf_ZnVuY3Rpb24gKHRleHQsZW52KSB7CiAgICAgICAgICAgICAgICAganNTY29wZS5ydW4odGV4dCxlbnYpCiAgICAgICAgICAgICAgICB9","mode":"r","evalUser":"RRun","overlay":1,"label":"Error Map","heightC":30,"heightE":30,"collapsed":false},"code":"use math,plot,imager\nerror.map = array(dim=[500,500])\nfor (r in result.1) {\n e=sqrt((500*(r$y-r$y0))**2+(500*(r$x-r$x0))**2)\n if (e>100) e=100\n for (dx in seq(-2,2)) {\n for (dy in seq(-2,2)) {\n if (error.map[r$y0*500+dy,r$x0*500+dx]==0) \n error.map[r$y0*500+dy,r$x0*500+dx]=e\n else\n error.map[r$y0*500+dy,r$x0*500+dx]=(error.map[r$y0*500+dy,r$x0*500+dx]+e)/2 \n }\n }\n}\nfor (r in result.2) {\n e=sqrt((500*(r$y-r$y0))**2+(500*(r$x-r$x0))**2)\n if (e>100) e=100\n for (dx in seq(-2,2)) {\n for (dy in seq(-2,2)) {\n if (error.map[r$y0*500+dy,r$x0*500+dx]==0) \n error.map[r$y0*500+dy,r$x0*500+dx]=e\n else\n error.map[r$y0*500+dy,r$x0*500+dx]=(error.map[r$y0*500+dy,r$x0*500+dx]+e)/2 \n }\n }\n}\ndev.new(height=600)\nplot(error.map[100:400,100:400],auto.scale=TRUE,keep.aspect=TRUE)"},{"options":{"eval":"_PxEnUf_ZnVuY3Rpb24gKHRleHQsZW52KSB7CiAgICAgICAgICAgICAgICAganNTY29wZS5ydW4odGV4dCxlbnYpCiAgICAgICAgICAgICAgICB9","mode":"r","evalUser":"RRun","overlay":1,"label":"Model XY-Gradient","heightC":30,"heightE":30,"collapsed":false},"code":"parameter { index:10 }\nsample = data.x[[parameter.index]]\nplot(sample,type='l')\nlogg(data.y[[parameter.index]]*500)\nlogg(predict(m,data.x[[parameter.index]])*500)\ng.x = vector(length(sample))\ng.y = vector(length(sample))\ndelta = 0.001\nfor (i in 1:length(sample)) {\n x = copy(sample) \n xy.1 = predict(m,x)\n x[i] = x[i]+delta\n xy.2 = predict(m,x)\n g.x[i] = (xy.2[1]-xy.1[1])/delta\n g.y[i] = (xy.2[2]-xy.1[2])/delta\n}\nplot({g.x=g.x,g.y=g.y},type='l')"},{"options":{"eval":"_PxEnUf_ZnVuY3Rpb24gKHRleHQsZW52KSB7CiAgICAgICAgICAgICAgICAganNTY29wZS5ydW4odGV4dCxlbnYpCiAgICAgICAgICAgICAgICB9","mode":"r","evalUser":"RRun","overlay":1,"label":"Noise Test","heightC":30,"heightE":30,"collapsed":false},"code":"yl=list()\nfor(i in 1:1000) {\n x=runif(60,min=-1,max=1)\n if (i==1) plot(x,type='l')\n y=predict(m,x)\n push(yl,y)\n}\nh.x=histogram(pluck(yl,1),breaks=50,xlim=[-0.5,3])\nplot(h.x$breaks,h.x$density,type='l',xlab='x [norm. units]',ylab='density')\nh.y=histogram(pluck(yl,2),breaks=50,xlim=[-0.5,3])\nplot(h.y$breaks,h.y$density,type='l',xlab='y [norm. units]',ylab='density')"},{"options":{"eval":"_PxEnUf_ZnVuY3Rpb24gKHRleHQsZW52KSB7CiAgICAgICAgICAgICAgICAganNTY29wZS5ydW4odGV4dCxlbnYpCiAgICAgICAgICAgICAgICB9","mode":"r","evalUser":"RRun","overlay":1,"label":"Random Sine Test","heightC":30,"heightE":30,"collapsed":false},"code":"yl=list()\nfor(i in 1:1000) {\n x=vector(60,0)\n for(j in 1:1000) {\n sin.off = runif(1,min=-10,max=10)\n x=x+runif(1,min=0.1,max=1)*sin((sin.off+seq(1,60))/runif(1,min=0.2,max=4))\n }\n x=x/max(x)\n if (i==1) plot(x,type='l')\n y=predict(m,x)\n push(yl,y)\n}\nlogg(minMax(pluck(yl,1)))\nlogg(minMax(pluck(yl,2)))\nh.x=histogram(pluck(yl,1),breaks=50,xlim=[-1,5])\nplot(h.x$breaks,h.x$density,type='l',xlab='x [norm. units]',ylab='density')\nh.y=histogram(pluck(yl,2),breaks=50,xlim=[-1,5])\nplot(h.y$breaks,h.y$density,type='l',xlab='y [norm. units]',ylab='density')"},{"options":{"label":" R+ Command Interpreter","evalUser":"RRun","height":20},"shell":true}]