Weird behavior with conditional formatting - arrays

I have added the following two equations to conditional formatting:
Green: =IF(REGEXMATCH(VLOOKUP(X2, INDIRECT("DEALS!$A$2:F"),5, FALSE), "Likes"), R2>=VLOOKUP(X2, INDIRECT("DEALS!$A$2:F"), 4, FALSE), T2>=VLOOKUP(X2, INDIRECT("DEALS!$A$2:F"), 4, FALSE))
Red: =IF(REGEXMATCH(VLOOKUP(X2, INDIRECT("DEALS!$A$2:F"),5, FALSE), "Likes"), NOT(R2>=VLOOKUP(X2, INDIRECT("DEALS!$A$2:F"), 4, FALSE)), NOT(T2>=VLOOKUP(X2, INDIRECT("DEALS!$A$2:F"), 4, FALSE)))
The colors should change accordingly depending on whether the target (views in this case) has been met or not.
Below I have also added the equation into the cells to check if the logic is correct, which it appears to be (left = green logic, right = red logic).
For whatever reason, the first row, despite the target not being met, has decided to select the green color. The row below that is doing the complete opposite. And to top it all off, the last two rows are not selecting a color at all even though I have applied the conditional formatting to the entire column:
I am also experiencing weird behavior when dragging equations within this P column, but do not see this same behavior in other columns that also use conditional formatting:
https://i.gyazo.com/5e002e3d08e8337591573b81d9fc92e2.mp4
This has left me completely baffled, and I am not sure what is going on since the equation's logic does not appear to be the issue.
Appreciate any help I can get with this issue!
For reference, here is the other sheet that the VLOOKUP() function is grabbing from:

do not lock ($) references inside INDIRECT. if stuff is between double quotes it's a text string, not an active reference, and text strings are not affected by dragging.
for green use:
=IF(REGEXMATCH(VLOOKUP(Z2, INDIRECT("DEALS!A2:F"), 5, 0), "Likes"),
R2>=VLOOKUP(Z2, INDIRECT("DEALS!A2:F"), 4, 0),
T2>=VLOOKUP(Z2, INDIRECT("DEALS!A2:F"), 4, 0))
for red use:
=IF(REGEXMATCH(VLOOKUP(Z2, INDIRECT("DEALS!A2:F"), 5, 0), "Likes"),
NOT(R2>=VLOOKUP(Z2, INDIRECT("DEALS!A2:F"), 4, 0)),
NOT(T2>=VLOOKUP(Z2, INDIRECT("DEALS!A2:F"), 4, 0)))
demo sheet
update:
don't drag anything. use this in P2:
=ARRAYFORMULA(IFNA(TEXT(VLOOKUP(Z2:Z,DEALS!A2:F,4,0),
"#,###,##0")& " " &VLOOKUP(Z2:Z,DEALS!A2:F,5,0)))

Related

How can I randomly select an item from a list in pinescript?

I'm new in coding, so...
How can we randomly select an item from a list in PineScript?
I want to randomly generate symbols for the security function
I have a list of symbols like BINANCE:BTCUSDT, BINANCE:ETHUSDT, BINANCE:ATOMUSDT etc
What I need to do to convert it to the array, and generate a random value from it, and put this value to the security function (I suppose when I will reload the page I will get a new randomly generated plot with a new symbol each time)
what I have right now
var symbols = array.new_string(5)
array.set(symbols, 0, "BINANCE:BTCUSDT")
array.set(symbols, 1, 'BINANCE:ETHUSDT')
array.set(symbols, 2, 'BINANCE:ATOMUSDT')
array.set(symbols, 3, 'BINANCE:SOLUSDT')
array.set(symbols, 4, 'BINANCE:AXSUSDT')
sec = request.security(str.tostring(array.get(symbols,0)), 'D', close)
plot(sec)
but it does not work
Thanks.
This can't be done as the compiler needs to know the symbol to be used in the security call at the time of compilation. Any method to generate a random value would result in a series variable for the symbol that can't be passed to the security call.

