diff --git a/nal/opennars2/fear.nal b/nal/opennars2/fear.nal new file mode 100644 index 0000000000000000000000000000000000000000..32c7e536fd3c90d16458a0cde45e18a9d99d7dfd --- /dev/null +++ b/nal/opennars2/fear.nal @@ -0,0 +1,6 @@ +<{SELF} --> [hurt]>! %0% +<{SELF} --> [hurt]>. :|: %0% +<(&/,<(*,{SELF},wolf) --> close_to>,+1000) =/> <{SELF} --> [hurt]>>. +<(*,{SELF},wolf) --> close_to>. :|: +<(&|,(^want,{SELF},$1,FALSE),(^anticipate,{SELF},$1)) =|> <(*,{SELF},$1) --> afraid_of>>. +<(*,{SELF},?what) --> afraid_of>? \ No newline at end of file diff --git a/nars_core/nars/control/ConceptProcessing.java b/nars_core/nars/control/ConceptProcessing.java index 2410445ddaf5187f364c15eb786821485dc37b94..652711da92c22225112f59ad3fe57976189f0019 100644 --- a/nars_core/nars/control/ConceptProcessing.java +++ b/nars_core/nars/control/ConceptProcessing.java @@ -13,15 +13,16 @@ import nars.language.*; import nars.operator.Operation; import nars.plugin.mental.InternalExperience; import nars.io.events.Events; -import nars.storage.LevelBag; - import static nars.inference.LocalRules.revisible; import static nars.inference.LocalRules.revision; import static nars.inference.LocalRules.trySolution; import nars.operator.FunctionOperator; import nars.operator.Operator; import nars.operator.mental.Anticipate; -import static nars.plugin.mental.InternalExperience.MINIMUM_BUDGET_SUMMARY_TO_CREATE_WONDER_EVALUATE; +import nars.operator.mental.Believe; +import nars.operator.mental.Want; +import nars.operator.mental.Evaluate; +import nars.operator.mental.Wonder; public class ConceptProcessing { /** @@ -37,7 +38,13 @@ public class ConceptProcessing { public static boolean processTask(Concept concept, final DerivationContext nal, final Task task) { if(task.isInput()) { if(task.sentence.isJudgment() && !task.sentence.isEternal() && task.sentence.term instanceof Operation) { - TemporalInferenceControl.NewOperationFrame(nal.memory, task); + Operation op = (Operation) task.sentence.term; + Operator o = (Operator) op.getPredicate(); + //only consider these mental ops an operation to track when executed not already when generated as internal event + if(!(o instanceof Believe) && !(o instanceof Want) && !(o instanceof Wonder) + && !(o instanceof Evaluate) && !(o instanceof Anticipate)) { + TemporalInferenceControl.NewOperationFrame(nal.memory, task); + } } concept.observable = true; } @@ -256,8 +263,8 @@ public class ConceptProcessing { Stamp s2=goal.stamp.clone(); s2.setOccurrenceTime(concept.memory.time()); - if(s2.after(task.sentence.stamp, nal.memory.param.duration.get())) { //this task is not up to date we have to project it first - Sentence projGoal = task.sentence.projection(concept.memory.time(), nal.memory.param.duration.get()); + if(s2.after(task.sentence.stamp, Parameters.DURATION)) { //this task is not up to date we have to project it first + Sentence projGoal = task.sentence.projection(concept.memory.time(), Parameters.DURATION); if(projGoal!=null && projGoal.truth.getExpectation() > nal.memory.param.decisionThreshold.get()) { nal.singlePremiseTask(projGoal, task.budget.clone()); //keep goal updated // return false; //outcommented, allowing "roundtrips now", relevant for executing multiple steps of learned implication chains @@ -269,7 +276,7 @@ public class ConceptProcessing { double AntiSatisfaction = 0.5f; //we dont know anything about that goal yet, so we pursue it to remember it because its maximally unsatisfied if (beliefT != null) { Sentence belief = beliefT.sentence; - Sentence projectedBelief = belief.projection(task.sentence.getOccurenceTime(), nal.memory.param.duration.get()); + Sentence projectedBelief = belief.projection(task.sentence.getOccurenceTime(), Parameters.DURATION); AntiSatisfaction = task.sentence.truth.getExpDifAbs(projectedBelief.truth); } @@ -427,7 +434,7 @@ public class ConceptProcessing { Term[] newprec = new Term[prec.length-3]; System.arraycopy(prec, 0, newprec, 0, prec.length - 3); - long add_tolerance = (long) Interval.magnitudeToTime(((Interval)prec[prec.length-1]).magnitude*Parameters.ANTICIPATION_TOLERANCE, nal.memory.param.duration); + long add_tolerance = (long) (((Interval)prec[prec.length-1]).time*Parameters.ANTICIPATION_TOLERANCE); mintime = nal.memory.time(); maxtime = nal.memory.time() + add_tolerance; @@ -542,7 +549,7 @@ public class ConceptProcessing { if(c.negConfirmation.sentence.term instanceof Implication) { Implication imp = (Implication) c.negConfirmation.sentence.term; Concept ctarget = nal.memory.concept(imp.getPredicate()); - if(ctarget != null && ctarget.getBudget().summary()>=InternalExperience.MINIMUM_BUDGET_SUMMARY_TO_CREATE_ANTICIPATION) { + if(ctarget != null && ctarget.getPriority()>=InternalExperience.MINIMUM_CONCEPT_PRIORITY_TO_CREATE_ANTICIPATION) { ((Anticipate)c.memory.getOperator("^anticipate")).anticipationFeedback(imp.getPredicate(), null, c.memory); } } diff --git a/nars_core/nars/control/DerivationContext.java b/nars_core/nars/control/DerivationContext.java index 47b9e0b4d2735bc3883780188ec421fa5e17651c..8e12f4d3c49b7c371f82fb9bc00dc6dca56b1f5c 100644 --- a/nars_core/nars/control/DerivationContext.java +++ b/nars_core/nars/control/DerivationContext.java @@ -138,12 +138,13 @@ public class DerivationContext { * @param newBudget The budget value in task */ public boolean doublePremiseTaskRevised(final Term newContent, final TruthValue newTruth, final BudgetValue newBudget) { + Stamp derived_stamp = getTheNewStamp().clone(); + this.resetOccurrenceTime(); //stamp was already obsorbed Sentence newSentence = new Sentence( newContent, getCurrentTask().sentence.punctuation, newTruth, - getTheNewStamp()); - + derived_stamp); Task newTask = new Task(newSentence, newBudget, getCurrentBelief()); return derivedTask(newTask, true, false, true); //allows overlap since overlap was already checked on revisable( function } //which is not the case for other single premise tasks @@ -177,13 +178,14 @@ public class DerivationContext { if(newContent.subjectOrPredicateIsIndependentVar()) { return null; } - + Stamp derive_stamp = getTheNewStamp().clone(); //because occurrence time will be reset: + this.resetOccurrenceTime(); //stamp was already obsorbed into task try { final Sentence newSentence = new Sentence( newContent, getCurrentTask().sentence.punctuation, newTruth, - getTheNewStamp()); + derive_stamp); newSentence.producedByTemporalInduction=temporalInduction; final Task newTask = Task.make(newSentence, newBudget, getCurrentTask(), getCurrentBelief()); @@ -206,7 +208,7 @@ public class DerivationContext { try { TruthValue truthEt=TruthFunctions.eternalize(newTruth); - Stamp st=getTheNewStamp().clone(); + Stamp st=derive_stamp.clone(); st.setEternal(); final Sentence newSentence = new Sentence( newContent, @@ -292,12 +294,15 @@ public class DerivationContext { if(newContent instanceof Interval) { return false; } + + Stamp derive_stamp = this.getTheNewStamp().clone(); + this.resetOccurrenceTime(); //stamp was already obsorbed into task Sentence newSentence = new Sentence( newContent, punctuation, newTruth, - getTheNewStamp()); + derive_stamp); Task newTask = Task.make(newSentence, newBudget, getCurrentTask()); if (newTask!=null) { @@ -347,14 +352,20 @@ public class DerivationContext { /** * @return the newStamp */ + private long original_time = 0; public Stamp getTheNewStamp() { if (newStamp == null) { //if newStamp==null then newStampBuilder must be available. cache it's return value as newStamp newStamp = newStampBuilder.build(); + original_time = newStamp.getOccurrenceTime(); newStampBuilder = null; } return newStamp; } + + public void resetOccurrenceTime() { + newStamp.setOccurrenceTime(original_time); + } /** * @param newStamp the newStamp to set diff --git a/nars_core/nars/entity/Sentence.java b/nars_core/nars/entity/Sentence.java index ba18665a14eb2976c65f0908799bcd69d526b2bf..ec988a02ae48bd3bb531e310bd9ab8e896bcb6f7 100644 --- a/nars_core/nars/entity/Sentence.java +++ b/nars_core/nars/entity/Sentence.java @@ -38,7 +38,6 @@ import nars.language.Conjunction; import nars.language.Equivalence; import nars.language.Implication; import nars.language.Interval; -import nars.language.Interval.AtomicDuration; import nars.language.Statement; import nars.language.Term; import nars.language.Variable; @@ -111,7 +110,7 @@ public class Sentence<T extends Term> implements Cloneable, Serializable { //refined: int u = 0; while(c.term[c.term.length-1-u] instanceof Interval) { - time += Interval.magnitudeToTime(((Interval)c.term[c.term.length-1]).magnitude,new AtomicDuration(Parameters.DURATION)); + time += ((Interval)c.term[c.term.length-1]).time; u++; } @@ -491,11 +490,11 @@ public class Sentence<T extends Term> implements Cloneable, Serializable { long diffabs = Math.abs(diff); String timediff = ""; - if(diffabs < nar.memory.param.duration.get()) { + if(diffabs < Parameters.DURATION) { timediff = "|"; } else { - int Int = Interval.timeToMagnitude(diffabs, nar.param.duration); + Long Int = diffabs; timediff = diff>0 ? "+"+String.valueOf(Int) : "-"+String.valueOf(Int); } String tenseString = ":"+timediff+":"; //stamp.getTense(t, nar.memory.getDuration()); diff --git a/nars_core/nars/entity/Stamp.java b/nars_core/nars/entity/Stamp.java index 58e8ed85dcfe1fcd292839c62dd53f2968f7cdf3..a505171ca1ef5408420c54f36a10c9062a0b2fb2 100644 --- a/nars_core/nars/entity/Stamp.java +++ b/nars_core/nars/entity/Stamp.java @@ -20,12 +20,9 @@ */ package nars.entity; -import com.google.common.collect.Iterators; import java.io.Serializable; import java.util.Arrays; -import java.util.Collection; import java.util.HashSet; -import java.util.LinkedHashSet; import nars.storage.Memory; import nars.main.Parameters; import nars.inference.TemporalRules; @@ -36,7 +33,6 @@ import nars.language.Tense; import static nars.language.Tense.Future; import static nars.language.Tense.Past; import static nars.language.Tense.Present; -import nars.language.Term; import static nars.inference.TemporalRules.order; public class Stamp implements Cloneable, Serializable { @@ -87,10 +83,6 @@ public class Stamp implements Cloneable, Serializable { return 1.0f / (evidentialBase.length + 1); } - public interface DerivationBuilder { - LinkedHashSet<Term> build(); - } - /** used for when the ocrrence time will be set later; so should not be called from externally but through another Stamp constructor */ protected Stamp(final Tense tense, final long serial) { this.baseLength = 1; @@ -175,7 +167,7 @@ public class Stamp implements Cloneable, Serializable { } public Stamp(final Memory memory, final Tense tense) { - this(memory.time(), tense, memory.newStampSerial(), memory.param.duration.get()); + this(memory.time(), tense, memory.newStampSerial(), Parameters.DURATION); } /** creates a stamp with default Present tense */ @@ -203,7 +195,6 @@ public class Stamp implements Cloneable, Serializable { public boolean evidenceIsCyclic() { HashSet<Long> task_base = new HashSet<Long>(this.evidentialBase.length); - boolean cyclic = false; for(int i=0; i < this.evidentialBase.length; i++) { if(task_base.contains(Long.valueOf(this.evidentialBase[i]))) { //can have an overlap in itself already return true; @@ -333,17 +324,6 @@ public class Stamp implements Cloneable, Serializable { return true; } - - - /** necessary because LinkedHashSet.equals does not compare order, only set content */ - public static boolean chainEquals(final Collection<Term> a, final Collection<Term> b) { - if (a == b) return true; - - if ((a instanceof LinkedHashSet) && (b instanceof LinkedHashSet)) - return Iterators.elementsEqual(a.iterator(), b.iterator()); - else - return a.equals(b); - } /** * The hash code of Stamp diff --git a/nars_core/nars/inference/CompositionalRules.java b/nars_core/nars/inference/CompositionalRules.java index c5d1e7a1258279ca11e967387932039d1ff99dcc..1b2e8b222b5d5f3429112248a6240e89567734c2 100644 --- a/nars_core/nars/inference/CompositionalRules.java +++ b/nars_core/nars/inference/CompositionalRules.java @@ -26,6 +26,7 @@ import nars.entity.BudgetValue; import nars.entity.Concept; import nars.control.DerivationContext; import nars.entity.Sentence; +import nars.entity.Stamp; import nars.entity.Task; import nars.entity.TruthValue; import static nars.inference.TruthFunctions.comparison; @@ -191,6 +192,14 @@ public final class CompositionalRules { if (term2 == null) { return; } + + long delta = 0; + while ((term2 instanceof Conjunction) && (((CompoundTerm) term2).term[0] instanceof Interval)) { + Interval interval = (Interval) ((CompoundTerm) term2).term[0]; + delta += interval.time; + term2 = ((CompoundTerm)term2).setComponent(0, null, nal.mem()); + } + Task task = nal.getCurrentTask(); Sentence sentence = task.sentence; Sentence belief = nal.getCurrentBelief(); @@ -264,6 +273,13 @@ public final class CompositionalRules { } if (truth != null) { BudgetValue budget = BudgetFunctions.compoundForward(truth, content, nal); + if (delta != 0) { + long baseTime = task.sentence.getOccurenceTime(); + if (baseTime != Stamp.ETERNAL) { + baseTime += delta; + nal.getTheNewStamp().setOccurrenceTime(baseTime); + } + } nal.doublePremiseTask(content, truth, budget, false, true); //(allow overlap), a form of detachment } } @@ -281,10 +297,11 @@ public final class CompositionalRules { if (isTemporalConjunction && (compound.getTemporalOrder() == TemporalRules.ORDER_FORWARD) && (index != 0)) { return; } + long occurrence_time = nal.getTheNewStamp().getOccurrenceTime(); if(isTemporalConjunction && (compound.getTemporalOrder() == TemporalRules.ORDER_FORWARD)) { if(!nal.getCurrentTask().sentence.isEternal() && compound.term[index + 1] instanceof Interval) { - long shift_occurrence = ((Interval)compound.term[1]).getTime(nal.memory); - nal.getTheNewStamp().setOccurrenceTime(nal.getCurrentTask().sentence.getOccurenceTime() + shift_occurrence); + long shift_occurrence = ((Interval)compound.term[1]).time; + occurrence_time = nal.getCurrentTask().sentence.getOccurenceTime() + shift_occurrence; } } @@ -299,6 +316,7 @@ public final class CompositionalRules { BudgetValue budget; if (taskSentence.isQuestion() || taskSentence.isQuest()) { budget = BudgetFunctions.compoundBackward(content, nal); + nal.getTheNewStamp().setOccurrenceTime(occurrence_time); nal.doublePremiseTask(content, truth, budget, false, false); // special inference to answer conjunctive questions with query variables if (taskSentence.term.hasVarQuery()) { @@ -315,6 +333,7 @@ public final class CompositionalRules { Term conj = Conjunction.make(component, content); truth = intersection(contentBelief.truth, belief.truth); budget = BudgetFunctions.compoundForward(truth, conj, nal); + nal.getTheNewStamp().setOccurrenceTime(occurrence_time); nal.doublePremiseTask(conj, truth, budget, false, false); } } else { @@ -351,6 +370,7 @@ public final class CompositionalRules { } budget = BudgetFunctions.compoundForward(truth, content, nal); } + nal.getTheNewStamp().setOccurrenceTime(occurrence_time); nal.doublePremiseTask(content, truth, budget, false, false); } diff --git a/nars_core/nars/inference/RuleTables.java b/nars_core/nars/inference/RuleTables.java index e97ab504aaf1f3a19346e3ae045b677cc34a5648..55931bb8a65e57f97a7a869560e2a050178ff7e8 100644 --- a/nars_core/nars/inference/RuleTables.java +++ b/nars_core/nars/inference/RuleTables.java @@ -105,14 +105,10 @@ public class RuleTables { }*/ //too restrictive, its checked for non-deductive inference rules in derivedTask (also for single prem) - if(Stamp.baseOverlap(task.sentence.stamp.evidentialBase, belief.stamp.evidentialBase)) { - nal.evidentalOverlap = true; - if(!task.sentence.isEternal() || !belief.isEternal()) { - return; //only allow for eternal reasoning for now to prevent derived event floods - } - //return; //preparisons are made now to support this nicely + nal.evidentalOverlap = Stamp.baseOverlap(task.sentence.stamp.evidentialBase, belief.stamp.evidentialBase); + if(nal.evidentalOverlap && (!task.sentence.isEternal() || !belief.isEternal())) { + return; //only allow for eternal reasoning for now to prevent derived event floods } - //comment out for recursive examples, this is for the future, it generates a lot of potentially useless tasks nal.emit(Events.BeliefReason.class, belief, beliefTerm, taskTerm, nal); diff --git a/nars_core/nars/inference/SyllogisticRules.java b/nars_core/nars/inference/SyllogisticRules.java index f948b25458b17911a9a9eae348815e49158a30ea..beb3afd5f834cdb2150ca0d435056c13393f208c 100644 --- a/nars_core/nars/inference/SyllogisticRules.java +++ b/nars_core/nars/inference/SyllogisticRules.java @@ -125,7 +125,7 @@ public final class SyllogisticRules { * removed? * @param nal Reference to the memory */ - static void abdIndCom(final Term term1, final Term term2, final Sentence sentence1, final Sentence sentence2, final int figure, final DerivationContext nal) { + static void abdIndCom(Term term1, Term term2, final Sentence sentence1, final Sentence sentence2, final int figure, final DerivationContext nal) { if (Statement.invalidStatement(term1, term2) || Statement.invalidPair(term1, term2)) { return; } @@ -164,13 +164,30 @@ public final class SyllogisticRules { budget2 = BudgetFunctions.forward(truth2, nal); budget3 = BudgetFunctions.forward(truth3, nal); } + + long delta2 = 0; + while ((term2 instanceof Conjunction) && (((CompoundTerm) term2).term[0] instanceof Interval)) { + Interval interval = (Interval) ((CompoundTerm) term2).term[0]; + delta2 += interval.time; + term2 = ((CompoundTerm)term2).setComponent(0, null, nal.mem()); + } + long delta1 = 0; + while ((term1 instanceof Conjunction) && (((CompoundTerm) term1).term[0] instanceof Interval)) { + Interval interval = (Interval) ((CompoundTerm) term1).term[0]; + delta1 += interval.time; + term1 = ((CompoundTerm)term1).setComponent(0, null, nal.mem()); + } + if (order != ORDER_INVALID) { + nal.getTheNewStamp().setOccurrenceTime(delta1); nal.doublePremiseTask( Statement.make(taskContent, term1, term2, order), truth1, budget1,false, false); + nal.getTheNewStamp().setOccurrenceTime(delta2); nal.doublePremiseTask( Statement.make(taskContent, term2, term1, reverseOrder(order)), truth2, budget2,false, false); + nal.getTheNewStamp().setOccurrenceTime(delta1); nal.doublePremiseTask( Statement.makeSym(taskContent, term1, term2, order), truth3, budget3,false, false); @@ -397,16 +414,14 @@ public final class SyllogisticRules { return; int order = statement.getTemporalOrder(); - boolean shiftedTimeForward = false; - if ((order != ORDER_NONE) && (order!=ORDER_INVALID) && (!taskSentence.isGoal()) && (!taskSentence.isQuest())) { - long baseTime = subSentence.getOccurenceTime(); - if (baseTime == Stamp.ETERNAL) { + long occurrence_time = nal.getTheNewStamp().getOccurrenceTime(); + if ((order != ORDER_NONE) && (order!=ORDER_INVALID)) { + long baseTime = subSentence.getOccurenceTime(); + if (baseTime == Stamp.ETERNAL) { // =/> always should produce events baseTime = nal.getTime(); } - long inc = order * nal.mem().param.duration.get(); - long time = (side == 0) ? baseTime+inc : baseTime-inc; - shiftedTimeForward = (side == 0); - nal.getTheNewStamp().setOccurrenceTime(time); + long inc = order * Parameters.DURATION; + occurrence_time = (side == 0) ? baseTime+inc : baseTime-inc; } TruthValue beliefTruth = beliefSentence.truth; @@ -457,6 +472,7 @@ public final class SyllogisticRules { } if(!Variables.indepVarUsedInvalid(content)) { boolean allowOverlap = taskSentence.isJudgment() && strong; + nal.getTheNewStamp().setOccurrenceTime(occurrence_time); nal.doublePremiseTask(content, truth, budget, false, allowOverlap); //(strong) when strong on judgement } } @@ -549,24 +565,23 @@ public final class SyllogisticRules { long mintime = 0; long maxtime = 0; boolean predictedEvent = false; - final Interval.AtomicDuration duration = nal.mem().param.duration; if (newCondition != null) { if (newCondition instanceof Interval) { - content = premise1.getPredicate(); - delta = ((Interval) newCondition).getTime(duration); - if(taskSentence.getOccurenceTime() != Stamp.ETERNAL) { - mintime = taskSentence.getOccurenceTime() + Interval.magnitudeToTime(((Interval) newCondition).magnitude - 1, duration); - maxtime = taskSentence.getOccurenceTime() + Interval.magnitudeToTime(((Interval) newCondition).magnitude + 2, duration); - predictedEvent = true; - } - } else if ((newCondition instanceof Conjunction) && (((CompoundTerm) newCondition).term[0] instanceof Interval)) { - Interval interval = (Interval) ((CompoundTerm) newCondition).term[0]; - delta = interval.getTime(duration); - newCondition = ((CompoundTerm)newCondition).setComponent(0, null, nal.mem()); - content = Statement.make(premise1, newCondition, premise1.getPredicate(), premise1.getTemporalOrder()); + content = premise1.getPredicate(); + delta = ((Interval) newCondition).time; + if(taskSentence.getOccurenceTime() != Stamp.ETERNAL) { + mintime = taskSentence.getOccurenceTime() + ((Interval) newCondition).time - 1; + maxtime = taskSentence.getOccurenceTime() + ((Interval) newCondition).time + 2; + predictedEvent = true; + } } else { - content = Statement.make(premise1, newCondition, premise1.getPredicate(), premise1.getTemporalOrder()); + while ((newCondition instanceof Conjunction) && (((CompoundTerm) newCondition).term[0] instanceof Interval)) { + Interval interval = (Interval) ((CompoundTerm) newCondition).term[0]; + delta += interval.time; + newCondition = ((CompoundTerm)newCondition).setComponent(0, null, nal.mem()); + } + content = Statement.make(premise1, newCondition, premise1.getPredicate(), premise1.getTemporalOrder()); } } else { @@ -576,28 +591,13 @@ public final class SyllogisticRules { if (content == null) return; - if(!predictedEvent && !((Conjunction) subj).isSpatial && ((Conjunction) subj).getTemporalOrder() == TemporalRules.ORDER_FORWARD) { //do not allow sequences - boolean last_ival = false; //which have two intervals as result of this, makes sure we only detach (&/ from left side - for(Term t: ((Conjunction) subj).term) { - boolean ival = t instanceof Interval; - if(last_ival && ival) { - return; - } - last_ival = ival; - } - } - + long occurrence_time = nal.getTheNewStamp().getOccurrenceTime(); if (delta != 0) { - long baseTime = (belief.term instanceof Implication) ? - taskSentence.getOccurenceTime() : belief.getOccurenceTime(); - if (baseTime == Stamp.ETERNAL) { - baseTime = nal.getTime(); - } - if(premise1.getTemporalOrder()==TemporalRules.ORDER_CONCURRENT) { - return; //https://groups.google.com/forum/#!topic/open-nars/ZfCM416Dx1M - Interval Simplification + long baseTime = taskSentence.getOccurenceTime(); + if (baseTime != Stamp.ETERNAL) { + baseTime += delta; + occurrence_time = baseTime; } - baseTime += delta; - nal.getTheNewStamp().setOccurrenceTime(baseTime); } TruthValue truth1 = taskSentence.truth; @@ -627,6 +627,7 @@ public final class SyllogisticRules { budget = BudgetFunctions.forward(truth, nal); } + nal.getTheNewStamp().setOccurrenceTime(occurrence_time); List<Task> ret = nal.doublePremiseTask(content, truth, budget,false, taskSentence.isJudgment() && deduction); //(allow overlap) when deduction on judgment if(!nal.evidentalOverlap && ret != null && ret.size() > 0) { if(predictedEvent && taskSentence.isJudgment() && truth != null && truth.getExpectation() > Parameters.DEFAULT_CONFIRMATION_EXPECTATION && diff --git a/nars_core/nars/inference/TemporalRules.java b/nars_core/nars/inference/TemporalRules.java index c6cdf89b26a6e3f1df3b506a2b79c56a1e69f018..06369f7863d90fb4b1d4a43afb06967af20ee7b2 100644 --- a/nars_core/nars/inference/TemporalRules.java +++ b/nars_core/nars/inference/TemporalRules.java @@ -245,11 +245,11 @@ public class TemporalRules { long time1 = s1.getOccurenceTime(); long time2 = s2.getOccurenceTime(); long timeDiff = time2 - time1; - List<Interval> interval=null; + Interval interval=null; if (!concurrent(time1, time2, durationCycles)) { - interval = Interval.intervalTimeSequence(Math.abs(timeDiff), Parameters.TEMPORAL_INTERVAL_PRECISION, nal.mem()); + interval = new Interval(Math.abs(timeDiff)); if (timeDiff > 0) { t1 = Conjunction.make(t1, interval, ORDER_FORWARD); diff --git a/nars_core/nars/io/Narsese.java b/nars_core/nars/io/Narsese.java index 1ef8d8d9b6184c85bbdecc8920b1aa596f876d36..5ee73f40e7a2041140e5169340db542a5da0a9d6 100644 --- a/nars_core/nars/io/Narsese.java +++ b/nars_core/nars/io/Narsese.java @@ -144,7 +144,7 @@ public class Narsese implements Serializable { char punc = str.charAt(last); Stamp stamp = new Stamp(-1 /* if -1, will be set right before the Task is input */, - tense, memory.newStampSerial(), memory.param.duration.get()); + tense, memory.newStampSerial(), Parameters.DURATION); TruthValue truth = parseTruth(truthString, punc); Term content = parseTerm(str.substring(0, last)); diff --git a/nars_core/nars/language/CompoundTerm.java b/nars_core/nars/language/CompoundTerm.java index 42de9f7162245e839cac31b1c7948168c4b8486c..eaf0b3a21ddeb9b8f2636bee8afe585db10066fb 100644 --- a/nars_core/nars/language/CompoundTerm.java +++ b/nars_core/nars/language/CompoundTerm.java @@ -207,7 +207,7 @@ public abstract class CompoundTerm extends Term implements Iterable<Term> { } } - static Interval conceptival = interval(1); + static Interval conceptival = new Interval(1); private static void ReplaceIntervals(CompoundTerm comp) { for(int i=0; i<comp.term.length; i++) { Term t = comp.term[i]; @@ -234,7 +234,7 @@ public abstract class CompoundTerm extends Term implements Iterable<Term> { for(int i=0; i<comp.term.length; i++) { Term t = comp.term[i]; if(t instanceof Interval) { - ivals.add(((Interval) t).getTime(mem.param.duration)); + ivals.add(((Interval) t).time); } else if(t instanceof CompoundTerm) { diff --git a/nars_core/nars/language/Conjunction.java b/nars_core/nars/language/Conjunction.java index f2df71dbe88dc16be67bd57318af145bf49eab70..3e3b8373139eab2263ffd97c3a61b678d3249a8f 100644 --- a/nars_core/nars/language/Conjunction.java +++ b/nars_core/nars/language/Conjunction.java @@ -37,17 +37,6 @@ public class Conjunction extends CompoundTerm { public final int temporalOrder; public final boolean isSpatial; - public static Term[] removeFirstInterval(Term[] arg) { - if(arg[0] instanceof Interval) { - Term[] argNew = new Term[arg.length - 1]; - for(int i=1;i<arg.length;i++) { - argNew[i - 1] = arg[i]; - } - return argNew; - } - return arg; - } - /** * Constructor with partial values, called by make * @@ -230,7 +219,8 @@ public class Conjunction extends CompoundTerm { } // special case: single component if (temporalOrder == TemporalRules.ORDER_FORWARD) { - Term[] newArgList = removeFirstInterval(spatial ? argList : flatten(argList, temporalOrder, spatial)); + Term[] newArgList = spatial ? argList : flatten(argList, temporalOrder, spatial); + if(newArgList.length == 1) { return newArgList[0]; } @@ -265,21 +255,19 @@ public class Conjunction extends CompoundTerm { } } - final public static Term make(final Term prefix, final List<Interval> suffix, final int temporalOrder) { - Term[] t = new Term[suffix.size()+1]; + final public static Term make(final Term prefix, final Interval suffix, final int temporalOrder) { + Term[] t = new Term[1+1]; int i = 0; t[i++] = prefix; - for (Term x : suffix) - t[i++] = x; + t[i++] = suffix; return make(t, temporalOrder); } - final public static Term make(final Term prefix, final List<Interval> ival, final Term suffix, final int temporalOrder) { - Term[] t = new Term[ival.size()+2]; + final public static Term make(final Term prefix, final Interval ival, final Term suffix, final int temporalOrder) { + Term[] t = new Term[1+2]; int i = 0; t[i++] = prefix; - for (Term x : ival) - t[i++] = x; + t[i++] = ival; t[i++] = suffix; return make(t, temporalOrder); } diff --git a/nars_core/nars/language/Interval.java b/nars_core/nars/language/Interval.java index 9fc33f81100acdb024525aac9e3dcc09ff79b82c..c0242f450707cbb92b5f8e7276d7d4eb95ecee63 100644 --- a/nars_core/nars/language/Interval.java +++ b/nars_core/nars/language/Interval.java @@ -17,11 +17,6 @@ package nars.language; -import com.google.common.collect.Lists; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import nars.storage.Memory; import nars.io.Symbols; /** @@ -32,103 +27,9 @@ import nars.io.Symbols; * @author peiwang / SeH */ public class Interval extends Term { - - public static class Lock extends Object implements Serializable { } - //Because AtomicInteger/Double ot supported by teavm - public static class PortableInteger implements Serializable { - public PortableInteger(){} - Lock lock = new Lock(); - int VAL = 0; - public PortableInteger(int VAL){synchronized(lock){this.VAL = VAL;}} - public void set(int VAL){synchronized(lock){this.VAL = VAL;}} - public int get() {return this.VAL;} - public float floatValue() {return (float)this.VAL;} - public float doubleValue() {return (float)this.VAL;} - public int intValue() {return (int)this.VAL;} - public int incrementAndGet(){int ret = 0; synchronized(lock){this.VAL++; ret=this.VAL;} return ret;} - } - public static class PortableDouble implements Serializable { - Lock lock = new Lock(); - public PortableDouble(){} - double VAL = 0; - public PortableDouble(double VAL){synchronized(lock){this.VAL = VAL;}} - public void set(double VAL){synchronized(lock){this.VAL = VAL;}} - public double get() {return this.VAL;} - public float floatValue() {return (float)this.VAL;} - public float doubleValue() {return (float)this.VAL;} - public int intValue() {return (int)this.VAL;} - } - - public static class AtomicDuration extends PortableInteger { - - /** this represents the amount of time in proportion to a duration in which - * Interval resolution calculates. originally, NARS had a hardcoded duration of 5 - * and an equivalent Interval scaling factor of ~1/2 (since ln(E) ~= 1/2 * 5). - * Since duration is now adjustable, this factor approximates the same result - * with regard to a "normalized" interval scale determined by duration. - */ - double linear = 0.5; - - double log; //caches the value here - int lastValue = -1; - - public AtomicDuration() { - super(); - } - - - public AtomicDuration(int v) { - super(v); - } - - public void setLinear(double linear) { - this.linear = linear; - update(); - } - - protected void update() { - int val = get(); - lastValue = val; - this.log = Math.log(val * linear ); - } - - public double getSubDurationLog() { - int val = get(); - if (lastValue != val) { - update(); - } - return log; - } - - } - - static final int INTERVAL_POOL_SIZE = 16; - static Interval[] INTERVAL = new Interval[INTERVAL_POOL_SIZE]; public static Interval interval(final String i) { - return interval( Integer.parseInt(i.substring(1)) - 1); - } - - public static Interval interval(final long time, final Memory memory) { - return interval( timeToMagnitude( time, memory.param.duration ) ); - } - - public static Interval interval(final long time, final AtomicDuration duration) { - return interval( timeToMagnitude( time, duration ) ); - } - - public static Interval interval(int magnitude) { - if (magnitude >= INTERVAL_POOL_SIZE) - return new Interval(magnitude, true); - else if (magnitude < 0) - magnitude = 0; - - Interval existing = INTERVAL[magnitude]; - if (existing == null) { - existing = new Interval(magnitude, true); - INTERVAL[magnitude] = existing; - } - return existing; + return new Interval( Long.parseLong(i.substring(1)) - 1); } @Override @@ -136,47 +37,19 @@ public class Interval extends Term { return true; } - - public final int magnitude; - - // time is a positive integer - protected Interval(final long timeDiff, final AtomicDuration duration) { - this(timeToMagnitude(timeDiff, duration), true); - } - + public final long time; /** this constructor has an extra unused argument to differentiate it from the other one, * for specifying magnitude directly. */ - protected Interval(final int magnitude, final boolean yesMagnitude) { + public Interval(final long time) { super(); - this.magnitude = magnitude; - setName(Symbols.INTERVAL_PREFIX + String.valueOf(1+magnitude)); - } - - public static int timeToMagnitude(final long timeDiff, final AtomicDuration duration) { - int m = (int) timeDiff; //Math.round(Math.log(timeDiff) / duration.getSubDurationLog()); - if (m < 0) return 0; - return m; - } - - public static double magnitudeToTime(final double magnitude, final AtomicDuration duration) { - //if (magnitude <= 0) - // return 1; - return magnitude; //Math.exp(magnitude * duration.getSubDurationLog()); - } + this.time = time; + setName(Symbols.INTERVAL_PREFIX + String.valueOf(time)); + } - public static long magnitudeToTime(final int magnitude, final AtomicDuration duration) { - return magnitude; //(long)Math.round(magnitudeToTime((double)magnitude, duration)); - } - - public final long getTime(final AtomicDuration duration) { - //TODO use a lookup table for this - return magnitude; //magnitudeToTime(magnitude, duration); - } - - public final long getTime(final Memory memory) { - return magnitude; //getTime(memory.param.duration); + public Interval(final String i) { + this(Long.parseLong(i.substring(1)) - 1); } @Override @@ -185,10 +58,4 @@ public class Interval extends Term { //originally: return new Interval(magnitude, true); return this; } - - /** returns a sequence of intervals which approximate a time period with a maximum number of consecutive Interval terms */ - public static List<Interval> intervalTimeSequence(final long t, final int maxTerms, final Memory memory) { - return Lists.newArrayList(interval(t, memory)); - } - } \ No newline at end of file diff --git a/nars_core/nars/main/NAR.java b/nars_core/nars/main/NAR.java index 2af568d1b9091ff088012717b671f1d880985a06..f09f0cf8057588f29a385b930d0c593360ddec84 100644 --- a/nars_core/nars/main/NAR.java +++ b/nars_core/nars/main/NAR.java @@ -108,16 +108,41 @@ public class NAR extends SensoryChannel implements Serializable,Runnable { */ public Memory memory; + + public static class Lock extends Object implements Serializable { } + //Because AtomicInteger/Double ot supported by teavm + public static class PortableInteger implements Serializable { + public PortableInteger(){} + Lock lock = new Lock(); + int VAL = 0; + public PortableInteger(int VAL){synchronized(lock){this.VAL = VAL;}} + public void set(int VAL){synchronized(lock){this.VAL = VAL;}} + public int get() {return this.VAL;} + public float floatValue() {return (float)this.VAL;} + public float doubleValue() {return (float)this.VAL;} + public int intValue() {return (int)this.VAL;} + public int incrementAndGet(){int ret = 0; synchronized(lock){this.VAL++; ret=this.VAL;} return ret;} + } + public static class PortableDouble implements Serializable { + Lock lock = new Lock(); + public PortableDouble(){} + double VAL = 0; + public PortableDouble(double VAL){synchronized(lock){this.VAL = VAL;}} + public void set(double VAL){synchronized(lock){this.VAL = VAL;}} + public double get() {return this.VAL;} + public float floatValue() {return (float)this.VAL;} + public float doubleValue() {return (float)this.VAL;} + public int intValue() {return (int)this.VAL;} + } /*NAR Parameters which can be changed during runtime.*/ public class RuntimeParameters implements Serializable { public RuntimeParameters() { } - public final Interval.PortableInteger noiseLevel = new Interval.PortableInteger(100); - public final Interval.AtomicDuration duration = new Interval.AtomicDuration(Parameters.DURATION); - public final Interval.PortableDouble conceptForgetDurations = new Interval.PortableDouble(Parameters.CONCEPT_FORGET_DURATIONS); - public final Interval.PortableDouble termLinkForgetDurations = new Interval.PortableDouble(Parameters.TERMLINK_FORGET_DURATIONS); - public final Interval.PortableDouble taskLinkForgetDurations = new Interval.PortableDouble(Parameters.TASKLINK_FORGET_DURATIONS); - public final Interval.PortableDouble eventForgetDurations = new Interval.PortableDouble(Parameters.EVENT_FORGET_DURATIONS); - public final Interval.PortableDouble decisionThreshold = new Interval.PortableDouble(Parameters.DECISION_THRESHOLD); + public final PortableInteger noiseLevel = new PortableInteger(100); + public final PortableDouble conceptForgetDurations = new PortableDouble(Parameters.CONCEPT_FORGET_DURATIONS); + public final PortableDouble termLinkForgetDurations = new PortableDouble(Parameters.TERMLINK_FORGET_DURATIONS); + public final PortableDouble taskLinkForgetDurations = new PortableDouble(Parameters.TASKLINK_FORGET_DURATIONS); + public final PortableDouble eventForgetDurations = new PortableDouble(Parameters.EVENT_FORGET_DURATIONS); + public final PortableDouble decisionThreshold = new PortableDouble(Parameters.DECISION_THRESHOLD); } public RuntimeParameters param; @@ -202,11 +227,13 @@ public class NAR extends SensoryChannel implements Serializable,Runnable { this.reset(); return true; } + else if(text.startsWith("*decisionthreshold=")) { Double value = Double.valueOf(text.split("decisionthreshold=")[1]); param.decisionThreshold.set(value); return true; } + else if(text.startsWith("*volume=")) { Integer value = Integer.valueOf(text.split("volume=")[1]); param.noiseLevel.set(value); diff --git a/nars_core/nars/main/Parameters.java b/nars_core/nars/main/Parameters.java index a92be725cb6d119280e8a04925c3604b50587190..48dadbb1bbdafed5d3094e33c9444e925f0f70fd 100644 --- a/nars_core/nars/main/Parameters.java +++ b/nars_core/nars/main/Parameters.java @@ -20,8 +20,7 @@ */ package nars.main; -import nars.language.Interval; -import nars.language.Interval.PortableDouble; +import nars.main.NAR.PortableDouble; /** diff --git a/nars_core/nars/main/Plugins.java b/nars_core/nars/main/Plugins.java index db9e24ee180ec2cd267483d6fa632116a7a74e0f..10a28afa8f4cf2f2cee62cc0209b71500e4d3f45 100644 --- a/nars_core/nars/main/Plugins.java +++ b/nars_core/nars/main/Plugins.java @@ -1,6 +1,5 @@ package nars.main; -import nars.main.NAR; import nars.operator.mental.Anticipate; import nars.plugin.mental.FullInternalExperience; import nars.plugin.mental.InternalExperience; @@ -8,6 +7,9 @@ import nars.plugin.misc.RuntimeNARSettings; import nars.plugin.mental.Emotions; import nars.plugin.mental.Counting; import nars.plugin.mental.Abbreviation; +import nars.language.SetInt; +import nars.language.Term; +//import nars.plugin.perception.VisionChannel; /** * Default set of NAR parameters which have been classically used for development. @@ -17,8 +19,10 @@ public class Plugins { public NAR init(NAR n) { n.addPlugin(new RuntimeNARSettings()); n.addPlugin(new Emotions()); - n.addPlugin(new Anticipate()); // expect an event - + 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)); boolean full_internal_experience = false; if(!full_internal_experience) { n.addPlugin(new InternalExperience()); diff --git a/nars_core/nars/operator/mental/Anticipate.java b/nars_core/nars/operator/mental/Anticipate.java index 3833fa8d6f714630c6ce8fb7f1ee2827a5bca300..b569d2a17198eecc7503dab587ca2c5d16c5e996 100644 --- a/nars_core/nars/operator/mental/Anticipate.java +++ b/nars_core/nars/operator/mental/Anticipate.java @@ -112,11 +112,11 @@ public class Anticipate extends Operator implements EventObserver { //since there is no way anymore that the observation would support <(&/,a,+4) =/> b> at this time, //also this way it is not applied to early, it seems to be the perfect time to me, //making hopeExpirationWindow parameter entirely osbolete - Interval Int=Interval.interval(aTime-predictionstarted, nal.memory); + Interval Int=new Interval(aTime-predictionstarted); //ok we know the magnitude now, let's now construct a interval with magnitude one higher //(this we can skip because magnitudeToTime allows it without being explicitly constructed) //ok, and what predicted occurence time would that be? because only if now is bigger or equal, didnt happen is true - double expiredate=predictionstarted+Interval.magnitudeToTime(Int.magnitude*Parameters.ANTICIPATION_TOLERANCE, nal.memory.param.duration); + double expiredate=predictionstarted+Int.time*Parameters.ANTICIPATION_TOLERANCE; // boolean didntHappen = (now>=expiredate); @@ -191,7 +191,7 @@ public class Anticipate extends Operator implements EventObserver { return null; //not as mental operator but as fundamental principle } - anticipate(args[1],memory,memory.time()+memory.param.duration.get(), null); + anticipate(args[1],memory,memory.time()+Parameters.DURATION, null); return null; } diff --git a/nars_core/nars/operator/mental/Believe.java b/nars_core/nars/operator/mental/Believe.java index bc5f28c874078cdfef30454bd4f17bbdf05beed2..69a93f8901745e55536ebce940bf5ec8f35dc266 100644 --- a/nars_core/nars/operator/mental/Believe.java +++ b/nars_core/nars/operator/mental/Believe.java @@ -33,8 +33,6 @@ import nars.inference.BudgetFunctions; import nars.io.Symbols; import nars.language.Term; import nars.operator.Operation; -import nars.operator.Operation; -import nars.operator.Operator; import nars.operator.Operator; /** diff --git a/nars_core/nars/plugin/mental/Abbreviation.java b/nars_core/nars/plugin/mental/Abbreviation.java index a09710b545a9d18d09977724aa55700b40d2948e..968344e31ec6ff825041259d6b905f0765263a31 100644 --- a/nars_core/nars/plugin/mental/Abbreviation.java +++ b/nars_core/nars/plugin/mental/Abbreviation.java @@ -16,8 +16,8 @@ import nars.entity.TruthValue; import nars.inference.BudgetFunctions; import nars.io.Symbols; import static nars.language.CompoundTerm.termArray; -import nars.language.Interval.PortableDouble; -import nars.language.Interval.PortableInteger; +import nars.main.NAR.PortableDouble; +import nars.main.NAR.PortableInteger; import nars.language.Similarity; import nars.language.Term; import nars.operator.Operation; diff --git a/nars_core/nars/plugin/mental/Counting.java b/nars_core/nars/plugin/mental/Counting.java index f77542cdfc7c4f02072391bbca4d329e9f0d66be..85f88b874f2aa7753b42268d6b8835af1672dfa0 100644 --- a/nars_core/nars/plugin/mental/Counting.java +++ b/nars_core/nars/plugin/mental/Counting.java @@ -38,7 +38,7 @@ public class Counting implements Plugin { return; Task task = (Task)a[0]; - if(task.budget.summary() < InternalExperience.MINIMUM_BUDGET_SUMMARY_TO_CREATE) { + if(task.getPriority() < InternalExperience.MINIMUM_PRIORITY_TO_CREATE_WANT_BELIEVE_ETC) { return; } diff --git a/nars_core/nars/plugin/mental/InternalExperience.java b/nars_core/nars/plugin/mental/InternalExperience.java index 17b15c545ecabf9830abb0978da09883d005b49f..7014132ac024662c250b997eefe459236d31db3b 100644 --- a/nars_core/nars/plugin/mental/InternalExperience.java +++ b/nars_core/nars/plugin/mental/InternalExperience.java @@ -33,9 +33,9 @@ import nars.operator.Operator; */ public class InternalExperience implements Plugin, EventObserver { - public static float MINIMUM_BUDGET_SUMMARY_TO_CREATE=0.92f; //0.92 - public static float MINIMUM_BUDGET_SUMMARY_TO_CREATE_WONDER_EVALUATE=0.92f; - public static float MINIMUM_BUDGET_SUMMARY_TO_CREATE_ANTICIPATION=0.92f; + public static float MINIMUM_PRIORITY_TO_CREATE_WANT_BELIEVE_ETC=0.3f; + public static float MINIMUM_PRIORITY_TO_CREATE_WONDER_EVALUATE=0.3f; + public static float MINIMUM_CONCEPT_PRIORITY_TO_CREATE_ANTICIPATION=0.1f; //internal experience has less durability? public static final float INTERNAL_EXPERIENCE_PROBABILITY=0.0001f; @@ -71,17 +71,17 @@ public class InternalExperience implements Plugin, EventObserver { public double getMinCreationBudgetSummary() { - return MINIMUM_BUDGET_SUMMARY_TO_CREATE; + return MINIMUM_PRIORITY_TO_CREATE_WANT_BELIEVE_ETC; } public void setMinCreationBudgetSummary(double val) { - MINIMUM_BUDGET_SUMMARY_TO_CREATE=(float) val; + MINIMUM_PRIORITY_TO_CREATE_WANT_BELIEVE_ETC=(float) val; } public double getMinCreationBudgetSummaryWonderEvaluate() { - return MINIMUM_BUDGET_SUMMARY_TO_CREATE_WONDER_EVALUATE; + return MINIMUM_PRIORITY_TO_CREATE_WONDER_EVALUATE; } public void setMinCreationBudgetSummaryWonderEvaluate(double val) { - MINIMUM_BUDGET_SUMMARY_TO_CREATE_WONDER_EVALUATE=(float) val; + MINIMUM_PRIORITY_TO_CREATE_WONDER_EVALUATE=(float) val; } private Memory memory; @@ -137,7 +137,7 @@ public class InternalExperience implements Plugin, EventObserver { arg[0]=Term.SELF; arg[1]=s.getTerm(); if (s.truth != null) { - arg[2] = s.truth.toWordTerm(); + arg[2] = s.projection(mem.time(), mem.time()).truth.toWordTerm(); } //Operation.make ? @@ -190,12 +190,12 @@ public class InternalExperience implements Plugin, EventObserver { // (!OLD_BELIEVE_WANT_EVALUATE_WONDER_STRATEGY && (task.sentence.punctuation==Symbols.QUESTION_MARK || task.sentence.punctuation==Symbols.QUEST_MARK))) { { if(task.sentence.punctuation == Symbols.QUESTION_MARK || task.sentence.punctuation == Symbols.QUEST_MARK) { - if(task.budget.summary()<MINIMUM_BUDGET_SUMMARY_TO_CREATE_WONDER_EVALUATE) { + if(task.getPriority()<MINIMUM_PRIORITY_TO_CREATE_WONDER_EVALUATE) { return false; } } else - if(task.budget.summary()<MINIMUM_BUDGET_SUMMARY_TO_CREATE) { + if(task.getPriority()<MINIMUM_PRIORITY_TO_CREATE_WANT_BELIEVE_ETC) { return false; } } diff --git a/nars_core/nars/plugin/misc/RuntimeNARSettings.java b/nars_core/nars/plugin/misc/RuntimeNARSettings.java index 8f655327ebcd054be2261781e2dd641d3453ade2..25ea79adf8ad94bd600800832ecea5884a285e06 100644 --- a/nars_core/nars/plugin/misc/RuntimeNARSettings.java +++ b/nars_core/nars/plugin/misc/RuntimeNARSettings.java @@ -29,13 +29,6 @@ public class RuntimeNARSettings implements Plugin { Parameters.IMMEDIATE_ETERNALIZATION=val; } - public double getDuration() { - return n.param.duration.get(); - } - public void setDuration(double val) { - n.param.duration.set((int) val); - } - public double getDerivationPriorityLeak() { return Parameters.DERIVATION_PRIORITY_LEAK; } diff --git a/nars_core/nars/plugin/perception/VisionChannel.java b/nars_core/nars/plugin/perception/VisionChannel.java new file mode 100644 index 0000000000000000000000000000000000000000..95d3e9f0485735999c7baa1c0e2b027860081978 --- /dev/null +++ b/nars_core/nars/plugin/perception/VisionChannel.java @@ -0,0 +1,71 @@ +package nars.plugin.perception; + +import nars.entity.BudgetValue; +import nars.entity.Sentence; +import nars.entity.Stamp; +import nars.main.NAR; +import nars.entity.Task; +import nars.entity.TruthValue; +import nars.inference.BudgetFunctions; +import nars.io.Symbols; +import nars.language.Inheritance; +import nars.language.Term; +import nars.main.Parameters; + +public class VisionChannel extends SensoryChannel { + double[][] inputs; + boolean[][] updated; + int cnt_updated = 0; + int height = 0; + int width = 0; + Term label; + NAR nar; + public VisionChannel(Term label, NAR nar, SensoryChannel reportResultsTo, int width, int height) { + super(nar,reportResultsTo); + this.nar = nar; + this.height = height; + this.width = width; + this.label = label; + inputs = new double[height][width]; + updated = new boolean[height][width]; + } + + public boolean AddToMatrix(Task t) { + int x = t.getTerm().term_indices[2]; + int y = t.getTerm().term_indices[3]; + inputs[y][x] = t.sentence.getTruth().getFrequency(); + if(!updated[y][x]) { + cnt_updated++; + updated[y][x] = true; + } + if(cnt_updated == height*width) { + cnt_updated = 0; + updated = new boolean[height][width]; + return true; + } + return false; + } + + @Override + public NAR addInput(Task t) { + if(AddToMatrix(t)) //new data complete + step_start(); + return nar; + } + + @Override + public void step_start() + { + Sentence s = new Sentence(Inheritance.make(new Term("A"), this.label), + Symbols.JUDGMENT_MARK, + new TruthValue(1.0f, + Parameters.DEFAULT_JUDGMENT_CONFIDENCE), + new Stamp(nar.memory)); + Task T = new Task(s, new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY, + Parameters.DEFAULT_JUDGMENT_DURABILITY, + BudgetFunctions.truthToQuality(s.truth)), true); + this.results.add(T);//feeds results into "upper" sensory channels: + this.step_finished(); + } + +} diff --git a/nars_core/nars/storage/Memory.java b/nars_core/nars/storage/Memory.java index e02eb0f8320565893cae39de4702c72435528a27..3e02748a530f8345d7347fe50e603b59727a15d6 100644 --- a/nars_core/nars/storage/Memory.java +++ b/nars_core/nars/storage/Memory.java @@ -59,7 +59,7 @@ import nars.operator.Operation; import nars.operator.Operator; import nars.language.CompoundTerm; import nars.language.Interval; -import nars.language.Interval.PortableDouble; +import nars.main.NAR.PortableDouble; /** @@ -261,7 +261,7 @@ public class Memory implements Serializable, Iterable<Concept> { Task task = (Task)t; Stamp s = task.sentence.stamp; if (s.getCreationTime()==-1) - s.setCreationTime(time(), param.duration.get()); + s.setCreationTime(time(), Parameters.DURATION); if(emitIn) { emit(IN.class, task); @@ -433,7 +433,7 @@ public class Memory implements Serializable, Iterable<Concept> { /** converts durations to cycles */ public final float cycles(PortableDouble durations) { - return param.duration.floatValue() * durations.floatValue(); + return Parameters.DURATION * durations.floatValue(); } @Override diff --git a/nars_gui/automenta/vivisect/swing/NSlider.java b/nars_gui/automenta/vivisect/swing/NSlider.java index 5ae24ee91ab5dce5779a7c4ca0cfd05892d4a09e..613c2bd88a928925aa515258c90908fcafb5cf7c 100644 --- a/nars_gui/automenta/vivisect/swing/NSlider.java +++ b/nars_gui/automenta/vivisect/swing/NSlider.java @@ -26,8 +26,7 @@ import java.awt.event.MouseMotionListener; import java.text.NumberFormat; import javax.swing.JLabel; import javax.swing.border.LineBorder; -import nars.language.Interval.PortableDouble; - +import nars.main.NAR.PortableDouble; /** diff --git a/nars_gui/nars/gui/NARControls.java b/nars_gui/nars/gui/NARControls.java index ce9e93b0eef22e860b74231f9e53260fb33e2a93..66e3fa91d7ae2f58c2380bb7e881c34047b10c98 100644 --- a/nars_gui/nars/gui/NARControls.java +++ b/nars_gui/nars/gui/NARControls.java @@ -34,7 +34,6 @@ import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; @@ -58,7 +57,7 @@ import nars.gui.output.TaskTree; import nars.gui.output.graph.NARGraphPanel; import nars.io.events.OutputHandler; import nars.io.events.TextOutputHandler; -import nars.language.Interval.PortableInteger; +import nars.main.NAR.PortableInteger; import nars.io.events.Events.CycleEnd; import nars.io.events.Events.CyclesEnd; diff --git a/nars_gui/nars/gui/graph/ImplicationGraph.java b/nars_gui/nars/gui/graph/ImplicationGraph.java index 76fc73a46bfffad549d3d564915d477a4e833cba..79676cdfdd242dba7e4d421eb8090357aea3e9af 100644 --- a/nars_gui/nars/gui/graph/ImplicationGraph.java +++ b/nars_gui/nars/gui/graph/ImplicationGraph.java @@ -5,7 +5,7 @@ import nars.entity.Item; import nars.entity.Sentence; import nars.io.Symbols; import nars.language.CompoundTerm; -import nars.language.Interval.PortableDouble; +import nars.main.NAR.PortableDouble; import nars.language.Statement; import nars.language.Term; diff --git a/nars_gui/nars/gui/graph/InheritanceGraph.java b/nars_gui/nars/gui/graph/InheritanceGraph.java index fba0751ff7f00399db392c53df1ddd58ba3b663a..d93498a5f0bcac8773c6a3e5e4b97105e86833ff 100644 --- a/nars_gui/nars/gui/graph/InheritanceGraph.java +++ b/nars_gui/nars/gui/graph/InheritanceGraph.java @@ -5,7 +5,7 @@ import nars.entity.Item; import nars.entity.Sentence; import nars.io.Symbols; import nars.language.CompoundTerm; -import nars.language.Interval.PortableDouble; +import nars.main.NAR.PortableDouble; import nars.language.Statement; import nars.language.Term; diff --git a/nars_gui/nars/gui/graph/SentenceGraph.java b/nars_gui/nars/gui/graph/SentenceGraph.java index 52c25941320bf384c30f6199148bc87c9d8682ea..cf5a6b405c7fbdd3f3b0fd9043bf0a3bf487ed26 100644 --- a/nars_gui/nars/gui/graph/SentenceGraph.java +++ b/nars_gui/nars/gui/graph/SentenceGraph.java @@ -14,7 +14,7 @@ import nars.entity.Item; import nars.entity.Sentence; import nars.entity.Task; import nars.language.CompoundTerm; -import nars.language.Interval.PortableDouble; +import nars.main.NAR.PortableDouble; import nars.language.Statement; import nars.language.Term; import org.jgrapht.EdgeFactory; diff --git a/nars_gui/nars/gui/output/JGraphXGraphPanel.java b/nars_gui/nars/gui/output/JGraphXGraphPanel.java index 0699fc6d04b510218d08d308e76745ce033fd6ea..1ea33eff69627024b7c2101a82591f5f4f8351e4 100644 --- a/nars_gui/nars/gui/output/JGraphXGraphPanel.java +++ b/nars_gui/nars/gui/output/JGraphXGraphPanel.java @@ -1,13 +1,11 @@ package nars.gui.output; -import com.mxgraph.layout.mxCompactTreeLayout; import com.mxgraph.layout.mxFastOrganicLayout; import com.mxgraph.swing.mxGraphComponent; import com.mxgraph.util.mxConstants; import java.awt.BorderLayout; import java.util.Map; import javax.swing.JPanel; -import javax.swing.JScrollPane; import nars.main.NAR; import nars.gui.util.DefaultGraphizer; import nars.gui.util.NARGraph; diff --git a/nars_gui/nars/gui/output/graph/NARGraphVis.java b/nars_gui/nars/gui/output/graph/NARGraphVis.java index a3c93bea03ef6d6512005b297699a07b1089f515..9a7c2792eb031dc1a5a05cc94145133a9aab310f 100644 --- a/nars_gui/nars/gui/output/graph/NARGraphVis.java +++ b/nars_gui/nars/gui/output/graph/NARGraphVis.java @@ -34,7 +34,7 @@ import nars.gui.util.NARGraph; import nars.gui.graph.InheritanceGraph; import nars.gui.graph.ImplicationGraph; import nars.gui.output.graph.layout.SpiralLayout; -import nars.language.Interval.PortableDouble; +import nars.main.NAR.PortableDouble; import org.jgrapht.Graph; /** diff --git a/nars_gui/nars/gui/util/DefaultGraphizer.java b/nars_gui/nars/gui/util/DefaultGraphizer.java index 5a114f321f53f1b1a866d2bc8822d41ef81b8d83..b86e9ea2547bdd00026494029d89c2dc9c9a1799 100644 --- a/nars_gui/nars/gui/util/DefaultGraphizer.java +++ b/nars_gui/nars/gui/util/DefaultGraphizer.java @@ -1,6 +1,5 @@ package nars.gui.util; -import java.util.Collection; import java.util.HashMap; import java.util.Map; import javax.swing.JTextField; @@ -11,7 +10,7 @@ import nars.entity.Task; import nars.entity.TaskLink; import nars.entity.TermLink; import nars.language.CompoundTerm; -import nars.language.Interval.PortableDouble; +import nars.main.NAR.PortableDouble; import nars.language.Term; diff --git a/nars_lab/nars/lab/narclear/NARPhysicsDemo.java b/nars_lab/nars/lab/narclear/NARPhysicsDemo.java index 1bb0fa568ddab2bfb87614ec776973664dd9d3b0..f533faf4358bea100e4f76ce37a327b956157528 100644 --- a/nars_lab/nars/lab/narclear/NARPhysicsDemo.java +++ b/nars_lab/nars/lab/narclear/NARPhysicsDemo.java @@ -6,6 +6,7 @@ import nars.main.NAR; import nars.entity.Task; import nars.lab.ioutils.ChangedTextInput; import nars.language.Term; +import nars.main.Parameters; import nars.operator.NullOperator; import nars.operator.Operation; import org.jbox2d.common.MathUtils; @@ -173,8 +174,8 @@ public class NARPhysicsDemo extends NARPhysics<RobotArm> { } public static void main(String[] args) { + Parameters.DURATION = 20; NAR n = new NAR(); - (n.param).duration.set(20); (n.param).decisionThreshold.set(0); (n.param).noiseLevel.set(5); //PhysicsModel model = new Car(); diff --git a/nars_lab/nars/lab/plugin/input/PerceptionAccel.java b/nars_lab/nars/lab/plugin/input/PerceptionAccel.java index 3d1b0c330888bec741b9fc2ed3c0889e6629d7dc..d2f2f5b07b0a46c742da51567ad2f07e1f07a985 100644 --- a/nars_lab/nars/lab/plugin/input/PerceptionAccel.java +++ b/nars_lab/nars/lab/plugin/input/PerceptionAccel.java @@ -83,7 +83,7 @@ public class PerceptionAccel implements Plugin, EventEmitter.EventObserver { if(i!=Len-1) { //if its not the last one, then there is a next one for which we have to put an interval truth=TruthFunctions.deduction(truth, current.sentence.truth); Task next=eventbuffer.get(j+1); - relterms[k+1]=Interval.interval(next.sentence.getOccurenceTime()-current.sentence.getOccurenceTime(), nal.memory); + relterms[k+1]=new Interval(next.sentence.getOccurenceTime()-current.sentence.getOccurenceTime()); } k+=2; } @@ -108,7 +108,7 @@ public class PerceptionAccel implements Plugin, EventEmitter.EventObserver { } //decide on the tense of &/ by looking if the first event happens parallel with the last one //Todo refine in 1.6.3 if we want to allow input of difference occurence time - boolean after=newEvent.sentence.stamp.after(eventbuffer.get(eventbuffer.size()-1-(Len-1)).sentence.stamp, nal.memory.param.duration.get()); + boolean after=newEvent.sentence.stamp.after(eventbuffer.get(eventbuffer.size()-1-(Len-1)).sentence.stamp, Parameters.DURATION); //critical part: (not checked for correctness yet): //we now have to look at if the first half + the second half already exists as concept, before we add it diff --git a/nars_lab/nars/lab/plugin/mental/GlobalAnticipation.java b/nars_lab/nars/lab/plugin/mental/GlobalAnticipation.java index ab1cc7ceaecce6916b67156d856eec7e4e9b7aca..ae622487c32e405c4ad93c4ca82077fbbe0144b1 100644 --- a/nars_lab/nars/lab/plugin/mental/GlobalAnticipation.java +++ b/nars_lab/nars/lab/plugin/mental/GlobalAnticipation.java @@ -107,7 +107,7 @@ public class GlobalAnticipation implements Plugin, EventEmitter.EventObserver { return; } - final long duration = nal.memory.param.duration.get(); + final long duration = Parameters.DURATION; ArrayList<Task> derivetasks=new ArrayList<Task>(); for(final Task c : current_tasks) { //a =/> b or (&/ a1...an) =/> b @@ -134,7 +134,7 @@ public class GlobalAnticipation implements Plugin, EventEmitter.EventObserver { //handling of intervals: if(args[i] instanceof Interval) { if(!concurrent_conjunction) { - expected_time+=((Interval)args[i]).getTime(nal.memory); + expected_time+=((Interval)args[i]).time; } off++; continue; diff --git a/nars_lab/nars/lab/tictactoe/TicTacToe.java b/nars_lab/nars/lab/tictactoe/TicTacToe.java index 3f41324bc47d4e75459461fc0e754a0bfa476c15..2f76fee86ceb8fb6080fa289da0a5f8723f14aea 100644 --- a/nars_lab/nars/lab/tictactoe/TicTacToe.java +++ b/nars_lab/nars/lab/tictactoe/TicTacToe.java @@ -49,6 +49,7 @@ import nars.language.Term; import nars.operator.Operation; import nars.operator.Operator; import nars.io.events.Events.CyclesEnd; +import nars.main.Parameters; /** * @@ -81,11 +82,10 @@ public class TicTacToe extends JPanel { public TicTacToe() { super(new BorderLayout()); - + Parameters.DURATION = 1000; nar = new NAR(); nar.memory.addOperator(new AddO("^addO")); - (nar.param).duration.set(1000); (nar.param).noiseLevel.set(0); new NARSwing(nar); diff --git a/nars_lab/nars/lab/vision/SymRecognizer.java b/nars_lab/nars/lab/vision/SymRecognizer.java index 4693dc4e9cc74f322330d00c7de7a623cf080700..d7ccbe9c794074d3924450b75e0314daad3322fd 100644 --- a/nars_lab/nars/lab/vision/SymRecognizer.java +++ b/nars_lab/nars/lab/vision/SymRecognizer.java @@ -387,7 +387,6 @@ public class SymRecognizer extends javax.swing.JFrame { } u++; } - nar.param.duration.set(1000); nar.param.noiseLevel.set(0); nar.addInput(inputPanel.getText()); nar.start(0); @@ -431,6 +430,7 @@ public class SymRecognizer extends javax.swing.JFrame { public static void main(String args[]) { NARSwing.themeInvert(); + Parameters.DURATION = 1000; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new SymRecognizer().setVisible(true); diff --git a/nars_lab/nars/lab/vision/SymRecognizerWithVisionChannel.java b/nars_lab/nars/lab/vision/SymRecognizerWithVisionChannel.java index d984b92fc0294d0ace8534b42761448558f04d71..933308a345a2526a4687075e0e724cdfe466a886 100644 --- a/nars_lab/nars/lab/vision/SymRecognizerWithVisionChannel.java +++ b/nars_lab/nars/lab/vision/SymRecognizerWithVisionChannel.java @@ -389,7 +389,6 @@ public class SymRecognizerWithVisionChannel extends javax.swing.JFrame { } u++; } - nar.param.duration.set(1000); nar.param.noiseLevel.set(0); nar.addInput(inputPanel.getText()); nar.start(0); @@ -433,6 +432,7 @@ public class SymRecognizerWithVisionChannel extends javax.swing.JFrame { public static void main(String args[]) { NARSwing.themeInvert(); + Parameters.DURATION = 1000; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new SymRecognizerWithVisionChannel().setVisible(true); diff --git a/nars_test/nars/core/IntervalTest.java b/nars_test/nars/core/IntervalTest.java deleted file mode 100644 index a0a774c660406526707008444b482a0bcecc91b7..0000000000000000000000000000000000000000 --- a/nars_test/nars/core/IntervalTest.java +++ /dev/null @@ -1,103 +0,0 @@ -package nars.core; - -import java.util.List; -import nars.storage.Memory; -import nars.main.NAR; -import nars.language.Interval; -import nars.language.Interval.AtomicDuration; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import org.junit.Test; - -/** - * - * @author me - */ - - -public class IntervalTest { - - @Test - public void testInterval() { - AtomicDuration dur5 = new AtomicDuration(5); - - //assertTrue(dur5.getSubDurationLog() == Math.log(5/2f)); - assertTrue(dur5.get() == 5); - - Interval i1 = Interval.interval(1, dur5); - assertTrue(i1.magnitude == 0); - assertTrue(i1.name().toString().equals("+1")); - assertTrue(i1.getTime(dur5) == 1); - - //testing 2 = floor(dur5/2) - Interval i2 = Interval.interval(2, dur5); - assertEquals(1, i2.magnitude); - assertTrue(i2.name().toString().equals("+2")); - assertEquals(3, i2.getTime(dur5)); - - ////testing 2 = floor(dur5/2) - Interval i3 = Interval.interval(3, dur5); - assertEquals(1, i3.magnitude); - assertTrue(i3.name().toString().equals("+2")); - assertEquals(3, i3.getTime(dur5)); - - Interval i5 = Interval.interval(5, dur5); - assertEquals(2, i5.magnitude); - assertTrue(i5.name().toString().equals("+3")); - assertEquals(6, i5.getTime(dur5)); - - /*for (int i = 0; i < 100; i++) { - System.out.println(i + " " + Interval.intervalTime(i, dur5)); - }*/ - - } - - @Test - public void testIntervalSequence() { - - NAR n = new NAR(); - Memory m = n.memory; - - List<Interval> a11 = Interval.intervalTimeSequence(1, 1, m); - assertEquals(1, a11.size()); - assertEquals(Interval.interval(1, m), a11.get(0)); - assertEquals(Interval.interval(0), a11.get(0)); - - List<Interval> a12 = Interval.intervalTimeSequence(1, 2, m); - assertEquals(a11, a12); - - - { - //half duration = magnitude 1 ("+2") - long halfDuration = (n.param).duration.get()/2; - - List<Interval> ad1 = Interval.intervalTimeSequence(halfDuration, 1, m); - assertEquals(1, ad1.size()); - assertEquals(Interval.interval(1), ad1.get(0)); - //assertEquals(halfDuration+1, Interval.intervalSequenceTime(ad1, m)); - - //unused extra term because time period was exactly reached - List<Interval> ad2 = Interval.intervalTimeSequence(halfDuration, 2, m); - assertEquals(2, ad2.size()); - //assertEquals(halfDuration, Interval.intervalSequenceTime(ad2, m)); - - } - { - //test ability to represent a range of time periods precisely with up to N terms - long duration = (n.param).duration.get(); - int numTerms = 6; - for (int t = 1; t < duration * duration * duration; t++) { - List<Interval> ad1 = Interval.intervalTimeSequence(t, numTerms, m); - /*Interval approx = Interval.intervalTime(t, m); - System.out.println(t + " = " + ad1 + "; ~= " + - approx + " (error=" + (approx.getTime(m) - t) + ")");*/ - - //assertEquals(t, Interval.intervalSequenceTime(ad1, m)); - } - } - - - - } - -} diff --git a/nars_test/nars/perf/BagPerf.java b/nars_test/nars/perf/BagPerf.java index 53c554fcc8af96f32e4b3d12a00b094cde8b2496..d33e5658eede16297894607e9d56fb27d3978a9e 100644 --- a/nars_test/nars/perf/BagPerf.java +++ b/nars_test/nars/perf/BagPerf.java @@ -29,7 +29,7 @@ import nars.main.NAR; import nars.main.Parameters; import nars.entity.BudgetValue; import nars.entity.Item; -import nars.language.Interval.PortableDouble; +import nars.main.NAR.PortableDouble; import nars.storage.Bag; import nars.storage.LevelBag;