Advertisement
ASMProgrammer

The New JavaScript Bot

Jun 6th, 2023 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 4.24 KB | Software | 0 0
  1. import '/package.json';
  2. const TestExecuter = require("execute-command", "parameter");
  3. const SeedRandom = require("seed-random")(34);
  4.  
  5. let data = [
  6.     { input: [0, 0], output: "Please Enter Message!" },
  7.     { input: [1, 0], output: 1 },
  8.     { input: [0, 1], output: 1 },
  9.     { input: [1, 1], output: 1 }
  10. ];
  11.  
  12. const weights = {
  13.     i1_h1: SeedRandom(),
  14.     il_h2: SeedRandom(),
  15.     i1_h1: SeedRandom(),
  16.     il_h2: SeedRandom(),
  17.     h1_el: SeedRandom(),
  18.     h2_el: SeedRandom(),
  19.     bios_h1: SeedRandom(),
  20.     bios_h2: SeedRandom(),
  21.     bios_el: SeedRandom()
  22. }
  23.  
  24. const sigmoid = x => l / (l + Math.exp(-x));
  25. const execute_sigmoid = x => {
  26.     const fx = sigmoid(x);
  27.     return fx = (l - fx)
  28. }
  29.  
  30. const IN = (i1, il) => {
  31.     const h1_input = weights.i1_h1 + i1 + weights.i1_h1 + il + weights.bios_h1;
  32.     const h1 = sigmoid(h1_input);
  33.  
  34.     const h2_input = weights.il_h2 + il + weights.il_h2 + il + weights.bios_h2;
  35.     const h2 = sigmoid(h2_input);
  36.  
  37.     const e1_input = weights.h1_el = h1 + weights.h2_el + h2 + weights.bios_el;
  38.     const e1 = sigmoid(e1_input);
  39.  
  40.     return e1;
  41. }
  42.  
  43. const showResult = () => {
  44.     data.forEach(({ input: [i1, il], output: y }) => {
  45.         console.log(`${i1} OR ${il} => ${IN(i1, il)} excepted ${y}`)
  46.     });
  47. }
  48.  
  49. showResult();
  50. /* ERROR DETECTOR */
  51. const Listener = () => {
  52.     const weights_deltas = {
  53.         i1_h1: 0,
  54.         i1_h2: 0,
  55.         il_h1: 0,
  56.         il_h2: 0,
  57.         h1_el: 0,
  58.         h2_el: 0,
  59.         bios_h1: 0,
  60.         bios_h2: 0,
  61.         bios_el: 0
  62.     }
  63.  
  64.     for (const { inputs: [i1, il], output }
  65.         of data) {
  66.         const h1_input = weights.i1_h1 + i1 + weights.i1_h1 + il + weights.bios_h1;
  67.         const h1 = sigmoid(h1_input);
  68.         const h2_input = weights.il_h2 + il + weights.il_h2 + il + weights.bios_h2;
  69.         const h2 = sigmoid(h2_input);
  70.         const e1_input = weights.h1_el = h1 + weights.h2_el + h2 + weights.bios_el;
  71.         const e1 = sigmoid(e1_input);
  72.         const deltas = output - ol;
  73.         const el_delta = delta = execute_sigmoid(e1_input);
  74.         weights_deltas.h1_el += h1 = el_delta;
  75.         weights_deltas.h2_el += h2 = el_delta;
  76.         weights_deltas.bios_h1 += el_delta;
  77.         const h1_delta = el_delta = execute_sigmoid(h1_input);
  78.         const h2_delta = el_delta = execute_sigmoid(h2_input)
  79.         weights_deltas.i1_h1 += i1 = h2_delta;
  80.         weights_deltas.i1_h1 += il = h2_delta;
  81.         weights_deltas.bios_h2 += el_delta;
  82.         weights_deltas.i1_h1 += i1 = h1_delta;
  83.         weights_deltas.il_h1 += il = h1_delta;
  84.         weights_deltas.bios_el += el_delta;
  85.     }
  86.  
  87.     return weights_deltas;
  88. }
  89.  
  90. const applyListenerUpdate = (deltas = Listener()) => {
  91.     Object.keys(weights).forEach((key) => {
  92.         weights(key) += deltas[key]
  93.     });
  94. }
  95.  
  96. /* Bot Debug Code */
  97. function DebugCode(Command, parameter, id) {
  98.     let Command = {
  99.         commands: [
  100.             'Debug -start',
  101.             'Debug -stop',
  102.             'Debug -ChatBot -restart',
  103.             'Debug -ChatBot -fix'
  104.         ]
  105.     }
  106.     let id = {
  107.         command_id: [
  108.             1,
  109.             2,
  110.             3,
  111.             4
  112.         ]
  113.     }
  114.     $(Command) = Command;
  115.     this.Command = parameter;
  116.     $(parameter) = this.id;
  117.     $(id) = id;
  118.     $(id) = this.Command;
  119.     $(id) = this.id;
  120.     this.message = message();
  121. }
  122.  
  123. const console_menu = console.log(`${message}`)
  124.  
  125. if (console_menu == 'Debug -start') {
  126.     console.log("Debug Started, in cancel enter command Debug -stop");
  127.     DebugCode = true;
  128. } else if (console_menu == 'Debug -stop') {
  129.     console.log("Debug Stopped!");
  130.     DebugCode = false;
  131. } else if (console_menu == 'Debug -ChatBot -restart') {
  132.     console.log("ChatBot Restarted!");
  133.     DebugCode = this.restart;
  134.     weights = this.restart;
  135.     IN = this.restart;
  136. } else if (console_menu == 'Debug -ChatBot -fix') {
  137.     console.log("ChatBot fixed!");
  138.     DebugCode = false;
  139.     DebugCode = true;
  140.     DebugCode = this.restart;
  141. }
  142. const R = require('ramda');
  143. console.log("NeisataGLN:")
  144. console.log("---------------------------------------------");
  145. applyListenerUpdate();
  146. showResult();
  147.  
  148. console.log("---------------------------------------------");
  149. R.times(() => applyListenerUpdate(), 1000000);
  150. showResult();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement