Re: Jxpath getting stuck on trying to do a getValue

2023-09-24 Thread Debraj Manna
I can share a reproducible project but I would like to avoid doing it in a
public link like in GitHub, etc. Is there a way to do that?

On Mon, 25 Sep, 2023, 01:10 Matt Benson,  wrote:

> TBH I'm somewhat surprised it doesn't already, but I haven't actually
> ran/debugged your example.
>
> On Sun, Sep 24, 2023 at 2:32 PM Debraj Manna 
> wrote:
>
> > Is there a way I can throw some error from jxpath when this situation
> > arises instead of getting stuck in a never ending loop?
> >
> > On Sun, 24 Sep, 2023, 22:54 Matt Benson,  wrote:
> >
> > > Well, to be clear, you can have linked nodes. But if N had both `next`
> > and
> > > `previous` members is where you'd run into trouble.
> > >
> > > On Sun, Sep 24, 2023 at 12:22 PM Matt Benson 
> > wrote:
> > >
> > > > If you're doing a search down the tree you'd need some way to keep
> > JXPath
> > > > from traversing these relationships, yes.
> > > >
> > > > On Sun, Sep 24, 2023 at 11:59 AM Debraj Manna <
> > subharaj.ma...@gmail.com>
> > > > wrote:
> > > >
> > > >> Are you saying that in JxPath we cannot use something like below?
> > > >>
> > > >> class A {
> > > >> int n;
> > > >> A next;
> > > >> }
> > > >>
> > > >> On Sun, Sep 24, 2023 at 8:43 PM Matt Benson 
> > wrote:
> > > >>
> > > >> > Is it possible the proto message (I'm not familiar with this API)
> is
> > > >> built
> > > >> > with internal recursive references, i.e. some child has a property
> > > that
> > > >> > points, possibly indirectly, to its parent? That would be the most
> > > >> probable
> > > >> > explanation, particularly as you say feeding jxpath the known
> > absolute
> > > >> path
> > > >> > works.
> > > >> >
> > > >> > Matt
> > > >> >
> > > >> > On Sun, Sep 24, 2023, 9:44 AM Debraj Manna <
> > subharaj.ma...@gmail.com>
> > > >> > wrote:
> > > >> >
> > > >> > > It looks like it is getting stuck in some infinite loop. The
> > thread
> > > >> stack
> > > >> > > looks like below after ~ 8 hours from the start.
> > > >> > >
> > > >> > > main  Runnable CPU usage on sample: 979ms
> > > >> > >   jdk.internal.reflect.GeneratedMethodAccessor640.invoke()
> > > >> > >
> > > >> > >
> > > >> > >
> > > >> >
> > > >>
> > >
> >
> jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > > >> > >   java.lang.reflect.Method.invoke(Method.java:568)
> > > >> > >
> > > >>
> > org.apache.commons.jxpath.util.ValueUtils.getValue(ValueUtils.java:367)
> > > >> > >
> > > >> > >
> > > >> > >
> > > >> >
> > > >>
> > >
> >
> org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.getBaseValue(BeanPropertyPointer.java:120)
> > > >> > >
> > > >> > >
> > > >> > >
> > > >> >
> > > >>
> > >
> >
> org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.getImmediateNode(BeanPropertyPointer.java:149)
> > > >> > >
> > > >> > >
> > > >> > >
> > > >> >
> > > >>
> > >
> >
> org.apache.commons.jxpath.ri.model.beans.PropertyPointer.getImmediateValuePointer(PropertyPointer.java:161)
> > > >> > >
> > > >> > >
> > > >> > >
> > > >> >
> > > >>
> > >
> >
> org.apache.commons.jxpath.ri.model.NodePointer.getValuePointer(NodePointer.java:297)
> > > >> > >
> > > >> > >
> > > >> > >
> > > >> >
> > > >>
> > >
> >
> org.apache.commons.jxpath.ri.model.beans.PropertyIterator.getNodePointer(PropertyIterator.java:121)
> > > >> > >
> > > >> > >
> > > >> > >
> > > >> >
> > > >>
> > >
> >
> org.apache.commo

Re: Jxpath getting stuck on trying to do a getValue

2023-09-24 Thread Debraj Manna
Is there a way I can throw some error from jxpath when this situation
arises instead of getting stuck in a never ending loop?

On Sun, 24 Sep, 2023, 22:54 Matt Benson,  wrote:

> Well, to be clear, you can have linked nodes. But if N had both `next` and
> `previous` members is where you'd run into trouble.
>
> On Sun, Sep 24, 2023 at 12:22 PM Matt Benson  wrote:
>
> > If you're doing a search down the tree you'd need some way to keep JXPath
> > from traversing these relationships, yes.
> >
> > On Sun, Sep 24, 2023 at 11:59 AM Debraj Manna 
> > wrote:
> >
> >> Are you saying that in JxPath we cannot use something like below?
> >>
> >> class A {
> >> int n;
> >> A next;
> >> }
> >>
> >> On Sun, Sep 24, 2023 at 8:43 PM Matt Benson  wrote:
> >>
> >> > Is it possible the proto message (I'm not familiar with this API) is
> >> built
> >> > with internal recursive references, i.e. some child has a property
> that
> >> > points, possibly indirectly, to its parent? That would be the most
> >> probable
> >> > explanation, particularly as you say feeding jxpath the known absolute
> >> path
> >> > works.
> >> >
> >> > Matt
> >> >
> >> > On Sun, Sep 24, 2023, 9:44 AM Debraj Manna 
> >> > wrote:
> >> >
> >> > > It looks like it is getting stuck in some infinite loop. The thread
> >> stack
> >> > > looks like below after ~ 8 hours from the start.
> >> > >
> >> > > main  Runnable CPU usage on sample: 979ms
> >> > >   jdk.internal.reflect.GeneratedMethodAccessor640.invoke()
> >> > >
> >> > >
> >> > >
> >> >
> >>
> jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >> > >   java.lang.reflect.Method.invoke(Method.java:568)
> >> > >
> >>  org.apache.commons.jxpath.util.ValueUtils.getValue(ValueUtils.java:367)
> >> > >
> >> > >
> >> > >
> >> >
> >>
> org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.getBaseValue(BeanPropertyPointer.java:120)
> >> > >
> >> > >
> >> > >
> >> >
> >>
> org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.getImmediateNode(BeanPropertyPointer.java:149)
> >> > >
> >> > >
> >> > >
> >> >
> >>
> org.apache.commons.jxpath.ri.model.beans.PropertyPointer.getImmediateValuePointer(PropertyPointer.java:161)
> >> > >
> >> > >
> >> > >
> >> >
> >>
> org.apache.commons.jxpath.ri.model.NodePointer.getValuePointer(NodePointer.java:297)
> >> > >
> >> > >
> >> > >
> >> >
> >>
> org.apache.commons.jxpath.ri.model.beans.PropertyIterator.getNodePointer(PropertyIterator.java:121)
> >> > >
> >> > >
> >> > >
> >> >
> >>
> org.apache.commons.jxpath.ri.axes.DescendantContext.nextNode(DescendantContext.java:115)
> >> > >
> >>  org.apache.commons.jxpath.ri.EvalContext.nextSet(EvalContext.java:349)
> >> > >
> >> > >
> >> > >
> >> >
> >>
> org.apache.commons.jxpath.ri.axes.ChildContext.getSingleNodePointer(ChildContext.java:70)
> >> > >
> >>  org.apache.commons.jxpath.ri.compiler.Path.searchForPath(Path.java:201)
> >> > >
> >> > >
> >> > >
> >> >
> >>
> org.apache.commons.jxpath.ri.compiler.Path.getSingleNodePointerForSteps(Path.java:176)
> >> > >
> >> > >
> >> > >
> >> >
> >>
> org.apache.commons.jxpath.ri.compiler.LocationPath.computeValue(LocationPath.java:87)
> >> > >
> >> > >
> >> > >
> >> >
> >>
> org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:353)
> >> > >
> >> > >
> >> > >
> >> >
> >>
> org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:313)
> >> > >
> >> > >
> >> > >
> >> >
> >>
> com.spotnana.webhooks.isos.PNRListBuilderTest.testJxPathCtx(PNRListBuilderTest.java:366)
> >> > >
> >> > > On Sun, Sep 24, 2023 at 1:24 AM Debraj Manna <
> >> subharaj.ma...@gmail.com>
> >> > > wrote:
> >> > >
> >> > > > I am trying to search using JxPath on a proto message, My proto
> >> message
> >> > > is
> >> > > > placed here
> >> > > > <
> >> https://gist.github.com/debraj-manna/4a8ded5d79dc9aee8d4c03d460327284
> >> > >.
> >> > > >
> >> > > > val protoStr =
> >> > > >
> getStringFromFile("classpath:BookingEnginePnrUpdateEventProto.txt");
> >> > > > val msgBld = BookingEnginePNRUpdateEvent.newBuilder();
> >> > > > TextFormat.getParser().merge(protoStr, msgBld);
> >> > > > val msgCtx = JXPathContext.newContext(msgBld.build());
> >> > > > System.out.println(msgCtx.getValue("//employeeId"));
> >> > > >
> >> > > > I am observing that  msgCtx.getValue("//employeeId") is taking a
> >> lot of
> >> > > > time. Thread dumps at various points are placed in the below gist.
> >> > > >
> >> > > >
> >> https://gist.github.com/debraj-manna/47852fa190075abdacd527969f355cde
> >> > > >
> >> > > > If I specify the entire path like
> >> > > >
> >> > >
> >> >
> >>
> msgCtx.getValue("/metadata/bookerInfo/traveler/userBusinessInfo/employeeId").
> >> > > > It is working fine.
> >> > > >
> >> > > > Can someone let me know what is going wrong? Is this expected?
> >> > > >
> >> > > >
> >> > > >
> >> > > >
> >> > > >
> >> > >
> >> >
> >>
> >
>


Re: Jxpath getting stuck on trying to do a getValue

2023-09-24 Thread Debraj Manna
Are you saying that in JxPath we cannot use something like below?

class A {
int n;
A next;
}

On Sun, Sep 24, 2023 at 8:43 PM Matt Benson  wrote:

> Is it possible the proto message (I'm not familiar with this API) is built
> with internal recursive references, i.e. some child has a property that
> points, possibly indirectly, to its parent? That would be the most probable
> explanation, particularly as you say feeding jxpath the known absolute path
> works.
>
> Matt
>
> On Sun, Sep 24, 2023, 9:44 AM Debraj Manna 
> wrote:
>
> > It looks like it is getting stuck in some infinite loop. The thread stack
> > looks like below after ~ 8 hours from the start.
> >
> > main  Runnable CPU usage on sample: 979ms
> >   jdk.internal.reflect.GeneratedMethodAccessor640.invoke()
> >
> >
> >
> jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >   java.lang.reflect.Method.invoke(Method.java:568)
> >   org.apache.commons.jxpath.util.ValueUtils.getValue(ValueUtils.java:367)
> >
> >
> >
> org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.getBaseValue(BeanPropertyPointer.java:120)
> >
> >
> >
> org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.getImmediateNode(BeanPropertyPointer.java:149)
> >
> >
> >
> org.apache.commons.jxpath.ri.model.beans.PropertyPointer.getImmediateValuePointer(PropertyPointer.java:161)
> >
> >
> >
> org.apache.commons.jxpath.ri.model.NodePointer.getValuePointer(NodePointer.java:297)
> >
> >
> >
> org.apache.commons.jxpath.ri.model.beans.PropertyIterator.getNodePointer(PropertyIterator.java:121)
> >
> >
> >
> org.apache.commons.jxpath.ri.axes.DescendantContext.nextNode(DescendantContext.java:115)
> >   org.apache.commons.jxpath.ri.EvalContext.nextSet(EvalContext.java:349)
> >
> >
> >
> org.apache.commons.jxpath.ri.axes.ChildContext.getSingleNodePointer(ChildContext.java:70)
> >   org.apache.commons.jxpath.ri.compiler.Path.searchForPath(Path.java:201)
> >
> >
> >
> org.apache.commons.jxpath.ri.compiler.Path.getSingleNodePointerForSteps(Path.java:176)
> >
> >
> >
> org.apache.commons.jxpath.ri.compiler.LocationPath.computeValue(LocationPath.java:87)
> >
> >
> >
> org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:353)
> >
> >
> >
> org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:313)
> >
> >
> >
> com.spotnana.webhooks.isos.PNRListBuilderTest.testJxPathCtx(PNRListBuilderTest.java:366)
> >
> > On Sun, Sep 24, 2023 at 1:24 AM Debraj Manna 
> > wrote:
> >
> > > I am trying to search using JxPath on a proto message, My proto message
> > is
> > > placed here
> > > <https://gist.github.com/debraj-manna/4a8ded5d79dc9aee8d4c03d460327284
> >.
> > >
> > > val protoStr =
> > > getStringFromFile("classpath:BookingEnginePnrUpdateEventProto.txt");
> > > val msgBld = BookingEnginePNRUpdateEvent.newBuilder();
> > > TextFormat.getParser().merge(protoStr, msgBld);
> > > val msgCtx = JXPathContext.newContext(msgBld.build());
> > > System.out.println(msgCtx.getValue("//employeeId"));
> > >
> > > I am observing that  msgCtx.getValue("//employeeId") is taking a lot of
> > > time. Thread dumps at various points are placed in the below gist.
> > >
> > > https://gist.github.com/debraj-manna/47852fa190075abdacd527969f355cde
> > >
> > > If I specify the entire path like
> > >
> >
> msgCtx.getValue("/metadata/bookerInfo/traveler/userBusinessInfo/employeeId").
> > > It is working fine.
> > >
> > > Can someone let me know what is going wrong? Is this expected?
> > >
> > >
> > >
> > >
> > >
> >
>


Re: Jxpath getting stuck on trying to do a getValue

2023-09-24 Thread Debraj Manna
It looks like it is getting stuck in some infinite loop. The thread stack
looks like below after ~ 8 hours from the start.

main  Runnable CPU usage on sample: 979ms
  jdk.internal.reflect.GeneratedMethodAccessor640.invoke()

jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  java.lang.reflect.Method.invoke(Method.java:568)
  org.apache.commons.jxpath.util.ValueUtils.getValue(ValueUtils.java:367)

org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.getBaseValue(BeanPropertyPointer.java:120)

org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.getImmediateNode(BeanPropertyPointer.java:149)

org.apache.commons.jxpath.ri.model.beans.PropertyPointer.getImmediateValuePointer(PropertyPointer.java:161)

org.apache.commons.jxpath.ri.model.NodePointer.getValuePointer(NodePointer.java:297)

org.apache.commons.jxpath.ri.model.beans.PropertyIterator.getNodePointer(PropertyIterator.java:121)

org.apache.commons.jxpath.ri.axes.DescendantContext.nextNode(DescendantContext.java:115)
  org.apache.commons.jxpath.ri.EvalContext.nextSet(EvalContext.java:349)

org.apache.commons.jxpath.ri.axes.ChildContext.getSingleNodePointer(ChildContext.java:70)
  org.apache.commons.jxpath.ri.compiler.Path.searchForPath(Path.java:201)

org.apache.commons.jxpath.ri.compiler.Path.getSingleNodePointerForSteps(Path.java:176)

org.apache.commons.jxpath.ri.compiler.LocationPath.computeValue(LocationPath.java:87)

org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:353)

org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:313)

com.spotnana.webhooks.isos.PNRListBuilderTest.testJxPathCtx(PNRListBuilderTest.java:366)

On Sun, Sep 24, 2023 at 1:24 AM Debraj Manna 
wrote:

> I am trying to search using JxPath on a proto message, My proto message is
> placed here
> <https://gist.github.com/debraj-manna/4a8ded5d79dc9aee8d4c03d460327284>.
>
> val protoStr =
> getStringFromFile("classpath:BookingEnginePnrUpdateEventProto.txt");
> val msgBld = BookingEnginePNRUpdateEvent.newBuilder();
> TextFormat.getParser().merge(protoStr, msgBld);
> val msgCtx = JXPathContext.newContext(msgBld.build());
> System.out.println(msgCtx.getValue("//employeeId"));
>
> I am observing that  msgCtx.getValue("//employeeId") is taking a lot of
> time. Thread dumps at various points are placed in the below gist.
>
> https://gist.github.com/debraj-manna/47852fa190075abdacd527969f355cde
>
> If I specify the entire path like
> msgCtx.getValue("/metadata/bookerInfo/traveler/userBusinessInfo/employeeId").
> It is working fine.
>
> Can someone let me know what is going wrong? Is this expected?
>
>
>
>
>


Jxpath getting stuck on trying to do a getValue

2023-09-23 Thread Debraj Manna
I am trying to search using JxPath on a proto message, My proto message is
placed here
<https://gist.github.com/debraj-manna/4a8ded5d79dc9aee8d4c03d460327284>.

val protoStr =
getStringFromFile("classpath:BookingEnginePnrUpdateEventProto.txt");
val msgBld = BookingEnginePNRUpdateEvent.newBuilder();
TextFormat.getParser().merge(protoStr, msgBld);
val msgCtx = JXPathContext.newContext(msgBld.build());
System.out.println(msgCtx.getValue("//employeeId"));

I am observing that  msgCtx.getValue("//employeeId") is taking a lot of
time. Thread dumps at various points are placed in the below gist.

https://gist.github.com/debraj-manna/47852fa190075abdacd527969f355cde

If I specify the entire path like
msgCtx.getValue("/metadata/bookerInfo/traveler/userBusinessInfo/employeeId").
It is working fine.

Can someone let me know what is going wrong? Is this expected?


Is commons-jxpath still maintained?

2023-09-22 Thread Debraj Manna
Hi

We are using commons-jxpath 1.3 but the last release was done about 7 years
ago. There are some open vulnerabilities also in 1.3 version. Can someone
let me know if this project is still maintained or if I should be using
some other dependency instead of the one below?


commons-jxpath
commons-jxpath
1.3


If this is not the right mailing list for asking this query can you please
point me to the correct mailing list?


Re: CVE-2022-40160O on commons-jxpath

2023-06-30 Thread Debraj Manna
commons-jxpath 1.3 is also getting flagged for CVE-2022-401
<https://security.snyk.io/vuln/SNYK-JAVA-COMMONSJXPATH-3040994>59.

On Fri, Jun 30, 2023 at 6:28 PM Debraj Manna 
wrote:

> Hi
>
> We have been flagged for CVE-2022-401600
> <https://security.snyk.io/vuln/SNYK-JAVA-COMMONSJXPATH-3040995> on
> commons-jxpath, version 1.3.
>
> Can someone let me know commons-jxpath is really affected by this
> vulnerability? If yes, is there any plan to fix this?
>


CVE-2022-40160O on commons-jxpath

2023-06-30 Thread Debraj Manna
Hi

We have been flagged for CVE-2022-401600
 on
commons-jxpath, version 1.3.

Can someone let me know commons-jxpath is really affected by this
vulnerability? If yes, is there any plan to fix this?


Updating common-beanutils 1.9.2 on common-validator

2020-05-27 Thread Debraj Manna
Hi

common-validator 1.6 uses common-beanutils 1.9.2 which has a vulnerability
as explained in the below link

https://vuldb.com/?id.140386

Is there any plan for updating the common-beanutils to the latest in
common-validator?

Thanks,


commons-io dependency for file-upload

2018-10-12 Thread Debraj Manna
Hi

The dependency page
 state
commons-io 2.2 is one of the required dependency for file-upload. Can
someone let me know if I have to use exact version 2.2 for commons-io with
file-upload 1.3.3 or I can use any version of commons-io >= 2.2 ?

Thanks,


Re: [Math] Calculate R-Square for PolynomialCurveFitter

2018-03-18 Thread Debraj Manna
Thanks Giles for the pointers.

On Sun, Mar 18, 2018 at 10:29 PM, Gilles <gil...@harfang.homelinux.org>
wrote:

> On Sun, 18 Mar 2018 20:52:27 +0530, Debraj Manna wrote:
>
>> Cross-posting from stackoverflow
>>
>> <https://stackoverflow.com/questions/49349580/calculate-r-
>> square-for-polynomialcurvefitter-in-apache-commons-math3>
>> .
>>
>> OLSMultipleLinearRegression, SimpleRegression provide a method that
>> returns calculateRSquared(),
>> getRSquare(). But I am not able to find any such method for
>> PolynomialCurveFitter ?
>>
>> Right now I am doing it myself like below :-
>>
>> Is there any such method in common-math which does this?
>>
>
> "PolynomialCurveFitter" is one of the syntactic sugar/wrapper
> around the least-squares optimizers.
> No state is maintained in the (immutable) instance.
>
> private PolynomialFunction getPolynomialFitter(List<List>
>> pointlist) {
>> final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(2);
>> final WeightedObservedPoints obs = new WeightedObservedPoints();
>> for (List point : pointlist) {
>> obs.add(point.get(0), point.get(1));
>> }
>>
>> double[] fit = fitter.fit(obs.toList());
>> System.out.printf("\nCoefficient %f, %f, %f", fit[0], fit[1],
>> fit[2]);
>> final PolynomialFunction fitted = new PolynomialFunction(fit);
>> return fitted;
>> }
>>
>
> This is indeed one the intended use-cases.
>
> private double getRSquare(PolynomialFunction fitter,
>> List<List> pointList) {
>> final double[] coefficients = fitter.getCoefficients();
>> double[] predictedValues = new double[pointList.size()];
>> double residualSumOfSquares = 0;
>> final DescriptiveStatistics descriptiveStatistics = new
>> DescriptiveStatistics();
>> for (int i=0; i< pointList.size(); i++) {
>> predictedValues[i] = predict(coefficients,
>> pointList.get(i).get(0));
>> double actualVal = pointList.get(i).get(1);
>> double t = Math.pow((predictedValues[i] - actualVal), 2);
>> residualSumOfSquares  += t;
>> descriptiveStatistics.addValue(actualVal);
>> }
>> final double avgActualValues = descriptiveStatistics.getMean();
>> double totalSumOfSquares = 0;
>> for (int i=0; i<pointList.size(); i++) {
>> totalSumOfSquares += Math.pow( (predictedValues[i] -
>> avgActualValues),2);
>> }
>> return 1.0 - (residualSumOfSquares/totalSumOfSquares);
>> }
>>
>
> The "predict" method is not shown here, but note that the argument
> which you called "fitter" in the above, is actually a polynomial
> function:
>   http://commons.apache.org/proper/commons-math/apidocs/org/
> apache/commons/math4/analysis/polynomials/PolynomialFunction.html
>
> Hence:
>   predictedValues[i] = fitter.value(pointList.get(i).get(0));
>
> But otherwise, yes, the caller is responsible for choosing his
> assessement of the quality of the model.
>
> You could directly use the least-squares suite of classes; then
> the "Evaluation" object would allow to retrieve various measures
> of the fit:
>   http://commons.apache.org/proper/commons-math/apidocs/org/
> apache/commons/math4/fitting/leastsquares/LeastSquaresProbl
> em.Evaluation.html
>
> However, they might still not be what you are looking for...
>
> HTH,
> Gilles
>
> final PolynomialFunction polynomial = getPolynomialFitter(trainData);
>> System.out.printf("\nPolynimailCurveFitter R-Square %f",
>> getRSquare(polynomial, trainData));
>>
>
>
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>
>


[Math] Calculate R-Square for PolynomialCurveFitter

2018-03-18 Thread Debraj Manna
Cross-posting from stackoverflow

.

OLSMultipleLinearRegression, SimpleRegression provide a method that
returns calculateRSquared(),
getRSquare(). But I am not able to find any such method for
PolynomialCurveFitter ?

Right now I am doing it myself like below :-

Is there any such method in common-math which does this?

private PolynomialFunction getPolynomialFitter(List pointlist) {
final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(2);
final WeightedObservedPoints obs = new WeightedObservedPoints();
for (List point : pointlist) {
obs.add(point.get(0), point.get(1));
}

double[] fit = fitter.fit(obs.toList());
System.out.printf("\nCoefficient %f, %f, %f", fit[0], fit[1], fit[2]);
final PolynomialFunction fitted = new PolynomialFunction(fit);
return fitted;
}

