Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // author: Ryuuk
- #include<bits/stdc++.h>
- #define sz(a) int((a).size())
- #define pb push_back
- #define ZERO (1e-10)
- #define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
- #define all(c) (c).begin(),(c).end()
- #define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
- #define present(c,x) ((c).find(x) != (c).end())
- #define cpresent(c,x) (find(all(c),x) != (c).end())
- #define LSOne(i) (i&(-i))
- #define REP(i,a,b) for(int(i)=(a);(i)<(b);i++)
- #define BUG(x) {cout<<#x<<" = "<<x<<endl;}
- #define CL(A,I) (memset(A,I,sizeof(A)))
- static const int INF = 0x3f3f3f3f;
- static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
- static const long double epsilon = 1e-15;
- static const long double pi = acos((long double) -1);
- using namespace std;
- typedef vector<int> vi;
- typedef vector<vi> vvi;
- typedef pair<int,int> ii;
- typedef long long ll;
- inline void init_io(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
- int x[3]={1, 2, 3};
- double t[3]={0.1, 0.3, 0.7};
- double W[2][3]={{0.5, 0.3, 0.1},{0.3, 0.2, 0.1}};
- double Z[3][2]={{0.1, 0.2},{0.3, 0.4},{0.5, 0.6}};
- double b[2],a[3];
- double h[2], o[3], e[3];
- double rho_sortie[3], rho_cahe[2];
- void GoBack()
- {
- double temM[3][2];
- for(int i=0;i<3;i++)
- rho_sortie[i]=o[i]*(1-o[i])*e[i];
- memset(temM,0,sizeof temM);
- for(int i=0;i<3;i++)
- for(int j=0;j<2;j++)
- temM[i][j]+=rho_sortie[i]*h[j];
- for(int i=0;i<3;i++)
- for(int j=0;j<2;j++)
- Z[i][j]+=temM[i][j];
- for(int i=0;i<2;i++)
- {
- double tmp=0;
- for(int j=0;j<3;j++)
- tmp+=Z[j][i]*rho_sortie[j];
- rho_cahe[i]=h[i]*(1-h[i])*tmp;
- }
- memset(temM,0,sizeof temM);
- for(int i=0;i<2;i++)
- for(int j=0;j<3;j++)
- temM[i][j]+=rho_cahe[i]*x[j];
- for(int i=0;i<3;i++)
- for(int j=0;j<2;j++)
- W[i][j]+=temM[i][j];
- }
- bool first_step()
- {
- for(int i=0;i<2;i++)
- for(int j=0;j<3;j++)
- b[i]+=(x[j]*W[i][j]);
- for(int i=0;i<2;i++)
- h[i]=1.0/(1+exp(-1.0*b[i]));
- for(int i=0;i<3;i++)
- for(int j=0;j<2;j++)
- a[i]+=(h[j]*Z[i][j]);
- for(int i=0;i<3;i++)
- o[i]=1.0/(1+exp(-1.0*a[i]));
- bool verif = true;
- for(int i=0;i<3;i++)
- {
- e[i]=t[i]-o[i];
- if(e[i]!=0.0)
- verif=false;
- }
- return verif;
- }
- int main()
- {
- init_io();
- while(!first_step()){
- GoBack();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement