Is there a median equivalent to survey_mean() or svymean()? - survey

Is there a median equivalent to survey_mean() or svymean()?
I found weighted.median() but this doesn't include an argument for PSU or strata.

Related

Ruby returning imaginary number

Getting a confusing result when doing an exponential equation in ruby:
shifted_x = -97.0
exponent = 1.5
shifted_x**exponent
# Result: (0.0-955.3392067742221i)
-97.0**1.5
# Result: -955.3392067742221
My expectation is that the results would be the same but they are not. What changes when using the variable that causes ruby to return an imaginary (or complex) number?
Operator precedence.
-97.0**1.5 is equivalent to -(97.0**1.5)
shifted_x**exponent is, of course, equivalent to (-97.0)**1.5
Note that (-97.0)**1.5 is equivalent to sqrt((-97)^3) and taking the root of a negative real number gives you a complex number.

Prolog - How can I modify this clause to be able to print it in-depth first search DFS?

I was wondering how to modify the clause recorrido/2 to print it in depth first search, I have this so far:
input
arc(1,2).
arc(1,3).
arc(2,4).
arc(2,5).
arc(3,6).
arc(3,7).
arc(4,8).
arc(4,9).
arc(5,10).
arc(5,11).
arc(6,12).
arc(6,13).
arc(7,14).
arc(7,15).
imprime([]).
imprime([A|B]):-
write(A),nl,
imprime(B).
bimprime([]).
bimprime([A|B]):-
bimprime(B),
write(A),nl.
Typically, you would pass a level argument to the recursive function, to be incremented just before the recursive call.
recorrido(X,Z):- recorrido(X,Z,0).
recorrido(X,Z,L):- arco(X,Z),indent(L,Z).
recorrido(X,Z,L):- arco(X,Y),indent(L,Y),N is L+1,recorrido(Y,Z,N).
indent/2 would place some space, proportional to the current level, before the value. For instance
indent(L,V) :- forall(between(0,L,_),write(' ')),writeln(V).
Since this a bit too much verbose for my taste, I usually use a list instead of an integer to mark the level:
recorrido(X,Z):- recorrido(X,Z,[]).
recorrido(X,Z,L):- arco(X,Z),indent(L,Z).
recorrido(X,Z,L):- arco(X,Y),indent(L,Y),recorrido(Y,Z,[-|L]).
indent(L,V) :- forall(member(_,L),write(' ')),writeln(V).

Algorithm pseudocode

I have the pseudocode:
Algorithm exists(A,n,x):
lo=0
hi=n-1
while hi>=lo:
mid=floor((hi+lo)/2):
if x>A[mid]:
lo=mid+1
else: if x<A[mid]:
hi=mid-1
else:
return True
return False
and the array:
A[0]=1, A[1]=5, A[2]=6, A[3]=10, A[4]=12, A[5]=16, A[6]=17, A[7]=43
Then I have to find what exists(A,4,17) return.
Then we have l0=0 and hi=n-1=4-1=3 then hi>l0.
We get that mid=floor((hi+lo)/2)=floor((3+0)/2)=1 (floor is rounding to 1?).
We see that x<A[1] because 4<5. Then I think the pseudocode return: hi=mid-1=1-1=0?
The code you have written, it is binary search pseudocode. Through binary search, you can search for a number in a sorted array.
In your code, your explanation is wrong. Let me explain why.
Your array: A[0]=1, A[1]=5, A[2]=6, A[3]=10, A[4]=12, A[5]=16, A[6]=17,A[7]=43
Then you want to found exists(A,4,17), according to your algorithm,
A resembles your array, n=4, x=17
So, according to this your explanation in the last line is wrong because after the first iteration the mid=1 and then it will execute if x>A[mid]: condition because,
17 > 5 //as x=17 and A[1]= 5

Need Help in solving Binary Search

I am trying to solve another Question
I have implemented the binary search function required to solve this problem but i am unable to return the correct value which would help me in solving this question.Here's my code.
Please help me in solving this question.
def BinarySearch(arr,low,high,search):
while(low<=high):
middle=(low+high)/2
int_mid=int(middle)
print(int_mid)
if arr[int_mid]==search:
return int_mid
elif arr[int_mid]>search:
low=int_mid+1
elif arr[int_mid]<search:
high=int_mid-1
return arr[int_mid]
tc=int(input())
while(tc>0):
size=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
monkiness=[]
for i in range(len(A)):
for j in range(len(B)):
if (j>=i):
y=BinarySearch(B,0,len(B),B[j])
z=BinarySearch(A,0,len(A),A[i])
print(y,z)
if y>=z:
m=j-i
monkiness.append(m)
if len(monkiness)==0:
print(0)
else:
print(monkiness)
maxiumum=max(monkiness)
print(maxiumum)
tc-=1
You don't need binary search here ('here' means code you provided, not problem solution)
Even if you required binary search, BinarySearch is for non-decreasing array, but you have non-increasing array.
The goal is to find solution, that runs in less, than N^2 time, by exploiting the fact, that arrays are sorted.

mathematica exponential Nth derivative treated as an unknown function

I'd like to create a list of Hankel functions, defined in terms of an Nth derivative, but the Nth order derivatives get treated in the way that is described in the docs under "Derivatives of unknown functions", and left unevaluated. Here's an example:
Clear[x, gaussianExponential]
gaussianExponential[x_] := Exp[- x^2]
FullSimplify[Derivative[2][gaussianExponential[x]]]
I get:
(E^-x^2)^[Prime][Prime]
(instead of seeing the derivatives evaluated (and the final expressions are left unsimplified)).
Any idea what's going on here?
The correct syntax is:
Clear[x, gaussianExponential]
gaussianExponential[x_] := Exp[-x^2]
FullSimplify[Derivative[2][gaussianExponential][x]]
The Derivative applies to the function symbol f, not to the function evaluated at a point f[x]. So what you want is
Clear[x, gaussianExponential]
gaussianExponential[x_] := Exp[-x^2]
Derivative[2][gaussianExponential][x]//FullSimplify

Resources