Advertisement
Guest User

Induction Machine

a guest
May 10th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function InductionMachine()
  2. {
  3.     this.memory=[]
  4.     this.output_list=[]
  5.     this.train=function(i,o)
  6.     {
  7.         var oo=false;
  8.         this.memory.push({input:i,output:o})
  9.         for(i7=0;i7<this.output_list.length;i7++)
  10.         {
  11.             if(this.output_list[i7]==o)
  12.             {
  13.                 oo=true
  14.             }
  15.         }
  16.         if(oo==false)
  17.         {
  18.             this.output_list.push(o);
  19.         }
  20.     }
  21.     this.run= function(i,o)
  22.     {
  23.         var p=0;
  24.         var n=0;
  25.         var prob=0;
  26.         var probs=[];
  27.         var probs1=0;
  28.         for(iii=0;iii<this.memory.length;iii++)
  29.         {  
  30.             if(this.memory[iii].output==o)
  31.             {
  32.                 for(i4=0;i4<i.length;i4++)
  33.                 {
  34.                     if(this.memory[iii].input[i4]==i[i4])
  35.                     {
  36.                         p++
  37.                     }
  38.                     else
  39.                     {
  40.                         n++
  41.                     }
  42.                 }
  43.                 prob+=p/(p+n)
  44.                 n=0;
  45.                 p=0;
  46.             }
  47.             probs.push(prob);
  48.             probs1+=prob;
  49.             prob=0;
  50.         }
  51.         if(probs1<1)
  52.         {
  53.             return probs1;
  54.         }
  55.         else
  56.         {
  57.             var max=0;
  58.             for(y=0;y<probs.length;y++)
  59.             {
  60.                 if(probs[y]>max)
  61.                 {
  62.                     max=probs[y];
  63.                 }
  64.             }
  65.             return max;
  66.         }
  67.     }
  68.     this.saveLS=function()
  69.     {
  70.         var json= JSON.stringify(this.memory);
  71.         var out=JSON.stringify(this.output_list);
  72.         localStorage["json"]=json;
  73.         localStorage["outList"]=out;
  74.         console.log("Saved");
  75.         return json;
  76.     }
  77.     this.loadLS=function()
  78.     {
  79.         this.memory=JSON.parse(localStorage["json"]);
  80.         this.output_list=JSON.parse(localStorage["outList"]);
  81.         console.log("Loaded");
  82.     }
  83.     this.saveFile=function()
  84.     {
  85.         var json=JSON.stringify({memory:this.memory,out_list:this.output_list});
  86.         var f= new File(json,"data.json");
  87.         saveAs(f);
  88.     }
  89.     this.loadFile=function(vr,elmnt)
  90.     {
  91.         var reader= new FileReader()
  92.         reader.readAsText(elmnt.files[0])
  93.         reader.onload=function(){var json=JSON.parse(reader.result);vr.memory=json.memory;vr.output_list=json.out_list;}
  94.     }
  95.     this.run2=function(i)
  96.     {
  97.        
  98.         var res=[];
  99.         var max2=0;
  100.         var maxx;
  101.         for(i5=0;i5<this.output_list.length;i5++)
  102.         {
  103.             res.push({per:this.run(i,this.output_list[i5]),o:this.output_list[i5]});
  104.         }
  105.         for(i6=0;i6<res.length;i6++)
  106.         {
  107.             if(res[i6].per>max2)
  108.             {
  109.                 max2=res[i6].per;
  110.                 maxx=res[i6].o;
  111.             }
  112.         }
  113.         return maxx;
  114.     }
  115. }
  116.  
  117.  
  118. /* FileSaver.js
  119.  * A saveAs() FileSaver implementation.
  120.  * 1.3.2
  121.  * 2016-06-16 18:25:19
  122.  *
  123.  * By Eli Grey, http://eligrey.com
  124.  * License: MIT
  125.  *   See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
  126.  */
  127.  
  128. /*global self */
  129. /*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
  130.  
  131. /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
  132.  
  133. var saveAs = saveAs || (function(view) {
  134.     "use strict";
  135.     // IE <10 is explicitly unsupported
  136.     if (typeof view === "undefined" || typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
  137.         return;
  138.     }
  139.     var
  140.           doc = view.document
  141.           // only get URL when necessary in case Blob.js hasn't overridden it yet
  142.         , get_URL = function() {
  143.             return view.URL || view.webkitURL || view;
  144.         }
  145.         , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
  146.         , can_use_save_link = "download" in save_link
  147.         , click = function(node) {
  148.             var event = new MouseEvent("click");
  149.             node.dispatchEvent(event);
  150.         }
  151.         , is_safari = /constructor/i.test(view.HTMLElement) || view.safari
  152.         , is_chrome_ios =/CriOS\/[\d]+/.test(navigator.userAgent)
  153.         , throw_outside = function(ex) {
  154.             (view.setImmediate || view.setTimeout)(function() {
  155.                 throw ex;
  156.             }, 0);
  157.         }
  158.         , force_saveable_type = "application/octet-stream"
  159.         // the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to
  160.         , arbitrary_revoke_timeout = 1000 * 40 // in ms
  161.         , revoke = function(file) {
  162.             var revoker = function() {
  163.                 if (typeof file === "string") { // file is an object URL
  164.                     get_URL().revokeObjectURL(file);
  165.                 } else { // file is a File
  166.                     file.remove();
  167.                 }
  168.             };
  169.             setTimeout(revoker, arbitrary_revoke_timeout);
  170.         }
  171.         , dispatch = function(filesaver, event_types, event) {
  172.             event_types = [].concat(event_types);
  173.             var i = event_types.length;
  174.             while (i--) {
  175.                 var listener = filesaver["on" + event_types[i]];
  176.                 if (typeof listener === "function") {
  177.                     try {
  178.                         listener.call(filesaver, event || filesaver);
  179.                     } catch (ex) {
  180.                         throw_outside(ex);
  181.                     }
  182.                 }
  183.             }
  184.         }
  185.         , auto_bom = function(blob) {
  186.             // prepend BOM for UTF-8 XML and text/* types (including HTML)
  187.             // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
  188.             if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
  189.                 return new Blob([String.fromCharCode(0xFEFF), blob], {type: blob.type});
  190.             }
  191.             return blob;
  192.         }
  193.         , FileSaver = function(blob, name, no_auto_bom) {
  194.             if (!no_auto_bom) {
  195.                 blob = auto_bom(blob);
  196.             }
  197.             // First try a.download, then web filesystem, then object URLs
  198.             var
  199.                   filesaver = this
  200.                 , type = blob.type
  201.                 , force = type === force_saveable_type
  202.                 , object_url
  203.                 , dispatch_all = function() {
  204.                     dispatch(filesaver, "writestart progress write writeend".split(" "));
  205.                 }
  206.                 // on any filesys errors revert to saving with object URLs
  207.                 , fs_error = function() {
  208.                     if ((is_chrome_ios || (force && is_safari)) && view.FileReader) {
  209.                         // Safari doesn't allow downloading of blob urls
  210.                         var reader = new FileReader();
  211.                         reader.onloadend = function() {
  212.                             var url = is_chrome_ios ? reader.result : reader.result.replace(/^data:[^;]*;/, 'data:attachment/file;');
  213.                             var popup = view.open(url, '_blank');
  214.                             if(!popup) view.location.href = url;
  215.                             url=undefined; // release reference before dispatching
  216.                             filesaver.readyState = filesaver.DONE;
  217.                             dispatch_all();
  218.                         };
  219.                         reader.readAsDataURL(blob);
  220.                         filesaver.readyState = filesaver.INIT;
  221.                         return;
  222.                     }
  223.                     // don't create more object URLs than needed
  224.                     if (!object_url) {
  225.                         object_url = get_URL().createObjectURL(blob);
  226.                     }
  227.                     if (force) {
  228.                         view.location.href = object_url;
  229.                     } else {
  230.                         var opened = view.open(object_url, "_blank");
  231.                         if (!opened) {
  232.                             // Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html
  233.                             view.location.href = object_url;
  234.                         }
  235.                     }
  236.                     filesaver.readyState = filesaver.DONE;
  237.                     dispatch_all();
  238.                     revoke(object_url);
  239.                 }
  240.             ;
  241.             filesaver.readyState = filesaver.INIT;
  242.  
  243.             if (can_use_save_link) {
  244.                 object_url = get_URL().createObjectURL(blob);
  245.                 setTimeout(function() {
  246.                     save_link.href = object_url;
  247.                     save_link.download = name;
  248.                     click(save_link);
  249.                     dispatch_all();
  250.                     revoke(object_url);
  251.                     filesaver.readyState = filesaver.DONE;
  252.                 });
  253.                 return;
  254.             }
  255.  
  256.             fs_error();
  257.         }
  258.         , FS_proto = FileSaver.prototype
  259.         , saveAs = function(blob, name, no_auto_bom) {
  260.             return new FileSaver(blob, name || blob.name || "download", no_auto_bom);
  261.         }
  262.     ;
  263.     // IE 10+ (native saveAs)
  264.     if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
  265.         return function(blob, name, no_auto_bom) {
  266.             name = name || blob.name || "download";
  267.  
  268.             if (!no_auto_bom) {
  269.                 blob = auto_bom(blob);
  270.             }
  271.             return navigator.msSaveOrOpenBlob(blob, name);
  272.         };
  273.     }
  274.  
  275.     FS_proto.abort = function(){};
  276.     FS_proto.readyState = FS_proto.INIT = 0;
  277.     FS_proto.WRITING = 1;
  278.     FS_proto.DONE = 2;
  279.  
  280.     FS_proto.error =
  281.     FS_proto.onwritestart =
  282.     FS_proto.onprogress =
  283.     FS_proto.onwrite =
  284.     FS_proto.onabort =
  285.     FS_proto.onerror =
  286.     FS_proto.onwriteend =
  287.         null;
  288.  
  289.     return saveAs;
  290. }(
  291.        typeof self !== "undefined" && self
  292.     || typeof window !== "undefined" && window
  293.     || this.content
  294. ));
  295. // `self` is undefined in Firefox for Android content script context
  296. // while `this` is nsIContentFrameMessageManager
  297. // with an attribute `content` that corresponds to the window
  298.  
  299. if (typeof module !== "undefined" && module.exports) {
  300.   module.exports.saveAs = saveAs;
  301. } else if ((typeof define !== "undefined" && define !== null) && (define.amd !== null)) {
  302.   define("FileSaver.js", function() {
  303.     return saveAs;
  304.   });
  305. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement