mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
update multipleLineRegress_OLS function to support same number of samples and variables
This commit is contained in:
parent
9c85beea53
commit
2d46d37012
@ -1,32 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<MeteoInfo File="milconfig.xml" Type="configurefile">
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\3d_earth"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\hist"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\others"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\violinplot"/>
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\contour">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\traj"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\stats"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\random"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\model"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\stats"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\fitting"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\integrate"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\linalg"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\hist"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\contour"/>
|
||||
</Path>
|
||||
<File>
|
||||
<OpenedFiles>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\common_math\random\multivariate_normal_3.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\model\obj_Lion_1.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surf_spherical_harmonic_1.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\hist\hist_h_1.py"/>
|
||||
</OpenedFiles>
|
||||
<RecentFiles>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\common_math\random\multivariate_normal_3.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\model\obj_Lion_1.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surf_spherical_harmonic_1.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\hist\hist_h_1.py"/>
|
||||
</RecentFiles>
|
||||
</File>
|
||||
<Font>
|
||||
@ -34,5 +32,5 @@
|
||||
</Font>
|
||||
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
|
||||
<Figure DoubleBuffering="true"/>
|
||||
<Startup MainFormLocation="-7,0" MainFormSize="1351,753"/>
|
||||
<Startup MainFormLocation="-7,-7" MainFormSize="1293,685"/>
|
||||
</MeteoInfo>
|
||||
|
||||
Binary file not shown.
@ -1,11 +1,12 @@
|
||||
from .stats import *
|
||||
from .distributions import *
|
||||
from ._multivariate import *
|
||||
from .kde import GaussianKDE
|
||||
from .kde import *
|
||||
from ._jenks import *
|
||||
|
||||
__all__ = []
|
||||
__all__ += stats.__all__
|
||||
__all__ += distributions.__all__
|
||||
__all__ += _multivariate.__all__
|
||||
__all__ += kde.__all__
|
||||
__all__ += _jenks.__all__
|
||||
|
||||
Binary file not shown.
@ -2,6 +2,8 @@ from .. import core as np
|
||||
import stats
|
||||
from ..linalg import linalg
|
||||
|
||||
__all__ = ['gaussian_kde']
|
||||
|
||||
|
||||
class GaussianKDE(object):
|
||||
"""
|
||||
@ -54,11 +56,11 @@ class GaussianKDE(object):
|
||||
|
||||
if bw_method is None:
|
||||
pass
|
||||
elif (isString and bw_method == 'scott'):
|
||||
elif isString and bw_method == 'scott':
|
||||
self.covariance_factor = self.scotts_factor
|
||||
elif (isString and bw_method == 'silverman'):
|
||||
elif isString and bw_method == 'silverman':
|
||||
self.covariance_factor = self.silverman_factor
|
||||
elif (np.isscalar(bw_method) and not isString):
|
||||
elif np.isscalar(bw_method) and not isString:
|
||||
self._bw_method = 'use constant'
|
||||
self.covariance_factor = lambda: bw_method
|
||||
elif callable(bw_method):
|
||||
@ -135,4 +137,7 @@ class GaussianKDE(object):
|
||||
|
||||
return result
|
||||
|
||||
__call__ = evaluate
|
||||
__call__ = evaluate
|
||||
|
||||
|
||||
gaussian_kde = GaussianKDE
|
||||
Binary file not shown.
@ -2083,7 +2083,7 @@ class Axes(object):
|
||||
return barbreaks
|
||||
|
||||
def hist(self, x, bins=10, density=False, cumulative=False,
|
||||
rwidth=None, **kwargs):
|
||||
rwidth=None, orientation='vertical', **kwargs):
|
||||
"""
|
||||
Plot a histogram.
|
||||
|
||||
@ -2098,6 +2098,27 @@ class Axes(object):
|
||||
last bin gives the total number of datapoints.
|
||||
:param rwidth: (*float or None*) Default is `None`. The relative width of the bars as a
|
||||
fraction of the bin width. If None, automatically compute the width.
|
||||
:param orientation: (*str*) {'vertical', 'horizontal'}, default: 'vertical'. If
|
||||
'horizontal', barh will be used for bar-type histograms and the bottom kwarg will be
|
||||
the left edges.
|
||||
|
||||
Returns
|
||||
-------
|
||||
n : array or list of arrays
|
||||
The values of the histogram bins. See *density* and *weights* for a
|
||||
description of the possible semantics. If input *x* is an array,
|
||||
then this is an array of length *nbins*. If input is a sequence of
|
||||
arrays ``[data1, data2, ...]``, then this is a list of arrays with
|
||||
the values of the histograms for each of the arrays in the same
|
||||
order. The dtype of the array *n* (or of its element arrays) will
|
||||
always be float even if no weighting or normalization is used.
|
||||
bins : array
|
||||
The edges of the bins. Length nbins + 1 (nbins left edges and right
|
||||
edge of last bin). Always a single array even when multiple data
|
||||
sets are passed in.
|
||||
patches : `.BarContainer` or list of a single `.Polygon` or list of such objects
|
||||
Container of individual artists used to create the histogram
|
||||
or list of such containers if there are multiple input datasets.
|
||||
"""
|
||||
if isinstance(x, NDArray) and x.ndim == 1:
|
||||
m, bins = np.histogram(x, bins=bins, density=density)
|
||||
@ -2108,7 +2129,10 @@ class Axes(object):
|
||||
if rwidth is not None:
|
||||
width = width * rwidth
|
||||
|
||||
barbreaks = self.bar(bins[:-1], m, width, align='center', **kwargs)
|
||||
if orientation == 'vertical':
|
||||
barbreaks = self.bar(bins[:-1], m, width, align='center', **kwargs)
|
||||
else:
|
||||
barbreaks = self.barh(bins[:-1], m, width, align='center', **kwargs)
|
||||
|
||||
return m, bins, barbreaks
|
||||
else:
|
||||
@ -2140,7 +2164,10 @@ class Axes(object):
|
||||
kwargs['color'] = colors[i]
|
||||
if labels is not None:
|
||||
kwargs['label'] = labels[i]
|
||||
barbreaks = self.bar(bins[:-1] + width * i, m, width, align='center', **kwargs)
|
||||
if orientation == 'vertical':
|
||||
barbreaks = self.bar(bins[:-1] + width * i, m, width, align='center', **kwargs)
|
||||
else:
|
||||
barbreaks = self.barh(bins[:-1] + width * i, m, width, align='center', **kwargs)
|
||||
barbreaklist.append(barbreaks)
|
||||
|
||||
return mlist, bins, barbreaklist
|
||||
@ -2461,7 +2488,7 @@ class Axes(object):
|
||||
else:
|
||||
ls = LegendManage.createLegendScheme(vmin, vmax, cmap)
|
||||
ls = ls.convertTo(ShapeTypes.POLYGON)
|
||||
if not kwargs.has_key('edgecolor'):
|
||||
if 'edgecolor' not in kwargs.keys():
|
||||
kwargs['edgecolor'] = None
|
||||
plotutil.setlegendscheme(ls, **kwargs)
|
||||
# norm = kwargs.pop('norm', colors.Normalize(vmin, vmax))
|
||||
@ -2475,7 +2502,7 @@ class Axes(object):
|
||||
|
||||
visible = kwargs.pop('visible', True)
|
||||
if visible:
|
||||
if not xaxistype is None:
|
||||
if xaxistype is not None:
|
||||
self.set_xaxis_type(xaxistype)
|
||||
self._axes.updateDrawExtent()
|
||||
|
||||
|
||||
Binary file not shown.
@ -822,7 +822,7 @@ def setlegendscheme_line(ls, **kwargs):
|
||||
def setlegendscheme_polygon(ls, **kwargs):
|
||||
ls = ls.convertTo(ShapeTypes.POLYGON)
|
||||
fill = True
|
||||
if kwargs.has_key('facecolor'):
|
||||
if 'facecolor' in kwargs.keys():
|
||||
facecolor = kwargs['facecolor']
|
||||
if facecolor is None:
|
||||
fill = False
|
||||
@ -832,7 +832,7 @@ def setlegendscheme_polygon(ls, **kwargs):
|
||||
facecolor = None
|
||||
edge = True
|
||||
edgealpha = kwargs.pop('edgealpha', None)
|
||||
if kwargs.has_key('edgecolor'):
|
||||
if 'edgecolor' in kwargs.keys():
|
||||
edgecolor = kwargs['edgecolor']
|
||||
if edgecolor is None:
|
||||
edge = False
|
||||
@ -852,29 +852,29 @@ def setlegendscheme_polygon(ls, **kwargs):
|
||||
bgcolor = getcolor(bgcolor)
|
||||
for lb in ls.getLegendBreaks():
|
||||
lb.setDrawFill(fill)
|
||||
if not facecolor is None:
|
||||
if facecolor is not None:
|
||||
lb.setColor(facecolor)
|
||||
if not alpha is None:
|
||||
if alpha is not None:
|
||||
c = lb.getColor()
|
||||
c = getcolor(c, alpha)
|
||||
lb.setColor(c)
|
||||
if not edgesize is None:
|
||||
if edgesize is not None:
|
||||
lb.setOutlineSize(edgesize)
|
||||
lb.setDrawOutline(edge)
|
||||
if edgecolor is None:
|
||||
if not edgealpha is None:
|
||||
if edgealpha is not None:
|
||||
edgecolor = lb.getOutlineColor()
|
||||
edgecolor = getcolor(edgecolor, edgealpha)
|
||||
lb.setOutlineColor(edgecolor)
|
||||
else:
|
||||
lb.setOutlineColor(edgecolor)
|
||||
if not hatch is None:
|
||||
if hatch is not None:
|
||||
lb.setStyle(hatch)
|
||||
if not bgcolor is None:
|
||||
if bgcolor is not None:
|
||||
lb.setBackColor(bgcolor)
|
||||
if not hatchsize is None:
|
||||
if hatchsize is not None:
|
||||
lb.setStyleSize(hatchsize)
|
||||
if not hatchlinewidth is None:
|
||||
if hatchlinewidth is not None:
|
||||
lb.setStyleLineWidth(hatchlinewidth)
|
||||
return ls
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<MeteoInfo File="config.xml" Type="configurefile">
|
||||
<Path OpenPath="D:\Temp\Map"/>
|
||||
<Path OpenPath="D:\Temp\traj\test"/>
|
||||
<Font>
|
||||
<TextFont FontName="YaHei Consolas Hybrid" FontSize="14"/>
|
||||
<LegendFont FontName="宋体" FontSize="12"/>
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
package org.meteoinfo.math.stats;
|
||||
|
||||
import org.apache.commons.math4.legacy.stat.regression.OLSMultipleLinearRegression;
|
||||
|
||||
public class MIOLSMultipleLinearRegression extends OLSMultipleLinearRegression {
|
||||
/**
|
||||
* Loads model x and y sample data, overriding any previous sample.
|
||||
*
|
||||
* Computes and caches QR decomposition of the X matrix.
|
||||
* @param y the [n,1] array representing the y sample
|
||||
* @param x the [n,k] array representing the x sample
|
||||
* @throws MathIllegalArgumentException if the x and y array data are not
|
||||
* compatible for the regression
|
||||
*/
|
||||
@Override
|
||||
public void newSampleData(double[] y, double[][] x) {
|
||||
//validateSampleData(x, y);
|
||||
newYSampleData(y);
|
||||
newXSampleData(x);
|
||||
}
|
||||
}
|
||||
@ -364,7 +364,7 @@ public class StatsUtil {
|
||||
* @return Estimated regression parameters and residuals
|
||||
*/
|
||||
public static Array[] multipleLineRegress_OLS(Array y, Array x, boolean noIntercept) {
|
||||
OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
|
||||
OLSMultipleLinearRegression regression = new MIOLSMultipleLinearRegression();
|
||||
regression.setNoIntercept(noIntercept);
|
||||
y = y.reduce();
|
||||
double[] yy = (double[])ArrayUtil.copyToNDJavaArray_Double(y);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user