Re: How do I install and use Apache Commons?

2022-08-01 Thread Mark Fortner
Even simpler, is to create a groovy script.

   1. Use sdkman  to install groovy on your local
   machine if you don't already have it.
   2. Launch the Groovy console using the *groovyConsole* command in your
   Terminal Window (or equivalent).
   3. Go to the maven repository  and search for
   the libraries that you want to use. Let's say you want to play with Commons
   IO .
   View the *Grapes* tab in the web page and copy paste the contents into
   your groovyConsole window.
   4. Go to the Commons IO 
   web page (or any other package) and look for some sample code to try out,
   and copy and paste it into your groovyConsole window, then click the play
   button in the console. The script will execute and automatically download
   the library and add it to your classpath the first time it runs. Groovy
   uses both Java syntax and Groovy syntax, so either will work in your
   console.



Cheers,

Mark



On Tue, Jul 26, 2022 at 6:32 PM Turritopsis Dohrnii Teo En Ming <
tdtemc...@gmail.com> wrote:

> Noted with thanks.
>
> Mr. Turritopsis Dohrnii Teo En Ming
> Targeted Individual in Singapore
>
> On Tue, 26 Jul 2022 at 20:04, Gary Gregory  wrote:
> >
> > The simplest IMO is to use Apache Maven.
> >
> > That, or you'll have to download jars manually and configure your build
> > environment.
> >
> > Gary
> >
> > On Tue, Jul 26, 2022, 06:01 Turritopsis Dohrnii Teo En Ming <
> > tdtemc...@gmail.com> wrote:
> >
> > > Hi,
> > >
> > > I am just starting to try out numerous different Apache open source
> > > projects.
> > >
> > > Mr. Turritopsis Dohrnii Teo En Ming
> > > Targeted Individual in Singapore
> > >
> > >
> > > On Tue, 26 Jul 2022 at 17:51, Taher Koitawala 
> wrote:
> > > >
> > > > What do you mean by install and use? What is your use case. Please
> can
> > > you
> > > > explain more?
> > > >
> > > > On Tue, 26 Jul, 2022, 3:16 pm Turritopsis Dohrnii Teo En Ming, <
> > > > tdtemc...@gmail.com> wrote:
> > > >
> > > > > Subject: How do I install and use Apache Commons?
> > > > >
> > > > > Good day from Singapore,
> > > > >
> > > > > How do I install and use Apache Commons?
> > > > >
> > > > > Thank you.
> > > > >
> > > > > Regards,
> > > > >
> > > > > Mr. Turritopsis Dohrnii Teo En Ming
> > > > > Targeted Individual in Singapore
> > > > > 26 July 2022 Tuesday
> > > > > Blogs:
> > > > > https://tdtemcerts.blogspot.com
> > > > > https://tdtemcerts.wordpress.com
> > > > >
> > > > >
> -
> > > > > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> > > > > For additional commands, e-mail: user-h...@commons.apache.org
> > > > >
> > > > >
> > >
> > > -
> > > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> > > For additional commands, e-mail: user-h...@commons.apache.org
> > >
> > >
>
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>
>


Re: Use non-linear least squares to fit a function

2022-08-01 Thread Gilles Sadowski
Hello.

Le lun. 1 août 2022 à 16:03, Yaqiang Wang  a écrit :
>
> Gilles,
>
> Thanks so much for your patiently response! I know I can write a gradient
> method for a specific function, but my purpose is to make the gradient
> method suitable for any function of yi = f(xi, p1, p2, p3, ...). That means
> the users don't need to override a new fixed gradient method for a new
> function, just like the SciPy's curve_fit (
> https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html).
> So I tried to calculate gradient array through numerical differentiation (
> https://github.com/meteoinfo/MeteoInfo/blob/master/meteoinfo-math/src/main/java/org/meteoinfo/math/optimize/MyParametricUnivariateFunction.java#L33-L56,
> the code also is attache below), and please let me know whether the code is
> correct for my purpose? Thanks!

I'm still confused about your use case (maybe because I did not see
the figures of what you expect vs what you got).

I've never used the "DerivativeStructure" (and I've just noticed that the
link to the reference document is not accessible anymore).

What I gather from the documentation is that the intended purpose is
to track the values of some function and all its derivatives when the
function is defined programmatically (using the usual arithmetical
operators, and generalizations of the functions defined in the "Math"
JDK class).  IIUC, one gains automatic access to the derivatives
without defining them analytically (only the function need be defined).

