Nengo.ca

ca.nengo.math.impl
Class WeightedCostApproximator

java.lang.Object
  extended by ca.nengo.math.impl.WeightedCostApproximator
All Implemented Interfaces:
LinearApproximator, java.io.Serializable, java.lang.Cloneable

public class WeightedCostApproximator
extends java.lang.Object
implements LinearApproximator

A LinearApproximator in which error is evaluated at a fixed set of points, and the cost function that is minimized is a weighted integral of squared error.

Uses the Moore-Penrose pseudoinverse.

TODO: test

See Also:
Serialized Form

Nested Class Summary
static class WeightedCostApproximator.Factory
          An ApproximatorFactory that produces WeightedCostApproximators.
 
Constructor Summary
WeightedCostApproximator(float[][][] evaluationSignals, float[][][] values, Function costFunction, float noise, int nSV, boolean quiet)
           
WeightedCostApproximator(float[][] evaluationPoints, float[][] values, Function costFunction, float noise, int nSV)
           
WeightedCostApproximator(float[][] evaluationPoints, float[][] values, Function costFunction, float noise, int nSV, boolean quiet)
           
 
Method Summary
static boolean canUseGPU()
           
 LinearApproximator clone()
           
 float[] findCoefficients(float[] targetSignal)
          Similar to findCoefficients(ca.nengo.math.Function), but finds coefficients for a target signal (over time) rather than a target function.
 float[] findCoefficients(Function target)
          This implementation is adapted from Eliasmith & Anderson, 2003, appendix A.
 float[][] getEvalPoints()
           
static java.lang.String getGPUErrorMessage()
           
static boolean getUseGPU()
           
 float[][] getValues()
           
 double[][] pseudoInverse(double[][] matrix, float minSV, int nSV)
          Override this method to use a different pseudoinverse implementation (eg clustered).
static void setUseGPU(boolean use)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WeightedCostApproximator

public WeightedCostApproximator(float[][] evaluationPoints,
                                float[][] values,
                                Function costFunction,
                                float noise,
                                int nSV,
                                boolean quiet)
Parameters:
evaluationPoints - Points at which error is evaluated (should be uniformly distributed, as the sum of error at these points is treated as an integral over the domain of interest). Examples include vector inputs to an ensemble, or different points in time within different simulation regimes.
values - The values of whatever functions are being combined, at the evaluationPoints. Commonly neuron firing rates. The first dimension makes up the list of functions, and the second the values of these functions at each evaluation point.
costFunction - A cost function that weights squared error over the domain of evaluation points
noise - Standard deviation of Gaussian noise to add to values (to reduce sensitivity to simulation noise) as a proportion of the maximum absolute value over all values
nSV - Number of singular values to keep from the singular value decomposition (SVD)
quiet - Turn off logging?

WeightedCostApproximator

public WeightedCostApproximator(float[][][] evaluationSignals,
                                float[][][] values,
                                Function costFunction,
                                float noise,
                                int nSV,
                                boolean quiet)
Parameters:
evaluationSignals - Signals over which error is evaluated. First dimension is for each evaluation signal. Second dimension is for the dimensions of each signal. Third dimension is the value of the signal dimension over time.
values - The values of whatever functions are being combined, over the evaluation signals. Commonly neuron firing rates. The first dimension makes up the list of functions, the second the values of these functions for each evaluation signal, and the third the value of the function over time.
costFunction - A cost function that weights squared error over the domain of evaluation points
noise - Standard deviation of Gaussian noise to add to values (to reduce sensitivity to simulation noise) as a proportion of the maximum absolute value over all values
nSV - Number of singular values to keep from the singular value decomposition (SVD)
quiet - Turn off logging?

WeightedCostApproximator

public WeightedCostApproximator(float[][] evaluationPoints,
                                float[][] values,
                                Function costFunction,
                                float noise,
                                int nSV)
Parameters:
evaluationPoints - Points at which error is evaluated (should be uniformly distributed, as the sum of error at these points is treated as an integral over the domain of interest). Examples include vector inputs to an ensemble, or different points in time within different simulation regimes.
values - The values of whatever functions are being combined, at the evaluationPoints. Commonly neuron firing rates. The first dimension makes up the list of functions, and the second the values of these functions at each evaluation point.
costFunction - A cost function that weights squared error over the domain of evaluation points
noise - Standard deviation of Gaussian noise to add to values (to reduce sensitivity to simulation noise) as a proportion of the maximum absolute value over all values
nSV - Number of singular values to keep from the singular value decomposition (SVD)
Method Detail

setUseGPU

public static void setUseGPU(boolean use)
Parameters:
use - Use the GPU?

getUseGPU

public static boolean getUseGPU()
Returns:
Using the GPU?

canUseGPU

public static boolean canUseGPU()

getGPUErrorMessage

public static java.lang.String getGPUErrorMessage()

getEvalPoints

public float[][] getEvalPoints()
Specified by:
getEvalPoints in interface LinearApproximator
Returns:
Points at which target functions are evaluated. Each row (or float[]) corresponds to a single evaluation point. These points should usually be uniformly distributed, because the sum of error at these points is treated as an integral over the domain of interest.
See Also:
LinearApproximator.getEvalPoints()

getValues

public float[][] getValues()
Specified by:
getValues in interface LinearApproximator
Returns:
The values of component functions at the evaluation points. The first dimension makes up the list of functions, and the second the values of these functions at each evaluation point.
See Also:
LinearApproximator.getValues()

pseudoInverse

public double[][] pseudoInverse(double[][] matrix,
                                float minSV,
                                int nSV)
Override this method to use a different pseudoinverse implementation (eg clustered).

Parameters:
matrix - Any matrix
minSV - Hint as to smallest singular value to use
nSV - Max number of singular values to use
Returns:
The pseudoinverse of the given matrix

findCoefficients

public float[] findCoefficients(Function target)

This implementation is adapted from Eliasmith & Anderson, 2003, appendix A.

It solves PHI = GAMMA" UPSILON, where " denotes pseudoinverse, UPSILON_i = < cost(x) x a_i(x) >, and GAMMA_ij = < cost(x) a_i(x) a_j(x) >. <> denotes integration (the sum over eval points).

Specified by:
findCoefficients in interface LinearApproximator
Parameters:
target - Function to approximate
Returns:
coefficients on component functions which result in an approximation of the target
See Also:
LinearApproximator.findCoefficients(ca.nengo.math.Function)

findCoefficients

public float[] findCoefficients(float[] targetSignal)
Similar to findCoefficients(ca.nengo.math.Function), but finds coefficients for a target signal (over time) rather than a target function.

Parameters:
targetSignal - signal over time that the coefficients should fit to
Returns:
coefficients (weights on the output of each neuron)

clone

public LinearApproximator clone()
                         throws java.lang.CloneNotSupportedException
Specified by:
clone in interface LinearApproximator
Overrides:
clone in class java.lang.Object
Returns:
Valid clone
Throws:
java.lang.CloneNotSupportedException - if clone can't be made

Nengo.ca