Пример #1
0
 public void stop() {
   if (activation.procedure().isTask()) {
     throw NonLocalExit$.MODULE$;
   }
   if (activation.procedure().topLevel()) {
     // In the BehaviorSpace case, there are two cases: stop
     // used inside a procedure called from the go commands,
     // and stop used in the go commands themselves.  (People
     // probably shouldn't be doing the latter, since they
     // could just use a stop condition, but you know somebody
     // will try...)  If stop is used in the go commands
     // themselves, then the call to returnFromProcedure below
     // means that __experimentstepend won't run.  Thus we need
     // to set job.stopping to true ourselves, if we just
     // returned from a top level procedure.  If I've analyzed
     // this correctly, setting it to true will have no effect
     // in other settings besides BehaviorSpace.
     // - ST 3/8/06, 8/30/07
     job.stopping = true;
     finished = true;
   }
   returnFromProcedure();
   // this is so that we can stop our enclosing forever
   // button if we're immediately inside one.  __foreverbuttonend
   // will be looking for this to be true and if it is, will
   // stop the button.  this flag is reset to false by
   // _return and _report, so the next time a procedure
   // returns normally, the forever button will no longer
   // stop since "stop" wasn't used within a procedure called
   // directly by the button. - ST
   // It's also used to stop a BehaviorSpace run, using
   // __experimentstepend. - ST 3/8/06
   stopping = true;
 }
Пример #2
0
 public Object callReporterProcedure(Activation newActivation) {
   boolean oldInReporterProcedure = inReporterProcedure;
   Command command = null;
   inReporterProcedure = true; // so use of "ask" will create an exclusive job
   activation = newActivation;
   ip = 0;
   try {
     do {
       command = activation.procedure().code()[ip];
       if ((agentBit & command.agentBits) == 0) {
         command.throwAgentClassException(this, agent.kind());
       }
       command.perform(this);
       if (command.world.comeUpForAir) {
         comeUpForAir(command);
       }
     } while (!finished && job.result == null);
   } catch (NonLocalExit$ e) {
     // do nothing
   } catch (LogoException ex) {
     EngineException.rethrow(ex, this, command);
   } finally {
     inReporterProcedure = oldInReporterProcedure;
   }
   ip = activation.returnAddress();
   activation = activation.parent();
   Object result = job.result;
   job.result = null;
   return result;
 }
  @Test
  public void shouldSetSlotInFunctionsContext() {
    context.setSlot(local, environment.getUndefined());

    FunctionWithContext function = createFunctionWithContextThatSetsLocalToValue(context);
    function.execute(interpreter, object, new ArrayList<ObjectDOS>());

    assertThat(((ValueObject) context.getSlot(local)).getValue(), is(1234));
  }
Пример #4
0
  @Override
  public void step() {
    stateHidden.setSubVector(0, weights0.operate(stateIn));

    for (int i : series(h)) stateHidden.setEntry(i, activation.function(stateHidden.getEntry(i)));

    stateOut.setSubVector(0, weights1.operate(stateHidden));
  }
Пример #5
0
 public void runExclusiveJob(AgentSet agentset, int address) {
   new ExclusiveJob(job.owner, agentset, activation.procedure(), address, this, job.random).run();
   // this next check is here to handle an obscure special case:
   // check if the child has (gasp!) killed its parent
   // - ST 6/27/05, 1/10/07
   if (agent.id == -1) {
     finished = true;
   }
 }
 @Before
 public void setUp() {
   interpreter = new OpCodeInterpreter();
   environment = interpreter.getEnvironment();
   vm = VMObjectDOS.getVMObject(environment);
   object = environment.createNewObject();
   value = environment.createNewObject();
   context = interpreter.newActivation();
   context.setVictim(environment.createNewObject());
 }
  @Test
  public void shouldSetSlotInCurrentContextualFunction() {

    FunctionWithContext function =
        environment.createFunctionWithContext(
            createFunctionThatSetsAndReturnsValueToLocal(), context);

    ObjectDOS result = function.execute(interpreter, object, new ArrayList<ObjectDOS>());

    assertThat(((ValueObject) result).getValue(), is(1234));
    assertThat(context.getSlot(local), is(environment.getUndefined()));
  }
