1 | get("#265") -- json.encode |
2 | |
3 | images = {"#1000061", "A", "#1000056", "H", "#1000064", "P", "#1000063", "X", "#1000062", "B"} |
4 | features = {"#326", "#327", "#328"} |
5 | |
6 | -- make a letter lookup map |
7 | image2letter = {} |
8 | for i=1, #images, 2 do image2letter[images[i]] = images[i+1] end |
9 | |
10 | -- find out which results to load |
11 | toget = {} |
12 | for i=1, #images, 2 do table.insert(toget, images[i]) end |
13 | for i=1, #features do table.insert(toget, features[i]) end |
14 | results = getirresults(unpack(toget)) |
15 | |
16 | --map: feature -> letter -> value range |
17 | |
18 | map = {} |
19 | for image, subresults in pairs(results) do |
20 | letter = image2letter[image] |
21 | for feature, result in pairs(subresults) do |
22 | _, _, value = string.find(result, ": ([0-9.]+)") |
23 | if value ~= nil then |
24 | value = tonumber(value) |
25 | if map[feature] == nil then map[feature] = {} end |
26 | submap = map[feature] |
27 | range = submap[letter] |
28 | if range == nil then |
29 | range = {value, value} |
30 | else |
31 | range = {math.min(range[1], value), math.max(range[2], value)} |
32 | end |
33 | submap[letter] = range |
34 | end |
35 | end |
36 | end |
37 | |
38 | -- get serpent to serialize map into Lua code |
39 | serpent = go("#158") |
40 | |
41 | --if all features are within the known value ranges for the letter, just take the intersection of all the matching letters within each feature. |
42 | |
43 | -- serpent options: |
44 | -- block(map, {comment=false}) is that indented stuff |
45 | -- line(map, {comment=false}) is all in one line |
46 | -- dump(map) is...? |
47 | -- line(map, {comment=false, compact=true, sparse=true}) is in one line, very compact |
48 | -- line(map, {comment=false, compact=true, sparse=false}) is the same |
49 | |
50 | recognizer = " map = "..serpent.line(map, {comment=false, compact=true, sparse=false}).."\n"..[[ |
51 | allletters = {} |
52 | outmap = {} |
53 | |
54 | for feature, submap in pairs(map) do |
55 | f = otherresults[feature] |
56 | if f == nil then error("Need recalc, waiting for "..feature) end |
57 | _, _, value = string.find(f, ": ([0-9.]+)") |
58 | if value ~= nil then |
59 | value = tonumber(value) |
60 | for letter, range in pairs(submap) do |
61 | allletters[letter] = true |
62 | if value < range[1] or value > range[2] then |
63 | outmap[letter] = true -- can't be this letter |
64 | end |
65 | end |
66 | end |
67 | end |
68 | |
69 | candidates = {} |
70 | for letter, _ in pairs(allletters) do |
71 | if not outmap[letter] then |
72 | table.insert(candidates, letter) |
73 | end |
74 | end |
75 | |
76 | if #candidates ~= 0 then |
77 | return "Candidates: "..table.concat(candidates, ", ") |
78 | end |
79 | ]] |
80 | |
81 | print(recognizer) |
82 | |
83 | snippet = { |
84 | type = 26, -- Lua code - Image recognition |
85 | text = recognizer, |
86 | title = "A machine-made letter recognizer, v3" |
87 | } |
88 | |
89 | return json.encode(snippet) |
90 | |
91 | --todo: otherwise, expand all value ranges uniformly and try again. |
92 | |
93 | --more todo: repeat & increase ranges exponentially, finally at least one letter will match. |
I'm redefining the term PERCEPTRON... ^^ It means a production facility for a general "decider" based on a list of examples and feature extractors.
test run test run with input produce a snippet download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Recognizer | Recognition Result | Visualize | Recalc |
---|---|---|---|
#308 | javax.imageio.IIOException: Can't get input stream from URL! | [visualize] |
Snippet ID: | #329 |
Snippet name: | Simple perceptron [not really a perceptron] |
Eternal ID of this version: | #329/2 |
Text MD5: | bd993491c90d73e238bdb59189c62608 |
Author: | stefan |
Category: | meta letter recognizers |
Type: | Lua code - Snippet producer |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-09-05 17:12:14 |
Source code size: | 2846 bytes / 93 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 1086 / 187 |
Version history: | 1 change(s) |
Referenced in: | [show references] |