Package ca.nengo.math

Examples of ca.nengo.math.Function


     *      Creates the function through reflection of its constructor and
     *      passing the user parameters to it
     */
    public void completeConfiguration(ConfigResult props) throws ConfigException {
        try {
            Function function = createFunction(props);
            setFunction(function);
        } catch (Exception e) {
            throw new ConfigException("Error creating function");
        }
    }
View Full Code Here


        }
    }

    public ConfigSchema getSchema() {
        if (getFunction() != null) {
            Function func = getFunction();
            for (int i = 0; i < myProperties.length; i++) {
                Property property = myProperties[i];
                String getterName = getterNames[i];
                try {
                    Object result = func.getClass().getMethod(getterName).invoke(func);
                    property.setDefaultValue(result);
                } catch (NoSuchMethodException e) {
                  e.printStackTrace();
                } catch (SecurityException e) {
                  e.printStackTrace();
View Full Code Here

    private Function parseFunction(ConfigResult props) throws ConfigException {
        String expression = (String) props.getValue(pExpression);
//        int dimensions = (Integer) props.getValue(DIMENSION_STR);
        int dimensions = (Integer) props.getValue(pDimensions);

        Function function;
        try {
            function = interpreter.parse(expression, dimensions);
        } catch (Exception e) {
            throw new ConfigException(e.getMessage());
        }
View Full Code Here

                    ConfigResult props = ConfigManager.configure(new Property[] { pFnName,
                            pFunction }, "Register fuction", FunctionDialog.this,
                            ConfigMode.TEMPLATE_NOT_CHOOSABLE);

                    String name = (String) props.getValue(pFnName);
                    Function fn = (Function) props.getValue(pFunction);

                    interpreter.registerFunction(name, fn);
                    registeredFunctionsList.addItem(name);
                } catch (ConfigException e1) {
                    e1.defaultHandleBehavior();
View Full Code Here

        class PreviewFunctionAL implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                String functionName = (String) registeredFunctionsList.getSelectedItem();

                if (functionName != null) {
                    Function function = interpreter.getRegisteredFunctions().get(functionName);

                    if (function != null) {
                        PlotFunctionAction action = new PlotFunctionAction("Function preview",
                                function, FunctionDialog.this);
                        action.doAction();
View Full Code Here

            }

            /*
             * Configure the function
             */
            Function function = selectedConfigurableFunction.configureFunction(parent);

            setValue(function);
        } else {
            UserMessages.showError("Could not attach properties dialog");
        }
View Full Code Here

  public static void main(String[] args) {

    final float rl = 0.2f; //resting length

    float tauEA = .05f;
    Function CEForceLength = new ConstantFunction(1, 1f);

    final float vmax = -2f;
    final float af = 1f; //shaping parameter between 0.1 and 1
    Function CEForceVelocity = new AbstractFunction(1) {
      private static final long serialVersionUID = 1L;
      public float map(float[] from) {
        return Math.min(1.3f, (1 - from[0]/vmax) / (1 + from[0]/(vmax*af)));
      }
    };

    Function SEForceLength = new AbstractFunction(1) {
      private static final long serialVersionUID = 1L;
      public float map(float[] from) {
        return 200f * ( (float) Math.exp(200f*from[0]) - 1f );
      }
    };
View Full Code Here


      ourLogger.info("force: " + force + " lm: " + lm + " vm: " + vm + " a: " + a + " dadt: " + dadt);

      //find velocity corresponding to this multiplier
      final Function fv = myCEForceVelocity;
      Function f = new AbstractFunction(1) {
        private static final long serialVersionUID = 1L;

        public float map(float[] from) {
          float result = fv.map(from) - vm;
          //System.out.println("from: " + from[0] + " result: " + result);
View Full Code Here

    public ConfigSchema getSchema() {
        Property[] props = new Property[outputDimension];

        for (int i = 0; i < outputDimension; i++) {

            Function defaultValue = null;

            if (defaultValues != null && i < defaultValues.length && defaultValues[i] != null) {
                defaultValue = defaultValues[i];

            }
View Full Code Here

  /*
   * Test method for 'ca.nengo.math.impl.LinearCurveFitter.fit()'
   */
  public void testFindCoefficients() {
    Function target = new Polynomial(new float[]{1f,4f,-3f,0.5f});
    CurveFitter lcf = new LinearCurveFitter();
    float[][] values = new float[2][10];
   
    for (int i=0; i<values[0].length; i++) {
      values[0][i] = -9 + i * 2;
      values[1][i] = target.map(new float[]{values[0][i]});
    }
   
    Function fitted = lcf.fit(values[0], values[1]);
   
//    Plotter.plot(target, -10, 0.1f, 10, "target");
//    Plotter.plot(fitted, -10, 0.5f, 10, "fitted");
   
    float targetVal = 0f;
    float fittedVal = 0f;
    for (int i=-8; i<9; i=i+2) {
      targetVal = target.map(new float[]{i});
      fittedVal = fitted.map(new float[]{i});
      TestUtil.assertClose(targetVal, fittedVal, 15f);
    }
 
  }
View Full Code Here

TOP

Related Classes of ca.nengo.math.Function

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.