Round-off error detected, the requested tolerance (or default) cannot be achieved. Try using bigger tolerances in SCILAB - rounding-error

I am using integrate command but the scilab is showing me round off error detected and saying me to use high tolerance value which i have no clue.
a=4
b1=1
b2=3
N=6
v=-50
for n=1:N
h(n,n)=n^2+(v/a)*integrate('1-cos(2*n*%pi*(r/a))','r',b1,b2)
for m=n+1:N
h(m,n)=(v/a)*integrate('(cos((m-n)*%pi*(r/a))-cos((m+n)*%pi*(r/a)))','r',b1,b2)
h(n,m)=h(m,n)
end
end
[al,bl,R]=spec(h,s);
el=al./bl;
e=R;
[el,k]=gsort(el)
disp(h);
disp(el)

The default absolute tolerance of integrate may be too stringent in some cases. Below I changed it to 1e-13 in last argument of integrate at line 9 of your script, which now runs fine (I also added the definition of matrix s which I supposed to be the identity matrix, like in your previous message):
a=4
b1=1
b2=3
N=6
v=-50
for n=1:N
h(n,n)=n^2+(v/a)*integrate('1-cos(2*n*%pi*(r/a))','r',b1,b2)
for m=n+1:N
h(m,n)=(v/a)*integrate('(cos((m-n)*%pi*(r/a))-cos((m+n)*%pi*(r/a)))','r',b1,b2,1e-13)
h(n,m)=h(m,n)
end
end
s=eye(N,N);
[al,bl,R]=spec(h,s);
el=al./bl;
e=R;
[el,k]=gsort(el)
disp(h);
disp(el)

Related

How is the range of the last layer of a Neural Network determined when using ReLU

I'm relatively new to Neural Networks.
Atm I am trying to program a Neural Network for simple image recognition of numbers between 0 and 10.
The activation function I'm aiming for is ReLU (rectified linear unit).
With the sigmoid-function it is pretty clear how you can determine a probability for a certain case in the end (because its between 0 and 1).
But as far as I understand it, with the ReLU we don't have these limitations, but can get any value as a sum of previous "neurons" in the end.
So how is this commonly solved?
Do I just take the biggest of all values and say thats probability 100%?
Do I sum up all values and say thats the 100%?
Or is there another aproach I can't see atm?
I hope my question is understandable.
Thanks in advance for taking the time, looking at my question.
You can't use ReLU function as the output function for classification tasks because, as you mentioned, its range can't represent probability 0 to 1. That's why it is used only for regression tasks and hidden layers.
For binary classification, you have to use output function with range between 0 to 1 such as sigmoid. In your case, you would need a multidimensional extension such as softmax function.

T-SQL SEQUENCE runs out, no cycle, what happens?

My particular case is that I'm writing a unit test and I want to simulate an error for a sequence generator, but I can't find any documentation on what it does when it runs out.
Here, of course, is the documentation for SEQUENCE:
https://learn.microsoft.com/en-us/sql/t-sql/statements/create-sequence-transact-sql?view=sql-server-2017
It, very nicely, says everything about it, except: what happens if I run out.
Consider the case when I set the sequence to a very small value (1-10) and I "know" that it will never go over 10. Except there's a bug in the code, and it suddenly gets every last one... then asks for one more?
Hypothetical example:
CREATE SEQUENCE [dbo].[MY_SEQUENCE]
 AS [tinyint]
 START WITH 1
 INCREMENT BY 1
 MINVALUE 1
 MAXVALUE 10
NO CYCLE
 CACHE
External code asks for the 11th one.
SELECT NEXT VALUE FOR MY_SEQUENCE
What happens?
The documentation you mentioned specifies what happens: "[...] throw an exception when its minimum or maximum value is exceeded"
Regarding the error message you can find out using a simple Google search: https://www.google.com/search?q=t-sql+error+messages+sequence The fourth link is https://www.sqlshack.com/sequence-objects-in-sql-server/ and there you can find a screenshot of the error, which has the number 11728.
Of course, it would be easier to try it yourself, using one of the methods already specified in the comments.

Invalid floating point operation using SQRT()

