由买买提看人间百态

topics

全部话题 - 话题: random
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
e*******s
发帖数: 1979
1
Copy List with Random Pointer
A linked list is given such that each node contains an additional random
pointer which could point to any node in the list or null.
Return a deep copy of the list.
下面注释里面是别人写的能跑过的 上面的是我的 到现在都改得几乎一模一样了
可是还是超时
/**
* Definition for singly-linked list with a random pointer.
* struct RandomListNode {
* int label;
* RandomListNode *next, *random;
* RandomListNode(int x) : label(x), next(NULL), random(NULL) {}
* };
*/
class Solution {

public:
RandomList... 阅读全帖
o***d
发帖数: 313
2
http://www.careercup.com/question?id=12426697
Given a random number generator say r(5) generates number between 1-5
uniformly at random , use it to in r(7) which should generate a random
number between 1-7 uniformly at random.
===========solution:
my solution is the same with this:
>>>>>>>>>
Let f() be the random function that returns a number between (1,5).
Let g() = f() -1; then g is a function that returns a number between (0,4).
Let h() = g()/4; then h is a function that returns a number bet... 阅读全帖
g*****g
发帖数: 34805
3
来自主题: Programming版 - java random set seed question
Math.random()的值永远<1,所以setid=2.
Math.random调用的是Random的缺省constructor, 缺省constructor调用的是
Random() { this(System.currentTimeMillis()); }
所以如果你要固定的序列,用
public Random(long seed)方法
比如类似
Random random = new Random(0);
setid = random.nextInt(10) > 5? 2:1;
r****t
发帖数: 10904
4
random.sample in python uses random.random pseduo-RNG, 但是在 linux 上面
random.random 自动使用 /dev/urandom seed,所以 run it a second time, the
order should probably (not /dev/random yet) be different.
random.random() uses Mersenne Twister as the core generator,应该是很多地方
都在使用的。

random
not
s***e
发帖数: 403
5
/**
* Definition for singly-linked list with a random pointer.
* struct RandomListNode {
* int label;
* RandomListNode *next, *random;
* RandomListNode(int x) : label(x), next(NULL), random(NULL) {}
* };
*/
class Solution {
public:
RandomListNode *copyRandomList(RandomListNode *head) {
map corresponding;
corresponding[nullptr] = nullptr;

RandomListNode* nhead = new RandomListNode(0);
RandomListNode* last = ... 阅读全帖
a**********0
发帖数: 422
6
来自主题: JobHunting版 - copy list with random pointer 老出错
/**
* Definition for singly-linked list with a random pointer.
* class RandomListNode {
* int label;
* RandomListNode next, random;
* RandomListNode(int x) { this.label = x; }
* };
*/
public class Solution {
public RandomListNode copyRandomList(RandomListNode head) {

if(head == null)
return null;

if(head.next == null){
RandomListNode result = new RandomListNode(head.label);
result.next = null;
if(head.random != null)
re... 阅读全帖
g****v
发帖数: 971
7
来自主题: JobHunting版 - 请教下copy list with random pointer
我的代码在我自己机器上没问题,但leetcode上连最简单的case都通不过。
比如 [-1, #] 都没通过。
实在是找不出问题,请大家看看。
----------------------------------------------------------------------------
------------------
RandomListNode *copyRandomList(RandomListNode *head) {
if(head == NULL) return NULL;
RandomListNode *copyhead = new RandomListNode(head->label);
copyhead->random = head->random;
RandomListNode *ori = head->next;
RandomListNode *oritemp;
head->next = copyhead;
RandomListNode ... 阅读全帖
a**********0
发帖数: 422
8
来自主题: JobHunting版 - copy list with random pointer 老出错
检查了好几遍 没发现错误
/**
* Definition for singly-linked list with a random pointer.
* class RandomListNode {
* int label;
* RandomListNode next, random;
* RandomListNode(int x) { this.label = x; }
* };
*/
public class Solution {

public RandomListNode copyRandomList(RandomListNode head) {

if(head == null)
return null;

if(head.next == null){
RandomListNode result = new RandomListNode(head.label);
result.next = head.next;
result.random... 阅读全帖
A*****s
发帖数: 13748
9
刚才看答案的时候想当然了,仔细一想还是没明白
大牛这里说the gain at either boundary is independent of the paths
是说当非对称的Random Walk撞到边界后,Y_i的值是和路径独立么?
可是如果Random Walk从0开始,上下边界是2和-2
那么路径1:up-up(hit)的Y(Path1)是(1-p)+(1-p)
然而路径2:up-down-up-up(hit)的Y(Path2)是(1-p)-p+(1-p)+(1-p)!=Y(Path1)啊?
也就是Y_i和路径不独立啊?是我理解错了么?
另外我理解最后一个式子是:
P(Random Walk hits up)*Y(Random Walk hits up)
+ P(Random Walk hits down)*Y(Random Walk hits down) = 0
不知道理解对了没有,因为我们还是要关心RW的撞击概率,而不是Y_i的撞击概率。

it
c****t
发帖数: 19049
10
呵呵看来您不知道自己说反了。random effects之所以要用不同的设定是因为所用的
predictor表现特别;而不是因为不同的coefficient设定才把一个predictor变成了
random effect
比如说楼主决定用income作predictor,如果一个intercept,一个slope就可以算出不错
的prediction,那么fixed effect model就搞定。需要做random effect model最简单(
但不是最常见)的情况:不同income有不同的intercepts(假定slope还都一样)。比如
0-50k intercept 1000, 50k-100k intercept 1, 100k+ intercept 10。这样的
relationship不是linear,linear model可以做但predicition不好。而用smoother也许
能提高prediction但不make sense。这时用random effect model效果最好。
为深嘛这predictor这么特别。原因是income其实不是最合适的pr... 阅读全帖
c*****o
发帖数: 178
11
来自主题: JobHunting版 - random(5) generate random(7)
如下方法:
int Random7()
{ int i1,i2,i3;
i1=Random(5)%2;
i2=Random(5)%2;
i3=Random(5)%2;
return (i1*4+i2*2+i1);
}
i1,i2,i3 = 0 的概率是2/5,=1的概率是3/5。这样产生的random(7)是真的random
吗?
s******n
发帖数: 3946
12
Consider a Linked List with each Node, in addition to having a 'next'
pointer also has a 'random' pointer. The 'random' pointer points to some
random other Node on the linked list. It may also point to NULL. To simplify
things, no two 'random' pointers will point to the same node, but more than
1 Node's random pointer can point to NULL.
Now please reverse all the random pointers using space O(1)
b**********5
发帖数: 7881
13
来自主题: JobHunting版 - leetcode Copy List with Random Pointer
贴个我做的
public RandomListNode copyRandomList(RandomListNode head) {
// Note: The Solution object is instantiated only once and is reused
by each test case.
HashMap m = new HashMap<
RandomListNode, RandomListNode>();
RandomListNode result = null;
RandomListNode prev = null;
while (head != null) {
RandomListNode headCopy; RandomListNode randomCopy;
if (m.containsKey(head)) {
headCopy = m.... 阅读全帖
g***m
发帖数: 2999
14
来自主题: SanFrancisco版 - CD机的Random Play是咋回事
A "random number generator" based solely on deterministic computation cannot
be regarded as a "true" random number generator, since its output is
inherently predictable. How to distinguish a "true" random number from the
output of a pseudo-random number generator is a very difficult problem.
However, carefully chosen pseudo-random number generators can be used
instead of true random numbers in many applications. Rigorous statistical
analysis of the output is often needed to have confidence in th
c*******e
发帖数: 290
15
来自主题: Java版 - Random split of a file
测试了一下,跑 1000 次,按 3:7 分割,得到 299:701,大约是随机的,概率大约相等
。如果要求绝对相等,就要想其他办法了。不过该简洁办法符合我的需求,我上面说的
做到绝对随机,无重复。
Random r = new Random();
int a = 0;
int b = 0;
for(int i=0; i<1000; i++){
int random = r.nextInt(10);
System.out.println(random);

if( random < 3){
a++;
}else{
b++;
}
}

System.out.println("a=" + a + " b=" + b);

a=299 b=701
O*******d
发帖数: 20343
16
来自主题: Programming版 - random number generator in C++
These lines have problem. You will not get random numbers between lowest
and highest. You will, instead, get random numbers between lowest inclusive
and highest+1 exclusive. Take example highest = 3, lowest = 2, then range
is 2. The lower boundary of random number is 2.0 + 2.0 * 0.0 = 2.0. The
upper boundary of random number is 2.0 + 2.0 * 1.0 = 4.0. Because rand()/(
RAND_MAX + 1.0) can never be 1.0, the random numbers generated have upper
boundary of 4.0 exclusive.
int range=(highest-low
s*********x
发帖数: 1923
17
will the random.sample get the real random number of lines or pseduo-random
number? I tried STL
random_shuffle and found it's not a real random shuffle... meaning if you
run it twice, the random
"shuffled" numbers are in the same order. then the sampling procedure is not
right.
c*****a
发帖数: 3
18
来自主题: Computation版 - 有这样的random number generator吗 ?
不知道random nember generator 的工作远理是怎么样的,是不是一位一位的随机产生?
很多random number generator 都是产生某个范围之间的一个随机数。例如,在0和1之间
,产生0.34196. 而我实际上不需要知道这个随机数的精确值,我只需要知道它是比某个
数(例如0.75)大还是小就行了。有没有这样的random number generator,
给定一个(0,1)之间的参数,这个random number generator 每次只告诉我产生的随机数
是不是比给定参数小就可以了?
有谁对这些比较熟,帮忙指点一下?多谢!
如果有这样的random number generator,我的程序可能可以快很多。
l*******n
发帖数: 19
19
来自主题: Statistics版 - 这样还能算Randomized sample吗
"Random sample" and "Randomized design" are different concepts.
If there is no treatment intervention, you have an observational study.
Your samples (no matter old or not) are still random.
If there is treatment intervention, the subgroup design (old people) may
not be randomized even your overall design is randomized, when your design
was not stratified by age (with old as a stratum).
j*****e
发帖数: 182
20
来自主题: Statistics版 - 这样还能算Randomized sample吗
It seems like superray used the wrong terminology in his question. There is
no randomized sample. However, there is random sample, which most stat
analysis developed for.
It is hard to collect a random sample, since the population is not naturally
stratified by age here.
Assume they collected their original sample randomly,
you can view what they did as a two-stage sample. In stage one, you take a
random sample from the population. In stage two, you stratify stage one
sample by age and either ta
s******5
发帖数: 513
21
来自主题: Statistics版 - SAS-GLM random effects questions
the model is
y=mu + beta + g + e
where y is a vector with n individuals
beta is a fixed effect
g=(g1,,,,gm) is random effects
e is the random error
question 1:
we assume var(e)=R*square(sigma_e), where R is an known matrix. How to
incorporate this R matrix in the glm code?
question 2:
g=(g1,,,,gm) is random effects;we assume var(g)=D*square(sigma_g), D is a
known n*m matrix.
Is it to split the matrix D by columns as (d1,....,dm), and take individual
column as a random effect independently? Like:... 阅读全帖
c****u
发帖数: 243
22
:sample中有人来自同一行业,或相近地区,造成了natural grouping。
终于搜到了random effect的定义,可以用来佐证他人的结论了,
孺子可教啊,不过搜是搜到了,理解不理解就不一定了,

:fixed effects就是说你在严格控制的实验条件下观测了一批数据,而且你认为它 :
们都
:是符合某种条件的random variables; random effects就是说你测数据时没法严 :
格控制
:,所以观测结果受某个或某些没控制的random variable(s)影响了。
从这段来看,什么是effect,什么是predictor,估计还是一团浆糊,继续搜索
:把categorical variable叫作dummy variable,不懂latent variable,把random
:error 叫做measurement error都是特定的某类人嘿嘿
看看,通过搜索,知道了这些统计的基本概念,是不是马上就感觉高大上了?
不过以后最好在吹之前搜一下,减少making “don't mislead louzhu” 的comments
Keep sea... 阅读全帖
j********2
发帖数: 5
23
做了两年generalized linear mixed model的人飘过~~~
beta是parameter,不是任何factor/effect。
random effect指的是某个X。
natural grouping确实是核心概念之一,还有另外一点就是我们并不在乎random
effect的意义,我们并不interpret它。
fixed model跟random model实际上就是variance-covariance structure不同。
其实只要看formula就能明白的。fixed effect在formula里面不是随机的,而random
effect在formula里面是random的,服从某个分布的,通常这个分布是normal(0,
sigma)。
s********n
发帖数: 1962
24
【 以下文字转载自 Stock 讨论区 】
发信人: badcompany (bad), 信区: Stock
标 题: It's very wrong to say market is a random process
发信站: BBS 未名空间站 (Sat Jan 5 10:52:28 2008)
Modern financial economics is built on a foundation of sands by assuming
stock market follows random process.
Key point: if stock market price really follows a random process, you can
never make a prediction at certain point of time, the simplest version: a
random walk so up or down is always 50:50, so stock market is a casino, and
if you gamble
c***p
发帖数: 221
25
这题考的是,给定n, 如何用random(0,1)生成 random(0, n-1)
如果把random(0,1)的output看做是一个bit,这个题目就转化成integer的二进制表示
问题了。
A******g
发帖数: 612
26
来自主题: JobHunting版 - Leetcode新题 Copy List with Random Pointer
过不了,请大牛看看, 我在本地测试过好像没问题啊
----------------------------------------------
public class Solution {
public RandomListNode copyRandomList(RandomListNode head) {

if (head==null) return null;
RandomListNode p = head;
while (p != null) {
RandomListNode newNode = new RandomListNode(p.label);
newNode.next = p.next;
p.next = newNode;
p = newNode.next;
}

p = head;
RandomListNode p2 = head.next;
... 阅读全帖
m*********n
发帖数: 931
27
来自主题: JobHunting版 - copy list with random pointer 老出错
对java不熟 我感觉好像有点问题比如 这段代码:
if(head.next == null){
RandomListNode result = new RandomListNode(head.label);
result.next = head.next;
result.random = result.random;
return result;
}
result是一个新的node 然后result的next连null, result.random指向result.random
是什么意思?
N****g
发帖数: 2829
28
来自主题: EB23版 - 看来USCIS是randomly批的了。
看来USCIS是randomly批的了。至少TSC的PD 1/17/2007之前的完全random,不按任何PD
了。对1/17/2007之前PD靠前的不是什么好消息。
而且很有可能所有current的都是randomly批,也就是3/8/2007前的全都randomly批。
如果此消息属实,越靠近3/07的越合算,因为相当于可以插队到PD早他半年的人前面。
但从6月的批准情况看,貌似06年10月的较晚绿,大趋势上有一定PD顺序。继续观察。
b******y
发帖数: 9224
29
来自主题: Java版 - 关于Random怎么用?
首先,世界上没有绝对的random. random number generator 是根据一些算法做的,比
如说mod啥的。
用一个random instance好,或者,你需要用不同的变量初始化random object.
有啥问题接着问,我当初上过专门研究RND的课,另外也读了不少paper,哈哈
O******e
发帖数: 734
30
来自主题: Programming版 - random number generator in C++
If you want your random() to return an integer between lowest and highest
inclusively, then
range=highest-lowest+1;
random=lowest+(int)(range*rand()/(RAND_MAX+1.0));
But you want your random() to return a float between lowest and highest,
so you need
range=highest-lowest;
random=lowest+range*rand()/(RAND_MAX+1.0);
l*****s
发帖数: 774
31
来自主题: Computation版 - 急问:random number 问题
First time, generate the random number 1-5.
Second time, generate the random number 6-9.
Third time, generate the random number 10-14.
Forth time, generate the random number 15-18.
You need store the results of each time. I donot whether it works. You can
have a try.
j*****e
发帖数: 182
32
You should not use zero as the seed, because you will not be able to
duplicate the result. When you use zero, sas is using its internal clock to
choose a number. When you choose zero as the seed at differnt time, the
random number is different.
I often generate a seed by close my eye and punch the number key pad. Or,
you can use the random number table. Always keep a record your random number
, otherwise, your result is not stable.As long as you choose the seed
randomly, you will be fine.
Also,
C******n
发帖数: 284
33
貌似版上用Stata的不多,但愿熟悉random effects model的大牛们能提供些指导
我在Stata中用某些procedure,比如xtmelogit来做一个简单的two-level random
intercept logit model
在output中,by default,显示的是standard deviation of the random intercept,
如下表:
Random-effects Parameters | Estimate Std. Err.
b*******g
发帖数: 513
34
为什么在mixed models中加入random effects,response就conditionally
independent了?看了一些书上写的,random effects是用来消除corellated
responses中的correlation的。不管是general linear mixed models,还是genralized
linear mixed models,加入random effects,responses就从correlated,变为
conditionally independent了。基本上书上都这么写,但没写为什么?哪位大虾知道
?还有mixed models中都是什么样的effects能成为random effects?
p*7
发帖数: 45
35
来自主题: Statistics版 - fixed or random model
我刚刚开始学这个也不懂。我的感觉是FIXED,two way anova with multpile
replicants in each cell. Because there are only three levels in each factors
and all the levels are included here, it is fixed effect model. If there
are a lot of levels and we randomly selecet three, it will be random effect.
I have another question. Even we randomly select three from a population,
with only three samples, how we are going to estimate variance of the random
effect?

and
designs
p*7
发帖数: 45
36
来自主题: Statistics版 - fixed or random model
我刚刚开始学这个也不懂。我的感觉是FIXED,two way anova with multpile
replicants in each cell. Because there are only three levels in each factors
and all the levels are included here, it is fixed effect model. If there
are a lot of levels and we randomly selecet three, it will be random effect.
I have another question. Even we randomly select three from a population,
with only three samples, how we are going to estimate variance of the random
effect?

and
designs
k*******a
发帖数: 772
37
"SAS for mixed models"摘了几段话
An effect is called fixed if the levels in the
study represent all possible levels of the factor, or at least all levels
about which inference is to
be made.
Factor effects are random if they are used in the study to represent only a
sample (ideally, a
random sample) of a larger set of potential levels. The factor effects
corresponding to the larger
set of levels constitute a population with a probability distribution. The
last statement bears
repeating because it goe... 阅读全帖
n**m
发帖数: 156
38
我是这么理解的,
一般fixed factor是我们对这几个factor的effect感兴趣,比如你想知道某种药的效果
,某种教学方法对学生的成绩有没有提高。
random factor我们对factor中某个个体不感兴趣,但是random factor解释variation
,帮助设计正确的model。
另外,有一些条件限制,比如factor只有几个个体,比如3个,用random factor就不太
合适。有时候个体太多了,比如20多个,就会比较倾向于设计成random factor。
q**t
发帖数: 36
39
Hi All,
I am using lme in R to estimate standard error the random effect.
The output of the StdDev of lme is the SE of the random effects?
lme(y~1, random = ~1| s/p/k )
Random effects:
Formula: ~1 | s
(Intercept)
StdDev: 0.02100801
Formula: ~1 | p %in% s
(Intercept)
StdDev: 0.001980935
Formula: ~1 | k %in% p %in% s
(Intercept) Residual
StdDev: 0.01581869 0.006076241
Number of Observations: 240
Number of Groups:
s
5
p %in% s
... 阅读全帖
c****0
发帖数: 14490
40
是指一组数按group_id可以分为几个小组,然后你要在每个小组中randomly选一个obs
吗?
如果是,
说下想法,顺便等高手指正
1.用stata
sample 1,by group_id
2.用sas
PROC SURVEYSELECT DATA=temp;
STRATA variables; *这里的STRATA 变量要先sort过
3.如果取一些数,也可以考虑create new random variable,一般我用 random=ranuni
(n);然后sort random或者设条件取sample
F8
发帖数: 348
41
来自主题: Statistics版 - a quesiton about random effect
dataset with
a binary outcome y/n
4 different studies (treated as an 4-level categorical variable) and 3
treatment for each study
in a logistic model
found significant interaction of trt*study
Now try to consider random effect with study level covariate
As I know that nlmixed can only handle two random effects, in this case
Is there a way to fit a random effect model by treating study as a random
effect?
f****w
发帖数: 947
42
来自主题: _FanLaw版 - H-1B的Random Selection
CIS宣 布所 谓 “Random Selection” 的方 针。也就 是先统 计出有美 国硕 士学
位申 请人有多 少。若是超 出2万名额,就所 有硕 士的申 请先做一 次“Random
Selection” 。没 有抽中的,将这 些人再放到非硕 士学 位的H-1B申 请,再做一 次
“Random Selection” 。也就 是说这 些人有两 次的机 会。
CIS之 前没 有说 到还不 能寄 H-1B硕 士以 上的申 请,只 有提 到不 在接 受非美
国硕 士学 位的申 请。因 此有 些人还 是寄 出H-1B硕 士学 位的申 请。但 是今 天
CIS说4月2,3日时所 有的名额就已 经满了。想 必之 后送的H-1B都会被退回 去。
我 们目 前不知 道CIS什 么时 候会把所 有的案 件都整 理出 来。即 使目 前已 经
出到 Premium Processing 收 据的人,也不表 示CIS为马 上审 理。而 且还是要通
过 “Random Selection” 。
目 前的问 题好 几方 面。第 一申 请人的身 份问 题值 得研 究,第二若 是申 请人
无 法继 续工 作,
l**h
发帖数: 893
43
【 以下文字转载自 EB23 讨论区 】
发信人: lush (lush), 信区: EB23
标 题: 大家帮忙签一下这个加速PERM Random Audit的Petition
发信站: BBS 未名空间站 (Sun Apr 27 17:36:26 2014, 美东)
Random Audit本身就不太合理,真正应该被Audit的,是那些批量作假的阿三公司,但
是很多中国申请者也受拖累, PERM本身没有问题, 却被Random Audit。
所以不管PERM批了没批的,都请帮忙sign一下,帮助中国人。
http://www.change.org/petitions/dr-william-l-carlson-dol-please
It will be sent to:
Dr. William L. Carlson
Administrator, Office of Foreign Labor Certification
Department of Labor
Mr. Thomas Perez
The United States Secretary of Labor
Senator... 阅读全帖
w****o
发帖数: 2210
44
来自主题: JobHunting版 - random(5) generate random(7)
random(5) returns 0-4 or 1-5?

random
c***p
发帖数: 221
45
来自主题: JobHunting版 - 推荐一个random generation的总结
http://cseweb.ucsd.edu/~dasgupta/103/5.pdf
总结了一些random generation with (fair/biased) coins方面的知识.
个人觉得对于很多有关random generation的面试题有帮助。
比如:如何用rand(5)生成rand(7); bias toss; 生成[0,1]间nomal distribution random number.
l******c
发帖数: 2555
46
random(0,1) = 0 or 1
random(a, b) = a, a+1, ... b
r****o
发帖数: 1950
47
明白了,
那这样行吗?
用b-a的二进制形式,比如说是12=1100,共4位。
那么运行random(0,1)4次,每次相当于二进制的一位,如果凑成的二进制数小于等于
1100,则返回randNum+b-a,否则重来。
int diffSize=0;
int diff=b-a;
while(!diff)
{
diffSize++;
diff>>=1;
}
int randNum=MAX_INT;
while(randNum>b-a)
{
randNum=0;
for (int i=0; i {
randNum+=random(0,1)< }
}
return randNum+b-a;

learn
learn
S********0
发帖数: 29
48
来自主题: JobHunting版 - Leetcode新题 Copy List with Random Pointer
同求问题,本地是过的,runtime error, 上代码。
public class Solution {
public static RandomListNode copyRandomList(RandomListNode head) {
// Note: The Solution object is instantiated only once and is reused
by each test case.
if(head == null) return null;
RandomListNode pointer, res_pointer;
pointer = head;
while(pointer != null){
RandomListNode temp = new RandomListNode(pointer.label);
temp.random = null;
temp.next = pointer.next;
... 阅读全帖
f********4
发帖数: 988
49
来自主题: JobHunting版 - Leetcode新题 Copy List with Random Pointer
第二个loop就是改random pointer的,不能把链断开。因为后面的random pointer有可
能会指向前面的node,或者它本身,这样,你把前面的指针断开了,就找不到复制的那
个node了。。。所以第二个loop就改random pointer,再多加一个loop专门改链的指针
S********0
发帖数: 29
50
话不多说直接上代码,在本地测了没发现问题。。
谢谢.....
public static RandomListNode copyRandomList(RandomListNode head) {
// Note: The Solution object is instantiated only once and is reused
by each test case.
if(head == null) return null;
RandomListNode pointer, res_pointer;
pointer = head;
while(pointer != null){
RandomListNode temp = new RandomListNode(pointer.label);
temp.random = null;
temp.next = pointer.next;
RandomListNode n... 阅读全帖
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)