Package jsynoptic.builtin

Source Code of jsynoptic.builtin.GaussianRandomSource$OptionPanel

/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2003, by :
*     Corporate:
*         Astrium SAS
*         EADS CRC
*     Individual:
*         Nicolas Brodu
*
* $Id: GaussianRandomSource.java,v 1.3 2004/01/29 11:09:42 brodu Exp $
*
* Changes
* -------
* 21-Jan-2004 : Creation date (NB);
*
*/
package jsynoptic.builtin;

import simtools.data.DataSource;
import simtools.util.NumberStringComparator;
import jsynoptic.data.DataSourceAnimator;

/**
* Generate numbers using a gaussian distribution
*/
public class GaussianRandomSource extends RandomSource {

    public static final String ID_PREFIX = "GaussianRandomSource:";
   
    protected void setInfo() {
        info.comment = resources.getString("gaussianSourceComment");
        info.id = ID_PREFIX + info.id;
    }
   
    /**
     * @param mean
     * @param stdDev
     */
    public GaussianRandomSource(String name, double mean, double stdDev) {
        super(name, mean, stdDev);
        setInfo();
    }

    /**
     * @param mean
     * @param stdDev
     * @param nSamples
     */
    public GaussianRandomSource(String name, double mean, double stdDev, long nSamples) {
        super(name, mean, stdDev, nSamples);
        setInfo();
    }

    /**
     * @param seed
     * @param mean
     * @param stdDev
     */
    public GaussianRandomSource(String name, long seed, double mean, double stdDev) {
        super(name, seed, mean, stdDev);
        setInfo();
    }

    /**
     * @param seed
     * @param mean
     * @param stdDev
     * @param nSamples
     */
    public GaussianRandomSource(String name, long seed, double mean, double stdDev,
            long nSamples) {
        super(name, seed, mean, stdDev, nSamples);
        setInfo();
    }

    /* (non-Javadoc)
     * @see jsynoptic.builtin.RandomSource#nextRandomValue()
     */
    protected double nextRandomValue() {
        // convert the random variable from N(0,1) to N(param1, param2) where
        // param2 is the standard deviation and param1 the mean
        return param1 + param2 * generator.nextGaussian();
    }

    /**
     * @return Returns the mean.
     */
    public double getMean() {
        return param1;
    }

    /**
     * @return Returns the standard deviation.
     */
    public double getStandardDeviation() {
        return param2;
    }

    public static class OptionPanel extends RandomSource.OptionPanel {

        /* (non-Javadoc)
         * @see jsynoptic.builtin.RandomSource.OptionPanel#param1Name()
         */
        protected String param1Name() {
            return resources.getString("mean");
        }

        /* (non-Javadoc)
         * @see jsynoptic.builtin.RandomSource.OptionPanel#param2Name()
         */
        protected String param2Name() {
            return resources.getString("variance");
        }

        /* (non-Javadoc)
         * @see jsynoptic.builtin.RandomSource.OptionPanel#createSource()
         */
        public DataSource createSource(String name) {
           
            DataSource urs;
            Number seed = null;
            if (cbSeed.isSelected()) seed = NumberStringComparator.stringToNumber(tfSeed.getText());
            if (rbDynamic.isSelected()) {
                Number period = NumberStringComparator.stringToNumber(tfPeriod.getText());
                if (period==null) period = new Long(1000);
                if (seed!=null) urs = new DataSourceAnimator(new GaussianRandomSource(name, seed.longValue(), nfParam1.getDoubleValue(), nfParam2.getDoubleValue()), (int)nfSize.getLongValue(), period.intValue());
                else urs = new DataSourceAnimator(new GaussianRandomSource(name, nfParam1.getDoubleValue(), nfParam2.getDoubleValue()), (int)nfSize.getLongValue(), period.intValue());
            }
            else {
                if (seed!=null) urs = new GaussianRandomSource(name, seed.longValue(), nfParam1.getDoubleValue(), nfParam2.getDoubleValue(), nfSize.getLongValue());
                else urs = new GaussianRandomSource(name, nfParam1.getDoubleValue(), nfParam2.getDoubleValue(), nfSize.getLongValue());
            }
            return urs;
           
        }
       
    }
   
}
TOP

Related Classes of jsynoptic.builtin.GaussianRandomSource$OptionPanel

TOP
Copyright © 2018 www.massapi.com. 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.