>
> @Override
> public double[] gradient(double v, double... parameters) {
> function.setParameters(parameters);

How is "function" defined here?

>
> // create a differentiator
> FiniteDifferencesDifferentiator differentiator =
> new FiniteDifferencesDifferentiator(nbPoints, stepSize);

If you assume that "function" is defined analytically, you don't need to
use "FiniteDifferentiator" (moreover, its use is not recomended IIUC
the documentation).
However, if the derivatives cannot be expressed analytically, it seems
that "DerivativeStructure" is an overly complex utility if in the end, it's
just replacing the finite differences formulae[1] which you can write in
about the same number lines as your code below.

Regards,
Gilles

[1] https://en.wikipedia.org/wiki/Numerical_differentiation

>
> // create a new function that computes both the value and the derivatives
> // using DerivativeStructure
> UnivariateDifferentiableFunction diffFunc =
> differentiator.differentiate(function);
>
> double y = function.value(v);
> int n = parameters.length;
> double[] gradients = new double[n];
> for (int i = 0; i < n; i++) {
> DerivativeStructure xDS = new DerivativeStructure(n, 1, i,
> parameters[i]);
> DerivativeStructure yDS = diffFunc.value(xDS);
> int[] idx = new int[n];
> idx[i] = 1;
> gradients[i] = yDS.getPartialDerivative(idx);
> }
>
> return gradients;
> }
>
>
> By the way, I am using Apache commons math 3.6.1 at present. Today I also
> tried the 4.0-SNAPSHOT version but the result is the same.
>
> Regards
> Yaqiang
>
>>> [...]

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



Re: Use non-linear least squares to fit a function

2022-08-01 Thread Yaqiang Wang
Gilles,

Thanks so much for your patiently response! I know I can write a gradient
method for a specific function, but my purpose is to make the gradient
method suitable for any function of yi = f(xi, p1, p2, p3, ...). That means
the users don't need to override a new fixed gradient method for a new
function, just like the SciPy's curve_fit (
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html).
So I tried to calculate gradient array through numerical differentiation (
https://github.com/meteoinfo/MeteoInfo/blob/master/meteoinfo-math/src/main/java/org/meteoinfo/math/optimize/MyParametricUnivariateFunction.java#L33-L56,
the code also is attache below), and please let me know whether the code is
correct for my purpose? Thanks!

@Override
public double[] gradient(double v, double... parameters) {
function.setParameters(parameters);

// create a differentiator
FiniteDifferencesDifferentiator differentiator =
new FiniteDifferencesDifferentiator(nbPoints, stepSize);

// create a new function that computes both the value and the derivatives
// using DerivativeStructure
UnivariateDifferentiableFunction diffFunc =
differentiator.differentiate(function);

double y = function.value(v);
int n = parameters.length;
double[] gradients = new double[n];
for (int i = 0; i < n; i++) {
DerivativeStructure xDS = new DerivativeStructure(n, 1, i,
parameters[i]);
DerivativeStructure yDS = diffFunc.value(xDS);
int[] idx = new int[n];
idx[i] = 1;
gradients[i] = yDS.getPartialDerivative(idx);
}

return gradients;
}


By the way, I am using Apache commons math 3.6.1 at present. Today I also
tried the 4.0-SNAPSHOT version but the result is the same.

Regards
Yaqiang

On Mon, Aug 1, 2022 at 8:33 PM Gilles Sadowski  wrote:

