Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions include/braid_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <stdlib.h>

#include "braid.hpp"
#include "defs.hpp"
// #include "_braid.h"
#include "dataset.hpp"
#include "layer.hpp"
Expand All @@ -17,32 +16,32 @@ class myBraidVector {
int nbatch; /* Number of examples */
int nchannels; /* Number of channels */

MyReal *
double *
*state; /* Network state at one layer, dimensions: nbatch * nchannels */
Layer *layer; /* Pointer to layer information */

/* Flag that determines if the layer and state have just been received and
* thus should be free'd after usage (flag > 0) */
MyReal sendflag;
double sendflag;

public:
/* Get dimensions */
int getnBatch();
int getnChannels();

/* Get Pointer to the state at example exampleID */
MyReal *getState(int exampleID);
double *getState(int exampleID);

/* Get pointer to the full state matrix */
MyReal **getState();
double **getState();

/* Get and set pointer to the layer */
Layer *getLayer();
void setLayer(Layer *layer);

/* Get and set the sendflag */
MyReal getSendflag();
void setSendflag(MyReal value);
double getSendflag();
void setSendflag(double value);

/* Constructor */
myBraidVector(int nChannels, int nBatch);
Expand All @@ -64,7 +63,7 @@ class myBraidApp : public BraidApp {
BraidCore *core; /* Braid core for running PinT simulation */

/* Output */
MyReal objective; /* Objective function */
double objective; /* Objective function */

public:
/* Constructor */
Expand All @@ -74,7 +73,7 @@ class myBraidApp : public BraidApp {
~myBraidApp();

/* Return objective function */
MyReal getObjective();
double getObjective();

/* Return the core */
BraidCore *getCore();
Expand All @@ -83,7 +82,7 @@ class myBraidApp : public BraidApp {
void GetGridDistribution(int *ilower_ptr, int *iupper_ptr);

/* Return the time step index of current time t */
braid_Int GetTimeStepIndex(MyReal t);
braid_Int GetTimeStepIndex(double t);

/* Apply one time step */
virtual braid_Int Step(braid_Vector u_, braid_Vector ustop_,
Expand Down Expand Up @@ -131,7 +130,7 @@ class myBraidApp : public BraidApp {
virtual braid_Int EvaluateObjective();

/* Run Braid drive, return norm */
MyReal run();
double run();
};

/**
Expand Down
29 changes: 14 additions & 15 deletions include/config.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "defs.hpp"

#include "mpi.h"
#include <cstdio>

#pragma once
Expand Down Expand Up @@ -52,22 +51,22 @@ class Config {
/* Neural Network */
int nchannels;
int nlayers;
MyReal T;
double T;
int activation;
int network_type;
int openlayer_type;
MyReal weights_open_init;
MyReal weights_init;
MyReal weights_class_init;
double weights_open_init;
double weights_init;
double weights_class_init;

/* XBraid */
int braid_cfactor0;
int braid_cfactor;
int braid_maxlevels;
int braid_mincoarse;
int braid_maxiter;
MyReal braid_abstol;
MyReal braid_abstoladj;
double braid_abstol;
double braid_abstoladj;
int braid_printlevel;
int braid_accesslevel;
int braid_setskip;
Expand All @@ -78,15 +77,15 @@ class Config {
/* Optimization */
int batch_type;
int nbatch;
MyReal gamma_tik;
MyReal gamma_ddt;
MyReal gamma_class;
double gamma_tik;
double gamma_ddt;
double gamma_class;
int stepsize_type;
MyReal stepsize_init;
double stepsize_init;
int maxoptimiter;
MyReal gtol;
double gtol;
int ls_maxiter;
MyReal ls_factor;
double ls_factor;
int hessianapprox_type;
int lbfgs_stages;
int validationlevel;
Expand All @@ -105,5 +104,5 @@ class Config {

/* Returns a stepsize, depending on the selected stepsize type and current
* optimization iteration */
MyReal getStepsize(int optimiter);
double getStepsize(int optimiter);
};
9 changes: 4 additions & 5 deletions include/dataset.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <assert.h>
#include <mpi.h>
#include "config.hpp"
#include "defs.hpp"
#include "util.hpp"
#pragma once

Expand All @@ -11,8 +10,8 @@ class DataSet {
int nfeatures; /* Number of features per element */
int nlabels; /* Number of different labels (i.e. classes) per element */

MyReal **examples; /* Array of Feature vectors (dim: nelements x nfeatures) */
MyReal **labels; /* Array of Label vectors (dim: nelements x nlabels) */
double **examples; /* Array of Feature vectors (dim: nelements x nfeatures) */
double **labels; /* Array of Label vectors (dim: nelements x nlabels) */

int nbatch; /* Size of the batch */
int *batchIDs; /* Array of batch indicees */
Expand All @@ -39,11 +38,11 @@ class DataSet {

/* Return the feature vector of a certain batchID. If not stored on this
* processor, return NULL */
MyReal *getExample(int id);
double *getExample(int id);

/* Return the label vector of a certain batchID. If not stored on this
* processor, return NULL */
MyReal *getLabel(int id);
double *getLabel(int id);

/* Read data from file */
void readData(const char *datafolder, const char *examplefile,
Expand Down
12 changes: 0 additions & 12 deletions include/defs.hpp

This file was deleted.

45 changes: 22 additions & 23 deletions include/hessianApprox.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <stdio.h>
#include "defs.hpp"
#include "linalg.hpp"

#pragma once
Expand All @@ -16,59 +15,59 @@ class HessianApprox {
/**
* Compute the BFGS descent direction
*/
virtual void computeAscentDir(int k, MyReal *gradient, MyReal *ascentdir) = 0;
virtual void computeAscentDir(int k, double *gradient, double *ascentdir) = 0;

/**
* Update the BFGS memory (like s, y, rho, H0...)
*/
virtual void updateMemory(int k, MyReal *design, MyReal *gradient) = 0;
virtual void updateMemory(int k, double *design, double *gradient) = 0;
};

class L_BFGS : public HessianApprox {
protected:
int M; /* Length of the l-bfgs memory (stages) */

/* L-BFGS memory */
MyReal **s; /* storing M (x_{k+1} - x_k) vectors */
MyReal **y; /* storing M (\nabla f_{k+1} - \nabla f_k) vectors */
MyReal *rho; /* storing M 1/y^Ts values */
MyReal H0; /* Initial Hessian scaling factor */
MyReal *design_old; /* Design at previous iteration */
MyReal *gradient_old; /* Gradient at previous iteration */
double **s; /* storing M (x_{k+1} - x_k) vectors */
double **y; /* storing M (\nabla f_{k+1} - \nabla f_k) vectors */
double *rho; /* storing M 1/y^Ts values */
double H0; /* Initial Hessian scaling factor */
double *design_old; /* Design at previous iteration */
double *gradient_old; /* Gradient at previous iteration */

public:
L_BFGS(MPI_Comm comm, int dimN, /* Local design dimension */
int stage);
~L_BFGS();

void computeAscentDir(int k, MyReal *gradient, MyReal *ascentdir);
void computeAscentDir(int k, double *gradient, double *ascentdir);

void updateMemory(int k, MyReal *design, MyReal *gradient);
void updateMemory(int k, double *design, double *gradient);
};

class BFGS : public HessianApprox {
private:
MyReal *A;
MyReal *B;
MyReal *Hy;
double *A;
double *B;
double *Hy;

protected:
MyReal *s;
MyReal *y;
MyReal
double *s;
double *y;
double
*Hessian; /* Storing the Hessian approximation (flattened: dimN*dimN) */
MyReal *design_old; /* Design at previous iteration */
MyReal *gradient_old; /* Gradient at previous iteration */
double *design_old; /* Design at previous iteration */
double *gradient_old; /* Gradient at previous iteration */

public:
BFGS(MPI_Comm comm, int N);
~BFGS();

void setIdentity();

void computeAscentDir(int k, MyReal *gradient, MyReal *ascentdir);
void computeAscentDir(int k, double *gradient, double *ascentdir);

void updateMemory(int k, MyReal *design, MyReal *gradient);
void updateMemory(int k, double *design, double *gradient);
};

/**
Expand All @@ -79,7 +78,7 @@ class Identity : public HessianApprox {
Identity(MPI_Comm comm, int N);
~Identity();

void computeAscentDir(int k, MyReal *currgrad, MyReal *ascentdir);
void computeAscentDir(int k, double *currgrad, double *ascentdir);

void updateMemory(int k, MyReal *design, MyReal *gradient);
void updateMemory(int k, double *design, double *gradient);
};
Loading