Convert -WebKit-Filter hue into RGB - css

The -webkit-filter in CSS3 allows you to apply a hue filter by passing a degree value between 0-360
example:
-webkit-filter: hue-rotate(80deg);
How would you convert the degree value into an RGB value?

The CSS filter hue-rotate is not a true hue-rotation, it's an approximation in RGB space, and is not very accurate for saturated colors. If you want to duplicate what it's doing you need to use the same algorithm - which is not the standard HSL/RGB conversion. Its underlying algorithm is in the SVG 1.1 filter spec for feColorMatrix
For type="hueRotate", ‘values’ is a single one real number value (degrees). A hueRotate operation is equivalent to the following matrix operation:
| R' | | a00 a01 a02 0 0 | | R |
| G' | | a10 a11 a12 0 0 | | G |
| B' | = | a20 a21 a22 0 0 | * | B |
| A' | | 0 0 0 1 0 | | A |
| 1 | | 0 0 0 0 1 | | 1 |
where the terms a00, a01, etc. are calculated as follows:
| a00 a01 a02 | [+0.213 +0.715 +0.072]
| a10 a11 a12 | = [+0.213 +0.715 +0.072] +
| a20 a21 a22 | [+0.213 +0.715 +0.072]
[+0.787 -0.715 -0.072]
cos(hueRotate value) * [-0.213 +0.285 -0.072] +
[-0.213 -0.715 +0.928]
[-0.213 -0.715+0.928]
sin(hueRotate value) * [+0.143 +0.140-0.283]
[-0.787 +0.715+0.072]

Related

Overlap two equally dimension matrices in R

I have two matrices A and B, both have the same dimensions and are binary in nature. I want to overlap matrix A on matrix B.
Matrix A:
| Gene A | Gene B |
| -------- | ----------- |
| 0 | 1 |
| 0 | 1 |
Matrix B:
| Gene A | Gene B |
| -------- | ----------- |
| 1 | 0 |
| 0 | 0 |
Result:
Matrix C:
| Gene A | Gene B |
| -------- | ----------- |
| 1 | 1 |
| 0 | 1 |
The resultant matrix will also have the same dimension as the input.
How can this be done?
Please let me know.

Create vectors based on features of clustering in R

I have a the results of two clusterings and I would like to create vectors so that all features that belong to the cluster are listed in a vector.
The following dataframe results from a clustering algorithm. The columns "C" are the clusters from two different algorithms.
| A1 | A2 | A3 | A4 | A5 | C1 | C2 |
| -- | -- | -- | -- | -- | -- | -- |
| 0 | 0 | 0 | 15 | 0 | 1 | 1 |
| 0 | 20 | 34 | 0 | 0 | 2 | 2 |
| 33 | 0 | 0 | 7 | 0 | 1 | 1 |
| 0 | 0 | 0 | 0 | 85 | 3 | 2 |
| 0 | 0 | 0 | 0 | 94 | 3 | 2 |
| 0 | 12 | 57 | 0 | 0 | 2 | 2 |
I want to create one vector for each cluster so that at the end I have
c11 = ['A1','A4']
c12 = ['A2','A3']
c13 = ['A5']
c21 = ['A1','A4']
c22 = ['A2','A3', 'A5']
EDIT:
To be more specific, the code should create a vector for each cluster in this way: If the cluster has a value different from 0 in any of the cluster specific rows for a feature, then add this feature to the vector.
In the first step for the second clustering the algorithm looks at cluster C21 (Rows 1 and 3) according to this rows the features A4 and A1 might be positive in instances of the cluster. In the second step the algorithm looks at the rows 2, 4, 5 and 6 for C22. There the values A2, A3 might be positive (according to the 2nd and 6th row) and the A5 as well (according to the 4th and 5th row)
EDIT2: The question was already solved but I still have a question in the special case that each instance would be clustered in multiple clusters and these are not disjunct. In this case the clusters are given as a string.
| A1 | A2 | A3 | A4 | A5 | C |
| -- | -- | -- | -- | -- | ---- |
| 0 | 30 | 0 | 15 | 0 | "1,2"|
| 0 | 20 | 34 | 0 | 0 | "2" |
| 33 | 0 | 0 | 7 | 0 | "1" |
| 28 | 0 | 0 | 0 | 85 | "3,1"|
| 0 | 0 | 0 | 0 | 94 | "3" |
| 0 | 12 | 57 | 0 | 0 | "2,3"|
c1 = ['A2','A1','A4','A5']
c2 = ['A2','A4','A3']
c3 = ['A1','A5','A2','A3']
Create a list of column names for each row, where the value is not equal to 0, by looping across the row with apply and MARGIN = 1, Use the column 'C1', 'C2' to split the list, loop over the outer list and unlist the inner list elements, get the unique and sort it
l1 <- apply(df1[1:5] != 0, 1, FUN = function(x)
names(x)[x])
lst1 <- lapply(split(l1, df1$C1), function(x) sort(unique(unlist(x))))
lst2 <- lapply(split(l1, df1$C2), function(x) sort(unique(unlist(x))))
-output
> lst1
$`1`
[1] "A1" "A4"
$`2`
[1] "A2" "A3"
$`3`
[1] "A5"
> lst2
$`1`
[1] "A1" "A4"
$`2`
[1] "A2" "A3" "A5"

