Beispiel #1
0
  /**
   * @param samples The number of input vectors the error is sampled over
   * @return Mean-squared error of this origin over randomly selected points
   */
  public float[] getError(int samples) {
    float[] result = new float[getDimensions()];

    if (myNode instanceof NEFEnsemble) {
      NEFEnsemble ensemble = (NEFEnsemble) myNode;

      VectorGenerator vg = new RandomHypersphereVG(false, 1, 0);
      float[][] unscaled = vg.genVectors(samples, ensemble.getDimension());
      float[][] input = new float[unscaled.length][];
      for (int i = 0; i < input.length; i++) {
        input[i] = MU.prodElementwise(unscaled[i], ensemble.getRadii());
      }

      float[][] idealOutput = NEFUtil.getOutput(this, input, SimulationMode.DIRECT);
      float[][] actualOutput = NEFUtil.getOutput(this, input, SimulationMode.CONSTANT_RATE);

      float[][] error = MU.transpose(MU.difference(actualOutput, idealOutput));
      for (int i = 0; i < error.length; i++) {
        result[i] = MU.prod(error[i], error[i]) / error[i].length;
      }
    } else {
      ourLogger.warn(
          "Can't calculate error of a DecodedOrigin unless it belongs to an NEFEnsemble");
    }

    return result;
  }
Beispiel #2
0
  /**
   * With this constructor the target is a signal over time rather than a function.
   *
   * @param node The parent Node
   * @param name As in other constructor
   * @param nodes As in other constructor
   * @param nodeOrigin Name of the Origin on each given node from which output is to be decoded
   * @param targetSignal Signal over time that this origin should produce.
   * @param approximator A LinearApproximator that can be used to approximate new signals as a
   *     weighted sum of the node outputs.
   */
  public DecodedOrigin(
      Node node,
      String name,
      Node[] nodes,
      String nodeOrigin,
      TimeSeries targetSignal,
      LinearApproximator approximator)
      throws StructuralException {

    myNode = node;
    myName = name;
    myNodes = nodes;
    myNodeOrigin = nodeOrigin;
    myFunctions = new FixedSignalFunction[targetSignal.getDimension()];
    for (int i = 0; i < targetSignal.getDimension(); i++) // these are only used in direct mode
    myFunctions[i] = new FixedSignalFunction(targetSignal.getValues(), i);
    myDecoders = findDecoders(nodes, MU.transpose(targetSignal.getValues()), approximator);
    myMode = SimulationMode.DEFAULT;
    myIntegrator = new EulerIntegrator(.001f);

    reset(false);
  }