cx_Oracle freezes when left joining a table twice (two aliases) - left-join

Execute a query which contains double left join to same table and notice the cursor hangs (memory consumption keeps increasing).
Sample:
select aa.x, bb.y, bb2.y from aatable aa
left join bbtable bb on (aa.x2 = bb.y2)
left join bbtable bb2 on (aa.x3 = bb2.y2)
I use Python 3.7.4 / 64 bit.
Displaying aatable but replacing x2 and x3 with corresponding string from bbtable (lookup x2 and x3 in y2 column and return y)

Related

How do I stack an array variable and plot three of these stacked array variables on a barh?

% S
a1 = [2015/07/23 2015/11/25 2016/01/20];
b1 = [2011/06/22 2014/10/14 2015/03/01];
c1 = [2012/04/16 2013/06/23 2015/04/08];
d1 = [2013/09/15 2014/01/19 2016/09/13];
e1 = [2015/04/01 2016/04/04 2018/08/04];
% H
a2 = [2012/07/23 2015/06/25 2016/05/20];
b2 = [2009/06/22 2014/09/14 2015/11/01];
c2 = [2006/04/16 2013/12/23 2015/06/08];
d2 = [2008/09/15 2014/05/19 2016/02/13];
e2 = [2011/04/01 2016/05/04 2018/03/04];
% HS
a3 = [2009/07/23 2010/06/25 2018/02/20];
b3 = [2011/06/22 2014/07/14 2016/09/01];
c3 = [2013/04/16 2016/09/23 2019/05/08];
d3 = [2013/09/15 2018/05/19 2019/06/13];
e3 = [2014/04/01 2019/01/04 2019/12/04];
% T
t = [1 2 3 4 5];
dates = [a1 a2 a3; b1 b2 b3; c1 c2 c3; d1 d2 d3; e1 e2 e3];
% Plotted
figure
barh(t, dates, 'hist')
title('Script')
xlabel('Time')
ylabel('Tail')
legend({'S','H','HS'})
legend('Location', 'southoutside')
legend('Orientation','horizontal')
If you plot this, you will notice that there are 9 bar graphs associated with each 't'. There should be only three as stated in the 'dates' variable per t. How do I stack 'a1,a2,a3, then b1,b2,b3 ...... and e1,e2,e3 each individually' to accomplish this feat?
My script result:
What I want the output to look like
Note: 1. The y axis contains the 5 different elements 't'
2. The x axis should contain the date elements 'dates'
3. When you plot these values, there are 9 bars. There should be three per
't'.
4. On the x axis, I would like to have the dates represented.
5. I would like to eventually be able to create a user prompted system that
allows people to enter in dates for a corresponding array, and have that
date be stacked onto the chart.
The following bit of code does a bit of what I ask for but with the bars stacked vertically not horizontally, and also takes in different user inputs.
https://www.mathworks.com/matlabcentral/fileexchange/32884-plot-groups-of-stacked-bars
You are very close to a solution. Download that file from MATLAB file exchange, open it, replace bar with barh, you got your own horizontally stacked bar plot.
Your input does not fit the expected format, the function expects a 3d matrix. A minor change to your code:
dates = [cat(3,a1,a2,a3);cat(3,b1,b2,b3); cat(3,c1,c2,c3); cat(3,d1,d2,d3); cat(3,e1,e2,e3)];
plotBarHStackGroups(dates,t)

How do i run my M-file serially while changing a particular variable?

