Search in sources :

Example 11 with NAR

use of nars.main.NAR in project opennars by opennars.

the class BagFairness method main.

public static void main(String[] args) {
    Parameters.DEBUG = true;
    int inputs = 100;
    int maxConcepts = 1000;
    float inputRate = 0.2f;
    int displayedIterations = 600;
    int numIterations = 600;
    float minPri = 0.1f;
    float maxPri = 1.0f;
    new NWindow("_", new MultiTimeline(1, 1, 1) {

        @Override
        public Chart[] getCharts(int experiment) {
            final NAR n = new NAR();
            ArrayList<Chart> ch = new BagFairness(n, "nal/Examples/Example-MultiStep-edited.txt", maxConcepts, /* concepts */
            numIterations - displayedIterations, numIterations).charts;
            return ch.toArray(new Chart[ch.size()]);
        }
    }).show(1200, 900, true);
}
Also used : NWindow(automenta.vivisect.swing.NWindow) MultiTimeline(automenta.vivisect.timeline.MultiTimeline) StackedPercentageChart(automenta.vivisect.timeline.StackedPercentageChart) LineChart(automenta.vivisect.timeline.LineChart) Chart(automenta.vivisect.timeline.Chart) NAR(nars.main.NAR)

Example 12 with NAR

use of nars.main.NAR in project opennars by opennars.

the class KeyboardInputExample method main.

public static void main(String[] args) {
    // NAR n = NAR.build(new Neuromorphic().realTime());
    // NAR n = NAR.build(new Default().realTime());
    // n.param.duration.set(100);
    NARSwing.themeInvert();
    NAR n = new NAR();
    new NARSwing(n).themeInvert();
    new NWindow("Direct Keyboard Input", new KeyboardInputPanel(n)).show(300, 100, false);
    n.start(100);
}
Also used : KeyboardInputPanel(nars.gui.input.KeyboardInputPanel) NARSwing(nars.gui.NARSwing) NWindow(automenta.vivisect.swing.NWindow) NAR(nars.main.NAR)

Example 13 with NAR

use of nars.main.NAR in project opennars by opennars.

the class NARControls method actionPerformed.

/**
 * Handling button click
 *
 * @param e The ActionEvent
 */
