diff --git a/nasal_gc.h b/nasal_gc.h index 4746d8d..651e71b 100644 --- a/nasal_gc.h +++ b/nasal_gc.h @@ -633,10 +633,10 @@ void nasal_gc::info() "hash ","upval","obj ", "co " }; - std::cout<<"\ngarbage collector info:\n"; + std::cout<<"\ngarbage collector info\n"; for(uint8_t i=vm_str;ib.second;} ); - std::cout<<"\noperands call info:"; + std::cout<<"\noperands call info"; uint64_t total=0; for(auto& i:opcall) { @@ -386,7 +386,7 @@ void nasal_vm::die(std::string str) inline bool nasal_vm::condition(nasal_ref val) { if(val.type==vm_num) - return val.value.num; + return val.num(); else if(val.type==vm_str) { double num=str2num(val.str().c_str()); diff --git a/test/bp.nas b/test/bp.nas index ccf8814..7326b08 100644 --- a/test/bp.nas +++ b/test/bp.nas @@ -11,6 +11,16 @@ var new_neuron=func() }; } +var tanh=func(x) +{ + var (a,b)=(math.exp(x),math.exp(-x)); + return (a-b)/(a+b); +} +var difftanh=func(x) +{ + x=tanh(x); + return 1-x*x; +} var sigmoid=func(x) { return 1/(1+math.exp(-x)); @@ -21,7 +31,7 @@ var diffsigmoid=func(x) return x*(1-x); } -var (inum,hnum,onum,lr)=(2,4,1,0.1); +var (inum,hnum,onum)=(2,4,1); var training_set=[[0,0],[0,1],[1,0],[1,1]]; var expect=[0,1,1,0]; @@ -30,8 +40,8 @@ for(var i=0;i0.5?-2*rand():2*rand()); + hidden[i].bia=rand()>0.5?-5*rand():5*rand(); } var output=[]; @@ -39,8 +49,8 @@ for(var i=0;i0.5?-2*rand():2*rand()); + output[i].bia=rand()>0.5?-5*rand():5*rand(); } var forward=func(x) @@ -51,7 +61,7 @@ var forward=func(x) hidden[i].in=hidden[i].bia; for(var j=0;j