I want to carry out a sensitivity study for my Matlab script. The script has 3 different variables (velocity, searchVolume1, and searchVolume2) whose values are to be changed such that: both velocity and searchVolume2 are kept constant while searchVolume1 is being changed from say 0.5, 2.4, 3.7, 4.6, 5.1, etc. The procedure is repeated for next values of velocity (say: 10, 20, 30, 50, 70, etc) and afterwards, searchVolume2 is then also changed to different values (say: 1,2,3,4,5,etc). There are three output variables (t1, t2, and t3) for each run, but these come in the form of a distribution.
Now, I have made my script as a function (myMfile_sensitivity) with the three outputs (t1, t2, and t3) and I have another script where I would need to call myMfile_sensitivity. However due to the nature of the complexity, I have decided to only alter searchVolume1 and then use several computers for different velocities - after which I will repeat the runs for other values of searchVolume2.
I have re-edited my M-file to look this way:
Velocity = 10
searchVolume2 = 1
searchVolume1 = 0.5
% Pre-allocate storage for t1, t2, and t3
t1 = NaN(numel(X), kk)
t2 = NaN(numel(X), kk)
t3 = NaN(numel(X), kk)
For ii = 1: numel(X) %where X is the no. of data points for the distribution
Do….
Do….
While volume(ii,:) < searchVolume1(kk,:)
Do…
Do…
End
Do…
Do…
t1 = ….
t2 = ….
End
In my new script, I have:
searchVolume1 = [0.5, 0.5, 2.4, 3.7, 4.6, 5.1]';
For kk = 1: numel(searchVolume1)
[t1,t2,t3] = myMfile_sensitivity(searchVolume, kk)
End
The file runs but I end up seeing only the result for the last searchVolume1. How do I store all the outputs? Many thanks in advance guys!

Iteration of matrix-vector multiplication which stores specific index-positions

I need to solve a min distance problem, to see some of the work which has being tried take a look at:
link: click here
I have four elements: two column vectors: alpha of dim (px1) and beta of dim (qx1). In this case p = q = 50 giving two column vectors of dim (50x1) each. They are defined as follows:
alpha = alpha = 0:0.05:2;
beta = beta = 0:0.05:2;
and I have two matrices: L1 and L2.
L1 is composed of three column-vectors of dimension (kx1) each.
L2 is composed of three column-vectors of dimension (mx1) each.
In this case, they have equal size, meaning that k = m = 1000 giving: L1 and L2 of dim (1000x3) each. The values of these matrices are predefined.
They have, nevertheless, the following structure:
L1(kx3) = [t1(kx1) t2(kx1) t3(kx1)];
L2(mx3) = [t1(mx1) t2(mx1) t3(mx1)];
The min. distance problem I need to solve is given (mathematically) as follows:
d = min( (x-(alpha_p*t1_k - beta_q*t1_m)).^2 + (y-(alpha_p*t2_k - beta_q*t2_m)).^2 +
(z-(alpha_p*t3_k - beta_q*t3_m)).^2 )
the values x,y,z are three fixed constants.
My problem
I need to develop an iteration which can give me back the index positions from the combination of: alpha, beta, L1 and L2 which fulfills the min-distance problem from above.
I hope the formulation for the problem is clear, I have been very careful with the index notations. But if it is still not so clear... the step size for:
alpha is p = 1,...50
beta is q = 1,...50
for L1; t1, t2, t3 is k = 1,...,1000
for L2; t1, t2, t3 is m = 1,...,1000
And I need to find the index of p, index of q, index of k and index of m which gives me the min. distance to the point x,y,z.
Thanks in advance for your help!
I don't know your values so i wasn't able to check my code. I am using loops because it is the most obvious solution. Pretty sure that someone from the bsxfun-brigarde ( ;-D ) will find a shorter/more effective solution.
alpha = 0:0.05:2;
beta = 0:0.05:2;
L1(kx3) = [t1(kx1) t2(kx1) t3(kx1)];
L2(mx3) = [t1(mx1) t2(mx1) t3(mx1)];
idx_smallest_d =[1,1,1,1];
smallest_d = min((x-(alpha(1)*t1(1) - beta(1)*t1(1))).^2 + (y-(alpha(1)*t2(1) - beta(1)*t2(1))).^2+...
(z-(alpha(1)*t3(1) - beta(1)*t3(1))).^2);
%The min. distance problem I need to solve is given (mathematically) as follows:
for p=1:1:50
for q=1:1:50
for k=1:1:1000
for m=1:1:1000
d = min((x-(alpha(p)*t1(k) - beta(q)*t1(m))).^2 + (y-(alpha(p)*t2(k) - beta(q)*t2(m))).^2+...
(z-(alpha(p)*t3(k) - beta(q)*t3(m))).^2);
if d < smallest_d
smallest_d=d;
idx_smallest_d= [p,q,k,m];
end
end
end
end
end
What I am doing is predefining the smallest distance as the distance of the first combination and then checking for each combination rather the distance is smaller than the previous shortest distance.

