Search in sources :

Example 11 with NWindow

use of automenta.vivisect.swing.NWindow in project narchy by automenta.

the class BudgetExpense method main.

public static void main(String[] args) throws Exception {
    int cycles = 1000;
    NAR nar = new Default().build();
    NARTrace t = new NARTrace(nar);
    nar.addInput("<a --> b>.");
    nar.addInput("<b --> c>.");
    nar.addInput("<(^pick,x) =\\> a>.");
    nar.addInput("<(*, b, c) <-> x>.");
    nar.addInput("a!");
    TimelineVis tc = new TimelineVis(new LineChart(t.getCharts("task.novel.add", "task.immediate_processed")).height(3), new LineChart(t.getCharts("task.goal.process", "task.question.process", "task.judgment.process")).height(3), new LineChart(t.getCharts("emotion.busy")).height(1));
    nar.run(cycles);
    new NWindow("_", new PCanvas(tc)).show(800, 800, true);
}
Also used : TimelineVis(automenta.vivisect.timeline.TimelineVis) NARTrace(nars.util.NARTrace) NWindow(automenta.vivisect.swing.NWindow) PCanvas(automenta.vivisect.swing.PCanvas) Default(nars.model.Default) NAR(nars.core.NAR) LineChart(automenta.vivisect.timeline.LineChart)

Example 12 with NWindow

use of automenta.vivisect.swing.NWindow in project opennars by opennars.

the class NARControls method newParameterPanel.

private JComponent newParameterPanel() {
    JPanel p = new JPanel();
    JPanel pc = new JPanel();
    pc.setLayout(new GridLayout(1, 0));
    stopButton = new AwesomeButton(FA_StopCharacter);
    stopButton.setBackground(Color.DARK_GRAY);
    stopButton.addActionListener(this);
    pc.add(stopButton);
    walkButton = new AwesomeButton('\uf051');
    walkButton.setBackground(Color.DARK_GRAY);
    walkButton.setToolTipText("Walk 1 Cycle");
    walkButton.addActionListener(this);
    pc.add(walkButton);
    JButton focusButton = new AwesomeButton(FA_FocusCharacter);
    focusButton.setBackground(Color.DARK_GRAY);
    focusButton.setToolTipText("Focus");
    focusButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setSpeed(1.0f);
            volumeSlider.setValue(0.0f);
        }
    });
    pc.add(focusButton);
    JButton pluginsButton = new AwesomeButton(FA_ControlCharacter);
    pluginsButton.setToolTipText("Plugins");
    pluginsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            new NWindow("Plugins", new PluginPanel(nar)).show(350, 600);
        }
    });
    pc.add(pluginsButton);
    p.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.NORTH;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.gridx = 0;
    c.ipady = 8;
    p.add(pc, c);
    NSlider vs = newVolumeSlider();
    vs.setFont(vs.getFont().deriveFont(Font.BOLD));
    p.add(vs, c);
    NSlider ss = newSpeedSlider();
    ss.setFont(vs.getFont());
    p.add(ss, c);
    c.ipady = 4;
    p.add(new NSlider(memory.param.decisionThreshold, "Decision Threshold", 0.0f, 1.0f), c);
    p.add(new NSlider(Parameters.projectionDecay, "Projection Decay", 0.0f, 1.0f), c);
    p.add(new NSlider(memory.param.taskLinkForgetDurations, "Task Duration", 0.0f, 20), c);
    p.add(new NSlider(memory.param.termLinkForgetDurations, "Belief Duration", 0.0f, 20), c);
    p.add(new NSlider(memory.param.conceptForgetDurations, "Concept Duration", 0.0f, 20), c);
    p.add(new NSlider(memory.param.eventForgetDurations, "Event Duration", 0.0f, 20), c);
    return p;
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) GridBagConstraints(java.awt.GridBagConstraints) ActionListener(java.awt.event.ActionListener) GridBagLayout(java.awt.GridBagLayout) NSlider(automenta.vivisect.swing.NSlider) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) NWindow(automenta.vivisect.swing.NWindow) PluginPanel(nars.gui.output.PluginPanel) AwesomeButton(automenta.vivisect.swing.AwesomeButton)

Example 13 with NWindow

use of automenta.vivisect.swing.NWindow in project opennars by opennars.

the class NarseseTemplatePanel method main.