> Hi.
>
> Le dim. 31 juil. 2022 à 18:05, Yaqiang Wang  a
> écrit :
> >
> > Currently I just want to fit univariate function such as the following
> Python function:
> >
> > def func(x, a, b, c):
> > return a * exp(-b * x) + c
> >
> >
> > I also tried using SimpleCurveFitter to do it.
> MyParametricUnivariateFunction implements ParametricUnivariateFunction and
> overrides value and gradient methods (
> https://github.com/meteoinfo/MeteoInfo/blob/master/meteoinfo-math/src/main/java/org/meteoinfo/math/optimize/MyParametricUnivariateFunction.java),
> and the gradient array is calculated through numerical differentiation.
>
> Given a list of points, { xi } (i = 0, 1, ... , N), and their associated
> values,
> { y_i }, "SimpleCurveFitter" aims at finding the best fit of an assumed
> function "f"
>   yi = f(xi, p1, p2, p3, ...)
> whose parameters p1, p2, p3, ... can be adjusted.
> Internally, "SimpleCurveFitter" computes the Jacobian matrix
>   df(x0)/dp1 df(x0)/dp2 df(x0)/dp3 ...
>   df(x1)/dp1 df(x1)/dp2 df(x1)/dp3 ...
>  
>   df(xN)/dp1 df(xN)/dp2 df(xN)/dp3 ...
> needed by the "Levenberg-Marquardt" least-squares optimizer.
> The gradient of "f" is an array where each slot contains the partial
> derivative of the univariate function (at the given "x") wrt to each
> _parameter_.
> For your function above, the code would be (untested):
> ---CUT---
> public class MyFunction implements ParametricUnivariateFunction {
>
> public double value(double x, double ... parameters) {
> final double a = parameters[0];
> final double b = parameters[1];
> final double c = parameters[2];
> return a * Math.exp(-b * x) + c
> }
>
> public double[] gradient(double x, double ... parameters) {
> final double a = parameters[0];
> final double b = parameters[1];
> final double c = parameters[2];
> final double[] grad = new double[3];
> grad[0] = Math.exp(-b * x);
> grad[1] = -a * x * grad[0];
> grad[2] = 1;
> return grad;
> }
> }
> ---CUT---
>
> HTH,
> Gilles
>
> > [...]
>
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>
>

-- 
*
Dr. Yaqiang Wang
Chinese Academy of Meteorological Sciences (CAMS)
46, Zhong-Guan-Cun South Avenue
Beijing, 100081
China

yaqiang.w...@gmail.com

www.meteothink.org
**


Re: Use non-linear least squares to fit a function

2022-08-01 Thread Gilles Sadowski
Hi.

Le dim. 31 juil. 2022 à 18:05, Yaqiang Wang  a écrit :
>
> Currently I just want to fit univariate function such as the following Python 
> function:
>
> def func(x, a, b, c):
> return a * exp(-b * x) + c
>
>
> I also tried using SimpleCurveFitter to do it. MyParametricUnivariateFunction 
> implements ParametricUnivariateFunction and overrides value and gradient 
> methods 
> (https://github.com/meteoinfo/MeteoInfo/blob/master/meteoinfo-math/src/main/java/org/meteoinfo/math/optimize/MyParametricUnivariateFunction.java),
>  and the gradient array is calculated through numerical differentiation.

Given a list of points, { xi } (i = 0, 1, ... , N), and their associated values,
{ y_i }, "SimpleCurveFitter" aims at finding the best fit of an assumed
function "f"
  yi = f(xi, p1, p2, p3, ...)
whose parameters p1, p2, p3, ... can be adjusted.
Internally, "SimpleCurveFitter" computes the Jacobian matrix
  df(x0)/dp1 df(x0)/dp2 df(x0)/dp3 ...
  df(x1)/dp1 df(x1)/dp2 df(x1)/dp3 ...
 
  df(xN)/dp1 df(xN)/dp2 df(xN)/dp3 ...
needed by the "Levenberg-Marquardt" least-squares optimizer.
The gradient of "f" is an array where each slot contains the partial
derivative of the univariate function (at the given "x") wrt to each
_parameter_.
For your function above, the code would be (untested):
---CUT---
public class MyFunction implements ParametricUnivariateFunction {

public double value(double x, double ... parameters) {
final double a = parameters[0];
final double b = parameters[1];
final double c = parameters[2];
return a * Math.exp(-b * x) + c
}

public double[] gradient(double x, double ... parameters) {
final double a = parameters[0];
final double b = parameters[1];
final double c = parameters[2];
final double[] grad = new double[3];
grad[0] = Math.exp(-b * x);
grad[1] = -a * x * grad[0];
grad[2] = 1;
return grad;
}
}
---CUT---

HTH,
Gilles

> [...]

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



Re: EoS/EoL date required for FOSS ​Apache Commons Net 3.8.0 and Apache commons-codec 1.15

2022-08-01 Thread Gary Gregory
We've already replied many times to these types of questions recently,
please check the mail archives.

Gary

On Mon, Aug 1, 2022, 05:13 Sahil Sharma D
 wrote:

> Hello team,
>
> kindly help in getting EoS/EoL date for FOSS ​Apache Commons Net 3.8.0 and
> Apache commons-codec 1.15
>
> Regards,
> Sahil
>


EoS/EoL date required for FOSS ​Apache Commons Net 3.8.0 and Apache commons-codec 1.15

2022-08-01 Thread Sahil Sharma D
Hello team,

kindly help in getting EoS/EoL date for FOSS ​Apache Commons Net 3.8.0 and 
Apache commons-codec 1.15

Regards,
Sahil