Moving graph in windows form - winforms

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.

Related

Scalar multiplication of tensors

In TensorFlow Core for Python there is an operation called tf.math.scalar_mul.
I would like to scale tensors in TensorFlow.js. By trying for instance a * 0.1 I get an error message (at least from Typescript):The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.ts(2362).
Is scaling tensors applicable without making them arrays, scale elementwise then transform back to tensors?
Though, tf.scalar can be used, one can also use direclty tensor.mul(number) like the following
tf.tensor([1, 2, 3, 4]).mul(5).print(); // [5, 10, 15, 20]
I found the answer in the API documentation. For multiplying a tensor a with 5, just a.mul(tf.scalar(5)).

How to build a complex controlled gate in the Qiskit?

I work on theory tasks in quantum computing, and make simple experiments with Qiskit. Unfortunately, I can't find a way how to make a complex control gates there, where control is in the quantum register.
I would like to have a "c_if" analogue, which can be chained and use quantum bits as a control.
Smth like
swap(q1, q2).c_if(q0,Zero).c_if(q3,One)
Is there such an operation in the qiskit? How could I emulate such an operation if it doesn't exist?
Check out Qiskit documentation for the MCXGate, know as the Multi-controlled-X Gate. This gate lets you define how many control qubits you would like to include (perhaps the majority of your quantum register) and define a control state.
from qiskit import *
my_circuit = QuantumRegister(3,3)
my_circuit.append(circuit.library.MCXGate(2, ctrl_state='10'), [0,1,2])
Check out the documentation here.
There are also variations that will do Y gate Z gate or whatever you like depending if the circuit sees the correct control gate.
Thanks #Dulah for his answer. I found my old samples and they're working pretty fine with the 0.18.2 qiskit version.
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from qiskit.circuit.library.standard_gates.x import XGate, MCXGate
from qiskit.circuit.library.standard_gates.swap import SwapGate
simulator = Aer.get_backend('qasm_simulator')
qreg = QuantumRegister(4)
creg = ClassicalRegister(4)
qc = QuantumCircuit(qreg, creg)
control1 = XGate().control(3, None, '110') #: old-style multy-controlled qubits
#control1 = MCXGate(3, None, '110') # fashion-style multi-controlled qubits
control2 = SwapGate().control(2, None, '10')
qc.append(control1, [0, 1, 2, 3])
qc.append(control2, [0, 1, 2, 3])
qc.measure(qreg,creg)
job = execute(qc, simulator, shots=1000)
result = job.result()
counts = result.get_counts(qc)
print("\nTotal count for 00 and 11 are:",counts)
qc.draw()
The code gives me a result

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.

Creating time windows with Ruby

Having an array of several time series (timestamp, value) like this:
time_series = [[[1234567, 0.8], [1234568, 0,9], [1234569, 1.0]],
[[1234568, 0,7], [1234569, 0,2], [1234570, 1.2]],
[[1234560, 0,9], [1234561, 0.2], [1234568, 0,1]]]
I want to create an array of time windows of a given size time_size. For example, if I wanted to create time windows of time_size = 2:
time_size = 2
time_windows = create_time_windows(time_series, time_size)
puts time_windows
# time_windows => [[[], [], [[1234560, 0,9], [1234561, 0.2]]],
# [[[1234567, 0.8], [1234568, 0,9]], [[1234568, 0,7], [[1234568, 0,1]]],
# [[[1234569, 1.0]], [[1234569, 0,2], [1234570, 1.2]], []]]
I know it is not a very readable example, but the operation can be summarized as splitting an array of time series into an array of subarrays containing the segments of those time series whose timestamp is included into the pertinent interval of time.
In the example, I wanted to do that with a time window size of 2, so I picked the earliest time of the whole array of series, and began to count from there. So, my first time window contains all points from the three earlier series whose timestamp was included between 1234560 (the origin in my series, because the earlier point was that) and 1234560 + 2. You can see that the first window doesn't have elements from the first and second series, since there are no points whose timestamp was included within the interval. The next interval would be (1234560 + 2, 1234560 + 4), and so on.
I am not specially proficient in Ruby, so I would be glad if the community can help me solving this problem. I have considered using Enumerable methods such as slice_when combined with inject, but I got impossibly lost trying to code that.

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

Resources