Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: src/mlp_train.h

Issue 882843002: Update to opus-HEAD-66611f1. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/opus.git@master
Patch Set: Add the contents of Makefile.mips back. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/mlp_data.c ('k') | src/mlp_train.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2008-2011 Octasic Inc. 1 /* Copyright (c) 2008-2011 Octasic Inc.
2 Written by Jean-Marc Valin */ 2 Written by Jean-Marc Valin */
3 /* 3 /*
4 Redistribution and use in source and binary forms, with or without 4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions 5 modification, are permitted provided that the following conditions
6 are met: 6 are met:
7 7
8 - Redistributions of source code must retain the above copyright 8 - Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer. 9 notice, this list of conditions and the following disclaimer.
10 10
(...skipping 14 matching lines...) Expand all
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #ifndef _MLP_TRAIN_H_ 28 #ifndef _MLP_TRAIN_H_
29 #define _MLP_TRAIN_H_ 29 #define _MLP_TRAIN_H_
30 30
31 #include <math.h> 31 #include <math.h>
32 #include <stdlib.h> 32 #include <stdlib.h>
33 33
34 double tansig_table[501]; 34 double tansig_table[501];
35 static inline double tansig_double(double x) 35 static inline double tansig_double(double x)
36 { 36 {
37 » return 2./(1.+exp(-2.*x)) - 1.; 37 return 2./(1.+exp(-2.*x)) - 1.;
38 } 38 }
39 static inline void build_tansig_table() 39 static inline void build_tansig_table()
40 { 40 {
41 » int i; 41 int i;
42 » for (i=0;i<501;i++) 42 for (i=0;i<501;i++)
43 » » tansig_table[i] = tansig_double(.04*(i-250)); 43 tansig_table[i] = tansig_double(.04*(i-250));
44 } 44 }
45 45
46 static inline double tansig_approx(double x) 46 static inline double tansig_approx(double x)
47 { 47 {
48 » int i; 48 int i;
49 » double y, dy; 49 double y, dy;
50 » if (x>=10) 50 if (x>=10)
51 » » return 1; 51 return 1;
52 » if (x<=-10) 52 if (x<=-10)
53 » » return -1; 53 return -1;
54 » i = lrint(25*x); 54 i = lrint(25*x);
55 » x -= .04*i; 55 x -= .04*i;
56 » y = tansig_table[250+i]; 56 y = tansig_table[250+i];
57 » dy = 1-y*y; 57 dy = 1-y*y;
58 » y = y + x*dy*(1 - y*x); 58 y = y + x*dy*(1 - y*x);
59 » return y; 59 return y;
60 } 60 }
61 61
62 inline float randn(float sd) 62 inline float randn(float sd)
63 { 63 {
64 float U1, U2, S, x; 64 float U1, U2, S, x;
65 do { 65 do {
66 U1 = ((float)rand())/RAND_MAX; 66 U1 = ((float)rand())/RAND_MAX;
67 U2 = ((float)rand())/RAND_MAX; 67 U2 = ((float)rand())/RAND_MAX;
68 U1 = 2*U1-1; 68 U1 = 2*U1-1;
69 U2 = 2*U2-1; 69 U2 = 2*U2-1;
70 S = U1*U1 + U2*U2; 70 S = U1*U1 + U2*U2;
71 } while (S >= 1 || S == 0.0f); 71 } while (S >= 1 || S == 0.0f);
72 x = sd*sqrt(-2 * log(S) / S) * U1; 72 x = sd*sqrt(-2 * log(S) / S) * U1;
73 return x; 73 return x;
74 } 74 }
75 75
76 76
77 typedef struct { 77 typedef struct {
78 » int layers; 78 int layers;
79 » int *topo; 79 int *topo;
80 » double **weights; 80 double **weights;
81 » double **best_weights; 81 double **best_weights;
82 » double *in_rate; 82 double *in_rate;
83 } MLPTrain; 83 } MLPTrain;
84 84
85 85
86 #endif /* _MLP_TRAIN_H_ */ 86 #endif /* _MLP_TRAIN_H_ */
OLDNEW
« no previous file with comments | « src/mlp_data.c ('k') | src/mlp_train.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698