Combine different kind of items according to a previous rating - rating

I am building an experiment with the psychopy builder and I want to do an "evaluative conditioning" experiment. That is: first, different stimuli are rated according to their valence. Later, neutral stimuli will be paired with negative or positive stimuli.
Here is the structure, I have done so far:
Experiment structure
Specifically, in a first step, participants rate different items (pictures, shapes, ciphers). So far, no problem.
The next trials, the problem starts.
Trial structure in the builder
In a next routine, the pictures should be arranged according to their rating.
That is positive, neutral, negative pictures (1-3 = negative, 4-6 = neutral, 7-9 = positive). They are called UCStim.
First, I need, to know, if at least 5 pictures in the rating routine were rated < 3. If yes, the experiment can continue. If not, it has to be stopped.
Second step: select the 5 most negatively rated pictures. (But what, if 8 were rated with 1? Then a random selection of the images rated with 1 should take place).
Then select 5 pictures with values between 4 and 6 (neutral pictures).
Third step: combine the shapes (NeutralStim) with neutral Pictures and the ciphers (also NeutralStim) with negative pictures. The definition of shape vs. cipher is done in the excel-file of the loop (called condLoop.xlsx, column is called "kind"). The shapes should now be presented before negatively rated pictures and the ciphers before positively rated pictures.
My first problem is: how to I get the rated values? Do I have to import the csv-file? Or can I directly import them (the responses of the ratings are called rating.response_raw in the data file.

Related

Questions about R-CNN, RPN, anchor box

My brief understanding of Faster R-CNN
S1. assign anchor box
S2. finding anchor box objectness score (rather positive, negative, non) using ground truth (ROI pooling?)
S3. select a set of positive, negative boxes to train region proposal network (training for predicting objectness score in test set?)
S4-1. training classification layer using positive anchor box
S4-2. training box regression layer using positive anchor box
.....
Questions
Q1. When an anchor box has high IOU with several ground truth boxes is the highest box chosen as the target? Can an anchor box only have on target?
Q2. How is a positive anchor box and its target box matched in code? (Most explanation says an anchor box object contains four variables; center x, center y, width, height, which has no value for its target.)
Q3. Is ROI pooling referring to stage two?
Q4. Is the third stage training used to predict the objectness score for test set?
Q5. Is there a reason other than training speed, for not training anchor boxes that are not labeled as either positive or negative? (Aren’t all boxes’ objectness score estimated when training? Including positive, negative, non)
Q6. Shouldn’t 4-1 classification happen after moving of the box during 4-2 box regression? (Explanations say the two layers are independent and happen simultaneously) Shouldn’t the two layers have order?
Q7. Is the probability of an anchor box used for NMS referring to the classification score calculated in stage 4-1?
Q8. Unlike the RPN stage where all anchor boxes are used for training, the classification and regression stages only use a few positive anchor boxes. How does back-propagation happen when training a model like this, where some stages use only a part of the training set? (I heard the advantages of Faster-RCNN is the connection of all stages as a single deep-learning model. But if the latter models only use chosen boxes and if the classification/box regression stage works independently how can the full model work as one?)

Binary Snap [AIO 2015]

This is a question from the Australian Informatics Olympiad
The question is:
Have you ever heard of Melodramia, my friend? It is a land of forbidden forests and boundless swamps, of sprinting heroes and dashing heroines. And it is home to two dragons, Rose and Scarlet, who, despite their competitive streak, are the best of friends.
Rose and Scarlet love playing Binary Snap, a game for two players. The game is played with a deck of cards, each with a numeric label from 1 to N. There are two cards with each possible label, making 2N cards in total. The game goes as follows:
Rose shuffles the cards and places them face down in front of Scarlet.
Scarlet then chooses either the top card, or the second-from-top card from the deck and reveals it.
Scarlet continues to do this until the deck is empty. If at any point the card she reveals has the same label as the previous card she revealed, the cards are a Dragon Pair, and whichever dragon shouts `Snap!' first gains a point.
After many millenia of playing, the dragons noticed that having more possible Dragon Pairs would often lead to a more exciting game. It is for this reason they have summoned you, the village computermancer, to write a program that reads in the order of cards in the shuffled deck and outputs the maximum number of Dragon Pairs that the dragons can find.
I'm not sure how to solve this. I thought of something which is wrong(choosing the maximum over all cards, when compared with its previous occurence for each card)
Here's my code as of now:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream fin("snapin.txt");
ofstream fout("snapout.txt");
int n;
fin>>n;
int arr[(2*n)+1];
for(int i=0;i<2*n;i++){
fin>>arr[i];
}
int dp[(2*n) +1];
int maxi = 0;
int pos[n+1];
for(int i=0;i<n+1;i++){
pos[i] = -1;
}
int count = 0;
for(int i=2;i<(2*n)-2;i++){
if(pos[arr[i]] == -1){
pos[arr[i]] = i;
}else{
dp[i] = pos[arr[i]]+1;
maxi = max(dp[i],maxi);
}
dp[i] = max(dp[i],maxi);
}
fout<<dp[2*n -1];
}
Ok, let's get some basic measurements of the problem out of the way first:
There are 2N cards. 1 card is drawn at a time, without replacement. Therefore there are 2N draws, taking the deck from size 2N (before the first draw) to size 0 (after the last draw).
The final draw takes place from a deck of size 1, and must take the last remaining card.
The 2N-1 preceding draws have deck size 2N, ... 3, 2. For each of these you have a choice between the top two cards. 2N-1 decisions, each with 2 possibilities.
The brute force search space is therefore 22N-1.
That is exponential growth, every optimization scientist's favorite sort of challenge.
If N is small, say 20, the brute force method needs to search "only" a trillion possibilities, which you can get done in a few thousand seconds on a readily available PC that does a few billion operations per second (each solution takes more than one CPU instruction to check).
In N is not quite as small, perhaps 100, the brute force method is akin to breaking the encryption on government secrets.
Not happy with the brute force approach then? I'm not either.
Before we get to the optimal solution, let’s take a break to explore what the Markov assumption is and what it means for us. It shows up in different fields using different verbiage, but I’ll just paraphrase it in a way that is particularly useful for this problem involving gameplay choices:
Markov Assumption
A process is Markov if and only if The choices available to you in the future depend only on what you have now, and not how you got it.
A bad but often used real-world example is the stock market. Not only do taxation differences between short-term and long-term capital gains make history important in a small way, but investors do trend analysis and remember what stocks have done before, which affects future behavior in a big way.
A better example, especially for StackOverflow, is that of Turing machines and computer processors. What your program does next depends on the current instruction pointer and the contents of memory, but not the history of memory that’s since been overwritten. But there are many more. As we’ll see shortly, the Binary Snap problem can be formulated as Markov.
Now let’s talk about what makes the Markov assumption so important. For that, we’ll use the Travelling Salesman Problem. No, the Travelling International Salesman Problem. Still too messy. Let’s try the “Travelling International Salesman with a Single-Entry Visa Problem”. But we’ll go through all three of them briefly:
Travelling Salesman Problem
A salesman has to visit potential buyers in N cities. Plan an itinerary for the salesman which minimizes the total cost of visiting all N cities (variations: at least once / exactly once), given a matrix aj,k which is the cost of travel from city j to city k.
Another variation is whether the starting city is predetermined or not.
Travelling International Salesman Problem
The cities the salesman needs to visit are split between two (or more) nations. A subset of the cities have border crossings and have travel options to all cities. The other cities can only reach cities which are either in the same country or are border-equipped.
Alternatively, instead of cities along the border, use cities with international airports. Won’t make a difference in the end.
The cost matrix for this problem looks rather like the flag of the Dominican Republic. Travel between interior cities of country A is permitted, as is travel between interior cities of country B (blue fields). Border cities connect with interior and border cities in both countries (white cross). And direct travel between an interior city of country A and one of country B is impossible (red areas).
Travelling International Salesman with a Single-Entry Visa
Now not only does the salesman need to visit cities in both countries, but he can only cross the border once.
(For travel fanatics, assume he starts in a third country and has single-entry visas for both countries, so he can’t visit some of A, all of B, then return to A for the rest).
Let’s look at an extremely simple case first: Only one border city. We’ll use one additional trick, the one from proof by induction: We assume that all problems smaller than the current one can be solved.
It should be fairly obvious that the Markov assumption holds when the salesman reaches the border city. No matter what path he took through country A, he has exactly the same choice of paths through country B.
But there’s a really important point here: Any path through country A ending at the border and any path through country B starting at the border, can be combined into a feasible full itinerary. If we have two full itineraries x and y, and x spent more money in country A than y did, then even if x has a lower total cost than the total cost of y, we can plan a path better than both, using the portion of y in country A and the portion of x in country B. I’m going to call that “splicing”. The Markov assumption lets us do it, by making all roads leading to the border interchangeable!
In fact, we can look just at the cities of country A, pick the best of all routes to the border, and forget about all the other options as soon as (in our plan) the salesman steps across into B.
This means instead of having factorial(NA) * factorial(NB) routes to look at, there’s only factorial(NA) + factorial(NB). Which is pretty much factorial(NA) times better. Wow, is this Markov thing helpful or what?
Ok, that was too easy. Let’s mess it all up by having NAB border cities instead of just one. Now if I have a path x which costs less in country B and a path y which costs less in country A, but they cross the border in different cities, I can’t just splice them together. So I have to keep track of all the paths through all the cities again, right?
Not exactly. What if, instead of throwing away all the paths through country A except the best y path, I actually keep one path ending in each border city (the lowest cost of all paths ending in the same border city). Now, for any path x I look at in country B, I have a path yendpt(x) that uses the same border city, to splice it with. So I have to solve the country A and country B partitions each NAB times to find the best splice of a complete itinerary, for total work of NAB factorial(NA) + NAB factorial(NB) which is still way better than factorial(NA) * factorial(NB).
Enough development of tools. Let’s get back to the dragons, since they are they are subtle and quick to anger and I don’t want to be eaten or burnt to a crisp.
I claim that at any step T of the Binary Snap game, if we consider our “location” a pair of (card just drawn, card on top of deck), the Markov assumption will hold. These are the only things that determine our future options. All the cards below the top one in the deck must be in the same order no matter what we did before. And for knowing whether to count a Snap! with the next card, we need to know the last one taken. And that’s it!
Furthermore, there are N possible labels on the card last drawn, and N possible for the top card on the deck, for a total of N2 “border cities”. As we start playing the game, there are two choices on the first turn, two on the second, two on the third, so we start out with 2T possible game states (and a count of Snap!s for each). But by the pigeonhole principle, when 2T > N2, some of these plays must end in exactly the same game state (“border city”) as each other, and when that happens, we only need to keep the "dominating" one that got the best score on the way there.
Final complexity bound: 2*N timesteps, from no more than N2 game states, with 2 draw choices at each, equals an upper limit of 4*N3 simulated draws.
And that means the same trillion calculations that allowed us to do N=20 with the brute force method, now permit right around N=8000.
That makes the dragons happy, which makes us alive and well.
Implementation note: Since the challenge didn’t ask for the order of draws, but just the highest attainable number of snaps, all you data to keep track of in addition to the initial ordering of the cards is the time, T, and a 2-dimensional array (N rows, N columns) of the best score you can have and reach that state at time T.
Real world applications: If you take this approach and apply it to a digital radio (fixed uniform bit timing, discrete signal levels) receiving a signal using a convolutional error-correcting code, you have the Viterbi decoder. If you apply it to acquired medical data, with variable timing intervals and continuous signal levels, and add some other gnarly math, you get my doctoral project.

OpenCv gesture identification

I am working on opencv gesture identification and have hit a small snitch.
Suppose i am showing the number 3..the webcam identifies 3.
What i have done is print the number 3 or write the text 3 on the image.
However..due to minute variations..the output changes in small intervals of time..hence fluctuations arise.showing 2 for 0.1 second..and 3 for the next 1 second.
I need some help to find a way to display..say the average number for a certain period of time(average rounded off to the nearest integer)
Thanks in advance for any help!
how about some kind of lowpass filter. A concrete implementation of that would be a weighted average. (This is the direct answer to your question)
But regarding that the fluctuations are unwanted artifacts I would recommend to set a hard treshold regarding the minimum time interval a number has to be found over serveral images.
e.g. you want to detect a three, but the two will appear serveral times for lets say less than a second -> you only want to update the displayed number if the new number was detected for more than 1 second.

Declarative Data Mining: Frequent Itemset Tiling

For a course in my Computer Science studies, I have to come up with a set of constraints and a score-definition to find a tiling for frequent itemset mining. The matrix with the data consists of ones and zeroes.
My task is to come up with a set of constraints for the tiling (having a fixed amount of tiles), and a score-function that needs to be maximized. Since I started working out a solution that allows overlapping tiles, I tried to find a score-function to calculate the total "area" of all tiles. Bear in mind that the score function has to be evaluated for every possible solution, so I can't simply go over the total matrix (which contains about 100k elements) and see if it is part of a tile.
However, I only took into account overlap between only 2 tiles, and came up with the following:
TotalArea = Sum_a_in_Tiles(Area(a)) - Sum_a/b_in_tiles(Overlap(a,b))
Silly me, I didn't consider a possible overlap between 3 tiles. My question is the following:
Is it possible to come up with a generic score-function for n tiles, considering only area per tile and area per overlap between 2 (or more) tiles, and if so, how would I program it?
I could provide some code, but then again it has to be programmed in some obscure language called Comet :(

Counter in AS3 "without dynamic text field"

What is the best way to program an LED number tick. I need to have a number display that goes up to 1,000,000.00. Dynamic text fields are not an option because of symbol instances. How would I make a counter?
ANIMATION
The numbers move in increments like an LED display. This
NUMBERS
The numbers multiple by ten each space over
decimal point numbers are not whole, so they go really fast
There's a 16,000 frame limit in flash
SYMBOLS
column of numbers that moves in increments, for each number place
WHAT WOULD IT REQUIRE?
numbers move at a rate in multiples of 10
decimal points times one hundred
FRAME BASED OR TIME BASED?
There's a 16,000 frame limit in Flash
Time based method would require a lot of code
the add and remove child issue
alt text http://www.ashcraftband.com/myspace/videodnd/number_example.jpg
TRANSITION EFFECT
A "tick"
move 10 pixels each time etc.
9 and 0 roll over smoothly
In Flash, and to achieve the result in your picture there, I would create 2 MovieClips:
A black bar with a decimal point
The grey digits in a column, 0 -> 0, as suggested by your pic
Then, combine the black bar and 9 of the digit columns into a single MovieClip to represent your counter, along with a custom base class for it. This allows you fine-grained control over the entire counter.
Provide a CounterClip::Step() or ::Tick() method (or whatever you want to call it) that can move the individual columns. You can use the flash.transitions.Tween class to create smooth animations (I think thats what it's called... I'm a bit rusty.)
If you find you need more than the 9 columns, you can change your Counter MovieClip class to support dynamically adding more digits.
i think it totally depends on the transition effect you are using while switching the numbers.