public LinearExponentialTermination clone(Node node) throws CloneNotSupportedException {
   LinearExponentialTermination result = (LinearExponentialTermination) super.clone();
   result.myNode = node;
   result.myWeights = myWeights.clone();
   result.saveWeights();
   //		result.myWeightProbabilities = myWeightProbabilities.clone();
   result.myRawInput = (myRawInput != null) ? myRawInput.clone() : null;
   //		result.myRawInput = null;
   return result;
 }
  /**
   * @param values Can be either SpikeOutput or RealOutput
   * @see ca.nengo.model.Termination#setValues(ca.nengo.model.InstantaneousOutput)
   */
  public void setValues(InstantaneousOutput values) throws SimulationException {
    if (values.getDimension() != getDimensions()) {
      throw new SimulationException("Input must have dimension " + getDimensions());
    }

    myRawInput = values;

    myPreciseSpikeInputTimes =
        (values instanceof PreciseSpikeOutput)
            ? ((PreciseSpikeOutput) values).getSpikeTimes()
            : null;
    myIntegrationTime =
        0; // start at the beginning of these spike times (given as an offset increasing from the
           // previous time step)
    myNetSpikeInput =
        (values instanceof SpikeOutput && myPreciseSpikeInputTimes == null)
            ? combineSpikes((SpikeOutput) values, myWeights)
            : 0;

    // convert precise spike times that happen right at the beginning of the time window
    //  to be handled separately (we really don't need this, but I'm paranoid about losing
    //  single spikes that happen right at the step boundaries)
    if (myPreciseSpikeInputTimes != null) {
      if (myWeightProbabilities != null) {
        for (int i = 0; i < myPreciseSpikeInputTimes.length; i++) {
          if ((myPreciseSpikeInputTimes[i] == 0f)
              && (random.nextFloat() < myWeightProbabilities[i])) {
            myNetSpikeInput += myWeights[i];
          }
        }
      } else {
        for (int i = 0; i < myPreciseSpikeInputTimes.length; i++) {
          if (myPreciseSpikeInputTimes[i] == 0f) {
            myNetSpikeInput += myWeights[i];
          }
        }
      }
    }

    myNetRealInput =
        (values instanceof RealOutput) ? combineReals((RealOutput) values, myWeights) : 0;
  }
示例#3
0
  /**
   * Must be called at each time step after Nodes are run and before getValues().
   *
   * @param state Idealized state (as defined by inputs) which can be fed into (idealized) functions
   *     that make up the Origin, when it is running in DIRECT mode. This is not used in other
   *     modes, and can be null.
   * @param startTime simulation time of timestep onset
   * @param endTime simulation time of timestep end
   * @throws SimulationException If the given state is not of the expected dimension (ie the input
   *     dimension of the functions provided in the constructor)
   */
  public void run(float[] state, float startTime, float endTime) throws SimulationException {
    if (state != null && state.length != myFunctions[0].getDimension()) {
      throw new SimulationException(
          "Origin dimension is "
              + myFunctions[0].getDimension()
              + " but state dimension is "
              + state.length);
    }

    float[] values = new float[myFunctions.length];
    float stepSize = endTime - startTime;

    mySTPHistory = new float[myNodes.length];
    if (myMode == SimulationMode.DIRECT) {
      for (int i = 0; i < values.length; i++) {
        values[i] = myFunctions[i].map(state);
      }
    } else if (myMode == SimulationMode.EXPRESS) {
      for (int i = 0; i < values.length; i++) {
        values[i] = myFunctions[i].map(state);
      }

      // create default ExpressModel if necessary ...
      if (myExpressModel == null) {
        myExpressModel = new DefaultExpressModel(this);
      }

      values = myExpressModel.getOutput(startTime, state, values);
    } else {
      for (int i = 0; i < myNodes.length; i++) {
        try {
          InstantaneousOutput o = myNodes[i].getOrigin(myNodeOrigin).getValues();

          float val = 0;
          if (o instanceof SpikeOutput) {
            val = ((SpikeOutput) o).getValues()[0] ? 1f / stepSize : 0f;
          } else if (o instanceof RealOutput) {
            val = ((RealOutput) o).getValues()[0];
          } else {
            throw new Error(
                "Node output is of type "
                    + o.getClass().getName()
                    + ". DecodedOrigin can only deal with RealOutput and SpikeOutput, so it apparently has to be updated");
          }

          float[] decoder = getDynamicDecoder(i, val, startTime, endTime);
          for (int j = 0; j < values.length; j++) {
            values[j] += val * decoder[j];
          }
        } catch (StructuralException e) {
          throw new SimulationException(e);
        }
      }
    }

    if (myNoise != null) {
      for (int i = 0; i < values.length; i++) {
        values[i] = myNoises[i].getValue(startTime, endTime, values[i]);
      }
    }

    myTime = endTime;
    myOutput = new RealOutputImpl(values, Units.UNK, endTime);
  }