Package ptolemy.data

Examples of ptolemy.data.ArrayToken


    /** Check the dimensions of all parameters and ports.
     *  @exception IllegalActionException If the dimensions are illegal.
     */
    private void _checkParameters() throws IllegalActionException {
        // Check state variable names.
        ArrayToken stateNames = (ArrayToken) stateVariableNames.getToken();
        int n = stateNames.length();

        if (n < 1) {
            throw new IllegalActionException(this, "There must be at "
                    + "least one state variable for a differential system.");
        }

        // Check if any of the state variable names is an empty string.
        for (int i = 0; i < n; i++) {
            String name = (((StringToken) stateNames.getElement(i))
                    .stringValue()).trim();

            if (name.equals("")) {
                throw new IllegalActionException(this, "A state variable "
                        + "name should not be an empty string.");
View Full Code Here


     @exception IllegalActionException If there is no director.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        if (input.hasToken(0)) {
            ArrayToken token = (ArrayToken) input.get(0);

            if (token.length() == 0) {
                return;
            }

            Token sum = token.getElement(0);

            for (int i = 1; i < token.length(); i++) {
                sum = sum.add(token.getElement(i));
            }

            output.send(0, sum);
        }
    }
View Full Code Here

     *  coefficients, reflection coefficients, and prediction error power.
     *  @exception IllegalActionException If there is no director.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        ArrayToken autocorrelationValue = (ArrayToken) autocorrelation.get(0);
        int autocorrelationValueLength = autocorrelationValue.length();

        // If the length of the input is odd, then the order is
        // (length + 1)/2. Otherwise, it is 1 + length/2.
        // Both numbers are the result of integer division
        // (length + 2)/2.
        int order = autocorrelationValueLength / 2;

        DoubleToken[] power = new DoubleToken[order + 1];
        DoubleToken[] refl = new DoubleToken[order];
        DoubleToken[] lp = new DoubleToken[order];
        double[] a = new double[order + 1];
        double[] aP = new double[order + 1];
        double[] r = new double[order + 1];

        a[0] = 1.0;
        aP[0] = 1.0;

        // For convenience, read the autocorrelation lags into a vector.
        for (int i = 0; i <= order; i++) {
            r[i] = ((DoubleToken) autocorrelationValue
                    .getElement((autocorrelationValueLength - order + i) - 1))
                    .doubleValue();
        }

        // Output the zeroth order prediction error power, which is
        // simply the power of the input process.
        double P = r[0];
        power[0] = new DoubleToken(P);

        double gamma;

        // The order recurrence
        for (int M = 0; M < order; M++) {
            // Compute the new reflection coefficient.
            double deltaM = 0.0;

            for (int m = 0; m < (M + 1); m++) {
                deltaM += (a[m] * r[(M + 1) - m]);
            }

            // Compute and output the reflection coefficient
            // (which is also equal to the last AR parameter).
            if (SignalProcessing.close(P, 0.0)) {
                aP[M + 1] = gamma = 0.0;
            } else {
                aP[M + 1] = gamma = -deltaM / P;
            }

            refl[M] = new DoubleToken(-gamma);

            for (int m = 1; m < (M + 1); m++) {
                aP[m] = a[m] + (gamma * a[(M + 1) - m]);
            }

            // Update the prediction error power.
            P = P * (1.0 - (gamma * gamma));

            if ((P < 0.0) || SignalProcessing.close(P, 0.0)) {
                P = 0.0;
            }

            power[M + 1] = new DoubleToken(P);

            // Swap a and aP for next order recurrence.
            double[] temp = a;
            a = aP;
            aP = temp;
        }

        // Generate the lp outputs.
        for (int m = 1; m <= order; m++) {
            lp[m - 1] = new DoubleToken(-a[m]);
        }

        linearPredictor.broadcast(new ArrayToken(BaseType.DOUBLE, lp));
        reflectionCoefficients.broadcast(new ArrayToken(BaseType.DOUBLE, refl));
        errorPower.broadcast(new ArrayToken(BaseType.DOUBLE, power));
    }
View Full Code Here

     @exception IllegalActionException If there is no director.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        if (input.hasToken(0)) {
            ArrayToken token = (ArrayToken) table.getToken();

            if (token != null) {
                int indexValue = ((IntToken) input.get(0)).intValue();

                if ((indexValue >= 0) && (indexValue < token.length())) {
                    output.broadcast(token.getElement(indexValue));
                }
            }
        }
    }
