Package org.opensourcephysics.tools
Class DatasetCurveFitter
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.opensourcephysics.tools.DatasetCurveFitter
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
A panel that displays and controls functional curve fits to a Dataset.
- Version:
- 1.0
- Author:
- Douglas Brown
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
A function whose value is the total deviation squared between a multivariable function and a set of data points.class
A function whose value is the total deviation squared between a user function and a set of data points.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic boolean
static final String
static final String
static final String
protected JSplitPane
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorsConstructorDescriptionDatasetCurveFitter
(Dataset data, FitBuilder builder) Constructs a DatasetCurveFitter for the specified Dataset. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFitFunction
(KnownFunction f, boolean addToFitBuilder) Adds a fit function.protected UserFunction
createClone
(KnownFunction f, String name) protected void
Creates the GUI.void
doLinearRegression
(double[] xd, double[] yd) Determines the Pearson correlation and linear fit parameter SEs.double
fit
(KnownFunction fit) Fits a fit function to the current data.double
fit
(KnownFunction fit, boolean fromScratch) Fits a fit function to the current data.protected Dimension
String[]
formatUncertainParameter
(double value, double sigma, int extraPlaces, NumberFormat format) Returns two strings describing a parameter and its uncertainty.protected JDialog
Gets a color dialog for the plotted curve fit drawergetData()
Gets the data.Gets the function drawer.getFitFunction
(String name) Gets a fit function by name.String[]
void
getPolyFitNameOfDegree
(int degree) Gets the name of a fit function for specified polynomial degreeGets the selected fit parameters.double
getUncertainty
(int paramIndex) Gets the estimated uncertainty (standard error or other) of a best fit parameter.boolean
isActive()
protected void
protected void
Refreshes the decimal separators.protected void
Refreshes the fitDropDown.protected void
Refreshes the fit map with localized names.protected void
Refreshes the GUI.void
Refreshes the parent tab's status barprotected void
replaceFit
(String oldName, String newName, KnownFunction newFit) Replaces an existing fit function with a new one.protected void
Selects a named fit.void
setActiveAndFit
(boolean active) Sets the active flag if not already set and does a fit if setting it to true.void
setActiveNoFit
(boolean b) void
setAutofit
(boolean auto) Sets the autofit flag.void
setAutoFit
(boolean autofit) void
Sets the color.void
Sets the dataset.protected void
static void
setDefaultFitFunctions
(ArrayList<KnownFunction> functions) Sets the default fit functions.void
setFitVisible
(boolean vis) protected void
setFontLevel
(int level) Sets the font level.protected void
setParameterValue
(int row, double value) Sets the value of a parameter.void
setSelectedItem
(String fitName) void
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
PROPERTY_DATASETCURVEFITTER_CHANGED
- See Also:
-
PROPERTY_DATASETCURVEFITTER_DRAWER
- See Also:
-
PROPERTY_DATASETCURVEFITTER_FIT
- See Also:
-
isFixedDecimalFormat
public static boolean isFixedDecimalFormat -
splitPane
-
-
Constructor Details
-
DatasetCurveFitter
Constructs a DatasetCurveFitter for the specified Dataset.- Parameters:
data
- the datasetbuilder
- the FitBuilder used for constructing custom fits
-
-
Method Details
-
setActiveNoFit
public void setActiveNoFit(boolean b) -
isActive
public boolean isActive() -
setAutofit
public void setAutofit(boolean auto) Sets the autofit flag.- Parameters:
auto
- true to autofit
-
setAutoFit
public void setAutoFit(boolean autofit) -
getSplitPane
-
getDrawer
Gets the function drawer.- Returns:
- the drawer
-
getData
Gets the data.- Returns:
- the dataset
-
setData
Sets the dataset.- Parameters:
data
- the dataset - if null, then just initializing
-
setColor
Sets the color.- Parameters:
newColor
- the color
-
setActiveAndFit
public void setActiveAndFit(boolean active) Sets the active flag if not already set and does a fit if setting it to true.- Parameters:
active
- true
-
fit
Fits a fit function to the current data.- Parameters:
fit
- the function to fit- Returns:
- the rms deviation
-
fit
Fits a fit function to the current data.- Parameters:
fit
- the function to fit- Returns:
- the rms deviation
-
addFitFunction
Adds a fit function.- Parameters:
f
- the fit function to addaddToFitBuilder
- ignored--all fits are added to the fit builder
-
refreshStatusBar
public void refreshStatusBar()Refreshes the parent tab's status bar -
getUncertainty
public double getUncertainty(int paramIndex) Gets the estimated uncertainty (standard error or other) of a best fit parameter. Returns Double.NaN if uncertainty is unknown or is not best fit.- Parameters:
paramIndex
- the parameter index- Returns:
- the estimated uncertainty in the parameter
-
formatUncertainParameter
public String[] formatUncertainParameter(double value, double sigma, int extraPlaces, NumberFormat format) Returns two strings describing a parameter and its uncertainty. One for display, other with more sig figs for tooltip- Parameters:
value
- the parameter valuesigma
- the uncertainty (may be null)- Returns:
- the format values {decimal places, format} or null if uncert unknown or zero
-
getFitFunction
Gets a fit function by name.- Parameters:
name
- the name- Returns:
- the fit function, or null if none found
-
getSelectedFitParameters
Gets the selected fit parameters.- Returns:
- a map of parameter names to values
-
getMinimumSize
- Overrides:
getMinimumSize
in classJComponent
-
createGUI
protected void createGUI()Creates the GUI. -
fixSize
-
processPropertyChange
-
refreshGUI
protected void refreshGUI()Refreshes the GUI. -
refreshDecimalSeparators
protected void refreshDecimalSeparators()Refreshes the decimal separators. -
refreshFitDropDown
protected void refreshFitDropDown()Refreshes the fitDropDown. -
refreshFitMap
protected void refreshFitMap()Refreshes the fit map with localized names. -
getPolyFitNameOfDegree
Gets the name of a fit function for specified polynomial degree- Returns:
- the name of the function
-
setDataToolTab
-
setFontLevel
protected void setFontLevel(int level) Sets the font level.- Parameters:
level
- the level
-
setParameterValue
protected void setParameterValue(int row, double value) Sets the value of a parameter.- Parameters:
row
- the row numbervalue
- the value
-
selectFit
Selects a named fit.- Parameters:
name
- the name of the fit function
-
createClone
-
doLinearRegression
public void doLinearRegression(double[] xd, double[] yd) Determines the Pearson correlation and linear fit parameter SEs.- Parameters:
xd
- double[]yd
- double[]isLinearFit
- true if linear fit (sets uncertainties to slope and intercept SE)
-
replaceFit
Replaces an existing fit function with a new one.- Parameters:
oldName
- the (localized) name of the existing fit functionnewName
- the (localized) new name of the functionnewFit
- the new fit function
-
getColorDialog
Gets a color dialog for the plotted curve fit drawer -
setDefaultFitFunctions
Sets the default fit functions. Instances of DatasetCurveFitter instantiated AFTER this call will make these fits available to the user.- Parameters:
functions
- the fit functions
-
getFits
-
getFitNames
-
setSelectedItem
-
setText
-
setFitVisible
public void setFitVisible(boolean vis)
-