public static void main(String[] args) {
    List<NarseseTemplate> templates = new ArrayList();
    templates.addAll(Arrays.asList(new NarseseTemplate[] { new NarseseTemplate("<~#a--> ~#b>? %~t%", "Is ~#a is a ~#b? ~t"), new NarseseTemplate("<~#a--> ~#b>. %~t%", "~#a is a ~#b. ~t"), new NarseseTemplate("<~#a --> ~#b>. %1.00;0.99%", "~#a is a ~#b."), new NarseseTemplate("<~#a --> ~#b>. %0.00;0.99%", "~#a is not a ~#b."), new NarseseTemplate("<~#a --> ~#b>. %1.00;0.50%", "~#a is possibly a ~#b."), new NarseseTemplate("<~#a --> ~#b>. %0.00;0.50%", "~#a is possibly not a ~#b.") }));
    NWindow w = new NWindow("NarseseTemplatePanel test", NarseseTemplatePanel.newPanel(templates));
    w.setSize(400, 200);
    w.setVisible(true);
}
Also used : ArrayList(java.util.ArrayList) NWindow(automenta.vivisect.swing.NWindow)

Example 14 with NWindow

use of automenta.vivisect.swing.NWindow in project opennars by opennars.

the class ConceptButton method popup.

public static void popup(NAR nar, Concept concept) {
    ConceptsPanel cp;
    NWindow w = new NWindow(concept.term.toString(), new JScrollPane(cp = new ConceptsPanel(nar, concept)));
    cp.onShowing(true);
    w.pack();
    w.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) NWindow(automenta.vivisect.swing.NWindow)

Example 15 with NWindow

use of automenta.vivisect.swing.NWindow in project opennars by opennars.

the class Predict_NARS_Core method main.

