List of usage examples for org.apache.commons.math3.linear ArrayRealVector ArrayRealVector
public ArrayRealVector(double[] v1, double[] v2)
From source file:gamlss.distributions.PE.java
/** First derivative dldn = dl/dnu, where l - log-likelihood function. * @param y - vector of values of response variable * @return a vector of First derivative dldn = dl/dnu *//* www . j a v a 2 s .co m*/ public final ArrayRealVector dldn(final ArrayRealVector y) { double[] dldn = new double[size]; for (int i = 0; i < size; i++) { //dlogc.dv <- (1/(2*nu^2))*(2*log(2)-digamma(1/nu)+3*digamma(3/nu)) final double dlogcDv = (1 / (2 * nuV.getEntry(i) * nuV.getEntry(i))) * (2 * FastMath.log(2) - Gamma.digamma(1 / nuV.getEntry(i)) + 3 * Gamma.digamma(3 / nuV.getEntry(i))); //dldv <- (1/nu)-0.5*((log(abs(z/c)))*((abs(z/c))^nu)) dldn[i] = (1 / nuV.getEntry(i)) - 0.5 * ((FastMath.log(FastMath.abs(z[i] / c[i]))) * (FastMath.pow(FastMath.abs(z[i] / c[i]), nuV.getEntry(i)))); //dldv <- dldv+log(2)/(nu^2)+digamma(1/nu)/(nu^2) dldn[i] = dldn[i] + FastMath.log(2) / (nuV.getEntry(i) * nuV.getEntry(i)) + Gamma.digamma(1 / nuV.getEntry(i)) / (nuV.getEntry(i) * nuV.getEntry(i)); //dldv <- dldv+(-1+(nu/2)*((abs(z/c))^nu))*dlogc.dv dldn[i] = dldn[i] + (-1 + (nuV.getEntry(i) / 2) * (FastMath.pow(FastMath.abs(z[i] / c[i]), nuV.getEntry(i)))) * dlogcDv; } logC = null; c = null; z = null; return new ArrayRealVector(dldn, false); }
From source file:gamlss.distributions.JSUo.java
/** First derivative dldtau = dl/dtau, where l - log-likelihood function. * @param y - vector of values of response variable * @return a vector of First derivative dldtau = dl/dtau */// w w w . j a va 2 s . c o m public final ArrayRealVector dldt(final ArrayRealVector y) { dldt = new double[size]; for (int i = 0; i < size; i++) { //dldt <- (1+r*nu-r*r)/tau dldt[i] = (1 + r[i] * nuV.getEntry(i) - r[i] * r[i]) / tauV.getEntry(i); } r = null; z = null; return new ArrayRealVector(dldt, false); }
From source file:gamlss.distributions.BCPE.java
/** First derivative dldm = dl/dmu, where l - log-likelihood function. * @param y - vector of values of response variable * @return a vector of first derivative dldm = dl/dmu *//*from w w w. j ava 2 s . c o m*/ public final ArrayRealVector dldm(final ArrayRealVector y) { dldm = new double[size]; for (int i = 0; i < size; i++) { //dldm <- (tau/(2*mu*sigma*c^2))*(z+sigma*nu*z^2) //*((abs(z/c))^(tau-2))-(nu/mu) dldm[i] = (tauV.getEntry(i) / (2 * muV.getEntry(i) * sigmaV.getEntry(i) * c[i] * c[i])) * (z[i] + sigmaV.getEntry(i) * nuV.getEntry(i) * z[i] * z[i]) * (FastMath.pow(FastMath.abs(z[i] / c[i]), (tauV.getEntry(i) - 2))) - (nuV.getEntry(i) / muV.getEntry(i)); } c = null; logC = null; z = null; return new ArrayRealVector(dldm, false); }
From source file:gamlss.distributions.SST.java
/** First derivative dlds = dl/dsigma, where l - log-likelihood function. * @param y - vector of values of response variable * @return a vector of First derivative dlds = dl/dsigma *///from w ww . ja va 2 s. com public final ArrayRealVector dlds(final ArrayRealVector y) { //dldd <- -(m1/s1)*ST3()$dldm(y, mu1, sigma1, nu, tau) //+ (1/s1)*ST3()$dldd(y, mu1, sigma1, nu, tau) st3.setDistributionParameter(DistributionSettings.MU, new ArrayRealVector(mu1, false)); st3.setDistributionParameter(DistributionSettings.SIGMA, new ArrayRealVector(sigma1, false)); st3.setDistributionParameter(DistributionSettings.NU, nuV); st3.setDistributionParameter(DistributionSettings.TAU, tauV); double[] dldmTemp = st3.firstDerivative(DistributionSettings.MU, y).getDataRef(); double[] dldsTemp = st3.firstDerivative(DistributionSettings.SIGMA, y).getDataRef(); dlds = new double[size]; for (int i = 0; i < size; i++) { dlds[i] = -(m1[i] / s1[i]) * dldmTemp[i] + (1 / s1[i]) * dldsTemp[i]; } m1 = null; m2 = null; s1 = null; mu1 = null; sigma1 = null; return new ArrayRealVector(dlds, false); }
From source file:gamlss.distributions.GT.java
/** First derivative dlds = dl/dsigma, where l - log-likelihood function. * @param y - vector of values of response variable * @return a vector of First derivative dlds = dl/dsigma *//* ww w. jav a 2s . c o m*/ public final ArrayRealVector dlds(final ArrayRealVector y) { dlds = new double[size]; for (int i = 0; i < size; i++) { //dldd <- (w*zt-1)/sigma dlds[i] = (w[i] * zt[i] - 1) / sigmaV.getEntry(i); } w = null; z = null; zt = null; return new ArrayRealVector(dlds, false); }
From source file:edu.stanford.cfuller.imageanalysistools.fitting.BisquareLinearFitTest.java
@Test public void testbis10() { int test_size = 18; this.x = new ArrayRealVector(test_size, 0.0); this.y = new ArrayRealVector(test_size, 0.0); for (int i = 0; i < this.x.getDimension(); i++) { this.x.setEntry(i, i); this.y.setEntry(i, i + 1); }// www .j av a2s .c o m this.x.setEntry(test_size - 1, 92); this.y.setEntry(test_size - 1, 343); this.expected.setEntry(0, 1); this.expected.setEntry(1, 1); this.result = this.bslf.fit(x, y); this.success &= (this.result.subtract(this.expected).getNorm() < this.eps); assertTrue(success); }
From source file:gamlss.utilities.MatrixFunctions.java
/** * Calculates a difference of two vectors (v1 - v2). * @param v1 - first vector// w w w .j a v a 2 s . co m * @param v2 - second vector * @return vector (v1 - v2) */ public static ArrayRealVector vecSub(final ArrayRealVector v1, final ArrayRealVector v2) { int size = v1.getDimension(); double[] tempArr = new double[size]; for (int i = 0; i < size; i++) { tempArr[i] = v1.getEntry(i) - v2.getEntry(i); } return new ArrayRealVector(tempArr, false); }
From source file:gamlss.algorithm.CGAlgorithm.java
/** * Calculates values of wv vector/*from ww w .j av a 2 s . c o m*/ * @param eta - vector of linear predictor values * @param os - offset value * @param dldp - vector of the first derivative values with respect to the fitted distribution parameter * @param dr = vector of 1/(link function of the linear pridictoor) values * @param wt = vectr f -(second derivative values with respect to the fitted distribution parameter/(dr*dr)) values * @return wv = vector of values (eta-os)+dldp/(dr*wt) */ private ArrayRealVector wvSet(ArrayRealVector etaOldMU, double muStep, double os, ArrayRealVector dldp, ArrayRealVector dr, ArrayRealVector wt) { double[] out = new double[etaOldMU.getDimension()]; for (int i = 0; i < out.length; i++) { out[i] = (etaOldMU.getEntry(i) - os) + muStep * dldp.getEntry(i) / (dr.getEntry(i) * wt.getEntry(i)); } return new ArrayRealVector(out, false); }
From source file:com.bolatu.gezkoncsvlogger.GyroOrientation.RotationKalmanFilter.java
/** * Predict the internal state estimation one time step ahead. * * @param u// www .ja v a2 s . c o m * the control vector * @throws DimensionMismatchException * if the dimension of the control vector does not fit */ public void predict(final double[] u) throws DimensionMismatchException { predict(new ArrayRealVector(u, false)); }
From source file:gamlss.distributions.TF.java
/** Second derivative d2ldm2= (d^2l)/(dmu^2), * where l - log-likelihood function.//from ww w . j av a2 s .c om * @param y - vector of values of response variable * @return a vector of second derivative d2ldm2= (d^2l)/(dmu^2) */ private ArrayRealVector d2ldm2(final ArrayRealVector y) { double[] out = new double[size]; for (int i = 0; i < size; i++) { //d2ldm2 = function(sigma,nu) -(nu+1)/((nu+3)*(sigma^2)), out[i] = -(nuV.getEntry(i) + 1) / ((nuV.getEntry(i) + 3) * s2[i]); } s2 = null; muV = null; sigmaV = null; nuV = null; return new ArrayRealVector(out, false); }