separate chaining vs linear probing - chaining

a set of objects with keys: 12, 44, 13, 88, 23, 94, 11, 39, 20, 16, 5
Write the hash table where M=N=11 and collisions are handled using separate chaining.
h(x) = | 2x + 5 | mod M
So I did it with linear probing and got
11 39 20 5 16 44 88 12 23 13 94
which I am pretty sure is right, but how do you do it with separate chaining? I realize separate chaining uses linked lists, but how would the hash table look like?

Related

Understanding input and labels in word2vec (TensorFlow)

I am trying to properly understand the batch_input and batch_labels from the tensorflow "Vector Representations of Words" tutorial.
For instance, my data
1 1 1 1 1 1 1 1 5 251 371 371 1685 ...
... starts with
skip_window = 2 # How many words to consider left and right.
num_skips = 1 # How many times to reuse an input to generate a label.
Then the generated input array is:
bach_input = 1 1 1 1 1 1 5 251 371 ....
This makes sense, starts from after 2 (= window size) and then continuous. The labels:
batch_labels = 1 1 1 1 1 1 251 1 1685 371 589 ...
I don't understand these labels very well. There are supposed to be 4 labels for each input right (window size 2, on each side). But the batch_label variable is the same length.
From the tensorflow tutorial:
The skip-gram model takes two inputs. One is a batch full of integers
representing the source context words, the other is for the target
words.
As per the tutorial, I have declared the two variables as:
batch = np.ndarray(shape=(batch_size), dtype=np.int32)
labels = np.ndarray(shape=(batch_size, 1), dtype=np.int32)
How should I interpret the batch_labels?
There are supposed to be 4 labels for each input right (window size 2, on each side). But the batch_label variable is the same length.
The key setting is num_skips = 1. This value defines the number of (input, label) tuples each word generates. See the examples with different num_skips below (my data sequence seems to be different from yours, sorry about that).
Example #1 - num_skips=4
batch, labels = generate_batch(batch_size=8, num_skips=4, skip_window=2)
It generates 4 labels for each word, i.e. uses the whole context; since batch_size=8 only 2 words are processed in this batch (12 and 6), the rest will go into the next batch:
data = [5239, 3084, 12, 6, 195, 2, 3137, 46, 59, 156, 128, 742, 477, 10572, ...]
batch = [12 12 12 12 6 6 6 6]
labels = [[6 3084 5239 195 195 3084 12 2]]
Example #2 - num_skips=2
batch, labels = generate_batch(batch_size=8, num_skips=2, skip_window=2)
Here you would expect each word appear twice in the batch sequence; the 2 labels are randomly sampled from 4 possible words:
data = [5239, 3084, 12, 6, 195, 2, 3137, 46, 59, 156, 128, 742, 477, 10572, ...]
batch = [ 12 12 6 6 195 195 2 2]
labels = [[ 195 3084 12 195 3137 12 46 195]]
Example #3 - num_skips=1
batch, labels = generate_batch(batch_size=8, num_skips=1, skip_window=2)
Finally, this setting, same as yours, produces exactly one label per each word; each label is drawn randomly from the 4-word context:
data = [5239, 3084, 12, 6, 195, 2, 3137, 46, 59, 156, 128, 742, 477, 10572, ...]
batch = [ 12 6 195 2 3137 46 59 156]
labels = [[ 6 12 12 195 59 156 46 46]]
How should I interpret the batch_labels?
Each label is the center word to be predicted from the context. But the generated data may take not all (context, center) tuples, depending on the settings of the generator.
Also note that the train_labels tensor is 1-dimensional. Skip-Gram trains the model to predict any context word from the given center word, not all 4 context words at once. This explains why all training pairs (12, 6), (12, 3084), (12, 5239) and (12, 195) are valid.

How are 3-state cellular automata rules generated?

