Get request use OR / AND - request

I need to create a get request the repent the flowing query :
A = 1 or 2
B = 3 And 4
C = (1 or 2 ) and (5 or 6)
I know that I can do something like this :
a/b?A=1,2&B=3+4,C=[1,2]+[5,6]
But what is this the best practice? Are there any conventions about what we need to represent AND/OR symbols?

Related

Solve system of equations with data loaded, loop through group IDs and different observations

I have data for a large amount of Group IDs, and each group ID has anywhere from 4 to 30 observations. I would like to solve a (linear or nonlinear, depending on approach) system of equations using data in Matlab. I want to solve a system of three equations and three unknowns, but also load in data for known variables. I need observations 2 through 4 in order to solve this, but would also like to move to the next set of 3 observations (if it exists) to see how the solutions change. I would like to record these calculations as well.
What is the best way to accomplish this? I have a standard idea of how to solve the system using fsolve, but what is the best way to loop through group IDs with varying amounts of observations?
Here is some sample code I have written when thinking about this issue:
%%Load Data
Data = readtable('dataset.csv'); % Full Dataset
%Define Variables
%Main Data
groupID = Data{:,1};
Known1 = Data{:,7};
Known2 = Data{:,8};
Known3 = Data{:,9};
%%%%%%Function %%%%%
f = [A,B,C];
% Define the function handle for the system of equations
fun = #(f) [A^2 + B*Known3 - 2C*Known1 +1/Known2 - D2;
A + (B^2)Known3 - C*Known1 +1/Known2 - D3;
A - B*Known3 + C^2*Known1 +1/Known2 - D4];
% Define the initial guess for the solution
f0 = [0; 0; 0];
% Solve the nonlinear system of equations
f = fsolve(fun, f0)
%%%% Create Loop %%%%%%
% Set the number of observations to load at a time
numObservations = 3;
% Set the initial group ID
groupID = 1;
% Set the maximum number of groups
maxGroups = 100;
% Loop through the groups of data
while groupID <= maxGroups
% Load the data for the current group
data = loadData(groupID, numObservations);
% Update the solution using the new data
x = fsolve(fun, x);
% Print the updated solution
disp(x);
% Move on to the next group of data
groupID = groupID + 1;
end
What are the pitfalls with writing the code like this, and how can I improve it?

KDB:issue using recursive function with two variables