Пример #8
0
 // this had to be made public so that workspace.Evaluator could call it when
 // running command thunks. - JC 6/11/10
 public void runtimeError(Exception ex) {
   try {
     Instruction instruction = null;
     Context context = null;
     if (ex instanceof EngineException) {
       instruction = ((EngineException) ex).instruction();
       context = ((EngineException) ex).context();
     }
     if (instruction == null) {
       instruction = activation.procedure().code()[ip];
     }
     if (context == null) {
       context = this;
     }
     activation.procedure().code()[ip].workspace.runtimeError(job.owner, context, instruction, ex);
   } catch (RuntimeException ex2) {
     // well we tried to report the original exception to the user,
     // but a new exception happened. so we'll report the original
     // using plan B. - ST 8/29/07
     org.nlogo.util.Exceptions.handle(ex);
   }
 }
  /**
   * Adds activation information for the given profile.
   *
   * @param mavenProfileDescriptor The profile descriptor.
   * @param activation The activation information.
   * @param store The database.
   */
  private void addActivation(
      MavenProfileDescriptor mavenProfileDescriptor, Activation activation, Store store) {
    if (null == activation) {
      return;
    }
    MavenProfileActivationDescriptor profileActivationDescriptor =
        store.create(MavenProfileActivationDescriptor.class);
    mavenProfileDescriptor.setActivation(profileActivationDescriptor);

    profileActivationDescriptor.setJdk(activation.getJdk());
    profileActivationDescriptor.setActiveByDefault(activation.isActiveByDefault());

    ActivationFile activationFile = activation.getFile();
    if (null != activationFile) {
      MavenActivationFileDescriptor activationFileDescriptor =
          store.create(MavenActivationFileDescriptor.class);
      profileActivationDescriptor.setActivationFile(activationFileDescriptor);
      activationFileDescriptor.setExists(activationFile.getExists());
      activationFileDescriptor.setMissing(activationFile.getMissing());
    }
    ActivationOS os = activation.getOs();
    if (null != os) {
      MavenActivationOSDescriptor osDescriptor = store.create(MavenActivationOSDescriptor.class);
      profileActivationDescriptor.setActivationOS(osDescriptor);
      osDescriptor.setArch(os.getArch());
      osDescriptor.setFamily(os.getFamily());
      osDescriptor.setName(os.getName());
      osDescriptor.setVersion(os.getVersion());
    }
    ActivationProperty property = activation.getProperty();
    if (null != property) {
      PropertyDescriptor propertyDescriptor = store.create(PropertyDescriptor.class);
      profileActivationDescriptor.setProperty(propertyDescriptor);
      propertyDescriptor.setName(property.getName());
      propertyDescriptor.setValue(property.getValue());
    }
  }
Пример #10
0
 // this method runs until the context is finished
 void runExclusive() {
   if (agent.id == -1) // is our agent dead?
   {
     finished = true;
     return;
   }
   Command command = null;
   try {
     do {
       command = activation.procedure().code()[ip];
       if ((agentBit & command.agentBits) == 0) {
         command.throwAgentClassException(this, agent.kind());
       }
       command.perform(this);
       if (command.world.comeUpForAir) {
         comeUpForAir(command);
       }
     } while (!finished);
   } catch (LogoException ex) {
     EngineException.rethrow(ex, this, command);
   }
 }
Пример #11
0
  /**
   * Modifies this map through a single backpropagation iteration using the given error values on
   * the output nodes.
   *
   * @param error
   */
  public void train(List<Double> error, double learningRate) {
    RealVector eOut = new ArrayRealVector(error.size());
    for (int i : series(error.size())) eOut.setEntry(i, error.get(i));

    // * gHidden: delta for the non-bias nodes of the hidden layer
    gHidden.setSubVector(0, stateHidden.getSubVector(0, n)); // optimize

    for (int i : Series.series(gHidden.getDimension()))
      gHidden.setEntry(i, activation.derivative(gHidden.getEntry(i)));

    eHiddenL = weights1.transpose().operate(eOut);
    eHidden.setSubVector(0, eHiddenL.getSubVector(0, h));
    for (int i : series(h)) eHidden.setEntry(i, eHidden.getEntry(i) * gHidden.getEntry(i));

    weights1Delta = MatrixTools.outer(eOut, stateHidden);
    weights1Delta = weights1Delta.scalarMultiply(-1.0 * learningRate); // optimize

    weights0Delta = MatrixTools.outer(eHidden, stateIn);
    weights0Delta = weights0Delta.scalarMultiply(-1.0 * learningRate);

    weights0 = weights0.add(weights0Delta);
    weights1 = weights1.add(weights1Delta);
  }
Пример #12
0
 // this method runs only until a command switches
 void stepConcurrent() {
   if (agent.id == -1) // is our agent dead?
   {
     finished = true;
     return;
   }
   Command command = null;
   try {
     do {
       command = activation.procedure().code()[ip];
       if ((agentBit & command.agentBits) == 0) {
         command.throwAgentClassException(this, agent.kind());
       }
       command.perform(this);
       if (command.world.comeUpForAir) {
         comeUpForAir(command);
       }
     } while (!command.switches && !finished);
   } catch (LogoException ex) {
     EngineException.rethrow(ex, this, command);
   } catch (StackOverflowError ex) {
     throw new EngineException(this, "stack overflow (recursion too deep)");
   }
 }
Пример #13
0
 public void returnFromProcedure() {
   ip = activation.returnAddress();
   activation = activation.parent();
 }