NormalRandomSource.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.NormalRandom;
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;
/**
* 平均(デフォルト:0)から分散(デフォルト: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 NormalRandomSource<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 = "mean", description = "NormalRandomSource.2", update = true, internationalization = true)
private RS mean = this.sunit.create(0);
/** 分散 */
@Parameter(name = "variance", description = "NormalRandomSource.3", update = true, internationalization = true)
private RS variance = this.sunit.create(1);
/** 乱数のシード */
@Parameter(name = "seed", description = "NormalRandomSource.1", update = true, internationalization = true)
private long seed = 0L;
/** 乱数生成クラス */
private NormalRandom<RS, RM> random = new NormalRandom<>(this.sunit.createUniformRandomGenerator());
/**
* 新しく生成された<code>UniformRandomSource</code>オブジェクトを初期化します。
* @param sunit unit of scalar
*/
public NormalRandomSource(RS sunit) {
super(1, sunit);
}
/**
* {@inheritDoc}
*/
@Override
public RM outputEquation( final RS t) {
final RS y = this.random.nextValue().multiply(this.variance.sqrt()).add(this.mean);
RS[] yy = this.sunit.createArray(1);
yy[0]= y;
return this.sunit.createGrid(yy);
}
/**
* @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);
}
}