+
+
+
+
+Experimenting with 23andme
+
+
+
\ No newline at end of file
diff --git a/23andme.js b/23andme.js
new file mode 100644
index 0000000..5cdd0d5
--- /dev/null
+++ b/23andme.js
@@ -0,0 +1,33 @@
+//https://api.23andme.com/authorize/?redirect_uri=http://jmat.googlecode.com/git/23andme.html&response_type=code&client_id=09568fd79aa7911dad7727a024936f8d&scope=basic
+// response directed to http://jmat.googlecode.com/git/23andme.html, alternative URL:
+//https://dl-web.dropbox.com/get/http/jmat/23andme.html?w=bba1484b&code={borrow from above}
+//
+UAB={ // 23and me application document object model
+ code:null,
+ parms:{},
+ search4parms:function(){ // gets parameters from call and pushes them to .parms
+ var parms = window.document.location.search.slice(1).split('&');
+ parms.map(function(x){
+ xx = x.split('=');
+ UAB.parms[xx[0]]=xx[1]
+ })
+
+ //
+ }
+}
+
+
+
+// find out what is being provided and push it to parms
+UAB.search4parms();
+if(!!UAB.parms.code){
+ UAB.code=UAB.parms.code;
+ console.log('code = '+UAB.code);
+}
+else if (!!localStorage.getItem('code')){ // find out if there is one in the localstorage
+ UAB.code = localStorage.getItem('code');
+ console.log('code = '+UAB.code);
+}
+else{
+ throw('23andme access code not found :-(')
+}
\ No newline at end of file
diff --git a/f.png b/f.png
new file mode 100644
index 0000000..d730d99
Binary files /dev/null and b/f.png differ
diff --git a/fminsearch.html b/fminsearch.html
new file mode 100644
index 0000000..71f35ef
--- /dev/null
+++ b/fminsearch.html
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
x=[32,37,42,47,52,57,62,67,72,77,82,87,92];y=[0,34,59,77,99,114,121,133,146,159,165,173,170]; // some data
+
fun = function(x,P){return x.map(function(xi){return (1/(1/(P[0]*(xi-P[1]))+1/P[2]))})}; // some model
+
P=fminsearch(fun,[34.6,32,173],x,y); // the regression with some starting values
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/fminsearch.js b/fminsearch.js
new file mode 100644
index 0000000..5ccff12
--- /dev/null
+++ b/fminsearch.js
@@ -0,0 +1,89 @@
+fminsearch=function(fun,Parm0,x,y,Opt){// fun = function(x,Parm)
+ // example
+ //
+ // x = [32,37,42,47,52,57,62,67,72,77,82,87,92];y=[749,1525,1947,2201,2380,2537,2671,2758,2803,2943,3007,2979,2992]
+ // fun = function(x,P){return x.map(function(xi){return (P[0]+1/(1/(P[1]*(xi-P[2]))+1/P[3]))})}
+ // Parms=jmat.fminsearch(fun,[100,30,10,5000],x,y)
+ //
+ // Another test:
+ // x=[32,37,42,47,52,57,62,67,72,77,82,87,92];y=[0,34,59,77,99,114,121,133,146,159,165,173,170];
+ //
+ // Opt is an object will all other parameters, from the objective function (cost function), to the
+ // number of iterations, initial step vector and the display switch, for example
+ // Parms=fminsearch(fun,[100,30,10,5000],x,y,{maxIter:10000,display:false})
+
+ if(!Opt){Opt={}};
+ if(!Opt.maxIter){Opt.maxIter=1000};
+ if(!Opt.step){// initial step is 1/100 of initial value (remember not to use zero in Parm0)
+ Opt.step=Parm0.map(function(p){return p/100});
+ Opt.step=Opt.step.map(function(si){if(si==0){return 1}else{ return si}}); // convert null steps into 1's
+ };
+ if(typeof(Opt.display)=='undefined'){Opt.display=true};
+ if(!Opt.objFun){Opt.objFun=function(y,yp){return y.map(function(yi,i){return Math.pow((yi-yp[i]),2)}).reduce(function(a,b){return a+b})}} //SSD
+
+ var cloneVector=function(V){return V.map(function(v){return v})};
+ var ya,y0,yb,fP0,fP1;
+ var P0=cloneVector(Parm0),P1=cloneVector(Parm0);
+ var n = P0.length;
+ var step=Opt.step;
+ var funParm=function(P){return Opt.objFun(y,fun(x,P))}//function (of Parameters) to minimize
+ // silly multi-univariate screening
+ for(var i=0;i(Opt.maxIter-10)){console.log(i+1,funParm(P0),P0)}}
+ }
+ if (!!document.getElementById('plot')){ // if there is then use it
+ fminsearch.plot(x,y,fun(x,P0),P0);
+ }
+ return P0
+};
+
+fminsearch.load=function(src){ // script loading
+ // example: fminsearch.load('http://localhost:8888/jmat/jmat.js')
+ var s = document.createElement('script');
+ s.src = src;
+ document.head.appendChild(s);
+ s.parentElement.removeChild(s);
+};
+
+fminsearch.plot=function(x,y,yp,Parms,id){ // ploting results using
+ // defaults
+ var titulo='Model fitting';
+ if(!!Parms){titulo='Model parameters: '+Parms};
+ if(!id){var id='plot'}
+ // create Array in Google's format
+ var data = new google.visualization.DataTable();
+ data.addColumn('number', 'X');
+ data.addColumn('number', 'Observed');
+ data.addColumn('number', 'Model fit');
+ var n = x.length;
+ for (var i=0;i
+
+