📄 mexicanhat.java
字号:
* Gets the upper and lower boundary for the range of x * * @return the string containing the upper and lower boundary for * the range of x, separated by .. */ protected String getRange() { String fromTo = "" + Utils.doubleToString(getMinRange(), 2) + ".." + Utils.doubleToString(getMaxRange(), 2); return fromTo; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ protected String rangeTipText() { return "The upper and lower boundary for the range x is drawn from randomly."; } /** * returns the default min range * * @return the default min range */ protected double defaultMinRange() { return -10; } /** * Sets the lower boundary for the range of x * * @param value the lower boundary */ public void setMinRange(double value) { m_MinRange = value; } /** * Gets the lower boundary for the range of x * * @return the lower boundary for the range of x */ public double getMinRange() { return m_MinRange; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String minRangeTipText() { return "The lower boundary for the range x is drawn from randomly."; } /** * returns the default max range * * @return the default max range */ protected double defaultMaxRange() { return 10; } /** * Sets the upper boundary for the range of x * * @param value the upper boundary */ public void setMaxRange(double value) { m_MaxRange = value; } /** * Gets the upper boundary for the range of x * * @return the upper boundary for the range of x */ public double getMaxRange() { return m_MaxRange; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String maxRangeTipText() { return "The upper boundary for the range x is drawn from randomly."; } /** * returns the default gaussian noise rate * * @return the default gaussian noise rate */ protected double defaultNoiseRate() { return 0.0; } /** * Gets the gaussian noise rate. * * @return the gaussian noise rate */ public double getNoiseRate() { return m_NoiseRate; } /** * Sets the gaussian noise rate. * * @param value the gaussian noise rate */ public void setNoiseRate(double value) { m_NoiseRate = value; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String noiseRateTipText() { return "The gaussian noise rate to use."; } /** * returns the default variance of the noise rate * * @return the default variance of the noise rate */ protected double defaultNoiseVariance() { return 1.0; } /** * Gets the noise variance * * @return the noise variance */ public double getNoiseVariance() { return m_NoiseVariance; } /** * Sets the noise variance * * @param value the noise variance */ public void setNoiseVariance(double value) { if (value > 0) m_NoiseVariance = value; else throw new IllegalArgumentException( "Noise variance needs to be > 0 (provided: " + value + ")!"); } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String noiseVarianceTipText() { return "The noise variance to use."; } /** * Return if single mode is set for the given data generator * mode depends on option setting and or generator type. * * @return single mode flag * @throws Exception if mode is not set yet */ public boolean getSingleModeFlag() throws Exception { return true; } /** * Initializes the format for the dataset produced. * Must be called before the generateExample or generateExamples * methods are used. * Re-initializes the random number generator with the given seed. * * @return the format for the dataset * @throws Exception if the generating of the format failed * @see #getSeed() */ public Instances defineDataFormat() throws Exception { FastVector atts; m_Random = new Random(getSeed()); m_NoiseRandom = new Random(getSeed()); // number of examples is the same as given per option setNumExamplesAct(getNumExamples()); // initialize dataset format atts = new FastVector(); atts.addElement(new Attribute("x")); atts.addElement(new Attribute("y")); m_DatasetFormat = new Instances(getRelationNameToUse(), atts, 0); return m_DatasetFormat; } /** * Generates one example of the dataset. * * @return the generated example * @throws Exception if the format of the dataset is not yet defined * @throws Exception if the generator only works with generateExamples * which means in non single mode */ public Instance generateExample() throws Exception { Instance result; Random rand; double x; double y; double[] atts; result = null; rand = getRandom(); if (m_DatasetFormat == null) throw new Exception("Dataset format not defined."); // generate attributes atts = new double[m_DatasetFormat.numAttributes()]; // random x x = rand.nextDouble(); // fit into range x = x * (getMaxRange() - getMinRange()) + getMinRange(); // generate y if (Utils.eq(x, 0)) y = getAmplitude(); else y = getAmplitude() * StrictMath.sin(StrictMath.abs(x)) / StrictMath.abs(x); // noise y = y + getAmplitude() * m_NoiseRandom.nextGaussian() * getNoiseRate() * getNoiseVariance(); atts[0] = x; atts[1] = y; result = new Instance(1.0, atts); // dataset reference result.setDataset(m_DatasetFormat); return result; } /** * Generates all examples of the dataset. Re-initializes the random number * generator with the given seed, before generating instances. * * @return the generated dataset * @throws Exception if the format of the dataset is not yet defined * @throws Exception if the generator only works with generateExample, * which means in single mode * @see #getSeed() */ public Instances generateExamples() throws Exception { Instances result; int i; result = new Instances(m_DatasetFormat, 0); m_Random = new Random(getSeed()); for (i = 0; i < getNumExamplesAct(); i++) result.add(generateExample()); return result; } /** * Generates a comment string that documentates the data generator. * By default this string is added at the beginning of the produced output * as ARFF file type, next after the options. * * @return string contains info about the generated rules */ public String generateStart () { return ""; } /** * Generates a comment string that documentats the data generator. * By default this string is added at the end of theproduces output * as ARFF file type. * * @return string contains info about the generated rules * @throws Exception if the generating of the documentaion fails */ public String generateFinished() throws Exception { return ""; } /** * Main method for testing this class. * * @param args should contain arguments for the data producer: */ public static void main(String[] args) { runDataGenerator(new MexicanHat(), args); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -