I've got a matrix of values like the one below that I need to scale. I've been looking around for an inbuilt function if there is one that could do this for me. I haven't found one & so have ended up writing code to do the scaling using the below formula
scaledMatrix = (Matrix - MeanMatrix)/Standard Deviation
This code is a bit buggy & I'm working on correcting it. While I do that, I happened to bump on java.math.BigDecimal.scale() & did look up an equivalent for double as the matrix I have is double type numbers
If someone could please help me with details on
1) If there is an inbuilt function that accepts matrix of values & returns me the scaled matrix
2) `java.math.BigDecimal.scale()` equivalent for `double` type data
Any help would be much appreciated please.
The BigDecimal.scale() method does not do what you seem to think it is doing. A BigDecimal value is stored as a * 10^b (where ^ denotes exponentiation). The BigDecimal.scale() method basically returns the b part of that.
I do not know of a similar method for double values, nor do I know of a method which performs the function you need. Since you put apache-commons in the tags, I suggest you look into Apache Commons's extensive statistical library.
Related
I have this equation in java,
double BER = (Erf.erfc(Math.sqrt(3 * CodedEb_No) * Math.sin(Math.PI/8)))/3;
Erf.erfc is from org.apache.commons.math3.special.Erf
I don't know what is CodedEb_No, but BER is 1E-7. How can I calculate CodedEb_No?
I have a hint that I need to use erfcInv() from org.apache.commons.math3.special.Erf. But, since the rest of the values are also part of erfc function, I am bit confused on how to approach this. Can someone help me with this?
I think this is more of a maths than programming question after a very quick look and not testing, I guess you want to rearrange this function to make CodedEb_No the subject. I think that would be
CodedEb_No = Math.pow(Erf.erfcInv(BER * 3) / Math.sin(Math.PI/8), 2) / 3
You need to test this carefully!
I try to solve a large MIP in which the . If it does not solve optimally, it shall return the integrality gap (that is, difference between best integer solution and best solution of the linear relaxation).
Using getMIPRelativeGap of the Java+CPLEX interface, I sometimes got values in the range of 1.0E11-1.0E13 which does not make sense, as an integrality gap should be a percentage between 0 and 1. I tracked those cases down and found out that I get those results, if the best integer solution has a value of 0 (my inner problem is a profitable tour problem, thus, if the best route is not visiting any vertice). The integrality gap should be (bestobjective-bestinteger)/bestobjective (https://www.ibm.com/support/knowledgecenter/SSSA5P_12.6.0/ilog.odms.cplex.help/refdotnetcplex/html/M_ILOG_CPLEX_Cplex_MIPInfoCallback_GetMIPRelativeGap.htm), yet, it seems to be (bestobjective-bestinteger)/bestinteger.
I also tested a couple of other values (if the integer objective is positive), and were able to confirm this in examples.
Can someone else reproduce this behavior? Does this behavior make sense to you?
Thanks :)
Indeed, the documentation for CPXgetmiprelgap in the Callable Library (C API) says the following:
For a minimization problem, this value is computed by
(bestinteger - bestobjective) / (1e-10 + |bestinteger|)
where bestinteger is the value returned by CPXXgetobjval/CPXgetobjval
and bestobjective is the value returned by
CPXXgetbestobjval/CPXgetbestobjval. For a maximization problem,
the value is computed by:
(bestobjective - bestinteger) / (1e-10 + |bestinteger|)
So, it looks like the documentation for the Java API is buggy. The Java API just calls CPXgetmiprelgap under the hood, so it should be the same. Thanks for reporting this. I'll make sure that this gets passed on to the folks who can fix it.
In Anylogic there is a built-in function zidz, which does the following:
zidz(double a, double b)
Description
Tries to divide the first argument by the second. If the result is infinity or not a number, returns 0, otherwise returns the division result.
My question for you guys is: do you know a function that does the same operation but in Java?
I've searched and come up with Math#IEEEremainder, but I don't think it does the exact same thing as 'zidz'.
There isn't one in the common set of libraries. That's not to say there is nobody in the world who has written and published one, but the function is so trivial as to be unlikely to be included in a Java library.
--See update/answer below. User error!--
I'm trying to understand how to set the parameters in Imgproc.HoughLines() to find shorter lines. I've tried something like this that doesn't work at all:
Imgproc.HoughLines(matSrc, matLines, 1, Math.PI / 180, houghThreshCurrent, 25, 10);
I have tried several values for the last two parameters, but none seem to work--it finds no lines. However, using the version of the method without the last two parameters does a decent job of finding the lines I want, just not the shorter lines no matter how low the threshold is.
Here's the doc for the last two params:
srn For the multi-scale Hough transform, it is a divisor for the distance resolution rho. The coarse accumulator distance resolution is rho and the accurate accumulator resolution is rho/srn. If both srn=0 and stn=0, the classical Hough transform is used. Otherwise, both these parameters should be positive.
stn For the multi-scale Hough transform, it is a divisor for the distance resolution theta.
Could someone translate or provide example values for that? :)
I've also tried the probabalistic version, HoughLinesP(). It doesn't seem to work very well for my use case. The other option would be to scale my image to a larger size where the default HoughLines() works if I can't get the line distance parameters working.
Answer: My problem was I didn't realize the Mat returned by HoughLinesP() was in a different format than the one returned by HoughLines(). I was transforming the results from HoughLinesP() from polar coordinates when they were already in the XY coordinates! Turns out HoughLinesP() is far superior for our needs and its parameters work great for tuning line length. Here's the link that helped me see the error of my ways: https://dsp.stackexchange.com/questions/10467/influence-of-image-size-to-edge-detection-in-opencv
A very good example can be found here: http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html
Try using CV_PI instead of Math.PI? Other reasons could be because of your threshold. Try inserting a value like 50(play around with the numbers). The last 2 values, u can try leaving it to be zero and test it first before inserting values. Default Values for the last 2 is usually zero.
There could be many reasons why its not working, so let's slowly find the cause one by one. Also, you did Canny it or something before you applied Hough right?
Hope that helps, let me know if my suggestions are useful and helped(: Cheers.
Im currently using a program called KNIME, which is used for analysing data. For some of my data, I want each row in a column to be averaged with the value in the previous row. The 'java snippet' option requires a 'global value declaration' and a 'method body'. The column name is 'new acc'.
I understand to use this program more efficiently I'll probably need to learn simple java (and its on my to do), but just for this evening I would like a quick check on some of the data used.
Any help is really appreciated - ive attached an image of the layout.
Thanks!
If you aren't required to use the Java Snippet, I'd recommend the Math Formula node.
There's a Moving Average Node which might be suitable for the task.
What about putting
double acc = Double.NaN;
to the global area, and something like this to the method body:
if (Double.isNaN(acc)) {
acc = $z$;
return $z$;
} else {
double avg = (acc + $z$) / 2;
acc = $z$;
return avg;
}
As a partial answer to the one from Sylvansight, it should be noted that the Java Snippet node is executed on a per row basis, so it's not even possible to use the Java Snippet node to access the values in the previous or subsequent rows.
Math formula node fits better your problem, but if you want to use **java snippet node (simple) ** just put the formula in the return (using normal java sintax). return 1+9;