@Override
public void actionPerformed(ActionEvent e) {
    Object obj = e.getSource();
    if (obj instanceof JButton) {
        if (obj == stopButton) {
            setSpeed(0);
            updateGUI();
        } else if (obj == walkButton) {
            nar.stop();
            nar.cycles(1);
            updateGUI();
        }
    } else if (obj instanceof JMenuItem) {
        String label = e.getActionCommand();
        switch(label) {
            case "Save Memory":
                {
                    try {
                        FileDialog dialog = new FileDialog((Dialog) null, "Save memory", FileDialog.SAVE);
                        dialog.setVisible(true);
                        String directoryName = dialog.getDirectory();
                        String fileName = dialog.getFile();
                        String path = directoryName + fileName;
                        nar.SaveToFile(path);
                    } catch (IOException ex) {
                        Logger.getLogger(NARControls.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                break;
            case "Load Memory":
                {
                    try {
                        FileDialog dialog = new FileDialog((Dialog) null, "Load memory", FileDialog.LOAD);
                        dialog.setVisible(true);
                        String directoryName = dialog.getDirectory();
                        String fileName = dialog.getFile();
                        String filePath = directoryName + fileName;
                        NAR loadedNAR = NAR.LoadFromFile(filePath);
                        new NARSwing(loadedNAR);
                        loadedNAR.memory.emit(OutputHandler.ECHO.class, "Memory file " + fileName + " loaded successfully.");
                        // new javax.swing.JOptionPane.showInputDialog(new javax.swing.JFrame(), "Memory loaded");
                        parent.mainWindow.setVisible(false);
                        parent.mainWindow.dispose();
                    } catch (IOException ex) {
                        Logger.getLogger(NARControls.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (ClassNotFoundException ex) {
                        Logger.getLogger(NARControls.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    break;
                }
            case "Load Experience":
                openLoadFile();
                break;
            case "Save Experience":
                if (savingExp) {
                    experienceWriter.closeSaveFile();
                } else {
                    FileDialog dialog = new FileDialog((Dialog) null, "Save experience", FileDialog.SAVE);
                    dialog.setVisible(true);
                    String directoryName = dialog.getDirectory();
                    String fileName = dialog.getFile();
                    String path = directoryName + fileName;
                    experienceWriter.openSaveFile(path);
                }
                savingExp = !savingExp;
                break;
            case "Reset":
                // / TODO mixture of modifier and reporting
                // narsPlusItem.setEnabled(true);
                // internalExperienceItem.setEnabled(true);
                nar.reset();
                break;
            case "Related Information":
                // MessageDialog web =
                new MessageDialog(NAR.WEBSITE);
                break;
            case "About NARS":
                // MessageDialog info =
                new MessageDialog(NAR.VERSION + "\n\n" + NAR.WEBSITE);
                break;
        }
    }
}
Also used : JButton(javax.swing.JButton) IOException(java.io.IOException) FileDialog(java.awt.FileDialog) Dialog(java.awt.Dialog) JMenuItem(javax.swing.JMenuItem) OutputHandler(nars.io.events.OutputHandler) TextOutputHandler(nars.io.events.TextOutputHandler) FileDialog(java.awt.FileDialog) NAR(nars.main.NAR)

Example 14 with NAR

use of nars.main.NAR in project opennars by opennars.

the class NARSwing method main.

/**
 * The entry point of the standalone application.
 * <p>
 * Create an instance of the class
 *
 * @param args optional argument used : one addInput file, possibly followed by
 * --silence <integer>
 */
public static void main(String[] args) {
    themeInvert();
    NAR nar = new NAR();
    NARSwing swing = new NARSwing(nar);
    if (args.length > 0) {
        try {
            nar.addInputFile(args[0]);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    if (args.length > 1)
        swing.nar.start(0);
}
Also used : NAR(nars.main.NAR)

Example 15 with NAR

use of nars.main.NAR in project opennars by opennars.

the class NALTest method testNAL.

protected double testNAL(final String path) {
    Memory.resetStatic();
    final List<OutputCondition> expects = new ArrayList();
    NAR n = null;
    boolean error = false;
    try {
        n = newNAR();
        String example = getExample(path);
        if (showOutput) {
            System.out.println(example);
            System.out.println();
        }
        List<OutputCondition> extractedExpects = OutputCondition.getConditions(n, example, similarsToSave);
        for (OutputCondition e1 : extractedExpects) expects.add(e1);
        if (showOutput)
            new TextOutputHandler(n, System.out);
        if (showTrace) {
            new InferenceLogger(n, System.out);
        }
        n.addInputFile(path);
        n.cycles(minCycles);
    } catch (Throwable e) {
        System.err.println(e);
        if (Parameters.DEBUG) {
            e.printStackTrace();
        }
        error = true;
    }
    System.err.flush();
    System.out.flush();
    boolean success = expects.size() > 0 && (!error);
    for (OutputCondition e : expects) {
        if (!e.succeeded)
            success = false;
    }
    double score = Double.POSITIVE_INFINITY;
    if (success) {
        long lastSuccess = -1;
        for (OutputCondition e : expects) {
            if (e.getTrueTime() != -1) {
                if (lastSuccess < e.getTrueTime())
                    lastSuccess = e.getTrueTime();
            }
        }
        if (lastSuccess != -1) {
            // score = 1.0 + 1.0 / (1+lastSuccess);
            score = lastSuccess;
            scores.put(path, score);
        }
    } else {
        scores.put(path, Double.POSITIVE_INFINITY);
    }
    if ((!success & showFail) || (success && showSuccess)) {
        System.err.println('\n' + path + " @" + n.memory.time());
        for (OutputCondition e : expects) {
            System.err.println("  " + e);
        }
    }
    // System.err.println("Status: " + success + " total=" + expects.size() + " " + expects);
    if (requireSuccess)
        assertTrue(path, success);
    return score;
}
Also used : InferenceLogger(nars.gui.InferenceLogger) OutputCondition(nars.lab.testutils.OutputCondition) ArrayList(java.util.ArrayList) TextOutputHandler(nars.io.events.TextOutputHandler) NAR(nars.main.NAR)

Aggregations

NAR (nars.main.NAR)28 Test (org.junit.Test)10 Term (nars.language.Term)9 NARSwing (nars.gui.NARSwing)8 CompoundTerm (nars.language.CompoundTerm)8 Narsese (nars.io.Narsese)5 Sentence (nars.entity.Sentence)4 AnswerHandler (nars.io.events.AnswerHandler)4 NWindow (automenta.vivisect.swing.NWindow)3 TextOutputHandler (nars.io.events.TextOutputHandler)3 LineChart (automenta.vivisect.timeline.LineChart)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Concept (nars.entity.Concept)2 Inheritance (nars.language.Inheritance)2 TreeMLData (automenta.vivisect.TreeMLData)1 PCanvas (automenta.vivisect.swing.PCanvas)1 Chart (automenta.vivisect.timeline.Chart)1 MultiTimeline (automenta.vivisect.timeline.MultiTimeline)1 StackedPercentageChart (automenta.vivisect.timeline.StackedPercentageChart)1