List of usage examples for org.apache.commons.math3.analysis.function Gaussian value
public DerivativeStructure value(final DerivativeStructure t)
From source file:com.velonuboso.made.core.common.MadePattern.java
public static double gaussian(double value, double target, double amplitude) { Gaussian g = new Gaussian(); return g.value(3 * (target - value) / amplitude); }
From source file:com.velonuboso.made.core.common.Helper.java
public static double getGaussian(float ratio, Float from, Float to) { Gaussian gaussian = new Gaussian(); if (from == null && to == null) { return 1; } else if (from == null) { from = 1 - to;//from ww w .j a v a 2 s . c o m } else if (to == null) { to = 2 - from; } float target = (from + to) / 2f; float amplitude = to - from; return gaussian.value((ratio - target) / amplitude) / 0.40; }
From source file:net.sf.mzmine.chartbasics.HistogramChartFactory.java
/** * Adds a Gaussian curve to the plot/*from w w w .j a v a 2 s . co m*/ * * @param plot * @param fit double[] {normFactor, mean, sigma} * @param drawStart start of curve * @param drawEnd end of curve * @param gMin lower bound of Gaussian fit * @param gMax upper bound of Gaussian fit * @param sigDigits number of significant digits * @return */ public static double[] addGaussianFit(XYPlot plot, double[] fit, double drawStart, double drawEnd, double gMin, double gMax, int sigDigits, boolean annotations) { double gWidth = gMax - gMin; Gaussian g = new Gaussian(fit[0], fit[1], fit[2]); // create xy series for gaussian String mean = Precision.toString(fit[1], sigDigits, 7); String sigma = Precision.toString(fit[2], sigDigits, 7); String norm = Precision.toString(fit[0], sigDigits, 7); XYSeries gs = new XYSeries( "Gaussian: " + mean + " \u00B1 " + sigma + " [" + norm + "] (mean \u00B1 sigma [normalisation])"); // add lower dp number out of gaussian fit range int steps = 100; if (gMin > drawStart) { for (int i = 0; i <= steps; i++) { double x = drawStart + ((gMin - drawStart) / steps) * i; double y = g.value(x); gs.add(x, y); } } // add high resolution in gaussian fit area steps = 1000; for (int i = 0; i <= steps; i++) { double x = gMin + (gWidth / steps) * i; double y = g.value(x); gs.add(x, y); } // add lower dp number out of gaussian fit range steps = 100; if (gMax < drawEnd) { for (int i = 0; i <= steps; i++) { double x = gMax + ((drawEnd - gMax) / steps) * i; double y = g.value(x); gs.add(x, y); } } // add gaussian XYSeriesCollection gsdata = new XYSeriesCollection(gs); int index = plot.getDatasetCount(); plot.setDataset(index, gsdata); plot.setRenderer(index, new XYLineAndShapeRenderer(true, false)); if (annotations) addGaussianFitAnnotations(plot, fit); return fit; }
From source file:streaming.core.WindowOperation.java
@Override public Object[][] process(Object[] event) { long day = (Long) event[0]; String word = (String) event[1]; long freqs = (Long) event[2]; TreeMap<Long, Long> sortedFreq = map.get(word); if (sortedFreq == null) { sortedFreq = new TreeMap<Long, Long>(); map.put(word, sortedFreq);//from w w w . ja v a 2 s . c o m } Long t = sortedFreq.get(day); if (t != null) { freqs = freqs + t; } sortedFreq.put(day, freqs); Iterator<Entry<Long, Long>> iterator = sortedFreq.headMap(1 + day - numberOfDays).entrySet().iterator(); while (iterator.hasNext()) { iterator.next(); iterator.remove(); } DescriptiveStatistics stats = new DescriptiveStatistics(); long dayIndex = 1 + day - numberOfDays; for (Entry<Long, Long> e : sortedFreq.entrySet()) { while (e.getKey() > dayIndex) { dayIndex++; stats.addValue(0); } stats.addValue(e.getValue()); } if (sortedFreq.size() > numberOfDays) { System.out.println(day + " size=" + sortedFreq.size() + " " + sortedFreq); } double mean = stats.getMean(); double meadian = stats.getPercentile(50); mean = (mean == 0) ? 1 : mean; meadian = (meadian == 0) ? 1 : meadian; double stddev = stats.getStandardDeviation(); stddev = (stddev == 0) ? 1 : stddev; double cov = stddev / mean; //double swna = Math.log(freqs)*freqs/stats.getMean(); double swna1 = Math.log(meadian) * Math.abs(freqs - meadian) / stddev; if (Double.isNaN(swna1)) { System.out.println(); } double swna2 = Math.abs(freqs - meadian) / stddev; double swna3 = freqs / (meadian * cov); Gaussian gaussian = new Gaussian(100, 50); double swna4 = (0.1 + 100 * gaussian.value(meadian)) * freqs / (meadian * cov); int percentageAvialableValues = Math.round(100 * sortedFreq.size() / numberOfDays); //System.out.println("#"+ word + " " + freqs + " "+ stats.getMean() + Arrays.toString(stats.getValues())); return new Object[][] { { day, word, swna1, freqs, stats.getMean(), meadian, stddev, swna2, swna3, swna4, cov, percentageAvialableValues } }; // if(freqs > 3 && swna> 5){ // return new Object[][]{{day, word, swna}}; // }else{ // return null; // } }
From source file:tools.descartes.dlim.extractor.ModelExtractor.java
private static double[] createGaussianFilter(int width) { int filterWidth = width; if (filterWidth % 2 == 0) { filterWidth++;/* w w w .ja v a 2 s.c o m*/ } filterWidth = Math.max(1, filterWidth); double[] filter = new double[filterWidth]; double sigma = Math.sqrt((filterWidth * filterWidth - 1.0) / 12.0); int mean = filterWidth / 2; double filterSum = 0.0; Gaussian gaussian = new Gaussian(mean, sigma); for (int i = 0; i < filterWidth; i++) { filter[i] = gaussian.value(i); filterSum += filter[i]; } // normalize to 1 for (int i = 0; i < filterWidth; i++) { filter[i] = filter[i] / filterSum; } return filter; }
From source file:utils.TestGaussian.java
public static void main(String[] args) { Gaussian gaussian = new Gaussian(100, 50); for (int i = 0; i < 1000; i++) { int x = 10 * i; System.out.println(x + " = " + String.format("%.2f", 0.1 + 100 * gaussian.value(x))); }//w w w. java 2s . co m }