How to select one Tkinter Radiobutton per variable

I am trying to make a loop that populates 9 radio buttons, each with 4 options, and placed in a grid. The following code words, however, I can select more than one option for each question. My understanding is that for each variable I should only be able to select one. Is the loop constructed incorrectly?
MODES = [
('dep_name1', 'dep_but1', 2, "Not at all", 'op1'),
('dep_name2', 'dep_but2', 3, "Several days", 'op2'),
('dep_name3', 'dep_but3', 4, "More than half the days", 'op3'),
('dep_name4', 'dep_but4', 5, "Nearly everyday", 'op4'),
]
for r in range (2, 11):
for dep_name, button, c, text, b_val in MODES:
button = tk.StringVar()
# button.set("L")
dep_name = tk.Radiobutton(window, text=text, variable=button, indicatoron=0, value=b_val).grid(row=r, column=c, sticky='e')
window.columnconfigure("all", weight=1)
window.rowconfigure("all", weight=1)
window.mainloop()
You are creating one variable for each radiobutton. You should have one variable for each group of radiobuttons.
Since the variable can have only one value at a time, tkinter uses the variable to know which radiobuttons belong to a logical group. That is to say, all radiobuttons with the same variable are one logical group of buttons.
Here's one way to do it:
vars = []
for r in range (2, 11):
var = tk.StringVar(value="op1")
vars.append(var)
for dep_name, button, c, text, b_val in MODES:
tk.Radiobutton(window, text=text, variable=var, indicatoron=0, value=b_val).grid(row=r, column=c, sticky='e')
This example saves the variables to a list so that you can reference them by index elsewhere in your code.
I don't quite understand what dep_name and dep_button are supposed to represent. In both cases you initialize them from MODES, but then you change them inside the loops. Regardless, the point is that you need to create the variable just inside the outer loop so that you create one variable for each group of radiobuttons.

CNN with RGB input and BW binary output

