Multiplying two complex SeriesLists by a specific node - graphite

Let's say I have 4 different Serieslists:
foo.total
foo.succesful
bar.total
bar.succesful
I have generated a complex graphite query for both of them, so it goes like
function1(function2(foo.total))
function3(function4(foo.succesful))
I want to multiply these by each other. Well, that's not very difficult:
multiplySeries(function1(function2(foo.total)),function3(function4(foo.succesful)))
This draws one graph and works as intended.
The problem I am facing when trying to wildcard the foo-part, so I can do *.total. In this case I want to draw 2 graphs, because there are 2 wildcarded variables.
So my question is, how can I generalize the above query to not only work with foo but with n number of variables?
Thank you!

You need some kind of template function, the only one graphite provides is applyByNode and it should be sufficient in your case:
applyByNode(
*.{total,succesful},
'multiplySeries(f1(f2(%.total)), f3(f4(%.succesful)))',
'% some line'
)

Related

find the number of permutations for no two identical elements sit next to each other

I need some help for this problem ive been facing
suppose I have an array=[3,4,1,5,6,1,3]
now I need the permutation that the duplicate element 3 should not sit beside other 3 and same for 1.
how am I suppose to solve this ive watched a ton of YouTube and googled it but no luck
for the help thanks in advance.,,,
Are you looking for a general case solution or just for that particular array? If you are looking for more general case, I think you should specify the restrictions or the problem becomes too complex. Same applies for if you want to write a code. Some languages (like Python) have libraries that makes these works relatively simple, but the time complexity can get ugly.
Here's mathmatical approached to the problem:
Step 1: Suppose all the elements are different a = [3,4,5,6,1]
In this case we will have 5! different options (You have 5 options to choose the first element and 4 options to choose the second and so on)
Step 2: Suppose you have one repeated element a = [1,3,4,5,6,1]
In this case we have 6!/2! different options (6! comes from Step 1 and we divide it by 2! because if you switch the position of repeated element to itself the array does not chance).
Now you want to exclude options where repeated elements appear next to each other. The trick is to treat them as one element. So now we have a = [(1,1), 3, 4, 5, 6]. There 5! different options. We subtract this from total, that is 6!/2! - 5! will give you the answer.
Step 3: (your case) Two repeated elements a = [3,4,1,5,6,1,3]
We continue with the same logic. In total we have 7!/(2!x2!) options. From Step 2, if we want to exclude cases where 1 appear next to 1 then we will have to substract 6! from total. Also we have 3 that appears twice too. So, we will subtract another 6! from total. Unfortunately, we have subtracted some cases twice (can you guess which). If we find which cases we subtracted twice and add them we will get the answer.
The cases that we subtracted twice are when 1 comes after 1 at the same time 3 comes after 3, that is a = [(1,1),4,5,6,(3,3)]. We have subtracted those options for both one and three. There are 5! cases like that (can you guess why?).
To some it up get 7!/(2!x2!) - 2x6! + 5!.
If you are not looking for general solution those numbers are not big so you can write a bruteforce code (To save some time/space convert array to string).
I might have missed something in calculations but if you follow the logic you will get the answer. Also, if you want to understand why those things work try it with small data to get the intuition. If you need code, let me know. I will update the solution.

Ab Initio graph : partioning by key behavior with Replicate

I am asking myself a question concerning
Let's suppose I have a flow F which is replicated X times.
All the replicated flows are then Join on the same key but with different datasets each time.
I want the joins to be run in a parallel layout. For this particular case, do I need to use X time the "Partition by key" component or can I put only one at the input of the replicate (instead of 1 per replicate output) ?
TLDR :
Is this graph
https://ibb.co/hHmk5e
equivalent to
https://ibb.co/i2NNJz
supposing all joins occur on same key
Thank you,
Use Replicate into multiple Partition By Keys. Pay caution to the checkpoints, if you have 3 checkpoints after the replicate consider removing them and placing a single checkpoint before the replicate.

(wx)Maxima plot point by point, numbered

I have a list of roots and I want to plot the real/imaginary parts. If s=allroots(), r=realpart() and i=imagpart(), all with makelist(). Since length(s) can get ...lengthy, is there a way to plot point by point and have them numbered? Actually, the numbering part is what concerns me most. I can simply use points(r,i) and get the job done, but I'd like to know their occurence before and after some sorting algorithms. It's not always necessary to plot all the points, I can plot up until some number, but I do have to be able to see their order of having been sorted out.
I have tried multiplot_mode but it doesn't work:
multiplot_mode(wxt)$
for i:1 thru length(s) do draw2d(points([r[i]],[i[i]]))$
multiplot_mode(none)$
All I get is a single point. Now, if this should work, using draw2d's label(["label",posx,posy]) is very handy, but can I somehow evaluate i in the for loop inside the ""?
Or, is there any other way to do it? With Octave? or Scilab? I'm on Linux, btw.
Just to be clear, here's what I currently do: (I can't post images, here's the link: i.stack.imgur.com/hNYZF.png )
...and here is the wxMaxima code:
ptest:sortd(pp2); length(ptest);
draw2d(proportional_axes=xy,xrange=[sort(realpart(s))[1]-0.1,sort(realpart(s))[length(s)]+0.1],
yrange=[sort(imagpart(s))[1]-0.1,sort(imagpart(s))[length(s)]+0.1],point_type=0,
label(["1",realpart(ptest[1]),imagpart(ptest[1])]),points([realpart(ptest[1])],[imagpart(ptest[1])]),
label(["2",realpart(ptest[2]),imagpart(ptest[2])]),points([realpart(ptest[2])],[imagpart(ptest[2])]),
label(["3",realpart(ptest[3]),imagpart(ptest[3])]),points([realpart(ptest[3])],[imagpart(ptest[3])]),
label(["4",realpart(ptest[4]),imagpart(ptest[4])]),points([realpart(ptest[4])],[imagpart(ptest[4])]),
label(["5",realpart(ptest[5]),imagpart(ptest[5])]),points([realpart(ptest[5])],[imagpart(ptest[5])]),
label(["6",realpart(ptest[6]),imagpart(ptest[6])]),points([realpart(ptest[6])],[imagpart(ptest[6])]),
label(["7",realpart(ptest[7]),imagpart(ptest[7])]),points([realpart(ptest[7])],[imagpart(ptest[7])]),
label(["8",realpart(ptest[8]),imagpart(ptest[8])]),points([realpart(ptest[8])],[imagpart(ptest[8])]),
label(["9",realpart(ptest[9]),imagpart(ptest[9])]),points([realpart(ptest[9])],[imagpart(ptest[9])]),
label(["10",realpart(ptest[10]),imagpart(ptest[10])]),points([realpart(ptest[10])],[imagpart(ptest[10])]),
label(["11",realpart(ptest[11]),imagpart(ptest[11])]),points([realpart(ptest[11])],[imagpart(ptest[11])]),
label(["12",realpart(ptest[12]),imagpart(ptest[12])]),points([realpart(ptest[12])],[imagpart(ptest[12])]),/*
label(["13",realpart(ptest[13]),imagpart(ptest[13])]),points([realpart(ptest[13])],[imagpart(ptest[13])]),
label(["14",realpart(ptest[14]),imagpart(ptest[14])]),points([realpart(ptest[14])],[imagpart(ptest[14])]),*/
color=red,point_type=circle,point_size=3,points_joined=false,points(realpart(pp2),imagpart(pp2)),points_joined=false,
color=black,key="",line_type=dots,nticks=50,polar(1,t,0,2*%pi) )$
This is for 14 zeroes, only. For higher orders it would be very painful.
I gather that the problem is that you want to automatically construct all the points([realpart(...), imagpart(...)]). My advice is to construct the list of points expressions via makelist, then append that list to any other plotting arguments, then apply the plotting function to the appended list. Something like:
my_labels_and_points :
apply (append,
makelist ([label ([sconcat (i), realpart (ptest[i]), imagpart (ptest[i])]),
points ([realpart (ptest[i])], [imagpart (ptest[i])])],
i, 1, length (ptest)));
all_plot_args : append ([proptional_axes=..., ...], my_labels_and_points, [color=..., key=..., ...]);
apply (draw2d, all_plot_args);
The general idea is to build up the list of plotting arguments and then apply the plotting function to that.

What is wrong with this lines of my R script?What I am missing?

