Error Encountered: Value is not valid number: B2 Parameter name: serialDate - rsa

I'm trying to create my own calculation in RSA Archer. I'm comparing to Date fields.
Sample calculation:
Field name Field Type
Field 1 Date
Field 2 Date
Field 3 Values List
IF(DATEDIF([Field 1], [Field 2]) > 0, VALUEOF([Field 3], "Green"),
IF(DATEDIF([Field 1], [Field 2]) > 1, VALUEOF([Field 3], "Amber"),
IF(DATEDIF([Field 1], [Field 2]) > 3, VALUEOF([Field 3], "Red"),
VALUEOF([Field 3],"Not Calculated"))))
But unfortunately, I encountered an Error.
Can anyone help me fix this error message or can someone suggest a better way to manipulate this calculation?

The calculation you shared has a missing round bracket ")" at the end. You have 3 "IF" and only two closing brackets. So calculation you shared should fail validation in Archer formula editor.
The error you shared indicates an issue with one of the input fields: [Field 1] or [Field 2]. I see two possible issues:
a). Confirm that [Field 1] and [Field 2] are actually of the Date type. In some cases field time may be Text and calculation can fail.
b). You need to check in calculation and make sure that both fields are not empty. I would modify the calculation as such:
IF( OR(ISEMPTY([Field 1]), ISEMPTY([Field 2])), VALUEOF([Field 3],"Not Calculated"),
IF( DATEDIF([Field 1], [Field 2]) > 0, VALUEOF([Field 3], "Green"),
IF( DATEDIF([Field 1], [Field 2]) > 1, VALUEOF([Field 3], "Amber"),
IF( DATEDIF([Field 1], [Field 2]) > 3, VALUEOF([Field 3], "Red"),
VALUEOF([Field 3],"Not Calculated")
))))

Related

Seeking vectorized solution to sum up elements using accumarray in Matlab/Numpy

(To anyone who reads this, just to not waste your time, I wrote up this question and then came up with a solution to it right after I wrote it. I am posting this here just to help out anyone who happened to also be thinking about something like this.)
I have a vector with elements that I would like to sum up. The elements that I would like to add up are elements that share the same "triggerNumber". For example:
vector = [0, 1, 1, 1, 1]
triggerNumber = [1, 1, 1, 2, 2]
I will sum up the numbers that share a triggerNumber of 1 (so 0+1+1 =2) and share a triggerNumber of 2 (so 1+1+1 = 3). Therefore my desiredOutput is the array [2, 2].
accumarray accomplishes this task, and if I give it those two inputs:
output = accumarray(triggerNumber.',vector.').'
which returns [2, 2]. But, while my "triggerNumbers" are always increasing, they are not necessarily always increasing by one. So for example I might have the following situation:
vector = [0, 1, 1, 1, 1]
triggerNumber = [4, 4, 4, 6, 6]
output = accumarray(triggerNumber.',vector.').'
But now this returns the output:
output = [0, 0, 0, 2, 0, 2]
Which is not what I want. I want to just sum up elements with the same trigger number (in order), so the desired output is still [2, 2]. Naively I thought that just deleting the zeros would be sufficient, but then that messes up the situation with the inputs:
vector = [0, 0, 0, 1, 1]
triggerNumber = [4, 4, 4, 6, 6]
which if I deleted the zeroes would return just [2] instead of the desired [0, 2].
Any ideas for how I can accomplish this task (in a vectorized way of course)?
I just needed to turn things like [4, 4, 4, 6, 6] into [1, 1, 1, 2, 2], which can be done with a combination of cumsum and diff.
vector = [0, 0, 0, 1, 1];
triggerNumber = [4, 4, 4, 6, 6];
vec1 = cumsum(diff(triggerNumber)>0);
append1 = [0, vec1];
magic = append1+1;
output = accumarray(magic.',vector.').'
which returns [2, 2]....and hopefully my method works for all cases.

Printing n choose k combinations in matlab

I need to create an algorithm in matlab which returns any combination of n subset from the k set. For example I have a set {1,2,3,4,5} and I need any combination of 3 numbers included in this set. So this function should returns:
[[1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 3, 4], [1, 3, 5], [1, 4, 5], [2, 3, 4], [2, 3, 5], [2, 4, 5], [3, 4, 5]]
I have tried to write it by myself, but unsuccessfully and I give up. It partially works, but it creates endless loop.
for i=1:n
if(firstTime)
lastComb=min //123
firstTime=false
else
for d=k:-1:1
while(lastComb(:,end) < n-k+d && lastComb(:,end)<=n)
newComb=lastComb
newComb(d)=lastComb(d)+1
combos= [combos; newComb]
lastComb=newComb
end
while(lastComb(:,end) > n-k+d && lastComb(:,end)<=n)
newComb=lastComb
for p=d:-1:1
if(newComb(p)+1 <=n)
newComb(p)=newComb(p)+1
combos= [combos; newComb]
end
end
end
end
end
end
Overall, your syntax is a little confusing (as previously stated by someone else). If you're posting a question here, it's a good idea to include all of your code, including the defined variables just for ease of those that are helping you.
A few major issues that I'm seeing with what you have are as follows:
(1) You seem to only be getting "n" combinations with what you're writing, which I think is 3 combinations. Instead, you should be getting 10 combinations. The beginning of this function should probably have a combination calculation [nCk = n!/((n-k)!*k!)].
(2) You're defining the first combination as 1,2,3, but then you don't but it into the "combos" set that you are making. Instead you replace it with something else before it can reach "combos."
There are a couple more, but try fixing these parts and the others may come naturally.
Overall, this function already exists. Just type "open nchoosek" into MATLAB to see a refined version of what you are attempting if you get stuck!

