UniformRandomSource.java
/*
* Created on 2008/06/02
* Copyright (C) 2008 Koga Laboratory. All rights reserved.
*
*/
package org.mklab.tool.control.system.source;
import org.mklab.nfc.matrix.ComplexNumericalMatrix;
import org.mklab.nfc.matrix.RealNumericalMatrix;
import org.mklab.nfc.random.RandomGenerator;
import org.mklab.nfc.scalar.ComplexNumericalScalar;
import org.mklab.nfc.scalar.RealNumericalScalar;
import org.mklab.tool.control.system.parameter.Parameter;
import org.mklab.tool.control.system.parameter.ParameterUpdator;
import org.mklab.tool.control.system.parameter.StringExternalizable;
/**
* 最小値(デフォルト:-1)から最大値(デフォルト:1)の範囲の一様分布の乱数を生成するシステムを表わすクラスです。
*
* @author koga
* @version $Revision: 1.4 $, 2008/06/02
* @param <RS> type of real scalar
* @param <RM> type of real matrix
* @param <CS> type of complex scalar
* @param <CM> type of complex matrix
*/
public class UniformRandomSource<RS extends RealNumericalScalar<RS,RM,CS,CM>, RM extends RealNumericalMatrix<RS,RM,CS,CM>, CS extends ComplexNumericalScalar<RS,RM,CS,CM>, CM extends ComplexNumericalMatrix<RS,RM,CS,CM>> extends ContinuousSource<RS,RM,CS,CM> implements ParameterUpdator, StringExternalizable {
/** 最小値 */
@Parameter(name = "minimum", description = "UniformRandomSource.2", update = true, internationalization = true)
private RS minimum = this.sunit.create(1).unaryMinus();
/** 最大値 */
@Parameter(name = "maximum", description = "UniformRandomSource.3", update = true, internationalization = true)
private RS maximum = this.sunit.create(1);
/** 乱数のシード */
@Parameter(name = "seed", description = "UniformRandomSource.1", update = true, internationalization = true)
private long seed = 0L;
/** 乱数生成クラス */
private RandomGenerator<RS, RM> random = this.sunit.createUniformRandomGenerator();
/**
* 新しく生成された<code>UniformRandomSource</code>オブジェクトを初期化します。
* @param sunit unit of scalar
*/
public UniformRandomSource(RS sunit) {
super(1, sunit);
}
/**
* {@inheritDoc}
*/
@Override
public RM outputEquation(final RS t) {
final RS y = this.random.nextValue().multiply(this.maximum.subtract(this.minimum)).add(this.minimum);
RS[] oo = this.sunit.createArray(1);
oo[0] = y;
return this.sunit.createGrid(oo);
}
/**
* @see org.mklab.tool.control.system.continuous.BaseContinuousStaticSystem#initialize()
*/
@Override
public void initialize() {
super.initialize();
this.random.setSeed(this.seed);
}
/**
* @see org.mklab.tool.control.system.parameter.ParameterUpdator#updateWith(java.lang.String)
*/
public boolean updateWith(String parameter) {
if (parameter.equals("seed")) { //$NON-NLS-1$
this.random.setSeed(this.seed);
return true;
}
return false;
}
/**
* @see org.mklab.tool.control.system.parameter.StringExternalizable#getString(java.lang.String)
*/
@Override
public String getString(String key) {
return Messages.getString(key);
}
}