Skip to content

Commit

Permalink
c init 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuke Sugomori committed Feb 12, 2013
1 parent 41f7e86 commit 41c7a0c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion c/DBN.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,14 @@ void RBM__construct(RBM* this, int N, int n_visible, int n_hidden, \

if(hbias == NULL) {
this->hbias = (double *)malloc(sizeof(double) * n_hidden);
for(i=0; i<n_hidden; i++) this->hbias[i] = 0;
} else {
this->hbias = hbias;
}

if(vbias == NULL) {
this->vbias = (double *)malloc(sizeof(double) * n_visible);
for(i=0; i<n_visible; i++) this->vbias[i] = 0;
} else {
this->vbias = vbias;
}
Expand Down Expand Up @@ -430,7 +432,7 @@ void RBM_reconstruct(RBM* this, int *v, double *reconstructed_v) {

// LogisticRegression
void LogisticRegression__construct(LogisticRegression *this, int N, int n_in, int n_out) {
int i;
int i, j;
this->N = N;
this->n_in = n_in;
this->n_out = n_out;
Expand All @@ -439,6 +441,13 @@ void LogisticRegression__construct(LogisticRegression *this, int N, int n_in, in
this->W[0] = (double *)malloc(sizeof(double) * n_in * n_out);
for(i=0; i<n_out; i++) this->W[i] = this->W[0] + i * n_in;
this->b = (double *)malloc(sizeof(double) * n_out);

for(i=0; i<n_out; i++) {
for(j=0; j<n_in; j++) {
this->W[i][j] = 0;
}
this->b[i] = 0;
}
}

void LogisticRegression__destruct(LogisticRegression *this) {
Expand All @@ -453,6 +462,7 @@ void LogisticRegression_train(LogisticRegression *this, int *x, int *y, double l
double *dy = (double *)malloc(sizeof(double) * this->n_out);

for(i=0; i<this->n_out; i++) {
p_y_given_x[i] = 0;
for(j=0; j<this->n_in; j++) {
p_y_given_x[i] += this->W[i][j] * x[j];
}
Expand Down Expand Up @@ -492,6 +502,7 @@ void LogisticRegression_predict(LogisticRegression *this, int *x, double *y) {
int i,j;

for(i=0; i<this->n_out; i++) {
y[i] = 0;
for(j=0; j<this->n_in; j++) {
y[i] += this->W[i][j] * x[j];
}
Expand Down
11 changes: 10 additions & 1 deletion c/LogisticRegression.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void test_lr(void);


void LogisticRegression__construct(LogisticRegression *this, int N, int n_in, int n_out) {
int i;
int i, j;
this->N = N;
this->n_in = n_in;
this->n_out = n_out;
Expand All @@ -16,6 +16,13 @@ void LogisticRegression__construct(LogisticRegression *this, int N, int n_in, in
this->W[0] = (double *)malloc(sizeof(double) * n_in * n_out);
for(i=0; i<n_out; i++) this->W[i] = this->W[0] + i * n_in;
this->b = (double *)malloc(sizeof(double) * n_out);

for(i=0; i<n_out; i++) {
for(j=0; j<n_in; j++) {
this->W[i][j] = 0;
}
this->b[i] = 0;
}
}

void LogisticRegression__destruct(LogisticRegression *this) {
Expand All @@ -30,6 +37,7 @@ void LogisticRegression_train(LogisticRegression *this, int *x, int *y, double l
double *dy = (double *)malloc(sizeof(double) * this->n_out);

for(i=0; i<this->n_out; i++) {
p_y_given_x[i] = 0;
for(j=0; j<this->n_in; j++) {
p_y_given_x[i] += this->W[i][j] * x[j];
}
Expand Down Expand Up @@ -69,6 +77,7 @@ void LogisticRegression_predict(LogisticRegression *this, int *x, double *y) {
int i,j;

for(i=0; i<this->n_out; i++) {
y[i] = 0;
for(j=0; j<this->n_in; j++) {
y[i] += this->W[i][j] * x[j];
}
Expand Down
2 changes: 2 additions & 0 deletions c/RBM.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ void RBM__construct(RBM* this, int N, int n_visible, int n_hidden, \

if(hbias == NULL) {
this->hbias = (double *)malloc(sizeof(double) * n_hidden);
for(i=0; i<n_hidden; i++) this->hbias[i] = 0;
} else {
this->hbias = hbias;
}

if(vbias == NULL) {
this->vbias = (double *)malloc(sizeof(double) * n_visible);
for(i=0; i<n_visible; i++) this->vbias[i] = 0;
} else {
this->vbias = vbias;
}
Expand Down

0 comments on commit 41c7a0c

Please sign in to comment.