Converting datatypes for failing test function in Perl?

Minimum code
use strict;
use warnings;
use v5.16;
use Test::More tests => 2;
is_deeply(
[ [0, 0], [1, 0] ],
[ [0, 0], [1, 0] ],
'Intersects x-axis at (0, 0) and (1, 0)'
);
is_deeply(
( [0, 0], [1, 0] ),
( [0, 0], [1, 0] ),
'Intersects x-axis at (0, 0) and (1, 0)'
);
which returns
ok 1 - Intersects x-axis at (0, 0) and (1, 0)
is_deeply() takes two or three args, you gave 5.
This usually means you passed an array or hash instead
of a reference to it at test44.pl line 14
not ok 2
# Failed test at test44.pl line 14.
# Looks like you failed 1 test of 2 run.
The first code succeeds with [[-,-],[-,-]] entries but the second fails with ([-,-],[-,-]) entries.
My function returns everything as ([-,-], [-,-]) which I want to test if it is on the x-axis.
There are too many args for the test, which is the reason why the test fails.
So some conversion may be needed.
However, my data chunks are very big so no duplication of data is not a good idea because of speed.
How can you proceed testing such data ([-,-],[-,-]) to fit the expected result efficiently?
Use anonymous arrays, each one of them is interpreted as just 1 argument:
is_deeply(
[ [0, 0], [1, 0] ],
[ [0, 0], [1, 0] ],
'Intersects x-axis at (0, 0) and (1, 0)'
);
The parentheses in the original code do nothing, the lists are flattened, i.e. the code is equivalent to
is_deeply( [0, 0], [1, 0], [0, 0], [1, 0],
'Intersects x-axis at (0, 0) and (1, 0)'
);
5 arguments to is_deeply.

Prolog: dividing a number

I wanted to make a predicate that returns a list of a number dividers.
Example: 72 = 2*2*2*3*3.
prdel(A,[],_):-
A is 1.
prdel(P,[D|L],D):-
0 is mod(P,D),
P1 is P/D,
prdel(P1,L,D).
prdel(P,L,D):-
D1 is D+1,
prdel(P,L,D1).
This works and returns the right list. The problem is that it does not stop after that but returns the same list over and over again if I press space (I am sorry I don't know the term in English when you use the same predicate to get different answer). I want it to stop after the first time.
I tried to edit the last one like that,
prdel(P,L,D):-
D1 is D+1,
D1<P,
prdel(P,L,D1).
but now it returns only false and not the list.
EDIT:
I am looking for an answer without cut.
One problem in your code is that it keeps trying to divide the number P by D even when it is clear that the division is not going to succeed because D is too high. This lets D "run away" without a limit.
Adding a check for D1 to be below or equal to P fixes this problem:
prdel(1,[],_).
prdel(P,[D|L],D):-
0 is mod(P,D),
P1 is P/D,
prdel(P1,L,D).
prdel(P,L,D):-
D1 is D+1,
D1 =< P,
prdel(P,L,D1).
This produces all combinations of divisors, including non-prime ones (demo).
[[2, 2, 2, 3, 3], [2, 2, 2, 9], [2, 2, 3, 6],
[2, 2, 18], [2, 3, 3, 4], [2, 3, 12], [2, 4, 9],
[2, 6, 6], [2, 36], [3, 3, 8], [3, 4, 6], [3, 24],
[4, 18], [6, 12], [8, 9], [72]]
If you do not want that, add the condition that mod(P,D) > 0 in the last clause:
prdel(1,[],_).
prdel(P,[D|L],D):-
0 is mod(P,D),
P1 is P/D,
prdel(P1,L,D).
prdel(P,L,D):-
mod(P,D) > 0,
D1 is D+1,
D1 =< P,
prdel(P,L,D1).
This produces only [2, 2, 2, 3, 3] (demo).

Create array of points from single dimensional array of points

Waht i need to do is take a single dimensional array, ie:
[1, 1, 2, 2, 3, 3]
and turn it into an array of points:
[[1, 1], [2, 2], [3, 3]]
I am hoping for a simple native matlab way of doing it rather then a function. This will be going into sets of points ie:
[ [[1, 1], [2, 2], [3, 3]],
[[4, 4], [5, 5], [6, 6]],
[[7, 7], [7, 7], [8, 8]] ]
The reason this is going to happen is the points will be stored in a text file as a single stream and i need to turn them into something meaningful.
First note that a horizontal concatenation of row vectors will result in one larger row vector rather than in a row of pairs, that is [[1, 1], [2, 2], [3, 3]] is the same as [1 1 2 2 3 3]. Hence, you need to concatenate them vertically.
You can try
a = [1, 1, 2, 2, 3, 3];
b = reshape(a, 2, floor(length(a)/2))';
This will result in a matrix where each row represents the coordinates of one point.
b =
1 1
2 2
3 3
I'm just adding this answer for the sake of diversity:
Just as H.Muster said, concatenation of vectors will result in a larger vector or a matrix (depending on your operation). You can go with that.
But you can also use a cell array, which is a set of data containers called "cells". A cell can contain any type of data, regradless of what other cells contain in the same cell array.
In your case, creating a cell array can be done using a slightly different syntax (than H.Muster's answer):
a = [1, 1, 2, 2, 3, 3];
p = mat2cell(a, 1, 2 * ones(1, numel(a) / 2))
p is a cell array, each cell containing a 1-by-2 point vector. To access an element in a cell array, you'll have to use curly braces. For instance, the second point would be p{2} = [2, 2].