Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

32
LINES

< > BotCompany Repo | #1026920 // Perceptron Spike, compacted [learn 3 weights, OK]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (5524L/28K).

1  
!7
2  
3  
cmodule PerceptronSpike > DynPrintLogAndEnabled {
4  
  switchable int nExamples = 2000;
5  
  L<Perceptron.Example> examples;
6  
  transient Perceptron perceptron;
7  
  switchable double c = 1;
8  
  switchable bool randomizeC = false;
9  
  switchable bool startWithRandomWeights = true;
10  
  
11  
  // function to be learned
12  
  double f(double x) {
13  
    ret x * 0.7 + 40;
14  
  }
15  
16  
  start-thread {
17  
    if (l(examples) != nExamples)
18  
      setField(examples := repF(nExamples, () -> {
19  
        int x = rand(640), y = rand(360);
20  
        ret new Perceptron.Example(new double[] {x, y}, y > f(x));
21  
      }));
22  
    
23  
    perceptron = new Perceptron;
24  
    copyAllFields(module(), perceptron);
25  
    for ping (Double error : perceptron.trainingIterator()) {
26  
      if (deleted) ret;
27  
      if (!enabled) continue with sleepSeconds(1);
28  
      if (error != null)
29  
        perceptron.printWithWeights();
30  
    }
31  
  }
32  
}

Author comment

Began life as a copy of #1026916

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1026920
Snippet name: Perceptron Spike, compacted [learn 3 weights, OK]
Eternal ID of this version: #1026920/8
Text MD5: 0b9c20e705a125f225deead1d32f6f8d
Transpilation MD5: 75a9e73475b3f9ca08a967fa81f83e0c
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-02 19:35:08
Source code size: 897 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 179 / 526
Version history: 7 change(s)
Referenced in: [show references]