I am a beginner to deep learning and I am working with Keras built on top of Tensorflow. I am trying to using RGB images (540 x 360) resolution to predict bounding boxes.
My labels are binary (black/white) 2 dimensional np array of dimensions (540, 360) where all pixels are 0 except for the box edges which are a 1.
Like this:
[[0 0 0 0 0 0 ... 0]
[0 1 1 1 1 0 ... 0]
[0 1 0 0 1 0 ... 0]
[0 1 0 0 1 0 ... 0]
[0 1 1 1 1 0 ... 0]
[0 0 0 0 0 0 ... 0]]
There can be more than one bounding box in every picture. A typical image could look like this:
So, my input has the dimension (None, 540, 360, 3), output has dimensions (None, 540, 360) but if I add an internal array I can change the shape to (None, 540, 360, 1)
How would I define a CNN model such that my model could fit this criteria? How can I design a CNN with these inputs and outputs?
You have do differentiate between object detection and object segmentation. While both can be used for similar problems, the underlying CNN architectures look very different.
Object detection models use a CNN classification/regression architecure, where the output refers to the coordinates of the bounding boxes. It's common practice to use 4 values belonging to vertical center, horizontal center, width and height of each bounding box. Search for Faster R-CNN, SSD or YOLO to find popular object detection models for keras. In your case you would need to define a function that converts the current labels to the 4 coordinates I mentioned.
Object segmentation models commonly use an architecture referred to as encoder-decoder networks, where the original image is scaled down and compressed on the first half and then brought back to it's original resolution to predict a full image. Search for SegNet, U-Net or Tiramisu to find popular object segmentation models for keras. My own implementation of U-Net can be found here. In your case you would need to define a custom function, that fills all the 0s inside your bounding boxes with 1s. Understand that this solution will not predict bounding boxes as such, but segmentation maps showing regions of interest.
What is right for you, depends on what precisely you want to achieve. For getting actual bounding boxes you want to perform an object detection. However, if you're interested in highlighting regions of interest that go beyond rectangle windows a segmentation may be a better fit. In theory, you can use your rectangle labels for a segmentation, where the network will learn to create better masks than the inaccurate segmentation of the ground truth, provided you have enough data.
This is a simple example of how to write intermediate layers to achieve the output. You can use this as a starter code.
def model_360x540(input_shape=(360, 540, 3),num_classes=1):
inputs = Input(shape=input_shape)
# 360x540x3
downblock0 = Conv2D(32, (3, 3), padding='same')(inputs)
# 360x540x32
downblock0 = BatchNormalization()(block0)
downblock0 = Activation('relu')(block0)
downblock0_pool = MaxPooling2D((2, 2), strides=(2, 2))(block0)
# 180x270x32
centerblock0 = Conv2D(1024, (3, 3), padding='same')(downblock0_pool)
#180x270x1024
centerblock0 = BatchNormalization()(center)
centerblock0 = Activation('relu')(center)
upblock0 = UpSampling2D((2, 2))(centerblock0)
# 180x270x32
upblock0 = concatenate([downblock0 , upblock0], axis=3)
upblock0 = Activation('relu')(upblock0)
upblock0 = Conv2D(32, (3, 3), padding='same')(upblock0)
# 360x540x32
upblock0 = BatchNormalization()(upblock0)
upblock0 = Activation('relu')(upblock0)
classify = Conv2D(num_classes, (1, 1), activation='sigmoid')(upblock0)
#360x540x1
model = Model(inputs=inputs, outputs=classify)
model.compile(optimizer=RMSprop(lr=0.001), loss=bce_dice_loss, metrics=[dice_coeff])
return model
The downblock represents the block of layers which perform downsampling(MaxPooling2D).
The centerblock has no sampling layer.
The upblock represents the block of layers which perform up sampling(UpSampling2D).
So here you can see how (360,540,3) is being transformed to (360,540,1)
Basically, you can add such blocks of layers to create your model.
Also check out Holistically-Nested Edge Detection which will help you better with the edge detection task.
Hope this helps!
I have not worked with keras but I will provide a solution approach in more generalized way which can be used on any framework.
Here is full procedure.
Data preparation: I know your labels are edges of boxes which will also work but i will recommend that instead of edges you prepare dataset marking complete box like given in sample (I have marked for two boxes). Now your dataset have three classes (Box,Edges of box and background). Create two lists, Image and label.
Get a pre-trained model (RESNET-51 recommended) solver and train prototxt from here, Remove fc1000 layer and add de-convolution/up-sampling layers to match your input size. use paddding in first layer to make it square and crop in deconvolution layer to match input output dimensions.
Transfer weights from previously trained network (Original) and train your network.
Test your dataset and create bounding boxes using detected blobs.

calculate min max etc. using an array of numbers

Hi iI have a small GUI that contains 1 'Push Button' and 3 'Edit Texts' and a few static text labels to display the results.
What I want to do is to be able to calculate from a series of numbers their: sum, average, min, max, Standard Deviation and Skewness
The user will enter the following data [using Edit Text boxes]:
 Start Number of the sequence
 End Number of the sequence
 Increment step