MATLAB: multiple function fitting

I have a function, sum of three exponents:
F = f1*exp1 + f2*exp2 + f3*exp3
exactly:
F=1-((1-f(2)-f(3)).*(exp(-abs(data)./a(1)))+((1-f(1)-f(3)).*(exp(-abs(data)./a(2))))+((1-f(1)-f(2)).*(exp(-abs(data)./a(3)))));
where f1, f2, f3 is a fraction and each exp has one parameter, call it a1, a2 and a3.
So, fitting this function to experimental data gives six parameters (f1, f2, f3, a1, a2, a3).
Note, that
a1 > a2 > a3
and
f1 + f2 + f3 = 1
The fitting is done for several timelags (call it t1, t2, t3....). So for each timelag there is one set of six parameters.
Parameters a1, a2 and a3 are increasing with timelag in linear way ( a1(t1) < a1(t2) < a1(t3)... and so on). Fractions are the same for each timelag.
What I need is slope of a1(t), a2(t), a3(t) and fractions.
The problem is, that when I am fitting the function for each timelag, I often have a situation that a1 and a2 are nicely going up (perfect linear fits) but a3 is going down.
Also I have a problem with fractions - I can't take mean of each fraction because when I add f1(t) + f2(t) + f3(t) its never equal to 1.
Is there any (simple) way to fit it all 'at once'? How to do that?
Thanks!
First, I would suggest to reduce the number of parameters:
Replace f3 by 1-f1-f2
If ai(t) is always linear, replace by ai(t) = ai0 + bi*t. With bi>0, you can ensure that ai(t) is increasing.
That gives you two parameters for each ai(t), plus f1 and f2 for each time point, so a total of 6 + 2 * (# of timepoints) parameters. Depending on the number of timepoints, it may be possible to fit those with fmincon, as suggested by Chris Taylor.
With fmincon, you can add the parameter constraints in quite flexible ways. You probably want to add the constraint 0<=f1<=1 (and the same for f2) to the ones you already have.

How to multiply the subsets from table?

I have two figures of table.
One table is call H and another one call C. Both table is 4 by 3 table.
So if the user insert a value in two edit box. For example:
A = *value*
B = *value*
Then the user insert the data in H table. The user only use 2 rows. Let say this is the data:
ALPHA BETA GAMMA
H1
H2
H3
H4
So the user want to get the subset of H1 and multiply with A and subsets of H2 multiply with B. This is how it will be:
C1 = (ALPHA VALUE)*A (BETA VALUE)*A (GAMMA VALUE)*A
C2 = (ALPHA VALUE)*B (BETA VALUE)*B (GAMMA VALUE)*B
Then the user wants to display the answer on C table where it will become like this:
ALPHA BETA GAMMA
C1 NEW VALUE NEW VALUE NEW VALUE
C2 NEW VALUE NEW VALUE NEW VALUE
C3
C4
How can i make the coding of this problem?
I have already try this coding but it seems i failed. CAN ANYONE HELP ME PLEASE!!
H = cell2mat(get(handles.Mytable3,'Data'));
cost1 = str2num(get(handles.input2_editText,'String'));
cost2 = str2num(get(handles.input3_editText,'String'));
H1 = H(1,:)*cost1;
H2 = H(2,:)*cost2;
H = mat2cell([H1 H2]);
cost = get(H,'Data');
set(handles.Mytable2,'Data',cost)
Try:
H = num2cell([H1 H2]);
set(handles.Mytable2,'Data',H)