public static void main(String[] args) throws Narsese.InvalidInputException, InterruptedException {
    Parameters.DEBUG = false;
    int duration = 4;
    float freq = 1.0f / duration * 0.03f;
    double discretization = 10;
    n = new NAR();
    n.param.noiseLevel.set(0);
    Random rnd = new Random();
    n.on(TaskImmediateProcess.class, new TaskImmediateProcess() {

        @Override
        public void onProcessed(Task t, DerivationContext n) {
            // return;
            if (t.sentence.getOccurenceTime() >= n.memory.time() && t.sentence.truth.getExpectation() > 0.5) {
                Term term = t.getTerm();
                int time = (int) t.sentence.getOccurenceTime() / thinkInterval;
                /*if(positionTruthExp.containsKey(time)) {
                        if(positionTruthExp.get(time) > t.sentence.truth.getExpectation()) {
                            return;
                        }
                    }*/
                int value = -1;
                String ts = term.toString();
            // Prediction(t.sentence, ts, time);
            }
        }
    });
    TreeMLData observed = new TreeMLData("value", Color.WHITE).setRange(0, 1f);
    // predictions = new TreeMLData[(int)discretization];
    predicted = new TreeMLData("seen", Color.WHITE).setRange(0, 1f);
    // for (int i = 0; i < predictions.length; i++) {
    // predictions[i] = new TreeMLData("Pred" + i,
    // Color.getHSBColor(0.25f + i / 4f, 0.85f, 0.85f));
    // }
    pred = (LineChart) new LineChart(predicted).thickness(16f).height(128).drawOverlapped();
    TimelineVis tc = new TimelineVis(pred, new LineChart(observed).thickness(16f).height(128).drawOverlapped());
    new NWindow("_", new PCanvas(tc)).show(800, 800, true);
    n.cycles((int) discretization * 4);
    NARSwing.themeInvert();
    new NARSwing(n);
    ChangedTextInput chg = new ChangedTextInput(n);
    int k = 0;
    String lastInput = "";
    boolean pause = false;
    HashSet<String> qus = new HashSet<String>();
    int truecnt = 0;
    String saved = "";
    int lastOrival = 0;
    while (true) {
        int steps = 40;
        int h = 0;
        do {
            truecnt++;
            if (truecnt % 100 == 0) {
            // qus.clear();
            }
            for (int i = 0; i < thinkInterval; i++) {
                n.cycles(1);
            }
            Thread.sleep(10);
            h++;
            int repeat = 500;
            signal = (float) Math.sin(freq * (k / 2 % 500) - Math.PI / 2) * 0.5f + 0.5f;
            int time = (int) (n.time() / thinkInterval);
            int val2 = (int) (((int) (((signal) * discretization)) * (10.0 / discretization)));
            // System.out.println("observed "+val);
            int tmp = val2;
            if (!pause && val2 != lastOrival) {
                float noise_amp = 0.5f;
                // noise
                val2 += (rnd.nextDouble() * noise_amp * 0.5f - noise_amp * 0.25f);
            }
            lastOrival = tmp;
            final int val = val2;
            lastInput = "<{" + val + "} --> value>. :|:";
            if (k % repeat == 0 && k != 0) {
                pause = true;
                // new run
                n.memory.seq_current.clear();
            }
            if (!pause && !saved.isEmpty()) {
                chg.set(saved);
                saved = "";
            }
            observed.add((int) time, val / 10.0);
            int curval = val;
            if (QUAnswers.containsKey(val)) {
                curval = QUAnswers.get(val);
            }
            int curtime = time;
            int hh = 0;
            // QUAnswers.put(8, 0); //end to start link is fixed
            while (QUAnswers.containsKey(curval)) {
                int shift = QUShift.get(curval) / thinkInterval;
                for (int i = 0; i < shift; i++) {
                    predicted.add((int) curtime + i, (curval) / 10.0);
                    pred.customColor.put(curtime + i, Color.RED.getRGB());
                    pred.customColor.put(curtime + i + 1, Color.RED.getRGB());
                }
                curtime = curtime + shift;
                curval = QUAnswers.get(curval);
                if (curval == 0) {
                    break;
                }
                hh++;
                if (hh > discretization * 2) {
                    break;
                }
            }
            // if(!positionTruthExp.containsKey(time)) { //keep pred line up to date
            // but don't overwrite predictions
            predicted.add((int) time, val / 10.0);
            if (true) {
                chg.set(lastInput);
                if (!pause) {
                } else {
                    saved = lastInput;
                }
                // n.addInput(lastInput);
                String S = "<(&/," + "<{" + val + "} --> value>,?I1) =/> ?what>";
                if (!qus.contains(S)) {
                    // n.addInput(S);
                    AnswerHandler cur = new AnswerHandler() {

                        @Override
                        public void onSolution(Sentence belief) {
                            // System.out.println("solution: " + belief);
                            System.out.println(belief);
                            String rpart = belief.toString().split("=/>")[1];
                            Prediction(belief, rpart, -1, val);
                        }
                    };
                    try {
                        // if(truecnt%10 == 0) {
                        qus.add(S);
                        n.askNow(S, cur);
                    // }
                    } catch (Narsese.InvalidInputException ex) {
                        Logger.getLogger(Predict_NARS_Core.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
            if (h > 20) {
                pause = false;
            }
        } while (pause);
        k += steps;
    }
}
Also used : Task(nars.entity.Task) ChangedTextInput(nars.lab.ioutils.ChangedTextInput) NWindow(automenta.vivisect.swing.NWindow) Narsese(nars.io.Narsese) AnswerHandler(nars.io.events.AnswerHandler) TimelineVis(automenta.vivisect.timeline.TimelineVis) Random(java.util.Random) TreeMLData(automenta.vivisect.TreeMLData) PCanvas(automenta.vivisect.swing.PCanvas) Sentence(nars.entity.Sentence) HashSet(java.util.HashSet) Term(nars.language.Term) DerivationContext(nars.control.DerivationContext) TaskImmediateProcess(nars.io.events.Events.TaskImmediateProcess) NARSwing(nars.gui.NARSwing) NAR(nars.main.NAR) LineChart(automenta.vivisect.timeline.LineChart)

Aggregations

NWindow (automenta.vivisect.swing.NWindow)17 PCanvas (automenta.vivisect.swing.PCanvas)7 LineChart (automenta.vivisect.timeline.LineChart)6 TimelineVis (automenta.vivisect.timeline.TimelineVis)6 NAR (nars.core.NAR)5 Default (nars.model.Default)5 NARSwing (nars.gui.NARSwing)3 NARTrace (nars.util.NARTrace)3 JPanel (javax.swing.JPanel)2 Sentence (nars.entity.Sentence)2 Term (nars.language.Term)2 NAR (nars.main.NAR)2 Task (nars.nal.entity.Task)2 Term (nars.nal.language.Term)2 FALCON (automenta.falcon.FALCON)1 TreeMLData (automenta.vivisect.TreeMLData)1 AwesomeButton (automenta.vivisect.swing.AwesomeButton)1 NSlider (automenta.vivisect.swing.NSlider)1 Chart (automenta.vivisect.timeline.Chart)1 MultiTimeline (automenta.vivisect.timeline.MultiTimeline)1