Let's limit the neighborhood to n=1 (which means we always need 3 cells to evaluate the next-gen cell).
Here's an example of a 2 state rule. Note that the upper row of the rules are generated in a particular order, whereas the lower row is the bit representation of the number 30.
I cannot find a single visualization of the equivalent for a 3 state CA. Following the logic of 2 state CA, it should contain 27 possible outcomes, but I have no clue in which order they should be generated. The lower row should be 30 in ternary (with leading zeroes to occupy a total of 27 positions).
Is there a general algorithm for generating these permutations in the conventional order of CAs (regardless of the number of states)?
Thank you very much in advance and sorry if the question is stupid. :(
What you are using is called Wolfram's code (from Stephen Wolfram) that is used for elementary CAs.
If you use more states or bigger neighborhoods then it is sufficient to extend it naturally.
Your question is not stupid.
For three states, this will give you ternary numbers. First write all the three digits number in ternary (descending order):
222, 221, 220, 212, 211, 210, 202, 201, 200, 122, 121, 120, 112, 111, 110, 102, 101, 100, 022, 021, 020, 012, 011, 010, 002, 001, 000
There are 27 of them 3^3, and 222_3 = 26, 221_3 = 25, 001_3 = 1, 000_3 = 0
Now decompose 30 onto base 3 27-digits number: 30 = 1*3^3+ 1*3^1, so there is only two digits equals to 1, the fourth and the second (from the right), here is rule 30 for radius-1 3-states CA:
000000000000000000000001010
This CA has a very different behavior than rule 30 radius-1 2-states CA.
Here is rule 33 for radius-1 3-states (33 = 1*3^3 + 2*3^1):
000000000000000000000001020
So for n,r, enumerate in descending order all 2r+1 digits numbers in base n and associate for each of them a value in [0,n[.

Create 3-dimensional array from 2 dimensional array in matlab

I would like to know how to generate a 3-d array from a 2-d array in matlab. My lack of understanding may simply be the result of not knowing the correct nomenclature.
I have a 2-dimensional array or matrix, A:
A = [12, 62, 93, -8, 22; 16, 2, 87, 43, 91; -4, 17, -72, 95, 6]
and I would like to add a 3rd dimension with the same values such that:
A(:,:,1) = 12 62 93 -8 22
16 2 87 43 91
-4 17 -72 95 6
and
A(:,:,2) = 12 62 93 -8 22
16 2 87 43 91
-4 17 -72 95 6
to
A(:,:,p) = 12 62 93 -8 22
16 2 87 43 91
-4 17 -72 95 6
how would I go about doing so in the most efficient way (I might have a much larger array where m = 100, n = 50, p= 1000 where A(m,n,p).
Try
result = reshape(repmat(A,1,p),m,n,p)

Ordering array according to index ~ text

Please, put in R these datas:
S.names <- c("FXI", "XLB", "GLD", "IWM", "XLE", "XLF", "EWZ", "GDX", "XLK",
"TLT", "IYR", "QQQ", "SLV", "EWJ", "XLV", "DIA", "XHB", "EEM",
"USO", "VWO", "SPY", "EFA")
strike_vec <- structure(list(Strike = c(152, 43, 61, 11, 56, 37, 36, 159, 96,
74, 71, 27, 163, 128, 35, 44, 30, 40, 81, 19, 31, 48)), .Names = "Strike", row.names =
c("DIA", "EEM", "EFA", "EWJ", "EWZ", "FXI", "GDX", "GLD", "IWM", "IYR",
"QQQ", "SLV", "SPY", "TLT", "USO", "VWO", "XHB", "XLB", "XLE",
"XLF", "XLK", "XLV"), class = "data.frame")
As you can see, strike_vec row names are equal to S.names elements.
I would like to order strike_vec elements according to the order of S.names, that is associating each strike_vec element to the position in which you find the corresponding S.names row name.
The final result should be something like
> strike_vec.new
[,1]
FXI 37
XLB 40
GLD 159
IWM 96
...
...
...
where rownames(strike_vec.new) follows exactly the order of S.names.
How may I do?
Just use :
strike_vec[S.names,,drop=FALSE]
Which gives :
Strike
FXI 37
XLB 40
GLD 159
IWM 96
XLE 81
XLF 19
EWZ 56
GDX 36
XLK 31
TLT 128
IYR 74
QQQ 71
SLV 27
EWJ 11
XLV 48
DIA 152
XHB 30
EEM 43
USO 35
VWO 44
SPY 163
EFA 61
This works because if you index the rows of a data frame with a character vector, indexing will be based on row names.

In SSRS, what is meant by the OR's "bitwise disjunction on two numeric values."

I'd like to have my parameterized menu allow one option to represent the numbers(i.e when you click on my menu drop-down option X it stands for all the numbers):
= 30 or 31 or 32 or 33 or 34 or 35 or 36 or 37 or 38 or 39 or 130 ( this is what I typed into SSRS by the way)
On SSRS it says that OR is for "Used to perform a logical disjunction on two Boolean expressions, or bitwise disjunction on two numeric values."
I've tried this:
=join(Parameters!ClientResponseRange.30 "," Parameters!#ClientResponseRange.35)
but it does not work
You want the SQL IN function:
WHERE MyField IN (30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 130)
So if you have an #Options multi-value parameter, this will look like:
WHERE MyField IN #Options

Resources