SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
ContinuousDistChart.java
1/*
2 * Class: ContinuousDistChart
3 * Description:
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author Richard Simard
9 * @since May 2008
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.charts;
26
27import umontreal.ssj.probdist.ContinuousDistribution;
28
29import javax.swing.JFrame;
30
37public class ContinuousDistChart {
38 protected ContinuousDistribution dist;
39 protected double a, b;
40 protected int m;
41 protected XYLineChart cdfChart;
42 protected XYLineChart densityChart;
43
44 private void init() {
45 double[][] cdf = new double[2][m + 1];
46 double[][] density = new double[2][m + 1];
47 double h = (b - a) / m;
48 double x;
49 int coex = 0;
50
51 try {
52 for (int i = 0; i <= m; i++) {
53 x = a + i * h;
54 cdf[0][i] = x;
55 cdf[1][i] = dist.cdf(x);
56 }
57 cdfChart = new XYLineChart("cdf: " + dist.toString(), "", "", cdf);
58 } catch (UnsupportedOperationException e) {
59 coex++;
60 System.err.println(e);
61// e.printStackTrace();
62 }
63
64 try {
65 for (int i = 0; i <= m; i++) {
66 x = a + i * h;
67 density[0][i] = x;
68 density[1][i] = dist.density(x);
69 }
70 densityChart = new XYLineChart("density: " + dist.toString(), "", "", density);
71 } catch (UnsupportedOperationException e) {
72 System.err.println(e);
73 if (coex == 1)
74 throw e;
75 }
76 cdfChart.setprobFlag(true);
77 densityChart.setprobFlag(true);
78 }
79
90 public ContinuousDistChart(ContinuousDistribution dist, double a, double b, int m) {
91 this.dist = dist;
92 this.a = a;
93 this.b = b;
94 this.m = m;
95 init();
96 }
97
109 public JFrame viewCdf(int width, int height) {
110 return cdfChart.view(width, height);
111 }
112
120 public JFrame viewDensity(int width, int height) {
121 return densityChart.view(width, height);
122 }
123
136 public String toLatexCdf(int width, int height) {
137 return cdfChart.toLatex(width, height);
138 }
139
147 public String toLatexDensity(int width, int height) {
148 return densityChart.toLatex(width, height);
149 }
150
158 public void setParam(double a, double b, int m) {
159 this.a = a;
160 this.b = b;
161 this.m = m;
162 init();
163 }
164
165}
void setParam(double a, double b, int m)
Sets the parameters , and for this object.
ContinuousDistChart(ContinuousDistribution dist, double a, double b, int m)
Constructor for a new ContinuousDistChart instance.
JFrame viewDensity(int width, int height)
Similar to viewCdf, but for the probability density instead of the cdf.
JFrame viewCdf(int width, int height)
Displays a chart of the cumulative distribution function (cdf) on the screen using Swing.
String toLatexDensity(int width, int height)
Similar to toLatexCdf, but for the probability density instead of the cdf.
String toLatexCdf(int width, int height)
Exports a chart of the cdf to a LaTeX source code using PGF/TikZ.
void setprobFlag(boolean flag)
Must be set true when plotting probabilities, false otherwise.
Definition XYChart.java:133
Provides tools to create and manage curve plots.
Classes implementing continuous distributions should inherit from this base class.