private double getRSquare(PolynomialFunction fitter,
List pointList) {
final double[] coefficients = fitter.getCoefficients();
double[] predictedValues = new double[pointList.size()];
double residualSumOfSquares = 0;
final DescriptiveStatistics descriptiveStatistics = new
DescriptiveStatistics();
for (int i=0; i< pointList.size(); i++) {
predictedValues[i] = predict(coefficients, pointList.get(i).get(0));
double actualVal = pointList.get(i).get(1);
double t = Math.pow((predictedValues[i] - actualVal), 2);
residualSumOfSquares  += t;
descriptiveStatistics.addValue(actualVal);
}
final double avgActualValues = descriptiveStatistics.getMean();
double totalSumOfSquares = 0;
for (int i=0; i

Re: [Math] How to do Polynomial Regression ?

2018-03-13 Thread Debraj Manna
Thanks Phil

On Tue, Mar 13, 2018 at 4:03 AM, Phil Steitz <phil.ste...@gmail.com> wrote:

> On 3/12/18 10:15 AM, Debraj Manna wrote:
> > Crossposting from stackoverflow
> > <https://stackoverflow.com/questions/49238446/polynomial-
> regression-with-apache-maths-3-6-1>
> > as I did not get any reply there
> >
> > Can someone let me know how I can do Polynomial Regression with Apache
> Maths
> > <https://mvnrepository.com/artifact/org.apache.commons/commons-math3>
> 3.6.1
> > ?
> >
> > Below are the data points I used for my testing
> >
> > 60735214881.391304  152025480.0060697824142.469570
> > 152025840.0060651182200.208694
> > 152026200.0060684367132.939130
> > 152026560.0060676588613.008700
> > 152026920.0060641816564.869570
> > 152027280.0060604714824.233510
> > 152027640.0060580042814.330440
> > 152028000.0060536134542.469570
> > 152028360.0060566323732.034780
> > 152028720.0060578775249.252174
> > 152029080.0060547382844.104350
> > 152029440.0060536776546.802160
> > 152029800.0060474342718.330440
> > 152030160.0060452725477.286960
> > 152030520.0060486821569.669560
> > 152030880.0060247997139.995674
> > 152031240.0060248432181.426090
> > 152031600.0060217476247.373920
> > 152031960.0060170744493.634780  152032320.00
> >
> > My code looks like below
> >
> > private void polynomialFitter(List<List> pointlist) {
> > final PolynomialCurveFitter fitter =
> PolynomialCurveFitter.create(2);
> > final WeightedObservedPoints obs = new WeightedObservedPoints();
> > for (List point : pointlist) {
> > obs.add(point.get(1), point.get(0));
> > }
> > double[] fit = fitter.fit(obs.toList());
> > System.out.printf("\nCoefficient %f, %f, %f", fit[0], fit[1],
> fit[2]);
> > }
> >
> > The coefficients are reported as
> >
> > Coefficient 12.910025, 0.00, 0.00
> >
> > But these does not seem to be quite correct. If I use the same dataset
> > in Online
> > Polynimal Regression <http://polynomialregression.drque.net/online.php>
> and
> > in archanoid online regression <https://arachnoid.com/polysolve/> - both
> > reports same value as 654623237474.68250993904929103762,
> > 28.75921919628759991574, -0.023885199278
> >
> > Can someone let me know what is going wrong? I have seen this question
> > <https://stackoverflow.com/questions/28563361/polynomial-
> regression-with-apache-maths-java>
> >  but that is not helping me?
>
> Polynomial regression is not the same as curve fitting.  To do
> polynomial regression in Commons Math, use the
> OLSMultipleLinearRegression class, using, X, X^2 etc as the
> independent variables (as your second reference above shows).
>
> Phil
>
>
>
>
> >
> > Thanks,
> >
>
>


[Math] How to do Polynomial Regression ?

2018-03-12 Thread Debraj Manna
Crossposting from stackoverflow

as I did not get any reply there

Can someone let me know how I can do Polynomial Regression with Apache Maths
 3.6.1
?

Below are the data points I used for my testing

60735214881.391304  152025480.0060697824142.469570
152025840.0060651182200.208694
152026200.0060684367132.939130
152026560.0060676588613.008700
152026920.0060641816564.869570
152027280.0060604714824.233510
152027640.0060580042814.330440
152028000.0060536134542.469570
152028360.0060566323732.034780
152028720.0060578775249.252174
152029080.0060547382844.104350
152029440.0060536776546.802160
152029800.0060474342718.330440
152030160.0060452725477.286960
152030520.0060486821569.669560
152030880.0060247997139.995674
152031240.0060248432181.426090
152031600.0060217476247.373920
152031960.0060170744493.634780  152032320.00

My code looks like below

private void polynomialFitter(List pointlist) {
final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(2);
final WeightedObservedPoints obs = new WeightedObservedPoints();
for (List point : pointlist) {
obs.add(point.get(1), point.get(0));
}
double[] fit = fitter.fit(obs.toList());
System.out.printf("\nCoefficient %f, %f, %f", fit[0], fit[1], fit[2]);
}

The coefficients are reported as

Coefficient 12.910025, 0.00, 0.00

But these does not seem to be quite correct. If I use the same dataset
in Online
Polynimal Regression  and
in archanoid online regression  - both
reports same value as 654623237474.68250993904929103762,
28.75921919628759991574, -0.023885199278

Can someone let me know what is going wrong? I have seen this question

 but that is not helping me?

Thanks,