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);
}
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);
}
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;
}
}
}
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);
}
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;
}
Aggregations