I have tried to do the following in several different ways but haven't succeeded so far.
I have a list of tables that goes like this:
.rsk.list
extract1.csv | +`date`code etc.
...
I can call the table like this .rsk.list[`extract1.csv]
Or I can raze .rsk.list to get a table of all extracts. Except it's not really a table (type 0b)
My goal is to copy some extracts, let's say toload:`extract1.csv`extract5.csv to a second table, let's call it .rsk.list2
I have tried many variations of this
tmp:{.rsk.risk[x]} each toload \which works
{.rsk.list2[x]:y}[each toload;each tmp} \which does not
If you have any idea how to make the above work or how to cast raze .rsk.list to a table, I'll be forever grateful.
In order to join on extract1.csv and extract5.csv effectively it would help to see what they look like.
When you raze a list of non-conformant tables it will generate a mixed list (type 0) of dictionaries
e.g.:
q).rsk.list:`1.csv`2.csv!(([]a:`a`b`c;b:til 3);([]c:`d`e`f;d:2*til 3))
q).rsk.list[`1.csv]
a b
---
a 0
b 1
c 2
q).rsk.list[`2.csv]
c d
---
d 0
e 2
f 4
q)raze .rsk.list
`a`b!(`a;0)
`a`b!(`b;1)
`a`b!(`c;2)
`c`d!(`d;0)
`c`d!(`e;2)
`c`d!(`f;4)
q)type raze .rsk.list
0h
One method is using uj and over(/) but it depends on your usecase whether this achieves the desired result:
q)(uj/) .rsk.list[`1.csv`2.csv]
a b c d
-------
a 0
b 1
c 2
d 0
e 2
f 4
This is a table but not necessarily a useful one

django: SQL UNION or concatenate with queryset: not working properly when used with annotate

I have the below two querysets books1 and books2. On both i am using annotate to add another column with a constant of 10 for books1 and 30 for books2. The problem is after i Concatenate the querysets the final set shows the annotate value = 10 even for books2
author1 = Author.objects.get(pk=1)
books1 = author1.books_set.annotate(sample_var=Value(10))
author2 = Author.objects.get(pk=2)
books2 = author2.books_set.annotate(sample_var=Value(30))
combine = books1 | books2
what i see:
name author id sample_var
name1 (from books1) 1 10
.. 1 10
.. 1 10
.. 1 10
name2 (from books2) 2 10 (instead of 30)
.. 2 10 (instead of 30)
.. 2 10 (instead of 30)
.. 2 10 (instead of 30)
the reason is, the sql being used for the combine is as below. I get this when i try to access combine[0].name. It takes care of the WHERE part, but not the annotate part. It uses 10 AS "sample_var" for the combine queryset, which is not right, thats why all show 10 in the above table.
SELECT "books_books"."name", "books_books"."author_id", 10 AS "sample_var"
FROM "books_books"
WHERE ("books_books"."author_id" = 1 OR "books_books"."author_id" = 2)
I think if the union to happen properly the sql should be:
SELECT "books_books"."name", "books_books"."author_id", 10 AS "sample_var"
FROM "books_books"
WHERE ("books_books"."author_id" = 1)
union all
SELECT "books_books"."name", "books_books"."author_id", 30 AS "sample_var"
FROM "books_books"
WHERE ("books_books"."author_id" = 2)
In Django 1.11 you can do union, and in your case:
all_books = books1.union(books2, all=True)

Porting codes from MATLAB to C(OpenCV)

I've been working on trying to port a small meanshift tracking program, which is sort of different from the meanshift that involves performing back-projection, from MATLAB to C, but I'm having some problems with it.
I don't know how to interpret some of the lines from MATLAB to C(OpenCV).
https://drive.google.com/drive/folders/0B2r9FmkcbNwAbHdtVEVkSW1SQW8
I put the 2 .m files, 1 .cpp file and a directory where pictures are placed for both programs to use on my googledrive.
"demo_MultiMeanShift_1st_ver_0413.m" is what I'd like to port to C,
"boxfilter.m" is the function that's found in the following website:
http://blog.csdn.net/wds555/article/details/23176313
(It's a Chinese website however)
and "Meanshift_demo.cpp" is what I've done so far.
There're mainly two parts that I don't know how to interpret from MATLAB to C:
1st part:
bas = zeros(hei,wid,N) ;
for i = 1 : 1 : N
bas(:,:,i) = boxfilter( ones(hei,wid), floor(r/i) ) ;
end
Ic_mean = zeros(hei,wid,dep,N) ;
for i = 1 : 1 : N
for d = 1 : 1 : dep
%Average pixel value(s) of the object being tracked
Ic_mean(pc(2)-(r+sw) : pc(2)+(r+sw), pc(1)-(r+sw) : pc(1)+(r+sw), d, i) = boxfilter(Ip(pc(2)-(r+sw) : pc(2)+(r+sw), pc(1)-(r+sw) : pc(1)+(r+sw),d), floor(r/i)) ./ bas(pc(2)-(r+sw) : pc(2)+(r+sw), pc(1)-(r+sw) : pc(1)+(r+sw),i);
%Ic_mean(:,:,d,i) = boxfilter(Ip(:,:,d), floor(r/i)) ./ bas(:,:,i);
end
end
dis = zeros(1,N) ;
2nd part:
for i = -sw + pc(2) : 2 : sw + pc(2)
for j = -sw + pc(1) : 2 : sw + pc(1)
for d = 1 : 1 : N
dis(d) = sqrt( ... % (p1(R1, G1, B1) - p2(R2, G2, B2))^2
( Ic_mean(i,j,1,d) - Ip_mean(pc(2),pc(1),1,d) )^2 ...
+ ( Ic_mean(i,j,2,d) - Ip_mean(pc(2),pc(1),2,d) )^2 ...
+ ( Ic_mean(i,j,3,d) - Ip_mean(pc(2),pc(1),3,d) )^2 );
end
if disMin > mean(dis)
disMin = mean(dis) ;
i_hold = i ;
j_hold = j ;
end
end
end
In MATLAB I can read, access and change pixel values directly, such as:
Img(x,y) = 0 to set some pixel value to be 0
or
Img(:,:,1) = 1 to set the pixels of certain channel to all be 0.
Can I also do those things as rapidly as what's shown above is in OpenCV?
In MATLAB I can read, access and change pixel values directly, such
as:
Img(x,y) = 0 to set some pixel value to be 0 or Img(:,:,1) = 1 to set
the pixels of certain channel to all be 0.
Can I also do those things as rapidly as what's shown above is in
OpenCV?
Of course this is possible. To set value of single pixel use:
img.at<img_single_element_type>(y,x) = 0;
where img_single_element_type depends on mat type and might be double, unsigned char, int, etc... See documentation for more information.
To set values in whole image (or part of image) use setTo method.
I don't know much about Matlab, so i can't help you with porting this code, but look at this and this project. It's similar project (object tracker - Open TLD(Tracking Learning Detection) aka Predator) written in Matlab(first link) and ported to C++(second link). Hope it helps.

VBA Run-time error 13 - type mismatch- price time series calc not working on array

I suspect my question has a very simple answer, and yet I cannot find an answer that I understand in searching all over the site.
Ticker1 = an array of stock prices (1 to 2542)
PctChg1 = an array which I hope will ultimately hold the results of
(Price_last / Price_prev) - 1
i = counter
Code:
For i = 2 To UBound(Ticker1)
PctChg1(i, 1) = Ticker1(i, 1) / Ticker1(i - 1, 1) - 1
Next i
Something about the Ticker1(i - 1, 1) part it does not like - I have fooled around with ranges as well and cannot make sense of this. I don't know why it thinks I am dividing by a number that isn't there - if i am starting at point 2 of the array, why wouldn't I be able to reference point 1 ?
For i = 2 To UBound(Ticker1)
If Val(Ticker1(i - 1, 1)) <> 0 Then PctChg1(i, 1) = Ticker1(i, 1) / Ticker1(i - 1, 1) - 1
Next i
This works, but I still have not established why i-1 generates errors when I start the calculation on data point i=2.

Resources