I receive an invalid floating point operation error when I SQRT(X) a value.
Under which reasons does this error occur, and what could I to to the X value to prevent this error?
For some context, the X value is a calculated average sales for stock items.
I have tried SQRT(ABS(x)) with no luck.
Thanks
As far as I know, the only case when SQRT(X) gives the error "An invalid floating point operation occurred" is when X is negative. However, you already fixed this by using the ABS function like this: SQRT(ABS(X)).
So, my guess is that the error does not really come from the SQRT function but from something else nearby. Let's look at the expression you gave:
SQRT(2*50*ABS(X)) / NULLIF(B*0.2/12,0))
This expression obviously has an extra right parenthesis. This makes me think that it is only a part of a larger expression, and that the larger expression is the reason for the error.
For instance, if B is 0 then the NULLIF() becomes NULL. You divide by NULL, thus getting a NULL result. Now, what do you do with this result? Maybe some more calculations that does not handle the NULL well?
There is a lot of guessing here. If my guesses did not point you in the right direction, then it would be helpful to know which values of B and X that give the error, and also the full statement that includes the expression.
There is a T_SQL command that calculates the type of the variables. You can view the type of variable before calculating its square root.
The command is :
SQL_VARIANT_PROPERTY
(See the site https://blog.sqlauthority.com/2013/12/15/sql-server-how-to-identify-datatypes-and-properties-of-variable/)
On the other hand, I'm sorry to tell you that I do not know if it works with the 2018 version, because I do not have the means to check it. But you can find the equivalent command for your SQL Server version.
Hope that can help.

Matlab: Return input value with the highest output from a custom function

I have a vector of numbers like this:
myVec= [ 1 2 3 4 5 6 7 8 ...]
and I have a custom function which takes the input of one number, performs an algorithm and returns another number.
cust(1)= 55, cust(2)= 497, cust(3)= 14, etc.
I want to be able to return the number in the first vector which yielded the highest outcome.
My current thought is to generate a second vector, outcomeVec, which contains the output from the custom function, and then find the index of that vector that has max(outcomeVec), then match that index to myVec. I am wondering, is there a more efficient way of doing this?
What you described is a good way to do it.
outcomeVec = myfunc(myVec);
[~,ndx] = max(outcomeVec);
myVec(ndx) % input that produces max output
Another option is to do it with a loop. This saves a little memory, but may be slower.
maxOutputValue = -Inf;
maxOutputNdx = NaN;
for ndx = 1:length(myVec)
output = myfunc(myVec(ndx));
if output > maxOutputValue
maxOutputValue = output;
maxOutputNdx = ndx;
end
end
myVec(maxOutputNdx) % input that produces max output
Those are pretty much your only options.
You could make it fancy by writing a general purpose function that takes in a function handle and an input array. That method would implement one of the techniques above and return the input value that produces the largest output.
Depending on the size of the range of discrete numbers you are searching over, you may find a solution with a golden section algorithm works more efficiently. I tried for instance to minimize the following:
bf = -21;
f =#(x) round(x-bf).^2;
within the range [-100 100] with a routine based on a script from the Mathworks file exchange. This specific file exchange script does not appear to implement the golden section correctly as it makes two function calls per iteration. After fixing this the number of calls required is reduced to 12, which certainly beats evaluating the function 200 times prior to a "dumb" call to min. The gains can quickly become dramatic. For instance, if the search region is [-100000 100000], golden finds the minimum in 25 function calls as opposed to 200000 - the dependence of the number of calls in golden section on the range is logarithmic, not linear.
So if the range is sufficiently large, other methods can definitely beat min by requiring less function calls. Minimization search routines sometimes incorporate such a search in early steps. However you will have a problem with convergence (termination) criteria, which you will have to modify so that the routine knows when to stop. The best option is probably to narrow the search region for application of min by starting out with a few iterations of golden section.
An important caveat is that golden section is guaranteed to work only with unimodal regions, that is, displaying a single minimum. In a region containing multiple minima it's likely to get stuck in one and may miss the global minimum. In that sense min is a sure bet.
Note also that the function in the example here rounds input x, whereas your function takes an integer input. This means you would have to place a wrapper around your function which rounds the input passed by the calling golden routine.
Others appear to have used genetic algorithms to perform such a search, although I did not research this.

How to use ELKI for DBSCAN with precomputed distance matrix

I've a precomputed distance matrix for all the points in my database.
I'm trying to invoke ELKI gui with following command:
/usr/share/java/elki.jar
-dbc.in xml_files.1000
-dbc.filter FixedDBIDsFilter
-dbc.startid 0
-algorithm clustering.DBSCAN
-algorithm.distancefunction external.FileBasedDoubleDistanceFunction
-distance.matrix Distance.txt
-dbscan.epsilon 1
-dbscan.minpts 10
But I keep getting following error message :
Wrong parameter format! Parameter "dbscan.epsilon" requires a distance value, but the distance was not set!
I can't figure out what am I doing wrong here...
Which version of ELKI are you using?
This error message usually indicates an issue with the distance parser used by the matrix reader.
Since ELKI supports different valued distance functions, DBSCAN cannot parse the epsilon parameter until the actual distance value type is known (which will provide the value parsing function).
Any earlier error message? If you have any earlier error (including missing required parameters), it will prevent DBSCAN from being able to parse the value.
Try setting the epsilon value last, and also try the command line. In the MiniGUI, due to the incremental way the parameters are set, these dynamic-typed parameters unfortunately can be flaky. Any patch to improve the handling of such parameters is appreciated.

Resources