From 47d8a5ceb549a13a0f437f29477daa43d11098f8 Mon Sep 17 00:00:00 2001 From: Patrick Hammer <patham9@gmail.com> Date: Mon, 9 Apr 2018 03:23:09 -0400 Subject: [PATCH] First working version, also using Pei's relative indexing idea. --- nal/opennars2/vision.sage | 13 +++++++++++++ nars_core/nars/main/NAR.java | 16 ++++++++++++++++ nars_core/nars/main/Plugins.java | 2 +- .../nars/plugin/perception/SensoryChannel.java | 2 ++ .../nars/plugin/perception/VisionChannel.java | 4 ---- 5 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 nal/opennars2/vision.sage diff --git a/nal/opennars2/vision.sage b/nal/opennars2/vision.sage new file mode 100644 index 0000000000..80f59e1d61 --- /dev/null +++ b/nal/opennars2/vision.sage @@ -0,0 +1,13 @@ +#Generates input for the vision system, use https://sagecell.sagemath.org/ +A=random_matrix(RR,30,30) +size=30 +for i in range(size): + for j in range(size): + A[i,j]=random() +with open("Output.txt", "w") as text_file: + for i in range(30): + for j in range(30): + di = i/(size-1)*2-1 + dj = j/(size-1)*2-1 + text_file.write("<A["+str(di.n())+","+str(dj.n())+"] --> [bright]>. :|: %"+str(A[i,j])+"%\n") +show(plot(A)) \ No newline at end of file diff --git a/nars_core/nars/main/NAR.java b/nars_core/nars/main/NAR.java index 3bc3f90826..95ce17050d 100644 --- a/nars_core/nars/main/NAR.java +++ b/nars_core/nars/main/NAR.java @@ -39,6 +39,7 @@ import nars.language.Term; import nars.storage.LevelBag; import nars.io.events.Events.CyclesEnd; import nars.io.events.Events.CyclesStart; +import nars.io.events.OutputHandler; import nars.language.Inheritance; @@ -267,6 +268,21 @@ public class NAR extends SensoryChannel implements Serializable,Runnable { if(t != null && t instanceof Inheritance) { Term predicate = ((Inheritance) t).getPredicate(); if(this.sensoryChannels.containsKey(predicate)) { + Inheritance inh = (Inheritance) task.sentence.term; + Term subj = inh.getSubject(); + //map to pei's -1 to 1 indexing schema + if(subj.term_indices == null) { + String variable = subj.toString().split("\\[")[0]; + String[] vals = subj.toString().split("\\[")[1].split("\\]")[0].split(","); + double height = Double.parseDouble(vals[0]); + double width = Double.parseDouble(vals[1]); + int wval = (int) Math.round((width+1.0f)/2.0f*(this.sensoryChannels.get(predicate).width-1)); + int hval = (int) Math.round(((height+1.0f)/2.0f*(this.sensoryChannels.get(predicate).height-1))); + String newInput = "<"+variable+"["+hval+","+wval+"] --> "+predicate+">"+task.sentence.punctuation+ " :|:"; + this.emit(OutputHandler.IN.class, task); + this.addInput(newInput); + return; + } this.sensoryChannels.get(predicate).addInput((Task) task); return; } diff --git a/nars_core/nars/main/Plugins.java b/nars_core/nars/main/Plugins.java index 219706c37b..9a947fd4e8 100644 --- a/nars_core/nars/main/Plugins.java +++ b/nars_core/nars/main/Plugins.java @@ -22,7 +22,7 @@ public class Plugins { n.addPlugin(new Anticipate()); // expect an event Term label = SetInt.make(new Term("bright")); n.addSensoryChannel(label.toString(), - new VisionChannel(label, n, n, 1, 1)); + new VisionChannel(label, n, n, 30, 30)); boolean full_internal_experience = false; if(!full_internal_experience) { n.addPlugin(new InternalExperience()); diff --git a/nars_core/nars/plugin/perception/SensoryChannel.java b/nars_core/nars/plugin/perception/SensoryChannel.java index 595e1b75cd..027e79f3ce 100644 --- a/nars_core/nars/plugin/perception/SensoryChannel.java +++ b/nars_core/nars/plugin/perception/SensoryChannel.java @@ -17,6 +17,8 @@ public abstract class SensoryChannel implements Serializable { private Collection<SensoryChannel> reportResultsTo; public NAR nar; //for top-down influence of concept budgets public List<Task> results = new ArrayList<Task>(); + public int height = 0; //1D channels have height 1 + public int width = 0; public SensoryChannel(){} public SensoryChannel(NAR nar, Collection<SensoryChannel> reportResultsTo) { this.reportResultsTo = reportResultsTo; diff --git a/nars_core/nars/plugin/perception/VisionChannel.java b/nars_core/nars/plugin/perception/VisionChannel.java index 3c94ba0d4e..aa317564fd 100644 --- a/nars_core/nars/plugin/perception/VisionChannel.java +++ b/nars_core/nars/plugin/perception/VisionChannel.java @@ -8,7 +8,6 @@ import nars.entity.Task; import nars.entity.TruthValue; import nars.inference.BudgetFunctions; import nars.io.Symbols; -import nars.io.events.OutputHandler.IN; import nars.language.Inheritance; import nars.language.Term; import nars.main.Parameters; @@ -17,8 +16,6 @@ public class VisionChannel extends SensoryChannel { double[][] inputs; boolean[][] updated; int cnt_updated = 0; - int height = 0; - int width = 0; int px = 0; int py = 0; Term label; @@ -37,7 +34,6 @@ public class VisionChannel extends SensoryChannel { public boolean AddToMatrix(Task t) { Inheritance inh = (Inheritance) t.getTerm(); //channels receive inheritances String cur_subj = inh.getSubject().index_variable.toString(); - nar.emit(IN.class, t); if(!cur_subj.equals(subj)) { //when subject changes, we start to collect from scratch, cnt_updated = 0; //this way multiple matrices can be processed by the same vision channel updated = new boolean[height][width]; -- GitLab