commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ericbarnh...@apache.org
Subject [31/51] [partial] commons-complex git commit: First commit to commons-complex
Date Wed, 04 Jan 2017 10:05:41 GMT
http://git-wip-us.apache.org/repos/asf/commons-complex/blob/b0db8fca/site-content/.svn/pristine/02/025d8723c696f975683abf23fe48eb0590158d23.svn-base
----------------------------------------------------------------------
diff --git a/site-content/.svn/pristine/02/025d8723c696f975683abf23fe48eb0590158d23.svn-base b/site-content/.svn/pristine/02/025d8723c696f975683abf23fe48eb0590158d23.svn-base
new file mode 100644
index 0000000..8523828
--- /dev/null
+++ b/site-content/.svn/pristine/02/025d8723c696f975683abf23fe48eb0590158d23.svn-base
@@ -0,0 +1,649 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html lang="en">
+<head>
+<title>Source code</title>
+<link rel="stylesheet" type="text/css" href="../../../../../../../stylesheet.css" title="Style">
+</head>
+<body>
+<div class="sourceContainer">
+<pre><span class="sourceLineNo">001</span>/*<a name="line.1"></a>
+<span class="sourceLineNo">002</span> * Licensed to the Apache Software Foundation (ASF) under one or more<a name="line.2"></a>
+<span class="sourceLineNo">003</span> * contributor license agreements.  See the NOTICE file distributed with<a name="line.3"></a>
+<span class="sourceLineNo">004</span> * this work for additional information regarding copyright ownership.<a name="line.4"></a>
+<span class="sourceLineNo">005</span> * The ASF licenses this file to You under the Apache License, Version 2.0<a name="line.5"></a>
+<span class="sourceLineNo">006</span> * (the "License"); you may not use this file except in compliance with<a name="line.6"></a>
+<span class="sourceLineNo">007</span> * the License.  You may obtain a copy of the License at<a name="line.7"></a>
+<span class="sourceLineNo">008</span> *<a name="line.8"></a>
+<span class="sourceLineNo">009</span> *      http://www.apache.org/licenses/LICENSE-2.0<a name="line.9"></a>
+<span class="sourceLineNo">010</span> *<a name="line.10"></a>
+<span class="sourceLineNo">011</span> * Unless required by applicable law or agreed to in writing, software<a name="line.11"></a>
+<span class="sourceLineNo">012</span> * distributed under the License is distributed on an "AS IS" BASIS,<a name="line.12"></a>
+<span class="sourceLineNo">013</span> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<a name="line.13"></a>
+<span class="sourceLineNo">014</span> * See the License for the specific language governing permissions and<a name="line.14"></a>
+<span class="sourceLineNo">015</span> * limitations under the License.<a name="line.15"></a>
+<span class="sourceLineNo">016</span> */<a name="line.16"></a>
+<span class="sourceLineNo">017</span><a name="line.17"></a>
+<span class="sourceLineNo">018</span>package org.apache.commons.math3.optimization.general;<a name="line.18"></a>
+<span class="sourceLineNo">019</span><a name="line.19"></a>
+<span class="sourceLineNo">020</span>import org.apache.commons.math3.analysis.DifferentiableMultivariateVectorFunction;<a name="line.20"></a>
+<span class="sourceLineNo">021</span>import org.apache.commons.math3.analysis.FunctionUtils;<a name="line.21"></a>
+<span class="sourceLineNo">022</span>import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;<a name="line.22"></a>
+<span class="sourceLineNo">023</span>import org.apache.commons.math3.analysis.differentiation.MultivariateDifferentiableVectorFunction;<a name="line.23"></a>
+<span class="sourceLineNo">024</span>import org.apache.commons.math3.exception.DimensionMismatchException;<a name="line.24"></a>
+<span class="sourceLineNo">025</span>import org.apache.commons.math3.exception.NumberIsTooSmallException;<a name="line.25"></a>
+<span class="sourceLineNo">026</span>import org.apache.commons.math3.exception.util.LocalizedFormats;<a name="line.26"></a>
+<span class="sourceLineNo">027</span>import org.apache.commons.math3.linear.ArrayRealVector;<a name="line.27"></a>
+<span class="sourceLineNo">028</span>import org.apache.commons.math3.linear.RealMatrix;<a name="line.28"></a>
+<span class="sourceLineNo">029</span>import org.apache.commons.math3.linear.DiagonalMatrix;<a name="line.29"></a>
+<span class="sourceLineNo">030</span>import org.apache.commons.math3.linear.DecompositionSolver;<a name="line.30"></a>
+<span class="sourceLineNo">031</span>import org.apache.commons.math3.linear.MatrixUtils;<a name="line.31"></a>
+<span class="sourceLineNo">032</span>import org.apache.commons.math3.linear.QRDecomposition;<a name="line.32"></a>
+<span class="sourceLineNo">033</span>import org.apache.commons.math3.linear.EigenDecomposition;<a name="line.33"></a>
+<span class="sourceLineNo">034</span>import org.apache.commons.math3.optimization.OptimizationData;<a name="line.34"></a>
+<span class="sourceLineNo">035</span>import org.apache.commons.math3.optimization.InitialGuess;<a name="line.35"></a>
+<span class="sourceLineNo">036</span>import org.apache.commons.math3.optimization.Target;<a name="line.36"></a>
+<span class="sourceLineNo">037</span>import org.apache.commons.math3.optimization.Weight;<a name="line.37"></a>
+<span class="sourceLineNo">038</span>import org.apache.commons.math3.optimization.ConvergenceChecker;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>import org.apache.commons.math3.optimization.DifferentiableMultivariateVectorOptimizer;<a name="line.39"></a>
+<span class="sourceLineNo">040</span>import org.apache.commons.math3.optimization.PointVectorValuePair;<a name="line.40"></a>
+<span class="sourceLineNo">041</span>import org.apache.commons.math3.optimization.direct.BaseAbstractMultivariateVectorOptimizer;<a name="line.41"></a>
+<span class="sourceLineNo">042</span>import org.apache.commons.math3.util.FastMath;<a name="line.42"></a>
+<span class="sourceLineNo">043</span><a name="line.43"></a>
+<span class="sourceLineNo">044</span>/**<a name="line.44"></a>
+<span class="sourceLineNo">045</span> * Base class for implementing least squares optimizers.<a name="line.45"></a>
+<span class="sourceLineNo">046</span> * It handles the boilerplate methods associated to thresholds settings,<a name="line.46"></a>
+<span class="sourceLineNo">047</span> * Jacobian and error estimation.<a name="line.47"></a>
+<span class="sourceLineNo">048</span> * &lt;br/&gt;<a name="line.48"></a>
+<span class="sourceLineNo">049</span> * This class constructs the Jacobian matrix of the function argument in method<a name="line.49"></a>
+<span class="sourceLineNo">050</span> * {@link BaseAbstractMultivariateVectorOptimizer#optimize(int,<a name="line.50"></a>
+<span class="sourceLineNo">051</span> * org.apache.commons.math3.analysis.MultivariateVectorFunction,OptimizationData[])<a name="line.51"></a>
+<span class="sourceLineNo">052</span> * optimize} and assumes that the rows of that matrix iterate on the model<a name="line.52"></a>
+<span class="sourceLineNo">053</span> * functions while the columns iterate on the parameters; thus, the numbers<a name="line.53"></a>
+<span class="sourceLineNo">054</span> * of rows is equal to the dimension of the<a name="line.54"></a>
+<span class="sourceLineNo">055</span> * {@link org.apache.commons.math3.optimization.Target Target} while<a name="line.55"></a>
+<span class="sourceLineNo">056</span> * the number of columns is equal to the dimension of the<a name="line.56"></a>
+<span class="sourceLineNo">057</span> * {@link org.apache.commons.math3.optimization.InitialGuess InitialGuess}.<a name="line.57"></a>
+<span class="sourceLineNo">058</span> *<a name="line.58"></a>
+<span class="sourceLineNo">059</span> * @deprecated As of 3.1 (to be removed in 4.0).<a name="line.59"></a>
+<span class="sourceLineNo">060</span> * @since 1.2<a name="line.60"></a>
+<span class="sourceLineNo">061</span> */<a name="line.61"></a>
+<span class="sourceLineNo">062</span>@Deprecated<a name="line.62"></a>
+<span class="sourceLineNo">063</span>public abstract class AbstractLeastSquaresOptimizer<a name="line.63"></a>
+<span class="sourceLineNo">064</span>    extends BaseAbstractMultivariateVectorOptimizer&lt;DifferentiableMultivariateVectorFunction&gt;<a name="line.64"></a>
+<span class="sourceLineNo">065</span>    implements DifferentiableMultivariateVectorOptimizer {<a name="line.65"></a>
+<span class="sourceLineNo">066</span>    /**<a name="line.66"></a>
+<span class="sourceLineNo">067</span>     * Singularity threshold (cf. {@link #getCovariances(double)}).<a name="line.67"></a>
+<span class="sourceLineNo">068</span>     * @deprecated As of 3.1.<a name="line.68"></a>
+<span class="sourceLineNo">069</span>     */<a name="line.69"></a>
+<span class="sourceLineNo">070</span>    @Deprecated<a name="line.70"></a>
+<span class="sourceLineNo">071</span>    private static final double DEFAULT_SINGULARITY_THRESHOLD = 1e-14;<a name="line.71"></a>
+<span class="sourceLineNo">072</span>    /**<a name="line.72"></a>
+<span class="sourceLineNo">073</span>     * Jacobian matrix of the weighted residuals.<a name="line.73"></a>
+<span class="sourceLineNo">074</span>     * This matrix is in canonical form just after the calls to<a name="line.74"></a>
+<span class="sourceLineNo">075</span>     * {@link #updateJacobian()}, but may be modified by the solver<a name="line.75"></a>
+<span class="sourceLineNo">076</span>     * in the derived class (the {@link LevenbergMarquardtOptimizer<a name="line.76"></a>
+<span class="sourceLineNo">077</span>     * Levenberg-Marquardt optimizer} does this).<a name="line.77"></a>
+<span class="sourceLineNo">078</span>     * @deprecated As of 3.1. To be removed in 4.0. Please use<a name="line.78"></a>
+<span class="sourceLineNo">079</span>     * {@link #computeWeightedJacobian(double[])} instead.<a name="line.79"></a>
+<span class="sourceLineNo">080</span>     */<a name="line.80"></a>
+<span class="sourceLineNo">081</span>    @Deprecated<a name="line.81"></a>
+<span class="sourceLineNo">082</span>    protected double[][] weightedResidualJacobian;<a name="line.82"></a>
+<span class="sourceLineNo">083</span>    /** Number of columns of the jacobian matrix.<a name="line.83"></a>
+<span class="sourceLineNo">084</span>     * @deprecated As of 3.1.<a name="line.84"></a>
+<span class="sourceLineNo">085</span>     */<a name="line.85"></a>
+<span class="sourceLineNo">086</span>    @Deprecated<a name="line.86"></a>
+<span class="sourceLineNo">087</span>    protected int cols;<a name="line.87"></a>
+<span class="sourceLineNo">088</span>    /** Number of rows of the jacobian matrix.<a name="line.88"></a>
+<span class="sourceLineNo">089</span>     * @deprecated As of 3.1.<a name="line.89"></a>
+<span class="sourceLineNo">090</span>     */<a name="line.90"></a>
+<span class="sourceLineNo">091</span>    @Deprecated<a name="line.91"></a>
+<span class="sourceLineNo">092</span>    protected int rows;<a name="line.92"></a>
+<span class="sourceLineNo">093</span>    /** Current point.<a name="line.93"></a>
+<span class="sourceLineNo">094</span>     * @deprecated As of 3.1.<a name="line.94"></a>
+<span class="sourceLineNo">095</span>     */<a name="line.95"></a>
+<span class="sourceLineNo">096</span>    @Deprecated<a name="line.96"></a>
+<span class="sourceLineNo">097</span>    protected double[] point;<a name="line.97"></a>
+<span class="sourceLineNo">098</span>    /** Current objective function value.<a name="line.98"></a>
+<span class="sourceLineNo">099</span>     * @deprecated As of 3.1.<a name="line.99"></a>
+<span class="sourceLineNo">100</span>     */<a name="line.100"></a>
+<span class="sourceLineNo">101</span>    @Deprecated<a name="line.101"></a>
+<span class="sourceLineNo">102</span>    protected double[] objective;<a name="line.102"></a>
+<span class="sourceLineNo">103</span>    /** Weighted residuals<a name="line.103"></a>
+<span class="sourceLineNo">104</span>     * @deprecated As of 3.1.<a name="line.104"></a>
+<span class="sourceLineNo">105</span>     */<a name="line.105"></a>
+<span class="sourceLineNo">106</span>    @Deprecated<a name="line.106"></a>
+<span class="sourceLineNo">107</span>    protected double[] weightedResiduals;<a name="line.107"></a>
+<span class="sourceLineNo">108</span>    /** Cost value (square root of the sum of the residuals).<a name="line.108"></a>
+<span class="sourceLineNo">109</span>     * @deprecated As of 3.1. Field to become "private" in 4.0.<a name="line.109"></a>
+<span class="sourceLineNo">110</span>     * Please use {@link #setCost(double)}.<a name="line.110"></a>
+<span class="sourceLineNo">111</span>     */<a name="line.111"></a>
+<span class="sourceLineNo">112</span>    @Deprecated<a name="line.112"></a>
+<span class="sourceLineNo">113</span>    protected double cost;<a name="line.113"></a>
+<span class="sourceLineNo">114</span>    /** Objective function derivatives. */<a name="line.114"></a>
+<span class="sourceLineNo">115</span>    private MultivariateDifferentiableVectorFunction jF;<a name="line.115"></a>
+<span class="sourceLineNo">116</span>    /** Number of evaluations of the Jacobian. */<a name="line.116"></a>
+<span class="sourceLineNo">117</span>    private int jacobianEvaluations;<a name="line.117"></a>
+<span class="sourceLineNo">118</span>    /** Square-root of the weight matrix. */<a name="line.118"></a>
+<span class="sourceLineNo">119</span>    private RealMatrix weightMatrixSqrt;<a name="line.119"></a>
+<span class="sourceLineNo">120</span><a name="line.120"></a>
+<span class="sourceLineNo">121</span>    /**<a name="line.121"></a>
+<span class="sourceLineNo">122</span>     * Simple constructor with default settings.<a name="line.122"></a>
+<span class="sourceLineNo">123</span>     * The convergence check is set to a {@link<a name="line.123"></a>
+<span class="sourceLineNo">124</span>     * org.apache.commons.math3.optimization.SimpleVectorValueChecker}.<a name="line.124"></a>
+<span class="sourceLineNo">125</span>     * @deprecated See {@link org.apache.commons.math3.optimization.SimpleValueChecker#SimpleValueChecker()}<a name="line.125"></a>
+<span class="sourceLineNo">126</span>     */<a name="line.126"></a>
+<span class="sourceLineNo">127</span>    @Deprecated<a name="line.127"></a>
+<span class="sourceLineNo">128</span>    protected AbstractLeastSquaresOptimizer() {}<a name="line.128"></a>
+<span class="sourceLineNo">129</span><a name="line.129"></a>
+<span class="sourceLineNo">130</span>    /**<a name="line.130"></a>
+<span class="sourceLineNo">131</span>     * @param checker Convergence checker.<a name="line.131"></a>
+<span class="sourceLineNo">132</span>     */<a name="line.132"></a>
+<span class="sourceLineNo">133</span>    protected AbstractLeastSquaresOptimizer(ConvergenceChecker&lt;PointVectorValuePair&gt; checker) {<a name="line.133"></a>
+<span class="sourceLineNo">134</span>        super(checker);<a name="line.134"></a>
+<span class="sourceLineNo">135</span>    }<a name="line.135"></a>
+<span class="sourceLineNo">136</span><a name="line.136"></a>
+<span class="sourceLineNo">137</span>    /**<a name="line.137"></a>
+<span class="sourceLineNo">138</span>     * @return the number of evaluations of the Jacobian function.<a name="line.138"></a>
+<span class="sourceLineNo">139</span>     */<a name="line.139"></a>
+<span class="sourceLineNo">140</span>    public int getJacobianEvaluations() {<a name="line.140"></a>
+<span class="sourceLineNo">141</span>        return jacobianEvaluations;<a name="line.141"></a>
+<span class="sourceLineNo">142</span>    }<a name="line.142"></a>
+<span class="sourceLineNo">143</span><a name="line.143"></a>
+<span class="sourceLineNo">144</span>    /**<a name="line.144"></a>
+<span class="sourceLineNo">145</span>     * Update the jacobian matrix.<a name="line.145"></a>
+<span class="sourceLineNo">146</span>     *<a name="line.146"></a>
+<span class="sourceLineNo">147</span>     * @throws DimensionMismatchException if the Jacobian dimension does not<a name="line.147"></a>
+<span class="sourceLineNo">148</span>     * match problem dimension.<a name="line.148"></a>
+<span class="sourceLineNo">149</span>     * @deprecated As of 3.1. Please use {@link #computeWeightedJacobian(double[])}<a name="line.149"></a>
+<span class="sourceLineNo">150</span>     * instead.<a name="line.150"></a>
+<span class="sourceLineNo">151</span>     */<a name="line.151"></a>
+<span class="sourceLineNo">152</span>    @Deprecated<a name="line.152"></a>
+<span class="sourceLineNo">153</span>    protected void updateJacobian() {<a name="line.153"></a>
+<span class="sourceLineNo">154</span>        final RealMatrix weightedJacobian = computeWeightedJacobian(point);<a name="line.154"></a>
+<span class="sourceLineNo">155</span>        weightedResidualJacobian = weightedJacobian.scalarMultiply(-1).getData();<a name="line.155"></a>
+<span class="sourceLineNo">156</span>    }<a name="line.156"></a>
+<span class="sourceLineNo">157</span><a name="line.157"></a>
+<span class="sourceLineNo">158</span>    /**<a name="line.158"></a>
+<span class="sourceLineNo">159</span>     * Computes the Jacobian matrix.<a name="line.159"></a>
+<span class="sourceLineNo">160</span>     *<a name="line.160"></a>
+<span class="sourceLineNo">161</span>     * @param params Model parameters at which to compute the Jacobian.<a name="line.161"></a>
+<span class="sourceLineNo">162</span>     * @return the weighted Jacobian: W&lt;sup&gt;1/2&lt;/sup&gt; J.<a name="line.162"></a>
+<span class="sourceLineNo">163</span>     * @throws DimensionMismatchException if the Jacobian dimension does not<a name="line.163"></a>
+<span class="sourceLineNo">164</span>     * match problem dimension.<a name="line.164"></a>
+<span class="sourceLineNo">165</span>     * @since 3.1<a name="line.165"></a>
+<span class="sourceLineNo">166</span>     */<a name="line.166"></a>
+<span class="sourceLineNo">167</span>    protected RealMatrix computeWeightedJacobian(double[] params) {<a name="line.167"></a>
+<span class="sourceLineNo">168</span>        ++jacobianEvaluations;<a name="line.168"></a>
+<span class="sourceLineNo">169</span><a name="line.169"></a>
+<span class="sourceLineNo">170</span>        final DerivativeStructure[] dsPoint = new DerivativeStructure[params.length];<a name="line.170"></a>
+<span class="sourceLineNo">171</span>        final int nC = params.length;<a name="line.171"></a>
+<span class="sourceLineNo">172</span>        for (int i = 0; i &lt; nC; ++i) {<a name="line.172"></a>
+<span class="sourceLineNo">173</span>            dsPoint[i] = new DerivativeStructure(nC, 1, i, params[i]);<a name="line.173"></a>
+<span class="sourceLineNo">174</span>        }<a name="line.174"></a>
+<span class="sourceLineNo">175</span>        final DerivativeStructure[] dsValue = jF.value(dsPoint);<a name="line.175"></a>
+<span class="sourceLineNo">176</span>        final int nR = getTarget().length;<a name="line.176"></a>
+<span class="sourceLineNo">177</span>        if (dsValue.length != nR) {<a name="line.177"></a>
+<span class="sourceLineNo">178</span>            throw new DimensionMismatchException(dsValue.length, nR);<a name="line.178"></a>
+<span class="sourceLineNo">179</span>        }<a name="line.179"></a>
+<span class="sourceLineNo">180</span>        final double[][] jacobianData = new double[nR][nC];<a name="line.180"></a>
+<span class="sourceLineNo">181</span>        for (int i = 0; i &lt; nR; ++i) {<a name="line.181"></a>
+<span class="sourceLineNo">182</span>            int[] orders = new int[nC];<a name="line.182"></a>
+<span class="sourceLineNo">183</span>            for (int j = 0; j &lt; nC; ++j) {<a name="line.183"></a>
+<span class="sourceLineNo">184</span>                orders[j] = 1;<a name="line.184"></a>
+<span class="sourceLineNo">185</span>                jacobianData[i][j] = dsValue[i].getPartialDerivative(orders);<a name="line.185"></a>
+<span class="sourceLineNo">186</span>                orders[j] = 0;<a name="line.186"></a>
+<span class="sourceLineNo">187</span>            }<a name="line.187"></a>
+<span class="sourceLineNo">188</span>        }<a name="line.188"></a>
+<span class="sourceLineNo">189</span><a name="line.189"></a>
+<span class="sourceLineNo">190</span>        return weightMatrixSqrt.multiply(MatrixUtils.createRealMatrix(jacobianData));<a name="line.190"></a>
+<span class="sourceLineNo">191</span>    }<a name="line.191"></a>
+<span class="sourceLineNo">192</span><a name="line.192"></a>
+<span class="sourceLineNo">193</span>    /**<a name="line.193"></a>
+<span class="sourceLineNo">194</span>     * Update the residuals array and cost function value.<a name="line.194"></a>
+<span class="sourceLineNo">195</span>     * @throws DimensionMismatchException if the dimension does not match the<a name="line.195"></a>
+<span class="sourceLineNo">196</span>     * problem dimension.<a name="line.196"></a>
+<span class="sourceLineNo">197</span>     * @throws org.apache.commons.math3.exception.TooManyEvaluationsException<a name="line.197"></a>
+<span class="sourceLineNo">198</span>     * if the maximal number of evaluations is exceeded.<a name="line.198"></a>
+<span class="sourceLineNo">199</span>     * @deprecated As of 3.1. Please use {@link #computeResiduals(double[])},<a name="line.199"></a>
+<span class="sourceLineNo">200</span>     * {@link #computeObjectiveValue(double[])}, {@link #computeCost(double[])}<a name="line.200"></a>
+<span class="sourceLineNo">201</span>     * and {@link #setCost(double)} instead.<a name="line.201"></a>
+<span class="sourceLineNo">202</span>     */<a name="line.202"></a>
+<span class="sourceLineNo">203</span>    @Deprecated<a name="line.203"></a>
+<span class="sourceLineNo">204</span>    protected void updateResidualsAndCost() {<a name="line.204"></a>
+<span class="sourceLineNo">205</span>        objective = computeObjectiveValue(point);<a name="line.205"></a>
+<span class="sourceLineNo">206</span>        final double[] res = computeResiduals(objective);<a name="line.206"></a>
+<span class="sourceLineNo">207</span><a name="line.207"></a>
+<span class="sourceLineNo">208</span>        // Compute cost.<a name="line.208"></a>
+<span class="sourceLineNo">209</span>        cost = computeCost(res);<a name="line.209"></a>
+<span class="sourceLineNo">210</span><a name="line.210"></a>
+<span class="sourceLineNo">211</span>        // Compute weighted residuals.<a name="line.211"></a>
+<span class="sourceLineNo">212</span>        final ArrayRealVector residuals = new ArrayRealVector(res);<a name="line.212"></a>
+<span class="sourceLineNo">213</span>        weightedResiduals = weightMatrixSqrt.operate(residuals).toArray();<a name="line.213"></a>
+<span class="sourceLineNo">214</span>    }<a name="line.214"></a>
+<span class="sourceLineNo">215</span><a name="line.215"></a>
+<span class="sourceLineNo">216</span>    /**<a name="line.216"></a>
+<span class="sourceLineNo">217</span>     * Computes the cost.<a name="line.217"></a>
+<span class="sourceLineNo">218</span>     *<a name="line.218"></a>
+<span class="sourceLineNo">219</span>     * @param residuals Residuals.<a name="line.219"></a>
+<span class="sourceLineNo">220</span>     * @return the cost.<a name="line.220"></a>
+<span class="sourceLineNo">221</span>     * @see #computeResiduals(double[])<a name="line.221"></a>
+<span class="sourceLineNo">222</span>     * @since 3.1<a name="line.222"></a>
+<span class="sourceLineNo">223</span>     */<a name="line.223"></a>
+<span class="sourceLineNo">224</span>    protected double computeCost(double[] residuals) {<a name="line.224"></a>
+<span class="sourceLineNo">225</span>        final ArrayRealVector r = new ArrayRealVector(residuals);<a name="line.225"></a>
+<span class="sourceLineNo">226</span>        return FastMath.sqrt(r.dotProduct(getWeight().operate(r)));<a name="line.226"></a>
+<span class="sourceLineNo">227</span>    }<a name="line.227"></a>
+<span class="sourceLineNo">228</span><a name="line.228"></a>
+<span class="sourceLineNo">229</span>    /**<a name="line.229"></a>
+<span class="sourceLineNo">230</span>     * Get the Root Mean Square value.<a name="line.230"></a>
+<span class="sourceLineNo">231</span>     * Get the Root Mean Square value, i.e. the root of the arithmetic<a name="line.231"></a>
+<span class="sourceLineNo">232</span>     * mean of the square of all weighted residuals. This is related to the<a name="line.232"></a>
+<span class="sourceLineNo">233</span>     * criterion that is minimized by the optimizer as follows: if<a name="line.233"></a>
+<span class="sourceLineNo">234</span>     * &lt;em&gt;c&lt;/em&gt; if the criterion, and &lt;em&gt;n&lt;/em&gt; is the number of<a name="line.234"></a>
+<span class="sourceLineNo">235</span>     * measurements, then the RMS is &lt;em&gt;sqrt (c/n)&lt;/em&gt;.<a name="line.235"></a>
+<span class="sourceLineNo">236</span>     *<a name="line.236"></a>
+<span class="sourceLineNo">237</span>     * @return RMS value<a name="line.237"></a>
+<span class="sourceLineNo">238</span>     */<a name="line.238"></a>
+<span class="sourceLineNo">239</span>    public double getRMS() {<a name="line.239"></a>
+<span class="sourceLineNo">240</span>        return FastMath.sqrt(getChiSquare() / rows);<a name="line.240"></a>
+<span class="sourceLineNo">241</span>    }<a name="line.241"></a>
+<span class="sourceLineNo">242</span><a name="line.242"></a>
+<span class="sourceLineNo">243</span>    /**<a name="line.243"></a>
+<span class="sourceLineNo">244</span>     * Get a Chi-Square-like value assuming the N residuals follow N<a name="line.244"></a>
+<span class="sourceLineNo">245</span>     * distinct normal distributions centered on 0 and whose variances are<a name="line.245"></a>
+<span class="sourceLineNo">246</span>     * the reciprocal of the weights.<a name="line.246"></a>
+<span class="sourceLineNo">247</span>     * @return chi-square value<a name="line.247"></a>
+<span class="sourceLineNo">248</span>     */<a name="line.248"></a>
+<span class="sourceLineNo">249</span>    public double getChiSquare() {<a name="line.249"></a>
+<span class="sourceLineNo">250</span>        return cost * cost;<a name="line.250"></a>
+<span class="sourceLineNo">251</span>    }<a name="line.251"></a>
+<span class="sourceLineNo">252</span><a name="line.252"></a>
+<span class="sourceLineNo">253</span>    /**<a name="line.253"></a>
+<span class="sourceLineNo">254</span>     * Gets the square-root of the weight matrix.<a name="line.254"></a>
+<span class="sourceLineNo">255</span>     *<a name="line.255"></a>
+<span class="sourceLineNo">256</span>     * @return the square-root of the weight matrix.<a name="line.256"></a>
+<span class="sourceLineNo">257</span>     * @since 3.1<a name="line.257"></a>
+<span class="sourceLineNo">258</span>     */<a name="line.258"></a>
+<span class="sourceLineNo">259</span>    public RealMatrix getWeightSquareRoot() {<a name="line.259"></a>
+<span class="sourceLineNo">260</span>        return weightMatrixSqrt.copy();<a name="line.260"></a>
+<span class="sourceLineNo">261</span>    }<a name="line.261"></a>
+<span class="sourceLineNo">262</span><a name="line.262"></a>
+<span class="sourceLineNo">263</span>    /**<a name="line.263"></a>
+<span class="sourceLineNo">264</span>     * Sets the cost.<a name="line.264"></a>
+<span class="sourceLineNo">265</span>     *<a name="line.265"></a>
+<span class="sourceLineNo">266</span>     * @param cost Cost value.<a name="line.266"></a>
+<span class="sourceLineNo">267</span>     * @since 3.1<a name="line.267"></a>
+<span class="sourceLineNo">268</span>     */<a name="line.268"></a>
+<span class="sourceLineNo">269</span>    protected void setCost(double cost) {<a name="line.269"></a>
+<span class="sourceLineNo">270</span>        this.cost = cost;<a name="line.270"></a>
+<span class="sourceLineNo">271</span>    }<a name="line.271"></a>
+<span class="sourceLineNo">272</span><a name="line.272"></a>
+<span class="sourceLineNo">273</span>    /**<a name="line.273"></a>
+<span class="sourceLineNo">274</span>     * Get the covariance matrix of the optimized parameters.<a name="line.274"></a>
+<span class="sourceLineNo">275</span>     *<a name="line.275"></a>
+<span class="sourceLineNo">276</span>     * @return the covariance matrix.<a name="line.276"></a>
+<span class="sourceLineNo">277</span>     * @throws org.apache.commons.math3.linear.SingularMatrixException<a name="line.277"></a>
+<span class="sourceLineNo">278</span>     * if the covariance matrix cannot be computed (singular problem).<a name="line.278"></a>
+<span class="sourceLineNo">279</span>     * @see #getCovariances(double)<a name="line.279"></a>
+<span class="sourceLineNo">280</span>     * @deprecated As of 3.1. Please use {@link #computeCovariances(double[],double)}<a name="line.280"></a>
+<span class="sourceLineNo">281</span>     * instead.<a name="line.281"></a>
+<span class="sourceLineNo">282</span>     */<a name="line.282"></a>
+<span class="sourceLineNo">283</span>    @Deprecated<a name="line.283"></a>
+<span class="sourceLineNo">284</span>    public double[][] getCovariances() {<a name="line.284"></a>
+<span class="sourceLineNo">285</span>        return getCovariances(DEFAULT_SINGULARITY_THRESHOLD);<a name="line.285"></a>
+<span class="sourceLineNo">286</span>    }<a name="line.286"></a>
+<span class="sourceLineNo">287</span><a name="line.287"></a>
+<span class="sourceLineNo">288</span>    /**<a name="line.288"></a>
+<span class="sourceLineNo">289</span>     * Get the covariance matrix of the optimized parameters.<a name="line.289"></a>
+<span class="sourceLineNo">290</span>     * &lt;br/&gt;<a name="line.290"></a>
+<span class="sourceLineNo">291</span>     * Note that this operation involves the inversion of the<a name="line.291"></a>
+<span class="sourceLineNo">292</span>     * &lt;code&gt;J&lt;sup&gt;T&lt;/sup&gt;J&lt;/code&gt; matrix, where {@code J} is the<a name="line.292"></a>
+<span class="sourceLineNo">293</span>     * Jacobian matrix.<a name="line.293"></a>
+<span class="sourceLineNo">294</span>     * The {@code threshold} parameter is a way for the caller to specify<a name="line.294"></a>
+<span class="sourceLineNo">295</span>     * that the result of this computation should be considered meaningless,<a name="line.295"></a>
+<span class="sourceLineNo">296</span>     * and thus trigger an exception.<a name="line.296"></a>
+<span class="sourceLineNo">297</span>     *<a name="line.297"></a>
+<span class="sourceLineNo">298</span>     * @param threshold Singularity threshold.<a name="line.298"></a>
+<span class="sourceLineNo">299</span>     * @return the covariance matrix.<a name="line.299"></a>
+<span class="sourceLineNo">300</span>     * @throws org.apache.commons.math3.linear.SingularMatrixException<a name="line.300"></a>
+<span class="sourceLineNo">301</span>     * if the covariance matrix cannot be computed (singular problem).<a name="line.301"></a>
+<span class="sourceLineNo">302</span>     * @deprecated As of 3.1. Please use {@link #computeCovariances(double[],double)}<a name="line.302"></a>
+<span class="sourceLineNo">303</span>     * instead.<a name="line.303"></a>
+<span class="sourceLineNo">304</span>     */<a name="line.304"></a>
+<span class="sourceLineNo">305</span>    @Deprecated<a name="line.305"></a>
+<span class="sourceLineNo">306</span>    public double[][] getCovariances(double threshold) {<a name="line.306"></a>
+<span class="sourceLineNo">307</span>        return computeCovariances(point, threshold);<a name="line.307"></a>
+<span class="sourceLineNo">308</span>    }<a name="line.308"></a>
+<span class="sourceLineNo">309</span><a name="line.309"></a>
+<span class="sourceLineNo">310</span>    /**<a name="line.310"></a>
+<span class="sourceLineNo">311</span>     * Get the covariance matrix of the optimized parameters.<a name="line.311"></a>
+<span class="sourceLineNo">312</span>     * &lt;br/&gt;<a name="line.312"></a>
+<span class="sourceLineNo">313</span>     * Note that this operation involves the inversion of the<a name="line.313"></a>
+<span class="sourceLineNo">314</span>     * &lt;code&gt;J&lt;sup&gt;T&lt;/sup&gt;J&lt;/code&gt; matrix, where {@code J} is the<a name="line.314"></a>
+<span class="sourceLineNo">315</span>     * Jacobian matrix.<a name="line.315"></a>
+<span class="sourceLineNo">316</span>     * The {@code threshold} parameter is a way for the caller to specify<a name="line.316"></a>
+<span class="sourceLineNo">317</span>     * that the result of this computation should be considered meaningless,<a name="line.317"></a>
+<span class="sourceLineNo">318</span>     * and thus trigger an exception.<a name="line.318"></a>
+<span class="sourceLineNo">319</span>     *<a name="line.319"></a>
+<span class="sourceLineNo">320</span>     * @param params Model parameters.<a name="line.320"></a>
+<span class="sourceLineNo">321</span>     * @param threshold Singularity threshold.<a name="line.321"></a>
+<span class="sourceLineNo">322</span>     * @return the covariance matrix.<a name="line.322"></a>
+<span class="sourceLineNo">323</span>     * @throws org.apache.commons.math3.linear.SingularMatrixException<a name="line.323"></a>
+<span class="sourceLineNo">324</span>     * if the covariance matrix cannot be computed (singular problem).<a name="line.324"></a>
+<span class="sourceLineNo">325</span>     * @since 3.1<a name="line.325"></a>
+<span class="sourceLineNo">326</span>     */<a name="line.326"></a>
+<span class="sourceLineNo">327</span>    public double[][] computeCovariances(double[] params,<a name="line.327"></a>
+<span class="sourceLineNo">328</span>                                         double threshold) {<a name="line.328"></a>
+<span class="sourceLineNo">329</span>        // Set up the Jacobian.<a name="line.329"></a>
+<span class="sourceLineNo">330</span>        final RealMatrix j = computeWeightedJacobian(params);<a name="line.330"></a>
+<span class="sourceLineNo">331</span><a name="line.331"></a>
+<span class="sourceLineNo">332</span>        // Compute transpose(J)J.<a name="line.332"></a>
+<span class="sourceLineNo">333</span>        final RealMatrix jTj = j.transpose().multiply(j);<a name="line.333"></a>
+<span class="sourceLineNo">334</span><a name="line.334"></a>
+<span class="sourceLineNo">335</span>        // Compute the covariances matrix.<a name="line.335"></a>
+<span class="sourceLineNo">336</span>        final DecompositionSolver solver<a name="line.336"></a>
+<span class="sourceLineNo">337</span>            = new QRDecomposition(jTj, threshold).getSolver();<a name="line.337"></a>
+<span class="sourceLineNo">338</span>        return solver.getInverse().getData();<a name="line.338"></a>
+<span class="sourceLineNo">339</span>    }<a name="line.339"></a>
+<span class="sourceLineNo">340</span><a name="line.340"></a>
+<span class="sourceLineNo">341</span>    /**<a name="line.341"></a>
+<span class="sourceLineNo">342</span>     * &lt;p&gt;<a name="line.342"></a>
+<span class="sourceLineNo">343</span>     * Returns an estimate of the standard deviation of each parameter. The<a name="line.343"></a>
+<span class="sourceLineNo">344</span>     * returned values are the so-called (asymptotic) standard errors on the<a name="line.344"></a>
+<span class="sourceLineNo">345</span>     * parameters, defined as {@code sd(a[i]) = sqrt(S / (n - m) * C[i][i])},<a name="line.345"></a>
+<span class="sourceLineNo">346</span>     * where {@code a[i]} is the optimized value of the {@code i}-th parameter,<a name="line.346"></a>
+<span class="sourceLineNo">347</span>     * {@code S} is the minimized value of the sum of squares objective function<a name="line.347"></a>
+<span class="sourceLineNo">348</span>     * (as returned by {@link #getChiSquare()}), {@code n} is the number of<a name="line.348"></a>
+<span class="sourceLineNo">349</span>     * observations, {@code m} is the number of parameters and {@code C} is the<a name="line.349"></a>
+<span class="sourceLineNo">350</span>     * covariance matrix.<a name="line.350"></a>
+<span class="sourceLineNo">351</span>     * &lt;/p&gt;<a name="line.351"></a>
+<span class="sourceLineNo">352</span>     * &lt;p&gt;<a name="line.352"></a>
+<span class="sourceLineNo">353</span>     * See also<a name="line.353"></a>
+<span class="sourceLineNo">354</span>     * &lt;a href="http://en.wikipedia.org/wiki/Least_squares"&gt;Wikipedia&lt;/a&gt;,<a name="line.354"></a>
+<span class="sourceLineNo">355</span>     * or<a name="line.355"></a>
+<span class="sourceLineNo">356</span>     * &lt;a href="http://mathworld.wolfram.com/LeastSquaresFitting.html"&gt;MathWorld&lt;/a&gt;,<a name="line.356"></a>
+<span class="sourceLineNo">357</span>     * equations (34) and (35) for a particular case.<a name="line.357"></a>
+<span class="sourceLineNo">358</span>     * &lt;/p&gt;<a name="line.358"></a>
+<span class="sourceLineNo">359</span>     *<a name="line.359"></a>
+<span class="sourceLineNo">360</span>     * @return an estimate of the standard deviation of the optimized parameters<a name="line.360"></a>
+<span class="sourceLineNo">361</span>     * @throws org.apache.commons.math3.linear.SingularMatrixException<a name="line.361"></a>
+<span class="sourceLineNo">362</span>     * if the covariance matrix cannot be computed.<a name="line.362"></a>
+<span class="sourceLineNo">363</span>     * @throws NumberIsTooSmallException if the number of degrees of freedom is not<a name="line.363"></a>
+<span class="sourceLineNo">364</span>     * positive, i.e. the number of measurements is less or equal to the number of<a name="line.364"></a>
+<span class="sourceLineNo">365</span>     * parameters.<a name="line.365"></a>
+<span class="sourceLineNo">366</span>     * @deprecated as of version 3.1, {@link #computeSigma(double[],double)} should be used<a name="line.366"></a>
+<span class="sourceLineNo">367</span>     * instead. It should be emphasized that {@code guessParametersErrors} and<a name="line.367"></a>
+<span class="sourceLineNo">368</span>     * {@code computeSigma} are &lt;em&gt;not&lt;/em&gt; strictly equivalent.<a name="line.368"></a>
+<span class="sourceLineNo">369</span>     */<a name="line.369"></a>
+<span class="sourceLineNo">370</span>    @Deprecated<a name="line.370"></a>
+<span class="sourceLineNo">371</span>    public double[] guessParametersErrors() {<a name="line.371"></a>
+<span class="sourceLineNo">372</span>        if (rows &lt;= cols) {<a name="line.372"></a>
+<span class="sourceLineNo">373</span>            throw new NumberIsTooSmallException(LocalizedFormats.NO_DEGREES_OF_FREEDOM,<a name="line.373"></a>
+<span class="sourceLineNo">374</span>                                                rows, cols, false);<a name="line.374"></a>
+<span class="sourceLineNo">375</span>        }<a name="line.375"></a>
+<span class="sourceLineNo">376</span>        double[] errors = new double[cols];<a name="line.376"></a>
+<span class="sourceLineNo">377</span>        final double c = FastMath.sqrt(getChiSquare() / (rows - cols));<a name="line.377"></a>
+<span class="sourceLineNo">378</span>        double[][] covar = computeCovariances(point, 1e-14);<a name="line.378"></a>
+<span class="sourceLineNo">379</span>        for (int i = 0; i &lt; errors.length; ++i) {<a name="line.379"></a>
+<span class="sourceLineNo">380</span>            errors[i] = FastMath.sqrt(covar[i][i]) * c;<a name="line.380"></a>
+<span class="sourceLineNo">381</span>        }<a name="line.381"></a>
+<span class="sourceLineNo">382</span>        return errors;<a name="line.382"></a>
+<span class="sourceLineNo">383</span>    }<a name="line.383"></a>
+<span class="sourceLineNo">384</span><a name="line.384"></a>
+<span class="sourceLineNo">385</span>    /**<a name="line.385"></a>
+<span class="sourceLineNo">386</span>     * Computes an estimate of the standard deviation of the parameters. The<a name="line.386"></a>
+<span class="sourceLineNo">387</span>     * returned values are the square root of the diagonal coefficients of the<a name="line.387"></a>
+<span class="sourceLineNo">388</span>     * covariance matrix, {@code sd(a[i]) ~= sqrt(C[i][i])}, where {@code a[i]}<a name="line.388"></a>
+<span class="sourceLineNo">389</span>     * is the optimized value of the {@code i}-th parameter, and {@code C} is<a name="line.389"></a>
+<span class="sourceLineNo">390</span>     * the covariance matrix.<a name="line.390"></a>
+<span class="sourceLineNo">391</span>     *<a name="line.391"></a>
+<span class="sourceLineNo">392</span>     * @param params Model parameters.<a name="line.392"></a>
+<span class="sourceLineNo">393</span>     * @param covarianceSingularityThreshold Singularity threshold (see<a name="line.393"></a>
+<span class="sourceLineNo">394</span>     * {@link #computeCovariances(double[],double) computeCovariances}).<a name="line.394"></a>
+<span class="sourceLineNo">395</span>     * @return an estimate of the standard deviation of the optimized parameters<a name="line.395"></a>
+<span class="sourceLineNo">396</span>     * @throws org.apache.commons.math3.linear.SingularMatrixException<a name="line.396"></a>
+<span class="sourceLineNo">397</span>     * if the covariance matrix cannot be computed.<a name="line.397"></a>
+<span class="sourceLineNo">398</span>     * @since 3.1<a name="line.398"></a>
+<span class="sourceLineNo">399</span>     */<a name="line.399"></a>
+<span class="sourceLineNo">400</span>    public double[] computeSigma(double[] params,<a name="line.400"></a>
+<span class="sourceLineNo">401</span>                                 double covarianceSingularityThreshold) {<a name="line.401"></a>
+<span class="sourceLineNo">402</span>        final int nC = params.length;<a name="line.402"></a>
+<span class="sourceLineNo">403</span>        final double[] sig = new double[nC];<a name="line.403"></a>
+<span class="sourceLineNo">404</span>        final double[][] cov = computeCovariances(params, covarianceSingularityThreshold);<a name="line.404"></a>
+<span class="sourceLineNo">405</span>        for (int i = 0; i &lt; nC; ++i) {<a name="line.405"></a>
+<span class="sourceLineNo">406</span>            sig[i] = FastMath.sqrt(cov[i][i]);<a name="line.406"></a>
+<span class="sourceLineNo">407</span>        }<a name="line.407"></a>
+<span class="sourceLineNo">408</span>        return sig;<a name="line.408"></a>
+<span class="sourceLineNo">409</span>    }<a name="line.409"></a>
+<span class="sourceLineNo">410</span><a name="line.410"></a>
+<span class="sourceLineNo">411</span>    /** {@inheritDoc}<a name="line.411"></a>
+<span class="sourceLineNo">412</span>     * @deprecated As of 3.1. Please use<a name="line.412"></a>
+<span class="sourceLineNo">413</span>     * {@link BaseAbstractMultivariateVectorOptimizer#optimize(int,<a name="line.413"></a>
+<span class="sourceLineNo">414</span>     * org.apache.commons.math3.analysis.MultivariateVectorFunction,OptimizationData[])<a name="line.414"></a>
+<span class="sourceLineNo">415</span>     * optimize(int,MultivariateDifferentiableVectorFunction,OptimizationData...)}<a name="line.415"></a>
+<span class="sourceLineNo">416</span>     * instead.<a name="line.416"></a>
+<span class="sourceLineNo">417</span>     */<a name="line.417"></a>
+<span class="sourceLineNo">418</span>    @Override<a name="line.418"></a>
+<span class="sourceLineNo">419</span>    @Deprecated<a name="line.419"></a>
+<span class="sourceLineNo">420</span>    public PointVectorValuePair optimize(int maxEval,<a name="line.420"></a>
+<span class="sourceLineNo">421</span>                                         final DifferentiableMultivariateVectorFunction f,<a name="line.421"></a>
+<span class="sourceLineNo">422</span>                                         final double[] target, final double[] weights,<a name="line.422"></a>
+<span class="sourceLineNo">423</span>                                         final double[] startPoint) {<a name="line.423"></a>
+<span class="sourceLineNo">424</span>        return optimizeInternal(maxEval,<a name="line.424"></a>
+<span class="sourceLineNo">425</span>                                FunctionUtils.toMultivariateDifferentiableVectorFunction(f),<a name="line.425"></a>
+<span class="sourceLineNo">426</span>                                new Target(target),<a name="line.426"></a>
+<span class="sourceLineNo">427</span>                                new Weight(weights),<a name="line.427"></a>
+<span class="sourceLineNo">428</span>                                new InitialGuess(startPoint));<a name="line.428"></a>
+<span class="sourceLineNo">429</span>    }<a name="line.429"></a>
+<span class="sourceLineNo">430</span><a name="line.430"></a>
+<span class="sourceLineNo">431</span>    /**<a name="line.431"></a>
+<span class="sourceLineNo">432</span>     * Optimize an objective function.<a name="line.432"></a>
+<span class="sourceLineNo">433</span>     * Optimization is considered to be a weighted least-squares minimization.<a name="line.433"></a>
+<span class="sourceLineNo">434</span>     * The cost function to be minimized is<a name="line.434"></a>
+<span class="sourceLineNo">435</span>     * &lt;code&gt;&amp;sum;weight&lt;sub&gt;i&lt;/sub&gt;(objective&lt;sub&gt;i&lt;/sub&gt; - target&lt;sub&gt;i&lt;/sub&gt;)&lt;sup&gt;2&lt;/sup&gt;&lt;/code&gt;<a name="line.435"></a>
+<span class="sourceLineNo">436</span>     *<a name="line.436"></a>
+<span class="sourceLineNo">437</span>     * @param f Objective function.<a name="line.437"></a>
+<span class="sourceLineNo">438</span>     * @param target Target value for the objective functions at optimum.<a name="line.438"></a>
+<span class="sourceLineNo">439</span>     * @param weights Weights for the least squares cost computation.<a name="line.439"></a>
+<span class="sourceLineNo">440</span>     * @param startPoint Start point for optimization.<a name="line.440"></a>
+<span class="sourceLineNo">441</span>     * @return the point/value pair giving the optimal value for objective<a name="line.441"></a>
+<span class="sourceLineNo">442</span>     * function.<a name="line.442"></a>
+<span class="sourceLineNo">443</span>     * @param maxEval Maximum number of function evaluations.<a name="line.443"></a>
+<span class="sourceLineNo">444</span>     * @throws org.apache.commons.math3.exception.DimensionMismatchException<a name="line.444"></a>
+<span class="sourceLineNo">445</span>     * if the start point dimension is wrong.<a name="line.445"></a>
+<span class="sourceLineNo">446</span>     * @throws org.apache.commons.math3.exception.TooManyEvaluationsException<a name="line.446"></a>
+<span class="sourceLineNo">447</span>     * if the maximal number of evaluations is exceeded.<a name="line.447"></a>
+<span class="sourceLineNo">448</span>     * @throws org.apache.commons.math3.exception.NullArgumentException if<a name="line.448"></a>
+<span class="sourceLineNo">449</span>     * any argument is {@code null}.<a name="line.449"></a>
+<span class="sourceLineNo">450</span>     * @deprecated As of 3.1. Please use<a name="line.450"></a>
+<span class="sourceLineNo">451</span>     * {@link BaseAbstractMultivariateVectorOptimizer#optimize(int,<a name="line.451"></a>
+<span class="sourceLineNo">452</span>     * org.apache.commons.math3.analysis.MultivariateVectorFunction,OptimizationData[])<a name="line.452"></a>
+<span class="sourceLineNo">453</span>     * optimize(int,MultivariateDifferentiableVectorFunction,OptimizationData...)}<a name="line.453"></a>
+<span class="sourceLineNo">454</span>     * instead.<a name="line.454"></a>
+<span class="sourceLineNo">455</span>     */<a name="line.455"></a>
+<span class="sourceLineNo">456</span>    @Deprecated<a name="line.456"></a>
+<span class="sourceLineNo">457</span>    public PointVectorValuePair optimize(final int maxEval,<a name="line.457"></a>
+<span class="sourceLineNo">458</span>                                         final MultivariateDifferentiableVectorFunction f,<a name="line.458"></a>
+<span class="sourceLineNo">459</span>                                         final double[] target, final double[] weights,<a name="line.459"></a>
+<span class="sourceLineNo">460</span>                                         final double[] startPoint) {<a name="line.460"></a>
+<span class="sourceLineNo">461</span>        return optimizeInternal(maxEval, f,<a name="line.461"></a>
+<span class="sourceLineNo">462</span>                                new Target(target),<a name="line.462"></a>
+<span class="sourceLineNo">463</span>                                new Weight(weights),<a name="line.463"></a>
+<span class="sourceLineNo">464</span>                                new InitialGuess(startPoint));<a name="line.464"></a>
+<span class="sourceLineNo">465</span>    }<a name="line.465"></a>
+<span class="sourceLineNo">466</span><a name="line.466"></a>
+<span class="sourceLineNo">467</span>    /**<a name="line.467"></a>
+<span class="sourceLineNo">468</span>     * Optimize an objective function.<a name="line.468"></a>
+<span class="sourceLineNo">469</span>     * Optimization is considered to be a weighted least-squares minimization.<a name="line.469"></a>
+<span class="sourceLineNo">470</span>     * The cost function to be minimized is<a name="line.470"></a>
+<span class="sourceLineNo">471</span>     * &lt;code&gt;&amp;sum;weight&lt;sub&gt;i&lt;/sub&gt;(objective&lt;sub&gt;i&lt;/sub&gt; - target&lt;sub&gt;i&lt;/sub&gt;)&lt;sup&gt;2&lt;/sup&gt;&lt;/code&gt;<a name="line.471"></a>
+<span class="sourceLineNo">472</span>     *<a name="line.472"></a>
+<span class="sourceLineNo">473</span>     * @param maxEval Allowed number of evaluations of the objective function.<a name="line.473"></a>
+<span class="sourceLineNo">474</span>     * @param f Objective function.<a name="line.474"></a>
+<span class="sourceLineNo">475</span>     * @param optData Optimization data. The following data will be looked for:<a name="line.475"></a>
+<span class="sourceLineNo">476</span>     * &lt;ul&gt;<a name="line.476"></a>
+<span class="sourceLineNo">477</span>     *  &lt;li&gt;{@link Target}&lt;/li&gt;<a name="line.477"></a>
+<span class="sourceLineNo">478</span>     *  &lt;li&gt;{@link Weight}&lt;/li&gt;<a name="line.478"></a>
+<span class="sourceLineNo">479</span>     *  &lt;li&gt;{@link InitialGuess}&lt;/li&gt;<a name="line.479"></a>
+<span class="sourceLineNo">480</span>     * &lt;/ul&gt;<a name="line.480"></a>
+<span class="sourceLineNo">481</span>     * @return the point/value pair giving the optimal value of the objective<a name="line.481"></a>
+<span class="sourceLineNo">482</span>     * function.<a name="line.482"></a>
+<span class="sourceLineNo">483</span>     * @throws org.apache.commons.math3.exception.TooManyEvaluationsException if<a name="line.483"></a>
+<span class="sourceLineNo">484</span>     * the maximal number of evaluations is exceeded.<a name="line.484"></a>
+<span class="sourceLineNo">485</span>     * @throws DimensionMismatchException if the target, and weight arguments<a name="line.485"></a>
+<span class="sourceLineNo">486</span>     * have inconsistent dimensions.<a name="line.486"></a>
+<span class="sourceLineNo">487</span>     * @see BaseAbstractMultivariateVectorOptimizer#optimizeInternal(int,<a name="line.487"></a>
+<span class="sourceLineNo">488</span>     * org.apache.commons.math3.analysis.MultivariateVectorFunction,OptimizationData[])<a name="line.488"></a>
+<span class="sourceLineNo">489</span>     * @since 3.1<a name="line.489"></a>
+<span class="sourceLineNo">490</span>     * @deprecated As of 3.1. Override is necessary only until this class's generic<a name="line.490"></a>
+<span class="sourceLineNo">491</span>     * argument is changed to {@code MultivariateDifferentiableVectorFunction}.<a name="line.491"></a>
+<span class="sourceLineNo">492</span>     */<a name="line.492"></a>
+<span class="sourceLineNo">493</span>    @Deprecated<a name="line.493"></a>
+<span class="sourceLineNo">494</span>    protected PointVectorValuePair optimizeInternal(final int maxEval,<a name="line.494"></a>
+<span class="sourceLineNo">495</span>                                                    final MultivariateDifferentiableVectorFunction f,<a name="line.495"></a>
+<span class="sourceLineNo">496</span>                                                    OptimizationData... optData) {<a name="line.496"></a>
+<span class="sourceLineNo">497</span>        // XXX Conversion will be removed when the generic argument of the<a name="line.497"></a>
+<span class="sourceLineNo">498</span>        // base class becomes "MultivariateDifferentiableVectorFunction".<a name="line.498"></a>
+<span class="sourceLineNo">499</span>        return super.optimizeInternal(maxEval, FunctionUtils.toDifferentiableMultivariateVectorFunction(f), optData);<a name="line.499"></a>
+<span class="sourceLineNo">500</span>    }<a name="line.500"></a>
+<span class="sourceLineNo">501</span><a name="line.501"></a>
+<span class="sourceLineNo">502</span>    /** {@inheritDoc} */<a name="line.502"></a>
+<span class="sourceLineNo">503</span>    @Override<a name="line.503"></a>
+<span class="sourceLineNo">504</span>    protected void setUp() {<a name="line.504"></a>
+<span class="sourceLineNo">505</span>        super.setUp();<a name="line.505"></a>
+<span class="sourceLineNo">506</span><a name="line.506"></a>
+<span class="sourceLineNo">507</span>        // Reset counter.<a name="line.507"></a>
+<span class="sourceLineNo">508</span>        jacobianEvaluations = 0;<a name="line.508"></a>
+<span class="sourceLineNo">509</span><a name="line.509"></a>
+<span class="sourceLineNo">510</span>        // Square-root of the weight matrix.<a name="line.510"></a>
+<span class="sourceLineNo">511</span>        weightMatrixSqrt = squareRoot(getWeight());<a name="line.511"></a>
+<span class="sourceLineNo">512</span><a name="line.512"></a>
+<span class="sourceLineNo">513</span>        // Store least squares problem characteristics.<a name="line.513"></a>
+<span class="sourceLineNo">514</span>        // XXX The conversion won't be necessary when the generic argument of<a name="line.514"></a>
+<span class="sourceLineNo">515</span>        // the base class becomes "MultivariateDifferentiableVectorFunction".<a name="line.515"></a>
+<span class="sourceLineNo">516</span>        // XXX "jF" is not strictly necessary anymore but is currently more<a name="line.516"></a>
+<span class="sourceLineNo">517</span>        // efficient than converting the value returned from "getObjectiveFunction()"<a name="line.517"></a>
+<span class="sourceLineNo">518</span>        // every time it is used.<a name="line.518"></a>
+<span class="sourceLineNo">519</span>        jF = FunctionUtils.toMultivariateDifferentiableVectorFunction((DifferentiableMultivariateVectorFunction) getObjectiveFunction());<a name="line.519"></a>
+<span class="sourceLineNo">520</span><a name="line.520"></a>
+<span class="sourceLineNo">521</span>        // Arrays shared with "private" and "protected" methods.<a name="line.521"></a>
+<span class="sourceLineNo">522</span>        point = getStartPoint();<a name="line.522"></a>
+<span class="sourceLineNo">523</span>        rows = getTarget().length;<a name="line.523"></a>
+<span class="sourceLineNo">524</span>        cols = point.length;<a name="line.524"></a>
+<span class="sourceLineNo">525</span>    }<a name="line.525"></a>
+<span class="sourceLineNo">526</span><a name="line.526"></a>
+<span class="sourceLineNo">527</span>    /**<a name="line.527"></a>
+<span class="sourceLineNo">528</span>     * Computes the residuals.<a name="line.528"></a>
+<span class="sourceLineNo">529</span>     * The residual is the difference between the observed (target)<a name="line.529"></a>
+<span class="sourceLineNo">530</span>     * values and the model (objective function) value.<a name="line.530"></a>
+<span class="sourceLineNo">531</span>     * There is one residual for each element of the vector-valued<a name="line.531"></a>
+<span class="sourceLineNo">532</span>     * function.<a name="line.532"></a>
+<span class="sourceLineNo">533</span>     *<a name="line.533"></a>
+<span class="sourceLineNo">534</span>     * @param objectiveValue Value of the the objective function. This is<a name="line.534"></a>
+<span class="sourceLineNo">535</span>     * the value returned from a call to<a name="line.535"></a>
+<span class="sourceLineNo">536</span>     * {@link #computeObjectiveValue(double[]) computeObjectiveValue}<a name="line.536"></a>
+<span class="sourceLineNo">537</span>     * (whose array argument contains the model parameters).<a name="line.537"></a>
+<span class="sourceLineNo">538</span>     * @return the residuals.<a name="line.538"></a>
+<span class="sourceLineNo">539</span>     * @throws DimensionMismatchException if {@code params} has a wrong<a name="line.539"></a>
+<span class="sourceLineNo">540</span>     * length.<a name="line.540"></a>
+<span class="sourceLineNo">541</span>     * @since 3.1<a name="line.541"></a>
+<span class="sourceLineNo">542</span>     */<a name="line.542"></a>
+<span class="sourceLineNo">543</span>    protected double[] computeResiduals(double[] objectiveValue) {<a name="line.543"></a>
+<span class="sourceLineNo">544</span>        final double[] target = getTarget();<a name="line.544"></a>
+<span class="sourceLineNo">545</span>        if (objectiveValue.length != target.length) {<a name="line.545"></a>
+<span class="sourceLineNo">546</span>            throw new DimensionMismatchException(target.length,<a name="line.546"></a>
+<span class="sourceLineNo">547</span>                                                 objectiveValue.length);<a name="line.547"></a>
+<span class="sourceLineNo">548</span>        }<a name="line.548"></a>
+<span class="sourceLineNo">549</span><a name="line.549"></a>
+<span class="sourceLineNo">550</span>        final double[] residuals = new double[target.length];<a name="line.550"></a>
+<span class="sourceLineNo">551</span>        for (int i = 0; i &lt; target.length; i++) {<a name="line.551"></a>
+<span class="sourceLineNo">552</span>            residuals[i] = target[i] - objectiveValue[i];<a name="line.552"></a>
+<span class="sourceLineNo">553</span>        }<a name="line.553"></a>
+<span class="sourceLineNo">554</span><a name="line.554"></a>
+<span class="sourceLineNo">555</span>        return residuals;<a name="line.555"></a>
+<span class="sourceLineNo">556</span>    }<a name="line.556"></a>
+<span class="sourceLineNo">557</span><a name="line.557"></a>
+<span class="sourceLineNo">558</span>    /**<a name="line.558"></a>
+<span class="sourceLineNo">559</span>     * Computes the square-root of the weight matrix.<a name="line.559"></a>
+<span class="sourceLineNo">560</span>     *<a name="line.560"></a>
+<span class="sourceLineNo">561</span>     * @param m Symmetric, positive-definite (weight) matrix.<a name="line.561"></a>
+<span class="sourceLineNo">562</span>     * @return the square-root of the weight matrix.<a name="line.562"></a>
+<span class="sourceLineNo">563</span>     */<a name="line.563"></a>
+<span class="sourceLineNo">564</span>    private RealMatrix squareRoot(RealMatrix m) {<a name="line.564"></a>
+<span class="sourceLineNo">565</span>        if (m instanceof DiagonalMatrix) {<a name="line.565"></a>
+<span class="sourceLineNo">566</span>            final int dim = m.getRowDimension();<a name="line.566"></a>
+<span class="sourceLineNo">567</span>            final RealMatrix sqrtM = new DiagonalMatrix(dim);<a name="line.567"></a>
+<span class="sourceLineNo">568</span>            for (int i = 0; i &lt; dim; i++) {<a name="line.568"></a>
+<span class="sourceLineNo">569</span>               sqrtM.setEntry(i, i, FastMath.sqrt(m.getEntry(i, i)));<a name="line.569"></a>
+<span class="sourceLineNo">570</span>            }<a name="line.570"></a>
+<span class="sourceLineNo">571</span>            return sqrtM;<a name="line.571"></a>
+<span class="sourceLineNo">572</span>        } else {<a name="line.572"></a>
+<span class="sourceLineNo">573</span>            final EigenDecomposition dec = new EigenDecomposition(m);<a name="line.573"></a>
+<span class="sourceLineNo">574</span>            return dec.getSquareRoot();<a name="line.574"></a>
+<span class="sourceLineNo">575</span>        }<a name="line.575"></a>
+<span class="sourceLineNo">576</span>    }<a name="line.576"></a>
+<span class="sourceLineNo">577</span>}<a name="line.577"></a>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+</pre>
+</div>
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/commons-complex/blob/b0db8fca/site-content/.svn/pristine/02/025dd274e61ae4e2987b5ed84bf12b696e6024ae.svn-base
----------------------------------------------------------------------
diff --git a/site-content/.svn/pristine/02/025dd274e61ae4e2987b5ed84bf12b696e6024ae.svn-base b/site-content/.svn/pristine/02/025dd274e61ae4e2987b5ed84bf12b696e6024ae.svn-base
new file mode 100644
index 0000000..5800518
--- /dev/null
+++ b/site-content/.svn/pristine/02/025dd274e61ae4e2987b5ed84bf12b696e6024ae.svn-base
@@ -0,0 +1,335 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html lang="en">
+<head>
+<title>Source code</title>
+<link rel="stylesheet" type="text/css" href="../../../../../../../../stylesheet.css" title="Style">
+</head>
+<body>
+<div class="sourceContainer">
+<pre><span class="sourceLineNo">001</span>/*<a name="line.1"></a>
+<span class="sourceLineNo">002</span> * Licensed to the Apache Software Foundation (ASF) under one or more<a name="line.2"></a>
+<span class="sourceLineNo">003</span> * contributor license agreements.  See the NOTICE file distributed with<a name="line.3"></a>
+<span class="sourceLineNo">004</span> * this work for additional information regarding copyright ownership.<a name="line.4"></a>
+<span class="sourceLineNo">005</span> * The ASF licenses this file to You under the Apache License, Version 2.0<a name="line.5"></a>
+<span class="sourceLineNo">006</span> * (the "License"); you may not use this file except in compliance with<a name="line.6"></a>
+<span class="sourceLineNo">007</span> * the License.  You may obtain a copy of the License at<a name="line.7"></a>
+<span class="sourceLineNo">008</span> *<a name="line.8"></a>
+<span class="sourceLineNo">009</span> *      http://www.apache.org/licenses/LICENSE-2.0<a name="line.9"></a>
+<span class="sourceLineNo">010</span> *<a name="line.10"></a>
+<span class="sourceLineNo">011</span> * Unless required by applicable law or agreed to in writing, software<a name="line.11"></a>
+<span class="sourceLineNo">012</span> * distributed under the License is distributed on an "AS IS" BASIS,<a name="line.12"></a>
+<span class="sourceLineNo">013</span> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<a name="line.13"></a>
+<span class="sourceLineNo">014</span> * See the License for the specific language governing permissions and<a name="line.14"></a>
+<span class="sourceLineNo">015</span> * limitations under the License.<a name="line.15"></a>
+<span class="sourceLineNo">016</span> */<a name="line.16"></a>
+<span class="sourceLineNo">017</span>package org.apache.commons.math3.geometry.euclidean.threed;<a name="line.17"></a>
+<span class="sourceLineNo">018</span><a name="line.18"></a>
+<span class="sourceLineNo">019</span>import java.util.ArrayList;<a name="line.19"></a>
+<span class="sourceLineNo">020</span><a name="line.20"></a>
+<span class="sourceLineNo">021</span>import org.apache.commons.math3.geometry.Point;<a name="line.21"></a>
+<span class="sourceLineNo">022</span>import org.apache.commons.math3.geometry.euclidean.twod.Euclidean2D;<a name="line.22"></a>
+<span class="sourceLineNo">023</span>import org.apache.commons.math3.geometry.euclidean.twod.PolygonsSet;<a name="line.23"></a>
+<span class="sourceLineNo">024</span>import org.apache.commons.math3.geometry.euclidean.twod.Vector2D;<a name="line.24"></a>
+<span class="sourceLineNo">025</span>import org.apache.commons.math3.geometry.partitioning.AbstractSubHyperplane;<a name="line.25"></a>
+<span class="sourceLineNo">026</span>import org.apache.commons.math3.geometry.partitioning.BSPTree;<a name="line.26"></a>
+<span class="sourceLineNo">027</span>import org.apache.commons.math3.geometry.partitioning.BSPTreeVisitor;<a name="line.27"></a>
+<span class="sourceLineNo">028</span>import org.apache.commons.math3.geometry.partitioning.BoundaryAttribute;<a name="line.28"></a>
+<span class="sourceLineNo">029</span>import org.apache.commons.math3.geometry.partitioning.RegionFactory;<a name="line.29"></a>
+<span class="sourceLineNo">030</span>import org.apache.commons.math3.geometry.partitioning.SubHyperplane;<a name="line.30"></a>
+<span class="sourceLineNo">031</span>import org.apache.commons.math3.util.FastMath;<a name="line.31"></a>
+<span class="sourceLineNo">032</span><a name="line.32"></a>
+<span class="sourceLineNo">033</span>/** Extractor for {@link PolygonsSet polyhedrons sets} outlines.<a name="line.33"></a>
+<span class="sourceLineNo">034</span> * &lt;p&gt;This class extracts the 2D outlines from {{@link PolygonsSet<a name="line.34"></a>
+<span class="sourceLineNo">035</span> * polyhedrons sets} in a specified projection plane.&lt;/p&gt;<a name="line.35"></a>
+<span class="sourceLineNo">036</span> * @since 3.0<a name="line.36"></a>
+<span class="sourceLineNo">037</span> */<a name="line.37"></a>
+<span class="sourceLineNo">038</span>public class OutlineExtractor {<a name="line.38"></a>
+<span class="sourceLineNo">039</span><a name="line.39"></a>
+<span class="sourceLineNo">040</span>    /** Abscissa axis of the projection plane. */<a name="line.40"></a>
+<span class="sourceLineNo">041</span>    private Vector3D u;<a name="line.41"></a>
+<span class="sourceLineNo">042</span><a name="line.42"></a>
+<span class="sourceLineNo">043</span>    /** Ordinate axis of the projection plane. */<a name="line.43"></a>
+<span class="sourceLineNo">044</span>    private Vector3D v;<a name="line.44"></a>
+<span class="sourceLineNo">045</span><a name="line.45"></a>
+<span class="sourceLineNo">046</span>    /** Normal of the projection plane (viewing direction). */<a name="line.46"></a>
+<span class="sourceLineNo">047</span>    private Vector3D w;<a name="line.47"></a>
+<span class="sourceLineNo">048</span><a name="line.48"></a>
+<span class="sourceLineNo">049</span>    /** Build an extractor for a specific projection plane.<a name="line.49"></a>
+<span class="sourceLineNo">050</span>     * @param u abscissa axis of the projection point<a name="line.50"></a>
+<span class="sourceLineNo">051</span>     * @param v ordinate axis of the projection point<a name="line.51"></a>
+<span class="sourceLineNo">052</span>     */<a name="line.52"></a>
+<span class="sourceLineNo">053</span>    public OutlineExtractor(final Vector3D u, final Vector3D v) {<a name="line.53"></a>
+<span class="sourceLineNo">054</span>        this.u = u;<a name="line.54"></a>
+<span class="sourceLineNo">055</span>        this.v = v;<a name="line.55"></a>
+<span class="sourceLineNo">056</span>        w = Vector3D.crossProduct(u, v);<a name="line.56"></a>
+<span class="sourceLineNo">057</span>    }<a name="line.57"></a>
+<span class="sourceLineNo">058</span><a name="line.58"></a>
+<span class="sourceLineNo">059</span>    /** Extract the outline of a polyhedrons set.<a name="line.59"></a>
+<span class="sourceLineNo">060</span>     * @param polyhedronsSet polyhedrons set whose outline must be extracted<a name="line.60"></a>
+<span class="sourceLineNo">061</span>     * @return an outline, as an array of loops.<a name="line.61"></a>
+<span class="sourceLineNo">062</span>     */<a name="line.62"></a>
+<span class="sourceLineNo">063</span>    public Vector2D[][] getOutline(final PolyhedronsSet polyhedronsSet) {<a name="line.63"></a>
+<span class="sourceLineNo">064</span><a name="line.64"></a>
+<span class="sourceLineNo">065</span>        // project all boundary facets into one polygons set<a name="line.65"></a>
+<span class="sourceLineNo">066</span>        final BoundaryProjector projector = new BoundaryProjector(polyhedronsSet.getTolerance());<a name="line.66"></a>
+<span class="sourceLineNo">067</span>        polyhedronsSet.getTree(true).visit(projector);<a name="line.67"></a>
+<span class="sourceLineNo">068</span>        final PolygonsSet projected = projector.getProjected();<a name="line.68"></a>
+<span class="sourceLineNo">069</span><a name="line.69"></a>
+<span class="sourceLineNo">070</span>        // Remove the spurious intermediate vertices from the outline<a name="line.70"></a>
+<span class="sourceLineNo">071</span>        final Vector2D[][] outline = projected.getVertices();<a name="line.71"></a>
+<span class="sourceLineNo">072</span>        for (int i = 0; i &lt; outline.length; ++i) {<a name="line.72"></a>
+<span class="sourceLineNo">073</span>            final Vector2D[] rawLoop = outline[i];<a name="line.73"></a>
+<span class="sourceLineNo">074</span>            int end = rawLoop.length;<a name="line.74"></a>
+<span class="sourceLineNo">075</span>            int j = 0;<a name="line.75"></a>
+<span class="sourceLineNo">076</span>            while (j &lt; end) {<a name="line.76"></a>
+<span class="sourceLineNo">077</span>                if (pointIsBetween(rawLoop, end, j)) {<a name="line.77"></a>
+<span class="sourceLineNo">078</span>                    // the point should be removed<a name="line.78"></a>
+<span class="sourceLineNo">079</span>                    for (int k = j; k &lt; (end - 1); ++k) {<a name="line.79"></a>
+<span class="sourceLineNo">080</span>                        rawLoop[k] = rawLoop[k + 1];<a name="line.80"></a>
+<span class="sourceLineNo">081</span>                    }<a name="line.81"></a>
+<span class="sourceLineNo">082</span>                    --end;<a name="line.82"></a>
+<span class="sourceLineNo">083</span>                } else {<a name="line.83"></a>
+<span class="sourceLineNo">084</span>                    // the point remains in the loop<a name="line.84"></a>
+<span class="sourceLineNo">085</span>                    ++j;<a name="line.85"></a>
+<span class="sourceLineNo">086</span>                }<a name="line.86"></a>
+<span class="sourceLineNo">087</span>            }<a name="line.87"></a>
+<span class="sourceLineNo">088</span>            if (end != rawLoop.length) {<a name="line.88"></a>
+<span class="sourceLineNo">089</span>                // resize the array<a name="line.89"></a>
+<span class="sourceLineNo">090</span>                outline[i] = new Vector2D[end];<a name="line.90"></a>
+<span class="sourceLineNo">091</span>                System.arraycopy(rawLoop, 0, outline[i], 0, end);<a name="line.91"></a>
+<span class="sourceLineNo">092</span>            }<a name="line.92"></a>
+<span class="sourceLineNo">093</span>        }<a name="line.93"></a>
+<span class="sourceLineNo">094</span><a name="line.94"></a>
+<span class="sourceLineNo">095</span>        return outline;<a name="line.95"></a>
+<span class="sourceLineNo">096</span><a name="line.96"></a>
+<span class="sourceLineNo">097</span>    }<a name="line.97"></a>
+<span class="sourceLineNo">098</span><a name="line.98"></a>
+<span class="sourceLineNo">099</span>    /** Check if a point is geometrically between its neighbor in an array.<a name="line.99"></a>
+<span class="sourceLineNo">100</span>     * &lt;p&gt;The neighbors are computed considering the array is a loop<a name="line.100"></a>
+<span class="sourceLineNo">101</span>     * (i.e. point at index (n-1) is before point at index 0)&lt;/p&gt;<a name="line.101"></a>
+<span class="sourceLineNo">102</span>     * @param loop points array<a name="line.102"></a>
+<span class="sourceLineNo">103</span>     * @param n number of points to consider in the array<a name="line.103"></a>
+<span class="sourceLineNo">104</span>     * @param i index of the point to check (must be between 0 and n-1)<a name="line.104"></a>
+<span class="sourceLineNo">105</span>     * @return true if the point is exactly between its neighbors<a name="line.105"></a>
+<span class="sourceLineNo">106</span>     */<a name="line.106"></a>
+<span class="sourceLineNo">107</span>    private boolean pointIsBetween(final Vector2D[] loop, final int n, final int i) {<a name="line.107"></a>
+<span class="sourceLineNo">108</span>        final Vector2D previous = loop[(i + n - 1) % n];<a name="line.108"></a>
+<span class="sourceLineNo">109</span>        final Vector2D current  = loop[i];<a name="line.109"></a>
+<span class="sourceLineNo">110</span>        final Vector2D next     = loop[(i + 1) % n];<a name="line.110"></a>
+<span class="sourceLineNo">111</span>        final double dx1       = current.getX() - previous.getX();<a name="line.111"></a>
+<span class="sourceLineNo">112</span>        final double dy1       = current.getY() - previous.getY();<a name="line.112"></a>
+<span class="sourceLineNo">113</span>        final double dx2       = next.getX()    - current.getX();<a name="line.113"></a>
+<span class="sourceLineNo">114</span>        final double dy2       = next.getY()    - current.getY();<a name="line.114"></a>
+<span class="sourceLineNo">115</span>        final double cross     = dx1 * dy2 - dx2 * dy1;<a name="line.115"></a>
+<span class="sourceLineNo">116</span>        final double dot       = dx1 * dx2 + dy1 * dy2;<a name="line.116"></a>
+<span class="sourceLineNo">117</span>        final double d1d2      = FastMath.sqrt((dx1 * dx1 + dy1 * dy1) * (dx2 * dx2 + dy2 * dy2));<a name="line.117"></a>
+<span class="sourceLineNo">118</span>        return (FastMath.abs(cross) &lt;= (1.0e-6 * d1d2)) &amp;&amp; (dot &gt;= 0.0);<a name="line.118"></a>
+<span class="sourceLineNo">119</span>    }<a name="line.119"></a>
+<span class="sourceLineNo">120</span><a name="line.120"></a>
+<span class="sourceLineNo">121</span>    /** Visitor projecting the boundary facets on a plane. */<a name="line.121"></a>
+<span class="sourceLineNo">122</span>    private class BoundaryProjector implements BSPTreeVisitor&lt;Euclidean3D&gt; {<a name="line.122"></a>
+<span class="sourceLineNo">123</span><a name="line.123"></a>
+<span class="sourceLineNo">124</span>        /** Projection of the polyhedrons set on the plane. */<a name="line.124"></a>
+<span class="sourceLineNo">125</span>        private PolygonsSet projected;<a name="line.125"></a>
+<span class="sourceLineNo">126</span><a name="line.126"></a>
+<span class="sourceLineNo">127</span>        /** Tolerance below which points are considered identical. */<a name="line.127"></a>
+<span class="sourceLineNo">128</span>        private final double tolerance;<a name="line.128"></a>
+<span class="sourceLineNo">129</span><a name="line.129"></a>
+<span class="sourceLineNo">130</span>        /** Simple constructor.<a name="line.130"></a>
+<span class="sourceLineNo">131</span>         * @param tolerance tolerance below which points are considered identical<a name="line.131"></a>
+<span class="sourceLineNo">132</span>         */<a name="line.132"></a>
+<span class="sourceLineNo">133</span>        BoundaryProjector(final double tolerance) {<a name="line.133"></a>
+<span class="sourceLineNo">134</span>            this.projected = new PolygonsSet(new BSPTree&lt;Euclidean2D&gt;(Boolean.FALSE), tolerance);<a name="line.134"></a>
+<span class="sourceLineNo">135</span>            this.tolerance = tolerance;<a name="line.135"></a>
+<span class="sourceLineNo">136</span>        }<a name="line.136"></a>
+<span class="sourceLineNo">137</span><a name="line.137"></a>
+<span class="sourceLineNo">138</span>        /** {@inheritDoc} */<a name="line.138"></a>
+<span class="sourceLineNo">139</span>        public Order visitOrder(final BSPTree&lt;Euclidean3D&gt; node) {<a name="line.139"></a>
+<span class="sourceLineNo">140</span>            return Order.MINUS_SUB_PLUS;<a name="line.140"></a>
+<span class="sourceLineNo">141</span>        }<a name="line.141"></a>
+<span class="sourceLineNo">142</span><a name="line.142"></a>
+<span class="sourceLineNo">143</span>        /** {@inheritDoc} */<a name="line.143"></a>
+<span class="sourceLineNo">144</span>        public void visitInternalNode(final BSPTree&lt;Euclidean3D&gt; node) {<a name="line.144"></a>
+<span class="sourceLineNo">145</span>            @SuppressWarnings("unchecked")<a name="line.145"></a>
+<span class="sourceLineNo">146</span>            final BoundaryAttribute&lt;Euclidean3D&gt; attribute =<a name="line.146"></a>
+<span class="sourceLineNo">147</span>                (BoundaryAttribute&lt;Euclidean3D&gt;) node.getAttribute();<a name="line.147"></a>
+<span class="sourceLineNo">148</span>            if (attribute.getPlusOutside() != null) {<a name="line.148"></a>
+<span class="sourceLineNo">149</span>                addContribution(attribute.getPlusOutside(), false);<a name="line.149"></a>
+<span class="sourceLineNo">150</span>            }<a name="line.150"></a>
+<span class="sourceLineNo">151</span>            if (attribute.getPlusInside() != null) {<a name="line.151"></a>
+<span class="sourceLineNo">152</span>                addContribution(attribute.getPlusInside(), true);<a name="line.152"></a>
+<span class="sourceLineNo">153</span>            }<a name="line.153"></a>
+<span class="sourceLineNo">154</span>        }<a name="line.154"></a>
+<span class="sourceLineNo">155</span><a name="line.155"></a>
+<span class="sourceLineNo">156</span>        /** {@inheritDoc} */<a name="line.156"></a>
+<span class="sourceLineNo">157</span>        public void visitLeafNode(final BSPTree&lt;Euclidean3D&gt; node) {<a name="line.157"></a>
+<span class="sourceLineNo">158</span>        }<a name="line.158"></a>
+<span class="sourceLineNo">159</span><a name="line.159"></a>
+<span class="sourceLineNo">160</span>        /** Add he contribution of a boundary facet.<a name="line.160"></a>
+<span class="sourceLineNo">161</span>         * @param facet boundary facet<a name="line.161"></a>
+<span class="sourceLineNo">162</span>         * @param reversed if true, the facet has the inside on its plus side<a name="line.162"></a>
+<span class="sourceLineNo">163</span>         */<a name="line.163"></a>
+<span class="sourceLineNo">164</span>        private void addContribution(final SubHyperplane&lt;Euclidean3D&gt; facet, final boolean reversed) {<a name="line.164"></a>
+<span class="sourceLineNo">165</span><a name="line.165"></a>
+<span class="sourceLineNo">166</span>            // extract the vertices of the facet<a name="line.166"></a>
+<span class="sourceLineNo">167</span>            @SuppressWarnings("unchecked")<a name="line.167"></a>
+<span class="sourceLineNo">168</span>            final AbstractSubHyperplane&lt;Euclidean3D, Euclidean2D&gt; absFacet =<a name="line.168"></a>
+<span class="sourceLineNo">169</span>                (AbstractSubHyperplane&lt;Euclidean3D, Euclidean2D&gt;) facet;<a name="line.169"></a>
+<span class="sourceLineNo">170</span>            final Plane plane    = (Plane) facet.getHyperplane();<a name="line.170"></a>
+<span class="sourceLineNo">171</span><a name="line.171"></a>
+<span class="sourceLineNo">172</span>            final double scal = plane.getNormal().dotProduct(w);<a name="line.172"></a>
+<span class="sourceLineNo">173</span>            if (FastMath.abs(scal) &gt; 1.0e-3) {<a name="line.173"></a>
+<span class="sourceLineNo">174</span>                Vector2D[][] vertices =<a name="line.174"></a>
+<span class="sourceLineNo">175</span>                    ((PolygonsSet) absFacet.getRemainingRegion()).getVertices();<a name="line.175"></a>
+<span class="sourceLineNo">176</span><a name="line.176"></a>
+<span class="sourceLineNo">177</span>                if ((scal &lt; 0) ^ reversed) {<a name="line.177"></a>
+<span class="sourceLineNo">178</span>                    // the facet is seen from the inside,<a name="line.178"></a>
+<span class="sourceLineNo">179</span>                    // we need to invert its boundary orientation<a name="line.179"></a>
+<span class="sourceLineNo">180</span>                    final Vector2D[][] newVertices = new Vector2D[vertices.length][];<a name="line.180"></a>
+<span class="sourceLineNo">181</span>                    for (int i = 0; i &lt; vertices.length; ++i) {<a name="line.181"></a>
+<span class="sourceLineNo">182</span>                        final Vector2D[] loop = vertices[i];<a name="line.182"></a>
+<span class="sourceLineNo">183</span>                        final Vector2D[] newLoop = new Vector2D[loop.length];<a name="line.183"></a>
+<span class="sourceLineNo">184</span>                        if (loop[0] == null) {<a name="line.184"></a>
+<span class="sourceLineNo">185</span>                            newLoop[0] = null;<a name="line.185"></a>
+<span class="sourceLineNo">186</span>                            for (int j = 1; j &lt; loop.length; ++j) {<a name="line.186"></a>
+<span class="sourceLineNo">187</span>                                newLoop[j] = loop[loop.length - j];<a name="line.187"></a>
+<span class="sourceLineNo">188</span>                            }<a name="line.188"></a>
+<span class="sourceLineNo">189</span>                        } else {<a name="line.189"></a>
+<span class="sourceLineNo">190</span>                            for (int j = 0; j &lt; loop.length; ++j) {<a name="line.190"></a>
+<span class="sourceLineNo">191</span>                                newLoop[j] = loop[loop.length - (j + 1)];<a name="line.191"></a>
+<span class="sourceLineNo">192</span>                            }<a name="line.192"></a>
+<span class="sourceLineNo">193</span>                        }<a name="line.193"></a>
+<span class="sourceLineNo">194</span>                        newVertices[i] = newLoop;<a name="line.194"></a>
+<span class="sourceLineNo">195</span>                    }<a name="line.195"></a>
+<span class="sourceLineNo">196</span><a name="line.196"></a>
+<span class="sourceLineNo">197</span>                    // use the reverted vertices<a name="line.197"></a>
+<span class="sourceLineNo">198</span>                    vertices = newVertices;<a name="line.198"></a>
+<span class="sourceLineNo">199</span><a name="line.199"></a>
+<span class="sourceLineNo">200</span>                }<a name="line.200"></a>
+<span class="sourceLineNo">201</span><a name="line.201"></a>
+<span class="sourceLineNo">202</span>                // compute the projection of the facet in the outline plane<a name="line.202"></a>
+<span class="sourceLineNo">203</span>                final ArrayList&lt;SubHyperplane&lt;Euclidean2D&gt;&gt; edges = new ArrayList&lt;SubHyperplane&lt;Euclidean2D&gt;&gt;();<a name="line.203"></a>
+<span class="sourceLineNo">204</span>                for (Vector2D[] loop : vertices) {<a name="line.204"></a>
+<span class="sourceLineNo">205</span>                    final boolean closed = loop[0] != null;<a name="line.205"></a>
+<span class="sourceLineNo">206</span>                    int previous         = closed ? (loop.length - 1) : 1;<a name="line.206"></a>
+<span class="sourceLineNo">207</span>                    Vector3D previous3D  = plane.toSpace((Point&lt;Euclidean2D&gt;) loop[previous]);<a name="line.207"></a>
+<span class="sourceLineNo">208</span>                    int current          = (previous + 1) % loop.length;<a name="line.208"></a>
+<span class="sourceLineNo">209</span>                    Vector2D pPoint       = new Vector2D(previous3D.dotProduct(u),<a name="line.209"></a>
+<span class="sourceLineNo">210</span>                                                         previous3D.dotProduct(v));<a name="line.210"></a>
+<span class="sourceLineNo">211</span>                    while (current &lt; loop.length) {<a name="line.211"></a>
+<span class="sourceLineNo">212</span><a name="line.212"></a>
+<span class="sourceLineNo">213</span>                        final Vector3D current3D = plane.toSpace((Point&lt;Euclidean2D&gt;) loop[current]);<a name="line.213"></a>
+<span class="sourceLineNo">214</span>                        final Vector2D  cPoint    = new Vector2D(current3D.dotProduct(u),<a name="line.214"></a>
+<span class="sourceLineNo">215</span>                                                                 current3D.dotProduct(v));<a name="line.215"></a>
+<span class="sourceLineNo">216</span>                        final org.apache.commons.math3.geometry.euclidean.twod.Line line =<a name="line.216"></a>
+<span class="sourceLineNo">217</span>                            new org.apache.commons.math3.geometry.euclidean.twod.Line(pPoint, cPoint, tolerance);<a name="line.217"></a>
+<span class="sourceLineNo">218</span>                        SubHyperplane&lt;Euclidean2D&gt; edge = line.wholeHyperplane();<a name="line.218"></a>
+<span class="sourceLineNo">219</span><a name="line.219"></a>
+<span class="sourceLineNo">220</span>                        if (closed || (previous != 1)) {<a name="line.220"></a>
+<span class="sourceLineNo">221</span>                            // the previous point is a real vertex<a name="line.221"></a>
+<span class="sourceLineNo">222</span>                            // it defines one bounding point of the edge<a name="line.222"></a>
+<span class="sourceLineNo">223</span>                            final double angle = line.getAngle() + 0.5 * FastMath.PI;<a name="line.223"></a>
+<span class="sourceLineNo">224</span>                            final org.apache.commons.math3.geometry.euclidean.twod.Line l =<a name="line.224"></a>
+<span class="sourceLineNo">225</span>                                new org.apache.commons.math3.geometry.euclidean.twod.Line(pPoint, angle, tolerance);<a name="line.225"></a>
+<span class="sourceLineNo">226</span>                            edge = edge.split(l).getPlus();<a name="line.226"></a>
+<span class="sourceLineNo">227</span>                        }<a name="line.227"></a>
+<span class="sourceLineNo">228</span><a name="line.228"></a>
+<span class="sourceLineNo">229</span>                        if (closed || (current != (loop.length - 1))) {<a name="line.229"></a>
+<span class="sourceLineNo">230</span>                            // the current point is a real vertex<a name="line.230"></a>
+<span class="sourceLineNo">231</span>                            // it defines one bounding point of the edge<a name="line.231"></a>
+<span class="sourceLineNo">232</span>                            final double angle = line.getAngle() + 0.5 * FastMath.PI;<a name="line.232"></a>
+<span class="sourceLineNo">233</span>                            final org.apache.commons.math3.geometry.euclidean.twod.Line l =<a name="line.233"></a>
+<span class="sourceLineNo">234</span>                                new org.apache.commons.math3.geometry.euclidean.twod.Line(cPoint, angle, tolerance);<a name="line.234"></a>
+<span class="sourceLineNo">235</span>                            edge = edge.split(l).getMinus();<a name="line.235"></a>
+<span class="sourceLineNo">236</span>                        }<a name="line.236"></a>
+<span class="sourceLineNo">237</span><a name="line.237"></a>
+<span class="sourceLineNo">238</span>                        edges.add(edge);<a name="line.238"></a>
+<span class="sourceLineNo">239</span><a name="line.239"></a>
+<span class="sourceLineNo">240</span>                        previous   = current++;<a name="line.240"></a>
+<span class="sourceLineNo">241</span>                        previous3D = current3D;<a name="line.241"></a>
+<span class="sourceLineNo">242</span>                        pPoint     = cPoint;<a name="line.242"></a>
+<span class="sourceLineNo">243</span><a name="line.243"></a>
+<span class="sourceLineNo">244</span>                    }<a name="line.244"></a>
+<span class="sourceLineNo">245</span>                }<a name="line.245"></a>
+<span class="sourceLineNo">246</span>                final PolygonsSet projectedFacet = new PolygonsSet(edges, tolerance);<a name="line.246"></a>
+<span class="sourceLineNo">247</span><a name="line.247"></a>
+<span class="sourceLineNo">248</span>                // add the contribution of the facet to the global outline<a name="line.248"></a>
+<span class="sourceLineNo">249</span>                projected = (PolygonsSet) new RegionFactory&lt;Euclidean2D&gt;().union(projected, projectedFacet);<a name="line.249"></a>
+<span class="sourceLineNo">250</span><a name="line.250"></a>
+<span class="sourceLineNo">251</span>            }<a name="line.251"></a>
+<span class="sourceLineNo">252</span>        }<a name="line.252"></a>
+<span class="sourceLineNo">253</span><a name="line.253"></a>
+<span class="sourceLineNo">254</span>        /** Get the projection of the polyhedrons set on the plane.<a name="line.254"></a>
+<span class="sourceLineNo">255</span>         * @return projection of the polyhedrons set on the plane<a name="line.255"></a>
+<span class="sourceLineNo">256</span>         */<a name="line.256"></a>
+<span class="sourceLineNo">257</span>        public PolygonsSet getProjected() {<a name="line.257"></a>
+<span class="sourceLineNo">258</span>            return projected;<a name="line.258"></a>
+<span class="sourceLineNo">259</span>        }<a name="line.259"></a>
+<span class="sourceLineNo">260</span><a name="line.260"></a>
+<span class="sourceLineNo">261</span>    }<a name="line.261"></a>
+<span class="sourceLineNo">262</span><a name="line.262"></a>
+<span class="sourceLineNo">263</span>}<a name="line.263"></a>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+</pre>
+</div>
+</body>
+</html>


Mime
View raw message