Ok, So I got this long line of code as a part of a script which someone wrote ( I know it seems horrible). So I tried to simplify it.
dH=((-HMF )*( 1.013*10^10*((T+273.2)/298)*exp((292131/1.987)*(1/298-1/(T+273.2)))/(1+(exp((331573/1.987)*(1/284.9-1/(T+273.2))))))*( 4.371*10^-8*((RH+273.2)/298)*exp((55763.5/1.987)*(1/298-1/(RH+273.2)))/(1+(exp((77245.3/1.987)*(1/365.3-1/(RH+273.2))))))*(H[hour]*I[hour]))-((LGR1)*( 123.8*((T+273.2)/298)*exp((-390540/1.987)*(1/298-1/(T+273.2)))/(1+(exp((-402880/1.987)*(1/300.1-1/(T+273.2)))))) *H[hour]*L1a[hour])-((LGR2)*( 123.8*((T+273.2)/298)*exp((-390540/1.987)*(1/298-1/(T+273.2)))/(1+(exp((-402880/1.987)*(1/300.1-1/(T+273.2)))))) *H[hour]*L2a[hour])- ((LGR3)*( 123.8*((T+273.2)/298)*exp((-390540/1.987)*(1/298-1/(T+273.2)))/(1+(exp((-402880/1.987)*(1/300.1-1/(T+273.2)))))) *H[hour]*L3a[hour])
I simplified it like this:
a<-(1.013*10^10*((T+273.2)/298)*exp((292131/1.987)*(1/298-1/(T+273.2)))/(1+(exp((331573/1.987)*(1/284.9-1/(T+273.2))))))
b<-( 4.371*10^-8*((RH+273.2)/298)*exp((55763.5/1.987)*(1/298-1/(RH+273.2)))/(1+(exp((77245.3/1.987)*(1/365.3-1/(RH+273.2))))))
c<-(123.8*((T+273.2)/298)*exp((-390540/1.987)*(1/298-1/(T+273.2)))/(1+(exp((-402880/1.987)*(1/300.1-1/(T+273.2))))))
d<-(1.7168*((T+273.2)/298)*exp((14275.4/1.987)*(1/298-1/(T+273.2)))/(1+(exp((49087.1/1.987)*(1/298.85-1/(T+273.2))))))
dH=((-HMF )*a*b*(H[hour]*I[hour]))-(LGR1*c*H[hour]*L1a[hour])-(LGR2*c*H[hour]*L2a[hour])-(LGR3*c*H[hour]*L3a[hour])
So what basically the model does is that it takes T and RH for different hours and LGR1,LGR2 and LGR3 are constant values. Also L1a, L2a and L3a are also claculated for different hours and a,b,c and d are used to calculate L1a, L2a and L3a for different hours.
The odd thing is that when I only and simply replace the messy long formula with a,b,c, and d my output model changes which I expect not to. I know it might be vague but I was not sure if I can post the full script here.
Thanks in advance for your advice
I took it into an editor that is syntax-aware and use the parenthesis matching capacity to break into its 4 arithmetic terms (separated by minus signs):
dH=
((-HMF )*( 1.013*10^10*((T+273.2)/298)*exp((292131/1.987)*(1/298-1/(T+273.2)))/(1+(exp((331573/1.987)*(1/284.9-1/(T+273.2))))))*( 4.371*10^-8*((RH+273.2)/298)*exp((55763.5/1.987)*(1/298-1/(RH+273.2)))/(1+(exp((77245.3/1.987)*(1/365.3-1/(RH+273.2))))))*(H[hour]*I[hour]))-
((LGR1)*( 123.8*((T+273.2)/298)*exp((-390540/1.987)*(1/298-1/(T+273.2)))/(1+(exp((-402880/1.987)*(1/300.1-1/(T+273.2)))))) *H[hour]*L1a[hour])-
((LGR2)*( 123.8*((T+273.2)/298)*exp((-390540/1.987)*(1/298-1/(T+273.2)))/(1+(exp((-402880/1.987)*(1/300.1-1/(T+273.2)))))) *H[hour]*L2a[hour])-
((LGR3)*( 123.8*((T+273.2)/298)*exp((-390540/1.987)*(1/298-1/(T+273.2)))/(1+(exp((-402880/1.987)*(1/300.1-1/(T+273.2)))))) *H[hour]*L3a[hour])
The fact that your terms seem to start in different sections of that expression make me think you separated terms inappropriately. It does appear (in my editor that the last three terms all share a common factor and tht the only items that vary in those three terms are the first and last factors:
( 123.8*((T+273.2)/298)*exp((-390540/1.987)*(1/298-1/(T+273.2)))/(1+(exp((-402880/1.987)*(1/300.1-1/(T+273.2)))))) *H[hour]

Bubblesort in LabVIEW formula node

I'm trying to create a histogram of an image. I was thinking to first bubblesort the array of the pixels so every number is sorted from low to high.
Then its easier to count how many times a specific value of a pixels appears. And then later I can put it in a graph.
But it always gives an error then I don't understand.
I also want to make everything with the formula node instead of just blocks.
Visual:
http://i.stack.imgur.com/ZlmW2.png
Error:
http://i.stack.imgur.com/91TbS.png
In your code numbers is a scalar not an array.
Besides that the formula node does not maintain state, you'll need a feedback node to get history. Is there any reason why do you want to use the formula node instead of native LabVIEW code?
You need to remove the two nested LabVIEW for loops, you are iterating through your array inside the formula node so you don't need to do it with the loops.

Resources