From 07a88f74ebb828492cd12017befaf7cb69c5f4e2 Mon Sep 17 00:00:00 2001 From: Patrick Hammer <patham9@gmail.com> Date: Sat, 7 Apr 2018 07:17:53 -0400 Subject: [PATCH] NAL7 legacy boilerplate code for intervals removed. --- nars_core/nars/control/ConceptProcessing.java | 8 +- nars_core/nars/entity/Sentence.java | 7 +- nars_core/nars/entity/Stamp.java | 22 +-- .../nars/inference/CompositionalRules.java | 4 +- .../nars/inference/SyllogisticRules.java | 15 +- nars_core/nars/inference/TemporalRules.java | 4 +- nars_core/nars/io/Narsese.java | 2 +- nars_core/nars/language/CompoundTerm.java | 4 +- nars_core/nars/language/Conjunction.java | 14 +- nars_core/nars/language/Interval.java | 149 +----------------- nars_core/nars/main/NAR.java | 39 ++++- nars_core/nars/main/Parameters.java | 3 +- .../nars/plugin/mental/Abbreviation.java | 4 +- .../nars/plugin/misc/RuntimeNARSettings.java | 7 - nars_core/nars/storage/Memory.java | 6 +- .../automenta/vivisect/swing/NSlider.java | 3 +- nars_gui/nars/gui/NARControls.java | 3 +- nars_gui/nars/gui/graph/ImplicationGraph.java | 2 +- nars_gui/nars/gui/graph/InheritanceGraph.java | 2 +- nars_gui/nars/gui/graph/SentenceGraph.java | 2 +- .../nars/gui/output/JGraphXGraphPanel.java | 2 - .../nars/gui/output/graph/NARGraphVis.java | 2 +- nars_gui/nars/gui/util/DefaultGraphizer.java | 3 +- .../nars/lab/narclear/NARPhysicsDemo.java | 3 +- .../lab/plugin/input/PerceptionAccel.java | 4 +- .../lab/plugin/mental/GlobalAnticipation.java | 4 +- nars_lab/nars/lab/tictactoe/TicTacToe.java | 4 +- nars_lab/nars/lab/vision/SymRecognizer.java | 2 +- .../SymRecognizerWithVisionChannel.java | 2 +- nars_test/nars/core/IntervalTest.java | 103 ------------ nars_test/nars/perf/BagPerf.java | 2 +- 31 files changed, 92 insertions(+), 339 deletions(-) delete mode 100644 nars_test/nars/core/IntervalTest.java diff --git a/nars_core/nars/control/ConceptProcessing.java b/nars_core/nars/control/ConceptProcessing.java index f21f7c6f2a..652711da92 100644 --- a/nars_core/nars/control/ConceptProcessing.java +++ b/nars_core/nars/control/ConceptProcessing.java @@ -263,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 @@ -276,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); } @@ -434,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; diff --git a/nars_core/nars/entity/Sentence.java b/nars_core/nars/entity/Sentence.java index ba18665a14..ec988a02ae 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 58e8ed85dc..a505171ca1 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 4a4cb78100..1b2e8b222b 100644 --- a/nars_core/nars/inference/CompositionalRules.java +++ b/nars_core/nars/inference/CompositionalRules.java @@ -196,7 +196,7 @@ public final class CompositionalRules { long delta = 0; while ((term2 instanceof Conjunction) && (((CompoundTerm) term2).term[0] instanceof Interval)) { Interval interval = (Interval) ((CompoundTerm) term2).term[0]; - delta += interval.getTime(nal.memory); + delta += interval.time; term2 = ((CompoundTerm)term2).setComponent(0, null, nal.mem()); } @@ -300,7 +300,7 @@ public final class CompositionalRules { 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); + long shift_occurrence = ((Interval)compound.term[1]).time; occurrence_time = nal.getCurrentTask().sentence.getOccurenceTime() + shift_occurrence; } } diff --git a/nars_core/nars/inference/SyllogisticRules.java b/nars_core/nars/inference/SyllogisticRules.java index 04f77927ec..beb3afd5f8 100644 --- a/nars_core/nars/inference/SyllogisticRules.java +++ b/nars_core/nars/inference/SyllogisticRules.java @@ -168,13 +168,13 @@ public final class SyllogisticRules { long delta2 = 0; while ((term2 instanceof Conjunction) && (((CompoundTerm) term2).term[0] instanceof Interval)) { Interval interval = (Interval) ((CompoundTerm) term2).term[0]; - delta2 += interval.getTime(nal.memory); + 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.getTime(nal.memory); + delta1 += interval.time; term1 = ((CompoundTerm)term1).setComponent(0, null, nal.mem()); } @@ -420,7 +420,7 @@ public final class SyllogisticRules { if (baseTime == Stamp.ETERNAL) { // =/> always should produce events baseTime = nal.getTime(); } - long inc = order * nal.mem().param.duration.get(); + long inc = order * Parameters.DURATION; occurrence_time = (side == 0) ? baseTime+inc : baseTime-inc; } @@ -565,21 +565,20 @@ 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); + delta = ((Interval) newCondition).time; 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); + mintime = taskSentence.getOccurenceTime() + ((Interval) newCondition).time - 1; + maxtime = taskSentence.getOccurenceTime() + ((Interval) newCondition).time + 2; predictedEvent = true; } } else { while ((newCondition instanceof Conjunction) && (((CompoundTerm) newCondition).term[0] instanceof Interval)) { Interval interval = (Interval) ((CompoundTerm) newCondition).term[0]; - delta += interval.getTime(duration); + delta += interval.time; newCondition = ((CompoundTerm)newCondition).setComponent(0, null, nal.mem()); } content = Statement.make(premise1, newCondition, premise1.getPredicate(), premise1.getTemporalOrder()); diff --git a/nars_core/nars/inference/TemporalRules.java b/nars_core/nars/inference/TemporalRules.java index c6cdf89b26..06369f7863 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 1ef8d8d9b6..5ee73f40e7 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 42de9f7162..eaf0b3a21d 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 c4a834893d..3e3b837313 100644 --- a/nars_core/nars/language/Conjunction.java +++ b/nars_core/nars/language/Conjunction.java @@ -255,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 9fc33f8110..c0242f4507 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 fca28d8659..f09f0cf805 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; diff --git a/nars_core/nars/main/Parameters.java b/nars_core/nars/main/Parameters.java index a92be725cb..48dadbb1bb 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/plugin/mental/Abbreviation.java b/nars_core/nars/plugin/mental/Abbreviation.java index a09710b545..968344e31e 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/misc/RuntimeNARSettings.java b/nars_core/nars/plugin/misc/RuntimeNARSettings.java index 8f655327eb..25ea79adf8 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/storage/Memory.java b/nars_core/nars/storage/Memory.java index e02eb0f832..3e02748a53 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 5ae24ee91a..613c2bd88a 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 ce9e93b0ee..66e3fa91d7 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 76fc73a46b..79676cdfdd 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 fba0751ff7..d93498a5f0 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 52c2594132..cf5a6b405c 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 0699fc6d04..1ea33eff69 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 a3c93bea03..9a7c2792eb 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 5a114f321f..b86e9ea254 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 1bb0fa568d..f533faf435 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 3d1b0c3308..d2f2f5b07b 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 ab1cc7ceae..ae622487c3 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 3f41324bc4..2f76fee86c 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 4693dc4e9c..d7ccbe9c79 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 d984b92fc0..933308a345 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 a0a774c660..0000000000 --- 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 53c554fcc8..d33e5658ee 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; -- GitLab