And by using a Pushbutton all the above results will be returned in separate static texts.
I am very new to MATLAB can anyone push me into the direction i need to go inorder to achieve this.
My user interface if any help:
A simple solution should be :
function pushbutton1_Callback(hObject, eventdata, handles)
%[
startValue = str2num(get(handles.edit1,'string')) ;
stopValue = str2num(get(handles.edit2,'string')) ;
step = str2num(get(handles.edit3,'string')) ;
series = startValue:step:stopValue ;
average = mean(series) ;
minValue = min(series) ;
...
...
set(handles.text1,'string',average);
set(handles.text2,'string',minValue);
...
%]
Hope it will be helpful !
You might find these 41 complete GUI examples useful...
It'll answer you these questions:
1.How do I manipulate the strings in a uicontrol? GUI_1, 2, 4, 5, 13, 14, 15, 20, 21, 22, 37
2.How do make a uicontrol invisible/visible? GUI_3, 35 (See also GUI_10 for images)
3.How do I make a multi-line edit box? GUI_4
4.How can I initialize an editbox so that the cursor is blinking at startup? GUI_4, 24, 37
5.How can I let the user of my GUI know his actions are futile (or producing no results)? GUI_5
6.How can I tell which uicontrol is selected e.g., radiobuttons? GUI_6, 8
7.How do I tell how many times a uicontrol has been activated? GUI_7, 19, 28, 32, 33
8.How do I tell which button in a buttongroup is selected? GUI_8
9.How do I let the user know a process is running in the background? GUI_9
10.How can I set an image visible/invisible? GUI_10
11.How can I use a GUI to exit a FOR loop? GUI_11
12.How can I control the mouse pointer with a GUI? GUI_12
13.How do I access the value (current position) of a slider? GUI_13, 16
14.How do I use different colored strings in a listbox? GUI_14
15.What is the difference between 'listboxtop' and 'value' in a listbox? GUI_14
16.How do I make text that can be copied but not changed? GUI_15
17.How can I allow the user of my GUI to set the range of a slider? GUI_16
18.How can I display a digital clock in my GUI? GUI_17
19.How can I use a timer in a GUI? GUI_17
20.How do I use the buttondownfcn on an axes object? GUI_18, 28
21.How do I make a callback talk to another callback? GUI_19
22.How can I get the string from a popup or listbox? GUI_14, 20, 21, 22, 31, 32, 33
23.How can I set the string in a popup or listbox? GUI_21, 22
24.How can I add to the string in a popup or listbox? GUI_22
25.How do I tell which figure/axes was current before my callback executed? GUI_23
26.How do I get data from another GUI? GUI_24
27.How do I make a GUI to open image files only? GUI_25
28.How can I make popup choices mutually exclusive? GUI_26
29.How can I show the current pointer location in axes coordinates? GUI_27
30.How can I use uicontextmenus? GUI_28, 33, 39
31.How do I make my GUI control an axes in another figure? GUI_29, 30
32.What are callback strings? GUI_30
33.How can I make it so that when one of the figures closes, they all close? GUI_24, 29,
30, 41
34.How do I make several uicontrols interact in a more complicated GUI? GUI_31, 32, 33, 41
35.How do I get data from a GUI to the base workspace? GUI_25, 32, 33, 36
36.How can I use a GUI to take a screenshot of my desktop? GUI_34
37.How do I make toggle buttons act like tabbed-panels? GUI_35
38.How do I make a custom dialog box which returns a string to the base workspace? GUI_36
39.How can I make a password editbox that has the * symbols? GUI_37
40.How can I use nested function as callbacks? GUI_11, 17, 34, 36, 37, 39, 40, 41.
41.How can I use uiwait in a GUI? GUI_11, 34, 36, 37
42.How do I use JAVA in my GUI? GUI_38
43.How do I force the figure to maintain focus between uicontrol activations? GUI_38
44.How do I save an axes as an image? GUI_39
45.How can I make a simple drawing program? GUI_39
46.How can I set a button's background to match an image? GUI_40
47.How can I save the state of a system of GUIs to use later? GUI_41

Moving graph in windows form

I have two arraylist, x[],y[]. Suppose :
x[0]= 1, y[0]=2,
x[1]= 3, y[1]=3,
x[2]= 4, y[2]=6,
x[3]= 4, y[3]=9,
x[4]= 7, y[4]=22,
x[5]= -4, y[5]=5,
..............
in time delay of 10 sec, the graph goes [0] to [1] and then it goes on in same delay.
How i represent the graph? I think 3d graph is must here. But how do i use it in .Net winform?
You will need to use a component to visuialize the data as a graph.
Check out Microsoft Chart Controls, they are a good option.

Resources