由买买提看人间百态

topics

全部话题 - 话题: avg2
(共0页)
c*****a
发帖数: 808
1
来自主题: Statistics版 - 问题请教
只会用R,一直在学习SAS,试做了一下,感觉自己做的方法很怪。。。
求指点。好像可以直接用sql的avg()。
data work.temp;
input value freq_1 freq_2;
cards;
3 12 11
4 4 3
5 6 15
6 7 13
7 9 11
8 11 4
;
data temp2(keep=avg avg2);
set temp end=lastvar;
total1+freq_1;
total2+freq_2;
count+1;
if lastvar then do;
retain avg avg2;
avg=total1/count;
avg2=total2/count;
end;
run;
proc sql;
create table temp3 as
select max(avg,avg2) as maxx,avg,avg2 from (
select * from temp2 where avg is not missing and avg2 is no... 阅读全帖
w******1
发帖数: 520
2
来自主题: JobHunting版 - 刚phone完MS,好紧张。。。。
这个不错, 不过电话面试要是紧张了, 可能真做不出来。
count=1,
return avg1= a1,
count =2,
retun avg2 = a1+a2/2 = > a1-a1/2+a2=> a1 + (a2-a1)/2
=> avg1 + (a2-a1)/2
count =3,
retun avg3 = a1+a2+a3/3 => 2(a1+a2)/6 + 2 a3/6=> 2 avg2 /3 + a3/3
=> avg2 + (a3-avg2)/3
....
avgn = avg(n-1) + (an-avg(n-1))/n
g***s
发帖数: 3811
3
来自主题: JobHunting版 - 问一道题(1)
The idea is correct but the last step has error.
for i=1 to n {
avg = A * i;
find t closest to avg that S[n][t][i] = true;
if |t/i - avg| < |best - avg| then best = t/i;
}
then it would always divide to two group with size n and 0 since t/n-
avg=0 when t=sumOf(a);
even if using for i=1 to n-1, it is still not correct:e.g.
1,4,4,8,8 avg=5
by this way, you will divide to {1 4 8 8} and {4} but correct one should
be {1 8} { 4 4 8}
should change to:
for i=1 to n {
avg1 = t/i;
avg2 = (sum-t... 阅读全帖
g****v
发帖数: 971
4
来自主题: JobHunting版 - 问两道fb题
第一题挺难的。
suppose the array has n elements with an average "avg". then we divide the
array into two subarrays.
Suppose the first subarray has n1 elements with average "avg1" and 2nd
subarray has n2 elements with average "avg2".
we can have equations:
n1*avg1 + n2 * avg2 = n*avg
n1+n2=n
since we are looking for two subarrays with same average, we have :
avg1 = avg2
so we finally have :
(n1+n2)*avg1 = n*avg => n*avg1 = n*avg => avg1 = avg
结论: 数组的平均数就是要找的subarray的平均数
所以现在的问题就变成了怎么找到subset whose av... 阅读全帖
g****g
发帖数: 310
5
绝对没必要,也不应该写这类代码。根本没有任何速度上的提升。(如果有,那么是在
你做梦的时候)
unsigned long avg1=0, avg2=0;
for (int n=0;n<1000000; n++)
{
int j = 0, i=0;
a = rdtsc();
i+= !(!(j));
b=rdtsc()-a;
avg1+=b;
j=0; i=1;
a = rdtsc();
if( j!=0 ) i++;
b=rdtsc()-a;
avg2+=b;
j++;i++;

}
std::cout << "Take:" << avg1/1000000 << std::endl;
std::cout << "Take:" << avg2/1000000 << std::endl;
两者的结果基本相同。
g****g
发帖数: 310
6
一样的结果,整天讨论哪个快,却自己不去测试一下有意义么?
unsigned long avg1=0, avg2=0;
srand( (unsigned)time( NULL ) );
int j = 0, i=0;
for (int n=0;n<1000000; n++)
{
j = (rand() > RAND_MAX/2) ? 0 : 1;
a = rdtsc();
i+= !(!(j));
b=rdtsc()-a;
avg1+=b;
j=0; i=1;
a = rdtsc();
if( j!=0 ) i++;
b=rdtsc()-a;
avg2+=b;

}
std::cout << "Take:" << avg1/1000000 << std::endl;
std::cout << "Take:" << avg2/1000000 << std:
g***s
发帖数: 3811
7
来自主题: JobHunting版 - 问一道题(1)
the sample:
1 4 4 8 8
avg = 5
the best by your step will get best=0.25 -- (t = 21, i = 4, t/i-avg=0.25)
which is: {1 4 8 8} and {4}.
{1 4 8 8} {4} the |avg1 - avg2| = 1.25
correct one should be:
{1 8} { 4 4 8} the |avg1 - avg2| = 0.83
b**********5
发帖数: 7881
8
来自主题: JobHunting版 - 简单map reduce mean median, 傻逼回答
先问: map reduce mean
我说, mapper emit (number, 1), 可以弄几个combiner, emit (partial sum
, partial N), 然后最后一个reducer, add up sum divide by N
问: 会有什么问题
答: sum overflow, 可以用 long, 或者big integer?
此处省略一千字
原来是这样的:something called rolling average
let's say avg0 is average for a0... aN0, avg1 is average for aN0 .... aN1....
so the total average is avg0*(N0/N) + avg1*(N1/N) + avg2*(N2/N)....
so the combiner can emit (avg0, N0), (avg1, N1) ... pair
and the reducer would calculate the total average
=============... 阅读全帖
S******t
发帖数: 151
9
来自主题: JobHunting版 - 问两道fb题
我贴一个第一题能通过的代码吧:
vector bestA;
int bestLen;
void search(int idx, int sum, int len, vector>>& f,
vector& ret, vector& A) {
//cout << idx << " " << sum << " " << len << endl;
if (idx == 0) {
int lenA = bestA.size();
vector v = ret;
/*
for (int i = 0; i < v.size(); i++)
cout << v[i] << " ";
cout << endl;
*/
if (v.size() < lenA || lenA == 0) {
bestA = v;
return;
... 阅读全帖
x*********x
发帖数: 1402
10
来自主题: Stock版 - ABK破产,都得给我扒层皮
PMI去年我从1.8X开进,avg2.1捂到3.1出。然后跌倒2.5,我再入,谁知道赶上2月的大
跌。PMI给
跌倒2.1X,咬牙再进,然后又回到3。
PMI/RDN/MTG/MBI 这种股basher越多越要挺住。街上的忽悠师会时不时出个消息,跌几
点,受不住
的就割了。

shares
accept
more.
(共0页)