Rank formula-type in LimeSurvey - ranking

I have four formula type questions in a LimeSurvey were the resultants are integers
e.g
Q-1=23 Q-4=19 Q-7=45 Q-9=24
I need to find the greatest number and its related question #
In this case the greatest # is 45 and the question # is Q-7
I have been reading the Expression Manager documentation but am having no luck
Thank you

Well, if you have hyphens in your question codes you must be using an outdated version of LimeSurvey. This solution is for the current version (2.05) and assumes that there cannot be duplicates in the formula questions...
For the sake of simplicity, lets give your formula questions codes q1, q2, q3 and q4.
Create a new "Equation" type question (let's call it "maxVal") with this equation.
{max(q1, q2, q3, q4)}
Then you can use nested IFs to display the highest formula question code (line-breaks inserted for clarity):
{if(q1 == maxVal, 'q1',
if(q2 == maxVal, 'q2',
if(q3 == maxVal, 'q3',
if(q4 == maxVal, 'q4',
''
))))}

Related

Using ARRAYFORMULA and COUNTIF

I have a google form that asks different questions and each question has an individual correct answer.
In this example, the corresponding correct answers to each question are:
Question 1 = A
Question 2 = B
Question 3 = C
The expected output for each cell in column A are:
A2 = 2
A3 = 1
A4 = 1
This is my Formula in A2: =ArrayFormula(IF(ISBLANK($B$2:$B),"",countif(B2:B,"A")+countif(C2:C,"B")+countif(D2:D,"C")))
I want the formula to be able to automatically get the sum of all the correct answers of every row every time someone answers the form without having to drag the formula each time.
COUNTIF doesn't work with ARRAYFORMULA as you want. You should sum each column comparision:
=INDEX(IF(LEN(C2:C),(C2:C="A")+(D2:D="B")+(E2:E="C"),""))
or use MMULT:
=INDEX(IF(LEN(C2:C),MMULT(--(C2:E={"A","B","C"}),{1;1;1}),""))
=arrayformula(if(B2:B<>"",if(B2:B="A",1,0)+if(C2:C="B",1,0)+if(D2:D="C",1,0),))

Taking Derivative of a Matrix with functions in Maple. Want to leave functions as prime (f' or f'') and not evaluate

I want to evaluate a matrix that has a function named alpha. When I take the derivative of alpha, I would like the result to give me an alpha'
Example: if I have sin(alpha) I want to get cos(alpha)alpha' but throughout the matrix.
It is quite unclear what you mean by stating that you have a "function" in Maple, of which you intend to take the derivative.
That could mean some expression depending upon a name such as t, with respect to which you intend on differentiating using Maple's diff command. And such an expression may be assigned to alpha, or it may contain the function call alpha(t).
Or perhaps you wish to treat alpha as an operator name, and differentiate functionally with Maple's D command.
I shall make a guess as to what you meant.
restart;
Typesetting:-Suppress(alpha(t));
Typesetting:-Settings(prime=t):
Typesetting:-Settings(typesetprime=true):
M := Matrix([[ sin(alpha(t)), exp(p*alpha(t)) ]]);
map(diff, M, t);
If that's not the kind of thing that you're after then you should explain your purpose and needs in greater detail.
Your question's title mentions a desire to have something not "evaluate". What did you mean by that? Have you perhaps assigned something to the name f?
Thank you for answering. I found the solution after a lot of guess and checking and reading. Here is my code with my solution.
with(Typesetting) :
Settings(typesetdot = true);
a:= alpha(t)
Rna:= [ cos(alpha), -sin(alpha), 0; sin(alpha), cos(alpha), 0; 0, 0, 1 ]
b := beta(t)
Rab:= [ cos(beta), -sin(beta), 0; sin(beta), cos(beta), 0; 0, 0, 1 ]
Rnab:= Rna . Rab
Rnab:= map(diff, Rnab, t)
Sorry for the multiple answers, I am getting use to the website.

Is there a way to use range with Z3ints in z3py?

I'm relatively new to Z3 and experimenting with it in python. I've coded a program which returns the order in which different actions is performed, represented with a number. Z3 returns an integer representing the second the action starts.
Now I want to look at the model and see if there is an instance of time where nothing happens. To do this I made a list with only 0's and I want to change the index at the times where each action is being executed, to 1. For instance, if an action start at the 5th second and takes 8 seconds to be executed, the index 5 to 12 would be set to 1. Doing this with all the actions and then look for 0's in the list would hopefully give me the instances where nothing happens.
The problem is: I would like to write something like this for coding the problem
list_for_check = [0]*total_time
m = s.model()
for action in actions:
for index in range(m.evaluate(action.number) , m.evaluate(action.number) + action.time_it_takes):
list_for_check[index] = 1
But I get the error:
'IntNumRef' object cannot be interpreted as an integer
I've understood that Z3 isn't returning normal ints or bools in their models, but writing
if m.evaluate(action.boolean):
works, so I'm assuming the if is overwritten in a way, but this doesn't seem to be the case with range. So my question is: Is there a way to use range with Z3 ints? Or is there another way to do this?
The problem might also be that action.time_it_takes is an integer and adding a Z3int with a "normal" int doesn't work. (Done in the second part of the range).
I've also tried using int(m.evaluate(action.number)), but it doesn't work.
Thanks in advance :)
When you call evaluate it returns an IntNumRef, which is an internal z3 representation of an integer number inside z3. You need to call as_long() method of it to convert it to a Python number. Here's an example:
from z3 import *
s = Solver()
a = Int('a')
s.add(a > 4);
s.add(a < 7);
if s.check() == sat:
m = s.model()
print("a is %s" % m.evaluate(a))
print("Iterating from a to a+5:")
av = m.evaluate(a).as_long()
for index in range(av, av + 5):
print(index)
When I run this, I get:
a is 5
Iterating from a to a+5:
5
6
7
8
9
which is exactly what you're trying to achieve.
The method as_long() is defined here. Note that there are similar conversion functions from bit-vectors and rationals as well. You can search the z3py api using the interface at: https://z3prover.github.io/api/html/namespacez3py.html

Ruby - code to determine the most common characterS(plural) in a string [duplicate]

This question already has an answer here:
How do I count the frequencies of the letters in user input?
(1 answer)
Closed 5 years ago.
Those of you who are marking this as a duplicate - seriously, try to be more responsible. The question that you have marked as the same is quite different to the question I've asked. I've already got a great answer that was not available on any of the questions that were asked about similar topics.
My Original Question:
I see that many have asked how to find the most common letter in a string. My code for that is below. But I'd like to know how to get multiple answers to return. That is to say, if there are several letters that have the same count as most common, how do I get my method to return those only and all of them?
def ltr(string)
results = string.scan(/\w/).reduce(Hash.new(0)) {|h,c| h[c] += 1; h}
sorted = results.sort_by{|key,value| value}
sorted[-1]
end
For example, if the string I input to this method is ("oh how i hate to get up in the morning")...the there are 4 each of the letters 'h', 'o', and 't'. My current method only returns the 't' with the count of '4'. How do I get the others to be returned as well?
Note: Please read questions carefully before you decide to mark them as duplicates. The question that was suggested as a possible duplicate simply shows how to count the frequencies of characters, not how to have it return only those which are the most common. Matt's answer is perfect.
You had a good answer. Just keep going thru the resulting array keeping only the elements where the count is as high as the count of the first item:
def ltr(string)
results = string.scan(/\w/).reduce(Hash.new(0)) {|h,c| h[c] += 1; h}
sorted = results.sort_by{|key,value| value}.reverse
top = sorted[0][1]
sorted.take_while{|key,value| value == top}
end

USing AddExpression / MathExpression in Weka

I am working on a very basic WEKA assignment, and I'm trying to use WEKA to preprocess data from the GUI (most current version). I am trying to do very basic if statements and mathematical statements in the expression box when double clicking on MathExpression and I haven't had any success. For example I want to do
if (a5 == 2 || a5 == 0) then y = 1; else y = 0
Many different variations of this haven't worked for me and I'm also unclear on how to refer to "y" or if it needs a reference within the line.
Another example is -abs(log(a7)–3) which I wasn't able to work out either. Any ideas about how to make these statements work?
From javadoc of MathExpression
The 'A'
letter refers to the value of the attribute being processed.
Other attribute values (numeric only) can be accessed through
the variables A1, A2, A3, ...
Your filter applies to all attributes of your dataset. If I load iris dataset and apply following filter.
weka.filters.unsupervised.attribute.MathExpression -E log(A).
your attribute ,sepallength values change as following.
Before Filter After Filter
Minimum 4.3 Minimum 1.459
Maximum 7.9 Maximum 2.067
Mean 5.843 Mean 1.755
StdDev 0.828 StdDev 0.141
Also if you look to javadoc, there is no if else function but ifelse function. Therefore you should write something like
ifelse ( (A == 2 || A == 0), 1,0 )
Also this filter applies to all attributes. If you want to change only one attribute and according to other attribute values ; then you need to use "Ignore range option" and use A1,A2 to refer to other attribute values.
if you need to add new attribute use AddExpression.
An instance filter that creates a new attribute by applying a mathematical expression to existing attributes.

Resources