(AVB)&(AV~B) is logically equivalent to ~~A, it that true or false?

(AVB)&(AV~B) is logically equivalent to ~~A?
It kind of confused me since they are in different dimension.
Starting from:
(A∨B)∧(A∨¬B)
One can first apply one of De Morgan's laws to the AND:
¬(¬(A∨B)∨¬(A∨¬B))
Next, one of De Morgan's laws can be applied to each side:
¬((¬A∧¬B)∨(¬A∧B))
By applying distributivity of AND over OR in reverse, ¬A can be extracted:
¬(¬A∧(¬B∨B))
By complementation, ¬B∨B is 1:
¬(¬A∧1)
By identity for AND:
¬¬A
Applying double negation:
A
This goes through your target ¬¬A without going through simple A. It's much simpler not to do that.
Starting again from:
(A∨B)∧(A∨¬B)
By applying distributivity of OR over AND in reverse, A can be extracted:
A∨(B∧¬B)
By complementation, B∨¬B is 1:
A∧1
By identity for AND:
A
Applying double negation in reverse:
¬¬A
Since you mention doing it by truth table, here's my go at showing that they're equivalent that way:
+---+---+----+----+-------+--------+--------------+-----+
| A | B | ¬A | ¬B | (A∨B) | (A∨¬B) | (A∨B)∧(A∨¬B) | ¬¬A |
+---+---+----+----+-------+--------+--------------+-----+
| 0 | 0 | 1 | 1 | 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 |
+---+---+----+----+-------+--------+--------------+-----+

FSM for long bit sequence

Currently, I'm working on a mealy fsm that detects a 17 bit sequence 10100001010000001. Due to the length of the sequence, I'm having difficulty figuring out which state to return to when the input doesn't allow me to move on to the next state. Any suggestions ??
Think about what previous pattern is satisfied when the expected pattern is not met. The FSM for a 10100001010000001 Mealy machine is shown below, in ASCII art (not sure how it will render here...)
s0-1->s1-0->s2-1->s3-0->s4-0->s5-0->s6-0->s7-1->s8-0->s9-1->s10-0->s11-0->s12-0->s13-0->s14-0->s15-0->s16-1->s17-0->s2
| | | | | | | | | | | | | | | | | |
0 1 0 1 1 1 1 0 1 0 1 1 1 1 1 1 0 1
| | | | | | | | | | | | | | | | | |
s0 s1 s0 s1 s3 s1 s1 s0 s1 s0 s1 s3 s1 s1 s8 s1 s0 s1

Can modal operator be defined as a boolean function?

Let us consider for simplicity only Kripke structures with a single agent whose knowledge is described by the modal operator K. We know that in all the corresponding Kripke structures where K is interpreted by equivalence there holds for any formula A
a) the formula KA -> A (Knowledge Axiom) is valid ,
b) but the formulas A -> KA and ¬KA are not valid.
Utilize these facts to show that such a behaviour of the modal operator K cannot be encoded by any boolean function (ie. Truth values defined by a table).
Hint: Suppose the truth value of KA can be calculated from the truth value of A using a truth table for K (in the same way as ¬A is calculated form A). Consider all possible truth tables for K and show that none of them grants the properties a) and b) mentioned above.
I dont understand that hint... making truth table of K is like constructing truth table of negation symbol ¬ , which in my mind doesnt make sense I think it makes sense only to make negation of something and not just negation
Consider all possible truth tables for K:
| A | K₁A | K₂A | K₃A | K₄A |
—————————————————————————————
| 1 | 1 | 1 | 0 | 0 |
—————————————————————————————
| 0 | 1 | 0 | 1 | 0 |
Show that none of them grants the properties a) and b) mentioned above.
Case 1
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 1 | 1 | 1 | 0 |
—————————————————————————————————
| 0 | 1 | 0 | 1 | 0 |
In this case, KA->A is not a tautology.
Case 2
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 1 | 1 | 1 | 0 |
—————————————————————————————————
| 0 | 0 | 1 | 1 | 1 |
In this case, A->KA is a tautology.
Case 3
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 0 | 1 | 0 | 1 |
—————————————————————————————————
| 0 | 1 | 0 | 1 | 0 |
In this case, KA->A is not a tautology.
Case 4
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 0 | 1 | 0 | 1 |
—————————————————————————————————
| 0 | 0 | 1 | 1 | 1 |
In this case, ¬KA is a tautology.
Can desired behaviour of K be encoded by many-valued matrix?
For alethic modal systems, the answer is the following:
3 values are insufficient,
4 values are sufficient for the so-called basic modal logic,
any finite number of values is insufficient for syntactically “full” and deductively “natural” modal system.
See, e. g., introductory parts in the article by Jean-Yves Beseau.
I hope these results are relevant for epistemic modal systems.

Resources