use of nars.NARS in project narchy by automenta.
the class TermLinkTest method testTermLinkActivationOnConceptualization.
@Test
public void testTermLinkActivationOnConceptualization() throws Narsese.NarseseException {
NAR n = new NARS().get();
n.input("a:b.");
n.input("b:c.");
n.log();
for (int i = 0; i < 55; i++) {
System.out.println(n.time());
n.run();
}
}
use of nars.NARS in project narchy by automenta.
the class CaffeineIndexTest method testDynamicWeight.
@Test
public void testDynamicWeight() throws Narsese.NarseseException {
StringBuilder log = new StringBuilder();
CaffeineIndex index;
NAR n = new NARS().index(index = new CaffeineIndex(4000, (w) -> {
int newWeight = Math.round(1000 * (w.tasklinks().priSum() + w.termlinks().priSum()));
log.append("weigh ").append(w).append(' ').append(newWeight).append('\n');
return newWeight;
}) {
@Override
public Termed get(Term x, boolean createIfMissing) {
log.append("get ").append(x).append(createIfMissing ? " createIfMissing\n" : "\n");
return super.get(x, createIfMissing);
}
}).get();
n.believe("(x-->y).");
n.believe("(x-->y).");
System.out.println(log);
}
use of nars.NARS in project narchy by automenta.
the class JsonTermTest method testBigJSON.
@Test
public void testBigJSON() {
NAR d = new NARS().get();
// d.log();
int n = 0;
for (String json : new String[] { "{\"coord\":{\"lon\":-0.13,\"lat\":51.51},\"weather\":[{\"id\":300,\"main\":\"Drizzle\",\"description\":\"light intensity drizzle\",\"icon\":\"09d\"}],\"base\":\"stations\",\"main\":{\"temp\":280.32,\"pressure\":1012,\"humidity\":81,\"temp_min\":279.15,\"temp_max\":281.15},\"visibility\":10000,\"wind\":{\"speed\":4.1,\"deg\":80},\"clouds\":{\"all\":90},\"dt\":1485789600,\"sys\":{\"type\":1,\"id\":5091,\"message\":0.0103,\"country\":\"GB\",\"sunrise\":1485762037,\"sunset\":1485794875},\"id\":2643743,\"name\":\"London\",\"cod\":200}", "{\"coord\":{\"lon\":139.01,\"lat\":35.02},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01n\"}],\"base\":\"stations\",\"main\":{\"temp\":285.514,\"pressure\":1013.75,\"humidity\":100,\"temp_min\":285.514,\"temp_max\":285.514,\"sea_level\":1023.22,\"grnd_level\":1013.75},\"wind\":{\"speed\":5.52,\"deg\":311},\"clouds\":{\"all\":0},\"dt\":1485792967,\"sys\":{\"message\":0.0025,\"country\":\"JP\",\"sunrise\":1485726240,\"sunset\":1485763863},\"id\":1907296,\"name\":\"Tawarano\",\"cod\":200}" }) {
Atomic id = Atomic.the("WEATHER_" + (n++));
d.believe($.inh(JsonTerm.the(json), id), Tense.Eternal);
d.believe($.inst(id, Atomic.the("now")), Tense.Present);
}
d.run(256);
}
use of nars.NARS in project narchy by automenta.
the class ThermostatTest method main.
// @Test
// @Disabled
public static void main(String[] args) {
// void test1() {
// Param.DEBUG = true;
final int DUR = 1;
final int subTrainings = 2;
// pause between episodes
final int thinkDurs = 4;
NAR n = NARS.tmp();
n.time.dur(DUR);
n.timeFocus.set(2);
n.termVolumeMax.set(34);
// n.freqResolution.set(0.05f);
// n.confResolution.set(0.01f);
n.activationRate.set(0.5f);
n.goalPriDefault.set(1f);
// n.forgetRate.set(2f);
// n.deep.set(0.8);
// n.emotion.want(MetaGoal.Desire, 0.2f);
// n.want(MetaGoal.Believe, 0.1f);
// n.want(MetaGoal.Perceive, -0.01f);
float exeThresh = 0.51f;
// new ArithmeticIntroduction(8, n);
new ConjClustering(n, BELIEF, (t) -> true, 8, 32);
// n.priDefault(BELIEF, 0.3f);
// n.logPriMin(System.out, 0.5f);
// n.logWhen(System.out, false, true, true);
// n.log();
boolean[] training = new boolean[] { true };
Opjects op = new Opjects(n) {
// {
// pretend = true;
// }
@Override
@Nullable
protected synchronized Object invoked(Object obj, Method wrapped, Object[] args, Object result) {
if (training[0]) {
n.synch();
// n.runLater(nn -> nn.run(DUR)); //queue some thinking cycles
}
Object y = super.invoked(obj, wrapped, args, result);
if (training[0])
n.run(DUR * thinkDurs);
return y;
}
};
Teacher<Thermostat> env = new Teacher<>(op, Thermostat.class);
Consumer<Thermostat> hotToCold = Thermostat.change(true, false), coldToCold = Thermostat.change(false, false), coldToHot = Thermostat.change(false, true), hotToHot = Thermostat.change(true, true);
Predicate<Thermostat> isCold = x -> x.is() == Thermostat.cold;
Predicate<Thermostat> isHot = x -> x.is() == Thermostat.hot;
n.logWhen(System.out, true, true, true);
boolean stupid = true;
training: do {
training[0] = true;
op.exeThresh.set(1f);
for (int i = 0; i < subTrainings; i++) {
for (Consumer<Thermostat> condition : new Consumer[] { hotToCold, coldToCold }) {
System.out.println("EPISODE START");
n.clear();
env.teach("down", condition, (Thermostat x) -> {
// x.up(); //demonstrate no change
// x.report();
n.run(1);
while (x.is() > Thermostat.cold) {
x.down();
n.run(1);
}
x.report();
n.run(1);
// x.down(); //demonstrate no change
// x.report();
}, isCold);
System.out.println("EPISODE END");
n.run(thinkDurs * n.dur());
// n.concept("do(down)").print();
}
for (Consumer<Thermostat> condition : new Consumer[] { coldToHot, hotToHot }) {
System.out.println("EPISODE START");
n.clear();
env.teach("up", condition, x -> {
// x.down(); //demonstrate no change
// x.report();
n.run(1);
while (!isHot.test(x)) {
x.up();
n.run(1);
}
x.report();
n.run(1);
// x.up(); //demonstrate no change
// x.report();
}, isHot);
System.out.println("EPISODE END");
n.run(thinkDurs * n.dur());
}
}
System.out.println("VALIDATING");
System.out.println();
training[0] = false;
op.exeThresh.set(exeThresh);
// n.log();
// n.run(100);
// new Implier(n, new float[] { 1f },
// $.$("a_Thermostat(down,())"),
// $.$("a_Thermostat(up,())")
// //$.$("a_Thermostat(is,(),#x)")
// );
// try {
// make cold
// n.input(new NALTask($.$("a_Thermostat(should,(),0)"),
// BELIEF, $.t(1f, 0.99f),
// n.time(), n.time(), n.time()+1000,
// n.time.nextInputStamp()).pri(1f));
Thermostat t = env.x;
{
// n.clear();
t.is(3);
t.should(0);
n.run(thinkDurs * n.dur());
Term cold = $.$$("is(a_Thermostat,0)");
// Term cold = $.$safe("(a_Thermostat(is,(),0) &| --a_Thermostat(is,(),3))");
Term hot = $.$$("is(a_Thermostat,3)");
Truth goalTruth = $.t(1f, 0.9f);
DurService xPos = n.wantWhile(cold, goalTruth, new TaskConceptLogger(n, (w) -> (t.current != t.target)));
DurService xNeg = n.wantWhile(hot, goalTruth.neg(), new TaskConceptLogger(n, (w) -> t.current != t.target));
n.run(1);
for (int i = 0; i < 16 && xPos.isOn(); i++) {
int period = 100;
// t.report();
// n.run(period, pause);
n.run(period);
}
xPos.off();
xNeg.off();
t.report();
if (t.is() == t.should()) {
System.out.println("good job nars!");
n.believe($.$$("(learn(up) && learn(down))"), Tense.Present);
stupid = false;
} else {
System.out.println("bad job nars! try again");
n.believe($.$$("(--learn(up) && --learn(down))"), Tense.Present);
}
// n.input(new NALTask($.$safe("a_Thermostat(is,(),0)"),
// GOAL, $.t(1f, 0.95f),
// n.time(), n.time(), n.time() + periods,
// n.time.nextInputStamp()).pri(1f));
// n.input(new NALTask($.$safe("a_Thermostat(is,(),3)"),
// GOAL, $.t(0f, 0.95f),
// n.time(), n.time(), n.time() + periods,
// n.time.nextInputStamp()).pri(1f));
}
} while (false);
// n.run(thinkDurs * n.dur());
{
// n.input(new NALTask($.$safe("a_Thermostat(is,(),3)"),
// GOAL, $.t(0f, 0.99f),
// n.time(), n.time(), n.time()+1000,
// n.time.nextInputStamp()).pri(1f));
}
// while (t.is() != t.should()) {
// int period = 1000;
// t.report();
// n.run(period);
// }
n.tasks().forEach(t -> {
if (!t.isInput())
System.out.println(t);
});
}
use of nars.NARS in project narchy by automenta.
the class NLPTest method testNLP0.
// @Test
// public void testNLP1() throws IOException, Narsese.NarseseException {
// NAR n = new Default();
//
// }
@Test
@Disabled
public void testNLP0() throws Narsese.NarseseException {
// Param.DEBUG = true;
NAR n = new NARS().get();
// n.DEFAULT_QUEST_PRIORITY = 0.1f;
// n.quaMin.setValue(0.1f);
n.freqResolution.set(0.1f);
n.onOpN("say", (args, nn) -> {
System.err.println(Joiner.on(" ").join(args));
});
// n.log();
// n.logBudgetMin(System.out, 0.2f);
// n.log(System.out, x -> x instanceof Task && ((Task)x).isGoal());
n.input("((VERB:{$V} && SENTENCE($X,$V,$Y)) ==> (((/,MEANS,$X,_),(/,MEANS,$Y,_)) --> (/,MEANS,$V,_))).", "((&&, VERB:{$V}, ADV:{$A}, SENTENCE($X,$V,$A,$Y)) ==> (((/,MEANS,$X,_),(/,MEANS,$Y,_)) --> ((/,MEANS,$V,_)|(/,MEANS,$A,_)))).", "((&&, VERB:{$V}, DET:{#a}, SENTENCE($X,$V,#a,$Y)) ==> (((/,MEANS,$X,_),(/,MEANS,$Y,_)) --> (/,MEANS,$V,_))).", "((&&, VERB:{$V}, DET:{#a}, SENTENCE(#a,$X,$V,$Y)) ==> (((/,MEANS,$X,_),(/,MEANS,$Y,_)) --> (/,MEANS,$V,_))).", "VERB:{is,maybe,isnt,was,willBe,wants,can,likes}.", "DET:{a,the}.", "PREP:{for,on,in,with}.", "ADV:{never,always,maybe}.", "SENTENCE(tom,is,never,sky).", "SENTENCE(tom,is,always,cat).", "SENTENCE(tom,is,cat).", "SENTENCE(tom,is,a,cat).", "SENTENCE(tom,likes,the,sky).", "SENTENCE(tom,likes,maybe,cat).", "SENTENCE(the,sky,is,blue).", "SENTENCE(a,cat,likes,blue).", "SENTENCE(sky,wants,the,blue).", "SENTENCE(sky,is,always,blue).", "$0.9;0.9$ (SENTENCE:#y ==> say:#y).", "$0.9;0.9$ (SENTENCE:#y && say:#y)!");
n.run(1550);
// IO.saveTasksToTemporaryTextFile(n);
}
Aggregations