IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40376


Ignore:
Timestamp:
Mar 26, 2018, 12:54:01 PM (8 years ago)
Author:
eugene
Message:

add jdtolst function; add nnet write function

Location:
trunk/Ohana/src/opihi
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.astro/Makefile

    r39591 r40376  
    8282$(SRC)/wcs.$(ARCH).o         \
    8383$(SRC)/imsub.$(ARCH).o             \
     84$(SRC)/jdtolst.$(ARCH).o                   \
    8485$(SRC)/imfit.$(ARCH).o             \
    8586$(SRC)/imfit-fgauss.$(ARCH).o      \
  • trunk/Ohana/src/opihi/cmd.astro/init.c

    r39591 r40376  
    3333int imfit                   PROTO((int, char **));
    3434int imsub                   PROTO((int, char **));
     35int jdtolst                 PROTO((int, char **));
    3536int medianmap               PROTO((int, char **));
    3637int galsectors              PROTO((int, char **));
     
    103104  {1, "imfit",       imfit,        "fit function"},
    104105  {1, "imsub",       imsub,        "subtract function"},
     106  {1, "jdtolst",     jdtolst,      "JD to LST conversion"},
    105107  {1, "medianmap",   medianmap,    "small median image"},
    106108  {1, "mkgauss",     mkgauss,      "generate a 2-D gaussian centered in image"},
  • trunk/Ohana/src/opihi/cmd.data/nnet.c

    r40371 r40376  
    99  {1, "get",      nnet_get,      "get nnet node values"},
    1010  {1, "read",     nnet_read,     "read nnet values from a file"},
    11 // {1, "write",    nnet_write,    "write nnet values to a file"},
     11  {1, "write",    nnet_write,    "write nnet values to a file"},
    1212  {1, "train",    nnet_train,    "train nnet on a set of data"},
    1313  {1, "apply",    nnet_apply,    "apply nnet to a set of data"},
     
    2727    gprint (GP_ERR, "    nnet get    (nnet) [weights] [biases] ... [weights] [biases] : get nnet weights (images) and biases (vectors)\n");
    2828    gprint (GP_ERR, "    nnet read   (nnet) (filename) : set nnet weights and biases using a data file\n");
     29    gprint (GP_ERR, "    nnet write  (nnet) (filename) : save nnet weights and biases to a data file\n");
    2930    gprint (GP_ERR, "    nnet train  (nnet) [input] [input] ... [output] [output] ... : train nnet on data from a set of vectors\n");
    3031    gprint (GP_ERR, "    nnet apply  (nnet) [input] [input] ... [output] [output] ... : apply nnet to input data and generate output\n");
  • trunk/Ohana/src/opihi/cmd.data/nnet_commands.c

    r40371 r40376  
    258258}
    259259
     260int nnet_write (int argc, char **argv) {
     261
     262  if (argc < 3) {
     263    gprint (GP_ERR, "USAGE: nnet write (nnet) (filename) : save nnet weights and biases to a file\n");
     264    return FALSE;
     265  }
     266
     267  Nnet *nnet = FindNnet (argv[1]);
     268  if (nnet == NULL) {
     269    gprint (GP_ERR, "nnet %s not found, create it first\n", argv[1]);
     270    return FALSE;
     271  }
     272
     273  // open the file and read the number of layers
     274  FILE *f = fopen (argv[2], "w");
     275  if (f == NULL) {
     276    gprint (GP_ERR, "USAGE: nnet write (nnet) (filename) : save nnet weights and biases to a file\n");
     277    gprint (GP_ERR, "file %s could not be opened\n", argv[2]);
     278    return FALSE;
     279  }
     280
     281  // write the number of layers
     282  // NLAYER 3
     283  fprintf (f, "NLAYER %d\n", nnet->Nlayer);
     284
     285  // write the number of nodes for each layer
     286  // LAYERS 2 4 2
     287  fprintf (f, "LAYERS");
     288  for (int i = 0; i < nnet->Nlayer; i++) {
     289    fprintf (f, " %d", nnet->Nnodes[i]);
     290  }
     291  fprintf (f, "\n");
     292
     293  // read the weights and biases from the data file
     294  for (int L = 1; L < nnet[0].Nlayer; L++) {
     295   
     296    fprintf (f, "LAYER %d NX %d NY %d\n", L - 1, nnet->Nnodes[L-1], nnet->Nnodes[L]);
     297
     298    for (int j = 0; j < nnet->Nnodes[L]; j++) {
     299      for (int i = 0; i < nnet->Nnodes[L-1]; i++) {
     300        int k = i + j*nnet[0].Nnodes[L-1];
     301        fprintf (f, "%f ", nnet[0].weight[L][k]);
     302      }
     303      fprintf (f, "%f\n", nnet[0].biases[L][j]);
     304    }
     305  }
     306  fclose (f);
     307
     308  return TRUE;
     309}
     310
    260311int nnet_get (int argc, char **argv) {
    261312
  • trunk/Ohana/src/opihi/cmd.data/test/nnet.sh

    r40371 r40376  
     1
     2macro test.io
     3
     4  nnet create t1 2 3 2
     5 
     6  # biases:
     7  vlist v1 -0.2 0.0 0.2
     8  vlist v2 -0.3 0.3
     9
     10  # weights
     11  mcreate m1 2 3
     12  m1[0][0] =  0.2
     13  m1[1][0] = -0.2
     14  m1[0][1] = -0.6
     15  m1[1][1] =  0.5
     16  m1[0][2] = -0.2
     17  m1[1][2] =  0.2
     18
     19  mcreate m2 3 2
     20  m2[0][0] = -0.6
     21  m2[1][0] = -0.4
     22  m2[2][0] = -0.5
     23
     24  m2[0][1] = -0.2
     25  m2[1][1] = -0.5
     26  m2[2][1] =  0.1
     27
     28  # set weights and biases
     29  nnet set t1 m1 v1 m2 v2
     30
     31  nnet write t1 test.nnet.dat
     32  nnet read t2 test.nnet.dat
     33
     34  nnet get t2 M1 V1 M2 V2
     35
     36  set dM1 = M1 - m1
     37  set dM2 = M2 - m2
     38  set dV1 = V1 - v1
     39  set dV2 = V2 - v2
     40
     41  stat dM1
     42  stat dM2
     43 
     44  vstat dV1
     45  vstat dV2
     46end
    147
    248macro test.python
  • trunk/Ohana/src/opihi/include/data.h

    r40371 r40376  
    278278int nnet_get (int argc, char **argv);
    279279int nnet_read (int argc, char **argv);
     280int nnet_write (int argc, char **argv);
    280281int nnet_print (int argc, char **argv);
    281282
Note: See TracChangeset for help on using the changeset viewer.