~mwshinn/+junk/neural

« back to all changes in this revision

Viewing changes to src/config.c

  • Committer: Max Shinn
  • Date: 2012-11-22 22:50:42 UTC
  • Revision ID: trombonechamp@gmail.com-20121122225042-gxcmjuh4lt3qp242
Noise and the population/organisms bug.  Also, documented neural.c in notes format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* NOTE TO SELF:
 
2
 
 
3
There appears to be a minor bug in here.  Check over the code that
 
4
loads the organisms, populations, and demes.  It looks like the
 
5
organisms or populations tag have the same function, and whichever
 
6
comes last overwrites the other.  Look into this.
 
7
*/
 
8
 
1
9
/*----------------------------------------------------------------------------*
2
10
\Module{Configuration}
3
11
 
39
47
static bool ReadErrorWeightAlpha  (char *s, FILE *f);
40
48
static bool ReadErrorWeightBeta   (char *s, FILE *f);
41
49
static bool ReadCostOnB           (char *s, FILE *f);
 
50
static bool ReadSigma             (char *s, FILE *f);
42
51
static bool ReadVarMatrix         (char *s, FILE *f);
43
52
static bool ReadOutputFile        (char *s, FILE *f);
44
53
static void LoadDefaultVarMatrix  (void);
101
110
#define  MAX_DEMES    100
102
111
 
103
112
#define  MIN_POP      1
104
 
#define  MAX_POP      1000
 
113
#define  MAX_POP      10000
105
114
 
106
115
 
107
116
/*----------------------------------------------------------------------------*
162
171
    { "SynapseAlpha",  0,  &ReadErrorWeightAlpha  },
163
172
    { "SynapseBeta",   0,  &ReadErrorWeightBeta   },
164
173
    { "CostOnB",       0,  &ReadCostOnB           },
 
174
    { "NoiseSigma",    0,  &ReadSigma             },
165
175
    { "Matrix",        0,  &ReadVarMatrix         },
166
176
    { "Train",         0,  &ReadTrainSet          },
167
177
    { "Test",          0,  &ReadTestSet           },
213
223
  c.wbeta       = (real) 1.0;
214
224
  c.costonb     = TRUE;
215
225
 
 
226
  c.sigma       = 0;
 
227
 
216
228
  c.M = (Matrix *) 0;
217
229
  c.B = (Vector *) 0;
218
230
 
446
458
static bool ReadNumDemes (char *s, FILE *f)
447
459
{
448
460
  c.ndemes = atoi(s);
449
 
  return CheckRange(c.no, MIN_OUTPUT, MAX_OUTPUT, "demes");
 
461
  return CheckRange(c.no, MIN_DEMES, MAX_DEMES, "demes");
450
462
}
451
463
 
452
464
static bool ReadNumOrganisms (char *s, FILE *f)
453
465
{
454
466
  c.npop = atoi(s);
455
 
  return CheckRange(c.no, MIN_POP, MAX_POP, "organisms");
 
467
  return CheckRange(c.npop, MIN_POP, MAX_POP, "organisms");
456
468
}
457
469
 
458
470
static bool ReadInitZeroFlag (char *s, FILE *f)
479
491
  return CheckRange(c.stepnormal, FALSE, TRUE, "StepNormalize Flag");
480
492
}
481
493
 
482
 
static bool ReadErrorWeightAlpha (char *s, FILE *f)
483
 
{
484
 
  c.walpha = (real) atof(s);
485
 
  c.errorweight = TRUE;
486
 
  return CheckRange(c.diffeq, FALSE, TRUE, "ErrorWeight Alpha");
487
 
}
488
 
 
489
 
static bool ReadErrorWeightBeta (char *s, FILE *f)
490
 
{
491
 
  c.wbeta = (real) atof(s);
492
 
  c.errorweight = TRUE;
493
 
  return CheckRange(c.diffeq, FALSE, TRUE, "ErrorWeight Beta");
494
 
}
495
 
 
496
494
static bool ReadCostOnB (char *s, FILE *f)
497
495
{
498
496
  c.costonb = atoi(s);
499
497
  return CheckRange(c.costonb, FALSE, TRUE, "Cost On B");
500
498
}
501
499
 
502
 
/*----------------------------------------------------------------------------*
503
 
The remaining functions require no range checking.  That is, they have to
504
 
upper limit.
505
 
*/
506
 
 
507
 
static bool ReadRandSeed (char *s, FILE *f)
508
 
{
509
 
  c.seed = (uint32) atol(s);      // Seeds greater than $2^{31}$ are not supported.
510
 
  return TRUE;
511
 
}
512
 
 
513
 
static bool ReadNumGenerations (char *s, FILE *f)
514
 
{
515
 
  c.ngen = atol(s);
516
 
  return TRUE;
517
 
}
518
 
 
519
500
static bool ReadProbMutation (char *s, FILE *f)
520
501
{
521
502
  c.pmut = atof(s);
528
509
  return CheckRange(c.pzero, 0, 1, "Probability of zero");
529
510
}
530
511
 
 
512
 
 
513
/*----------------------------------------------------------------------------*
 
514
The remaining functions require no range checking.  That is, they have no
 
515
upper limit.
 
516
*/
 
517
 
 
518
static bool ReadRandSeed (char *s, FILE *f)
 
519
{
 
520
  c.seed = (uint32) atol(s);      // Seeds greater than $2^{31}$ are not supported.
 
521
  return TRUE;
 
522
}
 
523
 
 
524
static bool ReadNumGenerations (char *s, FILE *f)
 
525
{
 
526
  c.ngen = atol(s);
 
527
  return TRUE;
 
528
}
 
529
 
 
530
static bool ReadErrorWeightAlpha (char *s, FILE *f)
 
531
{
 
532
  c.walpha = (real) atof(s);
 
533
  c.errorweight = TRUE;
 
534
  return TRUE;
 
535
}
 
536
 
 
537
static bool ReadErrorWeightBeta (char *s, FILE *f)
 
538
{
 
539
  c.wbeta = (real) atof(s);
 
540
  c.errorweight = TRUE;
 
541
  return TRUE;
 
542
}
 
543
 
531
544
static bool ReadNumIterations (char *s, FILE *f)
532
545
{
533
546
  c.niter = atoi(s);
534
547
  return TRUE;
535
548
}
536
549
 
 
550
static bool ReadSigma (char *s, FILE *f)
 
551
{
 
552
  c.sigma = (real) atof(s);
 
553
  return TRUE;
 
554
}
 
555
 
537
556
/*----------------------------------------------------------------------------*
538
557
The final function reads a file path rather than a number.  It will
539
558
trim the whitespace from s and set c.outfile to the file path
951
970
    printf("Synaptic Penalty:  f(x) = %f x^%f\n", c.walpha, c.wbeta);
952
971
  else
953
972
    printf("Synaptic Penalty:  None\n");
 
973
  printf("Gaussian noise sigma: %f\n", c.sigma);
954
974
  if (c.outfile == NULL)
955
975
    printf("Output file: None\n");
956
976
  else