- PyTorchStepByStep - Chapter 3: A Simple Classification Problem
X,y=make_moons(n_samples=100,noise=.3,random_state=0)X_train,X_val,y_train,y_val=train_test_split(X,y,test_size=.2,random_state=13) sc=StandardScaler()sc.fit(X_train)X_train=sc.transform(X_train)X_val=sc.transform(X_val......
- PyTorchStepByStep - Chapter 2.1: Going Classy
classStepByStep():def__init__(self,model,loss_fn,optimizer):self.device='cuda'iftorch.cuda.is_available()else'cpu'self.model=model.to(self.device)self.loss_fn=loss_fnself.opti......
- PyTorchStepByStep - Chapter 2: Rethinking the Training Loop
defmake_train_step_fn(model,loss_fn,optimizer):defperform_train_step_fn(x,y):#SetmodeltoTRAINmodemodel.train()#Step1-Computemodel'spredictions-forwardpassyhat=model(x)......
- Cornell cs3110 - Chapter9 Lessons
使用Menhir构建SimPL的编译器LexerandParser语法分析模块Lexer,Parser,AST是三个依次耦合的模块,可以这么描述三者的关系:Lexer---tokens-->Parser---nodes-->AST相对于上面的图像化描述,cs3110反过来构建整个Lexer和Parser的结构在ast.ml中,定义了AST上......
- abc369D Bonus EXP
有N只怪兽,第i只怪兽的体力为A[i],需要按编号从小到大的顺序依次处理,对于每只怪兽可以选择打或不打,如果不打,经验值不变;如果打,将获得等同于怪兽体力的经验值。另外,对于第偶数次打的怪兽,经验值翻倍。求能获得的最大经验值。1<=N<=2E5;1<=A[i]<=1E9分析:获得的经验跟奇偶性有关,设dp0[......
- Cornell cs3110 - Chapter7 Exercises
(*Exercise:mutablefields*)typestudent={name:string;mutablegpa:float;}letstuA={name="Alice";gpa=3.7}let()=stuA.gpa<-4.0(*Exercise:intfun*)letinc=ref(funx->x+1)letnum=!inc3109(*Exercise:a......
- Cornell cs3110 - Chapter6 Exercises
(*Exercise:specgame*)(*Whereisanotherprogrammer?*)(*Exercise:polyspec*)(*[Poly]representsimmutablepolynomialswithintegercoeffcients*)moduletypePoly=sig(*[t]isthetypeofpolynomials*)typet(*[evalxp]is[p]e......
- Cornell cs3110 - Chapter5 Exercises
(*Exercise:complexsynonym*)moduletypeComplexSig=sigtypecomplexvalzero:complexvaladd:complex->complex->complexend(*Exercise:complexencapsulation*)moduleComplex:ComplexSig=structtypecomplex=float*flo......
- Cornell cs3110 - Chapter4 Exercises
(*Exercise:mysteryoperator1*)let($)fx=fx;;(*使得函数的连续调用具有一部分右结合的特质square$2+2与square2+2的运行结果分别是16和6*)(*Exercise:repeat*)letrecrepeatfnx=matchnwith|0->x|_->repeatf(n-1)......
- Cornell cs3110 - Chapter3 Exercises
(*Exercise:listexpressions*)letlist1=[1;2;3;4;5];;letlist2=1::2::3::4::5::[];;letlist3=[1]@[2;3;4;]@[5];;(*Exercise:product*)letrecproductl=matchlwith|[]->1|h::t->h*productt;;(*......