View Full Code Here

    public void fire() throws IllegalActionException {
        super.fire();
        if ((enable.getWidth() == 0)
                || (enable.hasToken(0) && ((BooleanToken) enable.get(0))
                        .booleanValue())) {
            ArrayToken valuesArray = (ArrayToken) values.getToken();

            if (_currentIndex < valuesArray.length()) {
                output.send(0, valuesArray.getElement(_currentIndex));
                _outputProduced = true;
            }
        }
    }
View Full Code Here

    public boolean postfire() throws IllegalActionException {
        if (_outputProduced) {
            _outputProduced = false;
            _currentIndex += 1;

            ArrayToken valuesArray = (ArrayToken) values.getToken();

            if (_currentIndex >= valuesArray.length()) {
                boolean repeatValue = ((BooleanToken) repeat.getToken())
                        .booleanValue();

                if (repeatValue) {
                    _currentIndex = 0;
                } else {
                    boolean holdLastOutputValue = ((BooleanToken) holdLastOutput
                            .getToken()).booleanValue();
                    if (holdLastOutputValue) {
                        // To repeatedly produce the last output.
                        _currentIndex = valuesArray.length() - 1;
                    } else {
                        // To prevent overflow.
                        _currentIndex = valuesArray.length();
                    }
                }
            }
        }
View Full Code Here

                throw new IllegalActionException(this,
                        "meanTime is required to be positive.  meanTime given: "
                                + mean);
            }
        } else if (attribute == values) {
            ArrayToken val = (ArrayToken) (values.getToken());
            _length = val.length();
        } else {
            super.attributeChanged(attribute);
        }
    }
View Full Code Here

    ////                         private methods                   ////

    /* Get the specified value, checking the form of the values parameter.
     */
    private Token _getValue(int index) throws IllegalActionException {
        ArrayToken val = (ArrayToken) (values.getToken());

        if ((val == null) || (index >= _length)) {
            throw new IllegalActionException(this,
                    "Index out of range of the values parameter.");
        }

        return val.getElement(index);
    }
View Full Code Here

     @exception IllegalActionException If there is no director.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        if (input.hasToken(0)) {
            ArrayToken token = (ArrayToken) input.get(0);

            if (token.length() == 0) {
                return;
            }

            Token sum = token.getElement(0);

            for (int i = 1; i < token.length(); i++) {
                sum = sum.add(token.getElement(i));
            }

            output.send(0, sum.divide(new IntToken(token.length())));
        }
    }
View Full Code Here

            // Check the argument lengths.
            for (int i = 0; i < argValues.length; i++) {
                if (_reducedArgs[i]) {
                    if (argValues[i] instanceof ArrayToken) {
                        ArrayToken arrayToken = (ArrayToken) argValues[i];

                        if ((dim != 0) && (arrayToken.length() != dim)) {
                            throw new IllegalActionException("Argument " + i
                                    + " is a reducible arrayToken that "
                                    + "does not have compatible length!");
                        } else {
                            dim = arrayToken.length();
                        }
                    } else {
                        throw new IllegalActionException("Argument " + i
                                + " is not an instance of " + "ArrayToken!");
                    }
                }
            }

            // Collect the not reducible args.
            // Kepler (jdk1.4?) requires this cast
            Object[] subArgs = (Object[]) argValues.clone();
            ptolemy.data.Token[] tokenArray = new ptolemy.data.Token[dim];

            for (int j = 0; j < dim; j++) {
                for (int i = 0; i < argValues.length; i++) {
                    if (_reducedArgs[i]) {
                        subArgs[i] = ((ArrayToken) argValues[i]).getElement(j);
                    }
                }

                tokenArray[j] = _cachedMethod.invoke(subArgs);
            }

            return new ArrayToken(tokenArray);
        }
View Full Code Here

TOP

Related Classes of ptolemy.data.ArrayToken

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.